GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
AccountEditor.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/AccountEditor.cpp"
2
3#include <Wt/WText.h>
4#include <Wt/WTextArea.h>
5#include <Wt/WVBoxLayout.h>
6#include <Wt/WFitLayout.h>
7#include <Wt/WGridLayout.h>
8#include <Wt/WPushButton.h>
9#include <Wt/WComboBox.h>
10#include <Wt/WCheckBox.h>
11
12#include "AccountEditor.h"
13
14namespace {
15
16class AccountParentCombo
17: public Wt::WComboBox
18{
19 public:
20
21 AccountParentCombo()
22 {
23 /// \todo this should be in a 'setValueText' thing
24// for( auto & account : GCW::Dbo::Accounts::activeAccountsAnd( _initialValue ) )
25// addItem( GCW::Dbo::Accounts::fullName( account ) );
26
27// setValueText( GCW::Dbo::Accounts::fullName( _initialValue ) );
28
29 } // endAccountTypeCombo( const std::string & _initialValue )
30
31}; // endclass AccountParentCombo
32
33class AccountTypeCombo
34: public Wt::WComboBox
35{
36 public:
37
38 AccountTypeCombo()
39 {
40#ifdef MOVE_ALL_THIS_TO_A_SETVALUETEXT_FUNCTION
41 /*
42 ** Load all the items in the combo box, based on a translation of the
43 ** backend name of the account type.
44 **
45 */
46 for( auto & def : GCW::Dbo::Accounts::s_accountDefs )
47 addItem( Wt::WString::tr( Wt::WString("gcw.AccountsType.{1}").arg( def.backendName ).toUTF8() ) );
48
49 /*
50 ** Find the backend name requested, and make sure that is the
51 ** selected item.
52 **
53 */
54 int index = 0;
55 for( auto & def : GCW::Dbo::Accounts::s_accountDefs )
56 {
57 if( def.backendName == _initialValue )
58 break;
59 index++;
60 }
61 setCurrentIndex( index );
62#endif
63
64 } // endAccountTypeCombo( const std::string & _initialValue )
65
66}; // endclass AccountTypeCombo
67
68class SecurityCombo
69: public Wt::WComboBox
70{
71 public:
72
73 SecurityCombo()
74 {
75 }
76
77}; // endclass SecurityCombo
78
79class SmallestFractionCombo
80: public Wt::WComboBox
81{
82 public:
83
84 SmallestFractionCombo()
85 {
86 addItem( TR( "gcw.AccountEditor.usecommodity" ) );
87 addItem( "1" );
88 addItem( "1/10" );
89 addItem( "1/100" );
90 addItem( "1/1000" );
91 addItem( "1/10000" );
92 addItem( "1/100000" );
93 addItem( "1/1000000" );
94 addItem( "1/10000000" );
95 addItem( "1/100000000" );
96 addItem( "1/1000000000" );
97 }
98
99}; // endclass SmallestFractionCombo
100
101} // endnamespace {
102
104Tab1()
105{
106 auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
107 auto t1 = lw-> addWidget( std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab1" ) ) );
108
109 t1-> bindString( "name-label" , TR( "gcw.AccountEditor.name" ) );
110 t1-> bindString( "code-label" , TR( "gcw.AccountEditor.code" ) );
111 t1-> bindString( "desc-label" , TR( "gcw.AccountEditor.desc" ) );
112 t1-> bindString( "parent-label" , TR( "gcw.AccountEditor.parent" ) );
113 t1-> bindString( "accountType-label" , TR( "gcw.AccountEditor.accountType" ) );
114 t1-> bindString( "security-label" , TR( "gcw.AccountEditor.security" ) );
115 t1-> bindString( "fraction-label" , TR( "gcw.AccountEditor.fraction" ) );
116 t1-> bindString( "color-label" , TR( "gcw.AccountEditor.color" ) );
117 t1-> bindString( "notes-label" , TR( "gcw.AccountEditor.notes" ) );
118
119 m_name = t1-> bindNew< Wt::WLineEdit >( "name" );
120 m_code = t1-> bindNew< Wt::WLineEdit >( "code" );
121 m_desc = t1-> bindNew< Wt::WLineEdit >( "desc" );
123 m_accountType = t1-> bindNew< AccountTypeCombo >( "accountType" );
124 m_security = t1-> bindNew< SecurityCombo >( "security" );
126 m_color = t1-> bindNew< Wt::WPushButton >( "color" , TR( "gcw.AccountEditor.colorpicker" ) );
127 auto colordefault = t1-> bindNew< Wt::WPushButton >( "colordefault" , TR( "gcw.AccountEditor.colordefault" ) );
128 m_notes = t1-> bindNew< Wt::WTextArea >( "notes" );
129 m_placeholder = t1-> bindNew< Wt::WCheckBox >( "placeholder" , TR( "gcw.AccountEditor.placeholder" ) );
130 m_hidden = t1-> bindNew< Wt::WCheckBox >( "hidden" , TR( "gcw.AccountEditor.hidden" ) );
131 m_autoTransfer = t1-> bindNew< Wt::WCheckBox >( "autoTransfer" , TR( "gcw.AccountEditor.autoTransfer" ) );
132 m_taxRelated = t1-> bindNew< Wt::WCheckBox >( "taxRelated" , TR( "gcw.AccountEditor.taxRelated" ) );
133 m_openingBalance = t1-> bindNew< Wt::WCheckBox >( "openingBalance" , TR( "gcw.AccountEditor.openingBalance" ) );
134
135 m_color -> setWidth( "100%" );
136 colordefault -> setWidth( "100%" );
137
139
140} // endTab1( const std::string & _accountGuid )
141
142auto
144loadData( const std::string & _accountGuid )-> void
145{
146}
147
148auto
150saveData( const std::string & _accountGuid )-> void
151{
152}
153
154
156Tab2()
157{
158 auto lw = setLayout( std::make_unique< Wt::WFitLayout >() );
159 auto t2 = lw-> addWidget( std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab2" ) ) );
160
161} // endTab2( const std::string & _accountGuid )
162
163auto
165loadData( const std::string & _accountGuid )-> void
166{
167}
168
169auto
171saveData( const std::string & _accountGuid )-> void
172{
173}
174
175
178{
179 addStyleClass( "AccountEditor" );
180
181 auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
182
183 m_accountName = lw-> addWidget( std::make_unique< Wt::WText >() );
184 m_accountName-> setAttributeValue( "style", "margin-bottom:5px" );
185
186 auto at1 = std::make_unique< Tab1 >();
187 m_tab1 = at1.get();
188
189 auto at2 = std::make_unique< Tab2 >();
190 m_tab2 = at2.get();
191
192 m_tabWidget = lw-> addWidget( std::make_unique< Wt::WTabWidget >(), 1 );
193 auto twt1 = tabWidget()-> addTab( std::move( at1 ), TR("gcw_gui.accounteditor.form.tab1") );
194 auto twt2 = tabWidget()-> addTab( std::move( at2 ), TR("gcw_gui.accounteditor.form.tab2") );
195
196 auto footer = lw-> addWidget( std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.footer" ) ) );
197
198 footer-> bindNew< Wt::WPushButton >( "help" , "help" )-> clicked().connect( this, &AccountEditor::do_help );
199 footer-> bindNew< Wt::WPushButton >( "cancel" , "cancel" )-> clicked().connect( this, &AccountEditor::do_cancel );
200 footer-> bindNew< Wt::WPushButton >( "ok" , "ok" )-> clicked().connect( this, &AccountEditor::do_ok );
201
202// m_placeholder
203// m_hidden
204// m_autoTransfer
205// m_taxRelated
206// m_openingBalance
207
208} // endGCW::AccountEditor::AccountEditor( const std::string & _accountGuid )
209
210auto
212do_help()-> void
213{
214 wApp-> doJavaScript( "window.open( '/dox/html/AccountEditor.html', '_blank' )" );
215
216} // enddo_help()-> void
217
218auto
220do_cancel()-> void
221{
222 cancel().emit();
223
224} // enddo_cancel()-> void
225
226auto
228do_ok()-> void
229{
230 save().emit();
231
232} // enddo_ok()-> void
233
234auto
236loadData( const std::string & _accountGuid )-> void
237{
238 /*
239 ** Get the accountItem loaded so we can pluck things from it.
240 **
241 */
243
244 m_accountName-> setText( TR("gcw.AccountEditor.editaccount").arg( accountItem-> fullName() ) );
245
248
249// m_name = t1-> bindNew< Wt::WLineEdit >( "name" , accountItem-> name() );
250// m_code = t1-> bindNew< Wt::WLineEdit >( "code" , accountItem-> code() );
251// m_desc = t1-> bindNew< Wt::WLineEdit >( "desc" , accountItem-> description() );
252// m_parent = t1-> bindNew< AccountParentCombo >( "parent" , accountItem-> parent_guid() );
253// m_accountType = t1-> bindNew< AccountTypeCombo >( "accountType" , accountItem-> accountTypeName() );
254// m_security = t1-> bindNew< SecurityCombo >( "security" );
255// m_fraction = t1-> bindNew< SmallestFractionCombo >( "fraction" );
256// m_color = t1-> bindNew< Wt::WPushButton >( "color" , TR( "gcw.AccountEditor.colorpicker" ) );
257// auto colordefault = t1-> bindNew< Wt::WPushButton >( "colordefault" , TR( "gcw.AccountEditor.colordefault" ) );
258// m_notes = t1-> bindNew< Wt::WTextArea >( "notes" );
259// m_placeholder = t1-> bindNew< Wt::WCheckBox >( "placeholder" , TR( "gcw.AccountEditor.placeholder" ) );
260// m_hidden = t1-> bindNew< Wt::WCheckBox >( "hidden" , TR( "gcw.AccountEditor.hidden" ) );
261// m_autoTransfer = t1-> bindNew< Wt::WCheckBox >( "autoTransfer" , TR( "gcw.AccountEditor.autoTransfer" ) );
262// m_taxRelated = t1-> bindNew< Wt::WCheckBox >( "taxRelated" , TR( "gcw.AccountEditor.taxRelated" ) );
263// m_openingBalance = t1-> bindNew< Wt::WCheckBox >( "openingBalance" , TR( "gcw.AccountEditor.openingBalance" ) );
264
265
266} // enddoSave()-> void
267
268auto
270saveData( const std::string & _accountGuid )-> void
271{
274
275} // enddoSave()-> void
276
277auto
279isDirty() const-> bool
280{
281 return true;
282
283} // enddo_ok()-> void
284
286AccountEditorDialog( const std::string & _accountGuid )
287: Wt::WDialog( "Edit Account" )
288{
290 setResizable( true );
291 setClosable( true );
292 setMinimumSize( "800px", "600px" );
293
294 contents()-> addNew< GCW::Gui::AccountEditor >()-> loadData( _accountGuid );
295
296
297}; // endclass GCW::Gui::AccountEditorDialog::AccountEditorDialog( const std::string & _accountGuid )
298
299
300
AccountEditorDialog(const std::string &_accountGuid)
auto loadData(const std::string &_accountGuid) -> void
auto saveData(const std::string &_accountGuid) -> void
auto loadData(const std::string &_accountGuid) -> void
auto saveData(const std::string &_accountGuid) -> void
auto save() -> Wt::Signal<> &
Wt::WTabWidget * m_tabWidget
auto isDirty() const -> bool
auto saveData(const std::string &_accountGuid) -> void
Wt::WTabWidget * tabWidget()
auto loadData(const std::string &_accountGuid) -> void
auto cancel() -> Wt::Signal<> &
auto tab1() -> Tab1 *
auto tab2() -> Tab2 *
void setCurrentIndex(int index)
void addItem(const WString &text)
Widget * addNew(Args &&...args)
void setLayout(std::unique_ptr< WLayout > layout)
virtual void addWidget(std::unique_ptr< WWidget > widget)
void setResizable(bool resizable)
virtual void setMinimumSize(const WLength &width, const WLength &height) override
WContainerWidget * contents() const
void rejectWhenEscapePressed(bool enable=true)
void setClosable(bool closable)
EventSignal< WMouseEvent > & clicked()
static WLength Auto
virtual void setAttributeValue(const std::string &name, const WString &value) override
virtual void doJavaScript(const std::string &javascript) override
virtual void setMaximumSize(const WLength &width, const WLength &height) override
virtual void addStyleClass(const WString &styleClass, bool force=false) override
void setWidth(const WLength &width)
#define TR(X)
Definition define.h:17
auto load(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
const std::vector< AccountDef_t > s_accountDefs
Definition App.h:18