46 #ifndef __WTX_DBO_TEMPLATEFORMVIEW_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__ 47 #define __WTX_DBO_TEMPLATEFORMVIEW_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__ 49 #include <Wt/WFormWidget.h> 51 #include <Wtx/Dbo/FieldDefBase.h> 52 #include <Wtx/Dbo/FormModel.h> 53 #include <Wtx/TemplateFormView.h> 69 FormWidgetWrapper( Wt::WFormModel * model, Wt::WFormModel::Field field, Wt::WFormWidget * widget )
75 widget-> focussed().connect(
this, &FormWidgetWrapper::on_focussed );
76 widget-> blurred() .connect(
this, &FormWidgetWrapper::on_blurred );
77 widget-> clicked() .connect(
this, &FormWidgetWrapper::on_clicked );
78 m_prevValue = widget-> valueText().toUTF8();
81 Wt::Signal<FormWidgetWrapper*> & focussed()
86 Wt::Signal<FormWidgetWrapper*> & blurred()
91 Wt::Signal<FormWidgetWrapper*> & clicked()
96 Wt::WFormModel::Field field()
const 101 std::string fieldName()
const 103 return std::string( m_field );
106 Wt::WFormWidget * widget()
const 111 const std::string & prevValue()
const 116 bool isChanged()
const 118 return m_prevValue != widget()-> valueText();
123 return fieldDef-> fieldName() == fieldName();
128 return fieldDef.fieldName() == fieldName();
131 void resetChangedFlags()
133 m_prevValue = widget()-> valueText().toUTF8();
136 Wt::WFormModel * model()
const 145 m_focussed.emit(
this);
150 m_blurred.emit(
this);
155 m_clicked.emit(
this);
158 Wt::WFormModel * m_model =
nullptr;
159 Wt::WFormModel::Field m_field =
nullptr;
160 Wt::WFormWidget * m_widget =
nullptr;
162 Wt::Signal<FormWidgetWrapper*> m_focussed;
163 Wt::Signal<FormWidgetWrapper*> m_blurred;
164 Wt::Signal<FormWidgetWrapper*> m_clicked;
166 std::string m_prevValue;
181 m_formModel( std::move(model) )
196 return m_formModel.get();
205 m_formModel = std::move(model);
224 return wtxModel-> tableDef().fieldDef( field );
267 std::unique_ptr<Wt::WWidget> createFormWidget( Wt::WFormModel::Field field )
271 auto retVal = createEditWidget( field );
273 auto fw =
dynamic_cast<Wt::WFormWidget*
>(retVal.get());
277 auto fww = std::make_unique<FormWidgetWrapper>(
formModel(), field, fw );
281 m_formWidgets.push_back(std::move(fww));
287 void resetEditWidgetChangedFlags()
289 for(
auto & fww : m_formWidgets )
291 fww-> resetChangedFlags();
299 std::unique_ptr<Wt::WWidget> createEditWidget( Wt::WFormModel::Field field )
304 return formModel()-> createEditWidget( field );
316 virtual void updateView()
318 Wtx::TemplateFormView::updateView(
formModel() );
320 resetEditWidgetChangedFlags();
334 Wtx::TemplateFormView::updateView( model );
335 resetEditWidgetChangedFlags();
342 virtual void updateViewField( Wt::WFormModel *model, Wt::WFormModel::Field field )
358 Wtx::TemplateFormView::updateViewField( model, field );
359 resetEditWidgetChangedFlags();
367 virtual void updateViewValue( Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit )
370 Wtx::TemplateFormView::updateViewValue( model, field, edit );
371 resetEditWidgetChangedFlags();
379 virtual bool updateViewValue( Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WWidget *edit )
382 return Wtx::TemplateFormView::updateViewValue( model, field, edit );
383 resetEditWidgetChangedFlags();
387 virtual void updateModel()
396 virtual void updateModel( Wt::WFormModel *model )
399 Wtx::TemplateFormView::updateModel( model );
407 virtual void updateModelField( Wt::WFormModel *model, Wt::WFormModel::Field field )
410 Wtx::TemplateFormView::updateModelField( model, field );
418 virtual void updateModelValue( Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit )
421 Wtx::TemplateFormView::updateModelValue( model, field, edit );
429 virtual bool updateModelValue( Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WWidget *edit )
432 return Wtx::TemplateFormView::updateModelValue( model, field, edit );
439 virtual void bindString(
const std::string & varName,
const Wt::WString & value, Wt::TextFormat textFormat=Wt::TextFormat::XHTML )
442 Wtx::TemplateFormView::bindString( varName, value, textFormat );
449 virtual void bindWidget(
const std::string & varName, std::unique_ptr< Wt::WWidget > widget )
452 Wtx::TemplateFormView::bindWidget( varName, std::move(widget) );
459 virtual std::unique_ptr< Wt::WWidget > removeWidget( Wt::WWidget *widget )
override 462 return Wtx::TemplateFormView::removeWidget( widget );
469 virtual bool conditionValue(
const std::string & name )
const 472 return Wtx::TemplateFormView::conditionValue( name );
479 virtual void resolveString(
const std::string & varName,
const std::vector< Wt::WString > & args, std::ostream & result )
481 show( __FUNCTION__, varName, args );
482 Wtx::TemplateFormView::resolveString( varName, args, result );
489 virtual void handleUnresolvedVariable(
const std::string & varName,
const std::vector< Wt::WString > & args, std::ostream & result )
491 show( __FUNCTION__, varName, args );
492 Wtx::TemplateFormView::handleUnresolvedVariable( varName, args, result );
499 virtual WWidget * resolveWidget(
const std::string & varName )
501 show( __FUNCTION__, varName );
502 return Wtx::TemplateFormView::resolveWidget( varName );
509 virtual bool resolveFunction(
const std::string & name,
const std::vector< Wt::WString > & args, std::ostream & result )
511 show( __FUNCTION__, name, args );
513 return Wtx::TemplateFormView::resolveFunction( name, args, result );
520 virtual void refresh()
override 523 Wtx::TemplateFormView::refresh();
530 virtual void renderTemplate( std::ostream & result )
533 Wtx::TemplateFormView::renderTemplate( result );
544 return m_formWidgets;
556 for(
auto & fww : m_formWidgets )
558 if( fww-> fieldName() == fieldDef.fieldName() )
567 for(
auto & fww : m_formWidgets )
569 if( fww-> fieldName() == fieldName )
585 for(
auto & fww : m_formWidgets )
587 if( fww-> fieldName() == fieldDef.fieldName() )
588 return fww-> widget();
600 std::unique_ptr<Wtx::Dbo::FormModel<C>> m_formModel;
602 std::vector<std::unique_ptr<FormWidgetWrapper>> m_formWidgets;
610 #endif // __WTX_DBO_TEMPLATEFORMVIEW_H___