Wtx ~ Wt Extension Library
WtxLib
FormModel.h
1 /**************************************************************************
2 ###########################################################################
3 ##
4 ## $SHOWOFFDB_BEGIN_LICENSE$
5 ## Copyright (C) 2011 Lorimark Solutions, LLC and/or its subsidiary(-ies).
6 ## All rights reserved.
7 ## Contact: Lorimark Solutions, LLC (info@showoff-db.org)
8 ##
9 ## This file is part of the Showoff Database Application Framework.
10 ##
11 ## Commercial Usage
12 ## Licensees holding valid ShowoffDB Commercial licenses may use this file in
13 ## accordance with the ShowoffDB Commercial License Agreement provided with the
14 ## Software or, alternatively, in accordance with the terms contained in
15 ## a written agreement between you and Lorimark Solutions, LLC.
16 ##
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ##
25 ## In addition, as a special exception, Lorimark Solutions, LLC gives
26 ## you certain additional rights. These rights are described in the
27 ## Lorimark Solutions, LLC ShowoffDB LGPL Exception version 1.0, included in
28 ## the file LGPL_EXCEPTION.txt in this package.
29 ##
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file. Please review the following information to
35 ## ensure the GNU General Public License version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
37 ##
38 ## If you have questions regarding the use of this file, please contact
39 ## Lorimark Solutions, LLC at info@showoff-db.org.
40 ## $SHOWOFFDB_END_LICENSE$
41 ##
42 #############################################################################
43 ****************************************************************************/
44 
45 
46 #ifndef __WTX_DBO_FORMMODEL_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__
47 #define __WTX_DBO_FORMMODEL_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__
48 
49 #include <Wt/Dbo/Query.h>
50 #include <Wt/WAny.h>
51 
52 #include <Wtx/Core/Core.h>
53 
54 #include "FieldDefBase.h"
55 #include "Session.h"
56 #include "../FormModel.h"
57 
58 namespace Wtx {
59  namespace Dbo {
60 
61 template <class C> class FormModel
63 {
64  public:
65 
66  enum State
67  {
73  Unknown = -1,
74 
80  Clean = 0,
81 
87  Dirty = 1,
88 
97 
98  }; // endenum State
99 
100  virtual ~FormModel();
101 
112  Wt::Dbo::ptr<C> load( int id, Wt::Dbo::Session * s );
113 
120  FormModel( int id, Wt::Dbo::Session * s );
121 
128  FormModel( const Wt::Dbo::ptr<C> & itm );
135  virtual std::string tableName() const;
136 
142  virtual int itemId() const;
143 
150  const Wt::Dbo::ptr<C> & item() const;
151 
158  Wt::Dbo::ptr<C> & item();
166  Wt::Dbo::Session * session() const;
167 
175  virtual bool remove();
176 
183  virtual int read();
184 
191  virtual void refresh();
192 
193  virtual std::unique_ptr<Wt::WWidget> createEditWidget( Wt::WFormModel::Field f ) const;
194 
195  virtual void staleRefresh();
196 
209  virtual bool isStale() const;
210 
221  virtual int diskVersion() const;
222 
223  virtual int itemVersion() const;
224 
232  const Field field( const std::string & fieldName ) const;
233 
234  virtual const Wt::cpp17::any & value( const std::string & fieldName ) const;
235 
236  virtual const Wt::cpp17::any & value( const Wtx::Dbo::FieldDefBase & fieldDef ) const;
237 
238  virtual const Wt::cpp17::any & value( const Wt::WFormModel::Field field ) const;
239 
240  virtual int accept();
241 
242  virtual void reset();
243 
244  virtual bool validate();
245 
246  virtual bool isVisible( Wt::WFormModel::Field field ) const;
247 
248  virtual bool isReadOnly( Wt::WFormModel::Field field ) const;
249 
250  virtual Wt::WString label( Wt::WFormModel::Field field ) const;
251 
252  virtual void setValue( Wt::WFormModel::Field field, const Wt::cpp17::any &value );
253 
254  virtual Wt::WString valueText( Wt::WFormModel::Field field ) const;
255 
256  virtual void setValidator( Wt::WFormModel::Field field, const std::shared_ptr< Wt::WValidator > &validator );
257 
258  virtual std::shared_ptr< Wt::WValidator > validator( Wt::WFormModel::Field field ) const;
259 
260  virtual bool validateField( Wt::WFormModel::Field field );
261 
262  virtual void setValidated( Wt::WFormModel::Field field, bool validated );
263 
264  virtual bool isValidated( Wt::WFormModel::Field field ) const;
265 
266  virtual void setValidation( Wt::WFormModel::Field field, const Wt::WValidator::Result &result );
267 
268  template <typename T> void act( Wt::Dbo::FieldRef<T> ref );
269 
270  template <typename T> void actPtr( const Wt::Dbo::PtrRef<T> & ref );
271 
272  template <typename T> void actWeakPtr( const Wt::Dbo::WeakPtrRef<T> & ref );
273 
274  template <typename T> void actCollection( const Wt::Dbo::CollectionRef<T> & ret );
275 
276  protected:
277 
278  Wt::Dbo::ptr<C> m_item;
279 
280  private:
281 
282  bool m_isReadMode = true;
283 
284 }; // endclass FormModel
285 
286 #include "FormModel_imp.h"
287 
288  } // endnamespace Dbo
289 } // endnamespace Wtx
290 
291 #endif
292 
virtual int read()
Read Item.
Definition: FormModel.h:146
virtual int diskVersion() const
Report disk version.
Definition: FormModel.h:211
virtual std::string tableName() const
Table Name.
Definition: FormModel.h:84
const Field field(const std::string &fieldName) const
Return Field Element.
Definition: FormModel.h:238
virtual void refresh()
Refresh Item.
Definition: FormModel.h:159
virtual int itemId() const
Item ID.
Definition: FormModel.h:93
const Wt::Dbo::ptr< C > & item() const
Referenced Item.
Definition: FormModel.h:102
FormModel(int id, Wt::Dbo::Session *s)
ctor
Definition: FormModel.h:62
Wt::Dbo::Session * session() const
Session Reference.
Definition: FormModel.h:120
Wt::Dbo::ptr< C > load(int id, Wt::Dbo::Session *s)
Return a loaded item.
Definition: FormModel.h:52
virtual bool isStale() const
Check Memory against Disk.
Definition: FormModel.h:199
virtual Wt::WString label(Wt::WFormModel::Field field) const
Get Field Label.
Definition: FormModel.h:378
witty extension library
Definition: Activity.h:51