Wtx ~ Wt Extension Library
WtxLib
Public Types | Public Member Functions | Protected Attributes | List of all members
Wtx::Dbo::FormModel< C > Class Template Reference
+ Inheritance diagram for Wtx::Dbo::FormModel< C >:

Public Types

enum  State { Unknown = -1, Clean = 0, Dirty = 1, Collision = 2 }
 

Public Member Functions

Wt::Dbo::ptr< C > load (int id, Wt::Dbo::Session *s)
 Return a loaded item. More...
 
 FormModel (int id, Wt::Dbo::Session *s)
 ctor More...
 
 FormModel (const Wt::Dbo::ptr< C > &itm)
 ctor More...
 
virtual std::string tableName () const
 Table Name.
 
virtual int itemId () const
 Item ID.
 
const Wt::Dbo::ptr< C > & item () const
 Referenced Item. More...
 
Wt::Dbo::ptr< C > & item ()
 Referenced Item. More...
 
Wt::Dbo::Session * session () const
 Session Reference. More...
 
virtual bool remove ()
 Delete Item from DB. More...
 
virtual int read ()
 Read Item. More...
 
virtual void refresh ()
 Refresh Item. More...
 
virtual std::unique_ptr< Wt::WWidget > createEditWidget (Wt::WFormModel::Field f) const
 
virtual void staleRefresh ()
 
virtual bool isStale () const
 Check Memory against Disk. More...
 
virtual int diskVersion () const
 Report disk version. More...
 
virtual int itemVersion () const
 
const Field field (const std::string &fieldName) const
 Return Field Element. More...
 
virtual const Wt::cpp17::any & value (const std::string &fieldName) const
 
virtual const Wt::cpp17::any & value (const Wtx::Dbo::FieldDefBase &fieldDef) const
 
virtual const Wt::cpp17::any & value (const Wt::WFormModel::Field field) const
 
virtual int accept ()
 
virtual void reset ()
 
virtual bool validate ()
 
virtual bool isVisible (Wt::WFormModel::Field field) const
 
virtual bool isReadOnly (Wt::WFormModel::Field field) const
 
virtual Wt::WString label (Wt::WFormModel::Field field) const
 Get Field Label. More...
 
virtual void setValue (Wt::WFormModel::Field field, const Wt::cpp17::any &value)
 
virtual Wt::WString valueText (Wt::WFormModel::Field field) const
 
virtual void setValidator (Wt::WFormModel::Field field, const std::shared_ptr< Wt::WValidator > &validator)
 
virtual std::shared_ptr< Wt::WValidator > validator (Wt::WFormModel::Field field) const
 
virtual bool validateField (Wt::WFormModel::Field field)
 
virtual void setValidated (Wt::WFormModel::Field field, bool validated)
 
virtual bool isValidated (Wt::WFormModel::Field field) const
 
virtual void setValidation (Wt::WFormModel::Field field, const Wt::WValidator::Result &result)
 
template<typename T >
void act (Wt::Dbo::FieldRef< T > ref)
 
template<typename T >
void actPtr (const Wt::Dbo::PtrRef< T > &ref)
 
template<typename T >
void actWeakPtr (const Wt::Dbo::WeakPtrRef< T > &ref)
 
template<typename T >
void actCollection (const Wt::Dbo::CollectionRef< T > &ret)
 
template<typename T >
void act (Wt::Dbo::FieldRef< T > ref)
 
template<typename T >
void actPtr (const Wt::Dbo::PtrRef< T > &ref)
 
template<typename T >
void actWeakPtr (const Wt::Dbo::WeakPtrRef< T > &ref)
 
template<typename T >
void actCollection (const Wt::Dbo::CollectionRef< T > &ref)
 
- Public Member Functions inherited from Wtx::FormModel
 FormModel (Wtx::Dbo::TableDef &td)
 
Wtx::Dbo::TableDeftableDef () const
 
virtual std::unique_ptr< Wt::WWidget > createWidget (Wtx::Dbo::Session &session)
 

Protected Attributes

Wt::Dbo::ptr< C > m_item
 

Detailed Description

template<class C>
class Wtx::Dbo::FormModel< C >

Definition at line 61 of file FormModel.h.

Member Enumeration Documentation

template<class C >
enum Wtx::Dbo::FormModel::State
Enumerator
Unknown 

state is unknown - data has not been read in from the database yet.

Clean 

model is clean - this is true after a read or immediately after a write to the database.

Dirty 

field data has been changed, but the model has not been pushed back out to the back-end db.

Collision 

we tried to write the data out to the back-end db but the version on the back-end db is out of sync with our in-memory copy. Data will not be written.

Definition at line 66 of file FormModel.h.

Constructor & Destructor Documentation

template<class C >
FormModel::FormModel ( int  id,
Wt::Dbo::Session *  s 
)

ctor

Initialize this model based solely on the item ID

Definition at line 62 of file FormModel.h.

template<class C >
FormModel::FormModel ( const Wt::Dbo::ptr< C > &  itm)

ctor

Initialize this model based on an item reference

Definition at line 73 of file FormModel.h.

Member Function Documentation

template<class C >
int FormModel::diskVersion ( ) const
virtual

Report disk version.

This function will check the version of the item on the back-end storage and return the version number of it there. This is used to check if the item is stale before any attempt is made to write the item back to disk ~ a task that will surely fail.

Definition at line 211 of file FormModel.h.

template<class C >
const Wt::WFormModel::Field FormModel::field ( const std::string &  fieldName) const

Return Field Element.

This returns the field element based on a string-representation of that same field name.

Definition at line 238 of file FormModel.h.

template<class C >
bool FormModel::isStale ( ) const
virtual

Check Memory against Disk.

This will return true if the item in back-end storage is out of sync with the memory item. This is based on the assumption that at least the item we are referencing actually has an ID assigned. For those items that have no ID assigned yet, this function simply returns 'false' that the item we are referencing is not stale ~ it has no storage yet, how can it be stale?

Definition at line 199 of file FormModel.h.

template<class C >
const Wt::Dbo::ptr< C > & Wtx::Dbo::FormModel< C >::item ( ) const

Referenced Item.

This returns a const reference to item.

Definition at line 102 of file FormModel.h.

template<class C >
Wt::Dbo::ptr< C > & FormModel::item ( )

Referenced Item.

This returns a non-const reference to item.

Definition at line 111 of file FormModel.h.

template<class C >
Wt::WString Wtx::Dbo::FormModel< C >::label ( Wt::WFormModel< C >::Field  field) const
virtual

Get Field Label.

This will return the proper 'label' for a form field.

This will try first to get a label from the field-definition.

If there is no value in the field-def object, then this will turn to the base-class to see if there is a field-name in the transaltion table somewhere. According to the Wt docs, the system by default will perform a WString::tr(fieldName) and return that by default, so if there is no transaltion for this field name, then the return value is going to have '??fieldName??' (double-question-marks) surrounding the field name.

if the field-name could not be transalted properly, then this will just default to the actual field name itself, so that it doesn't look 'goofy' on the screens like '??keyField??' and so on...

Reimplemented from Wtx::FormModel.

Definition at line 378 of file FormModel.h.

template<class C >
Wt::Dbo::ptr< C > FormModel::load ( int  id,
Wt::Dbo::Session *  s 
)

Return a loaded item.

This is used in a constructor to return an item pointer based on the ID number provided. In order for this task to be completed, a Wt::Transaction must exist. So it is all done here, so that the result can be used in a constructor.

Definition at line 52 of file FormModel.h.

template<class C >
int FormModel::read ( )
virtual

Read Item.

This will read the item in from the back-end DB.

Definition at line 146 of file FormModel.h.

template<class C >
void FormModel::refresh ( )
virtual

Refresh Item.

This will refresh the item from the back-end DB.

Definition at line 159 of file FormModel.h.

template<class C >
bool FormModel::remove ( )
virtual

Delete Item from DB.

This will remove the item from the back-end DB and purge it from memory as well.

Definition at line 129 of file FormModel.h.

template<class C >
Wt::Dbo::Session * FormModel::session ( ) const

Session Reference.

This returns a pointer to the current session.

Definition at line 120 of file FormModel.h.


The documentation for this class was generated from the following files: