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
15: public Wt::WComboBox
16{
17 public:
18
19 AccountTypeCombo( const std::string & _initialValue )
20 {
21 /*
22 ** Load all the items in the combo box, based on a translation of the
23 ** backend name of the account type.
24 **
25 */
26 for( auto & def : GCW::Dbo::Accounts::s_accountDefs )
27 addItem( Wt::WString::tr( Wt::WString("gcw.AccountsType.{1}").arg( def.backendName ).toUTF8() ) );
28
29 /*
30 ** Find the backend name requested, and make sure that is the
31 ** selected item.
32 **
33 */
34 int index = 0;
35 for( auto & def : GCW::Dbo::Accounts::s_accountDefs )
36 {
37 if( def.backendName == _initialValue )
38 break;
39 index++;
40 }
41 setCurrentIndex( index );
42
43 } // endAccountTypeCombo( const std::string & _initialValue )
44
45}; // endclass AccountTypeCombo
46
48: public Wt::WComboBox
49{
50 public:
51
53 {
54 }
55
56}; // endclass AccountTypeCombo
57
59: public Wt::WComboBox
60{
61 public:
62
64 {
65 addItem( TR( "gcw.AccountEditor.usecommodity" ) );
66 addItem( "1" );
67 addItem( "1/10" );
68 addItem( "1/100" );
69 addItem( "1/1000" );
70 addItem( "1/10000" );
71 addItem( "1/100000" );
72 addItem( "1/1000000" );
73 addItem( "1/10000000" );
74 addItem( "1/100000000" );
75 addItem( "1/1000000000" );
76 }
77
78}; // endclass AccountTypeCombo
79
81Tab1( const std::string & _accountGuid )
82: m_accountGuid( _accountGuid )
83{
84 /*
85 ** Get the accountItem loaded so we can pluck things from it.
86 **
87 */
89
90 auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
91 auto t1 = lw-> addWidget( std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab1" ) ) );
92
93 t1-> bindString( "name-label" , TR( "gcw.AccountEditor.name" ) );
94 t1-> bindString( "code-label" , TR( "gcw.AccountEditor.code" ) );
95 t1-> bindString( "desc-label" , TR( "gcw.AccountEditor.desc" ) );
96 t1-> bindString( "parent-label" , TR( "gcw.AccountEditor.parent" ) );
97 t1-> bindString( "accountType-label" , TR( "gcw.AccountEditor.accountType" ) );
98 t1-> bindString( "security-label" , TR( "gcw.AccountEditor.security" ) );
99 t1-> bindString( "fraction-label" , TR( "gcw.AccountEditor.fraction" ) );
100 t1-> bindString( "color-label" , TR( "gcw.AccountEditor.color" ) );
101 t1-> bindString( "notes-label" , TR( "gcw.AccountEditor.notes" ) );
102
103 auto name = t1-> bindNew< Wt::WLineEdit >( "name" , accountItem-> name() );
104 auto code = t1-> bindNew< Wt::WLineEdit >( "code" , accountItem-> code() );
105 auto desc = t1-> bindNew< Wt::WLineEdit >( "desc" , accountItem-> description() );
106 auto parent = t1-> bindNew< GCW::Gui::AccountsTreeView >( "parent" , accountItem-> parent_guid() , 7 );
107 auto accountType = t1-> bindNew< AccountTypeCombo >( "accountType" , accountItem-> accountTypeName() );
108 auto security = t1-> bindNew< SecurityCombo >( "security" );
109 auto fraction = t1-> bindNew< SmallestFractionCombo >( "fraction" );
110 auto color = t1-> bindNew< Wt::WPushButton >( "color" , TR( "gcw.AccountEditor.colorpicker" ) );
111 auto colordefault = t1-> bindNew< Wt::WPushButton >( "colordefault" , TR( "gcw.AccountEditor.colordefault" ) );
112 auto notes = t1-> bindNew< Wt::WTextArea >( "notes" );
113 auto placeholder = t1-> bindNew< Wt::WCheckBox >( "placeholder" , TR( "gcw.AccountEditor.placeholder" ) );
114 auto hidden = t1-> bindNew< Wt::WCheckBox >( "hidden" , TR( "gcw.AccountEditor.hidden" ) );
115 auto autoTransfer = t1-> bindNew< Wt::WCheckBox >( "autoTransfer" , TR( "gcw.AccountEditor.autoTransfer" ) );
116 auto taxRelated = t1-> bindNew< Wt::WCheckBox >( "taxRelated" , TR( "gcw.AccountEditor.taxRelated" ) );
117 auto openingBalance = t1-> bindNew< Wt::WCheckBox >( "openingBalance" , TR( "gcw.AccountEditor.openingBalance" ) );
118
119 color -> setWidth( "100%" );
120 colordefault -> setWidth( "100%" );
121
123
124} // endTab1( const std::string & _accountGuid )
125
127Tab2( const std::string & _accountGuid )
129{
130 auto lw = setLayout( std::make_unique< Wt::WFitLayout >() );
131 auto t2 = lw-> addWidget( std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab2" ) ) );
132
133} // endTab2( const std::string & _accountGuid )
134
135
137AccountEditor( const std::string & _accountGuid )
139{
140 addStyleClass( "AccountEditor" );
141
142 /*
143 ** Get the accountItem loaded so we can pluck things from it.
144 **
145 */
147
148 auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
149
150 lw-> addWidget( std::make_unique< Wt::WText >( TR("gcw.AccountEditor.editaccount").arg( accountItem-> fullName() ) ) )->
151 setAttributeValue( "style", "margin-bottom:5px" );
152
153// auto at1 = std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab1" ) );
154 auto at1 = std::make_unique< Tab1 >( m_accountGuid );
155 m_t1 = at1.get();
156
157// auto at2 = std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab2" ) );
158 auto at2 = std::make_unique< Tab2 >( m_accountGuid );
159 m_t2 = at2.get();
160
161 m_tabWidget = lw-> addWidget( std::make_unique< Wt::WTabWidget >(), 1 );
162 auto twt1 = tabWidget()-> addTab( std::move( at1 ), "General" );
163 auto twt2 = tabWidget()-> addTab( std::move( at2 ), "More Properties" );
164
165 auto model = std::make_shared< Wt::WFormModel >();
166 model-> addField( GCW::Dbo::Accounts::Field::name, "Account Name" );
167
168 auto footer = lw-> addWidget( std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.footer" ) ) );
169
170 footer-> bindNew< Wt::WPushButton >( "help" , "help" )-> clicked().connect( this, &AccountEditor::do_help );
171 footer-> bindNew< Wt::WPushButton >( "cancel" , "cancel" )-> clicked().connect( this, &AccountEditor::do_cancel );
172 footer-> bindNew< Wt::WPushButton >( "ok" , "ok" )-> clicked().connect( this, &AccountEditor::do_ok );
173
174// m_placeholder
175// m_hidden
176// m_autoTransfer
177// m_taxRelated
178// m_openingBalance
179
180} // endGCW::AccountEditor::AccountEditor( const std::string & _accountGuid )
181
182auto
184do_help()-> void
185{
186 wApp-> doJavaScript( "window.open( '/dox/html/AccountEditor.html', '_blank' )" );
187
188} // enddo_help()-> void
189
190auto
192do_cancel()-> void
193{
194 cancel().emit();
195
196} // enddo_cancel()-> void
197
198auto
200do_ok()-> void
201{
202 std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
203
204} // enddo_ok()-> void
205
207AccountEditorDialog( const std::string & _accountGuid )
208: Wt::WDialog( "Edit Account" )
209{
211 setResizable( true );
212 setClosable( true );
213 setMinimumSize( "800px", "600px" );
214
215 contents()-> addNew< GCW::Gui::AccountEditor >( _accountGuid );
216
217}; // endclass GCW::Gui::AccountEditorDialog::AccountEditorDialog( const std::string & _accountGuid )
218
219
220
AccountTypeCombo(const std::string &_initialValue)
AccountEditorDialog(const std::string &_accountGuid)
Tab1(const std::string &_accountGuid)
Tab2(const std::string &_accountGuid)
Wt::WTabWidget * m_tabWidget
auto t1() -> Tab1 *
auto t2() -> Tab2 *
Wt::WTabWidget * tabWidget()
AccountEditor(const std::string &_accountGuid)
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
static WString tr(const char *key)
std::string toUTF8() const
virtual void setAttributeValue(const std::string &name, const WString &value) override
virtual void setMaximumSize(const WLength &width, const WLength &height) override
virtual void addStyleClass(const WString &styleClass, bool force=false) override
WWidget * parent() const
void setWidth(const WLength &width)
#define TR(X)
Definition define.h:17
const Wt::WFormModel::Field name
auto load(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
const std::vector< AccountDef_t > s_accountDefs