GnuCashew ~ GnuCash Enabled Web
GCW
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 
81 Tab1( const std::string & _accountGuid )
82 : m_accountGuid( _accountGuid )
83 {
84  /*
85  ** Get the accountItem loaded so we can pluck things from it.
86  **
87  */
88  auto accountItem = GCW::Dbo::Accounts::load( m_accountGuid );
89 
90  auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
91  auto at1 = std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab1" ) );
92  auto t1 = at1.get();
93  lw-> addWidget( std::move( at1 ) );
94 
95  t1-> bindString( "name-label" , TR( "gcw.AccountEditor.name" ) );
96  t1-> bindString( "code-label" , TR( "gcw.AccountEditor.code" ) );
97  t1-> bindString( "desc-label" , TR( "gcw.AccountEditor.desc" ) );
98  t1-> bindString( "parent-label" , TR( "gcw.AccountEditor.parent" ) );
99  t1-> bindString( "accountType-label" , TR( "gcw.AccountEditor.accountType" ) );
100  t1-> bindString( "security-label" , TR( "gcw.AccountEditor.security" ) );
101  t1-> bindString( "fraction-label" , TR( "gcw.AccountEditor.fraction" ) );
102  t1-> bindString( "color-label" , TR( "gcw.AccountEditor.color" ) );
103  t1-> bindString( "notes-label" , TR( "gcw.AccountEditor.notes" ) );
104 
105  std::cout << __FILE__ << ":" << __LINE__ << " this:" << accountItem-> guid() << std::endl;
106  std::cout << __FILE__ << ":" << __LINE__ << " parn:" << accountItem-> parent_guid() << std::endl;
107 
108  auto name = t1-> bindNew< Wt::WLineEdit >( "name" , accountItem-> name() );
109  auto code = t1-> bindNew< Wt::WLineEdit >( "code" , accountItem-> code() );
110  auto desc = t1-> bindNew< Wt::WLineEdit >( "desc" , accountItem-> description() );
111  auto parent = t1-> bindNew< GCW::Gui::AccountsTreeView >( "parent" , accountItem-> parent_guid() , 7 );
112  auto accountType = t1-> bindNew< AccountTypeCombo >( "accountType" , accountItem-> accountTypeName() );
113  auto security = t1-> bindNew< SecurityCombo >( "security" );
114  auto fraction = t1-> bindNew< SmallestFractionCombo >( "fraction" );
115  auto color = t1-> bindNew< Wt::WPushButton >( "color" , TR( "gcw.AccountEditor.colorpicker" ) );
116  auto colordefault = t1-> bindNew< Wt::WPushButton >( "colordefault" , TR( "gcw.AccountEditor.colordefault" ) );
117  auto notes = t1-> bindNew< Wt::WTextArea >( "notes" );
118  auto placeholder = t1-> bindNew< Wt::WCheckBox >( "placeholder" , TR( "gcw.AccountEditor.placeholder" ) );
119  auto hidden = t1-> bindNew< Wt::WCheckBox >( "hidden" , TR( "gcw.AccountEditor.hidden" ) );
120  auto autoTransfer = t1-> bindNew< Wt::WCheckBox >( "autoTransfer" , TR( "gcw.AccountEditor.autoTransfer" ) );
121  auto taxRelated = t1-> bindNew< Wt::WCheckBox >( "taxRelated" , TR( "gcw.AccountEditor.taxRelated" ) );
122  auto openingBalance = t1-> bindNew< Wt::WCheckBox >( "openingBalance" , TR( "gcw.AccountEditor.openingBalance" ) );
123 
124  color -> setWidth( "100%" );
125  colordefault -> setWidth( "100%" );
126 
127  parent-> setMaximumSize( Wt::WLength::Auto, Wt::WLength("220px") );
128 
129 } // endTab1( const std::string & _accountGuid )
130 
132 Tab2( const std::string & _accountGuid )
133 : m_accountGuid( _accountGuid )
134 {
135  auto lw = setLayout( std::make_unique< Wt::WFitLayout >() );
136  auto at2 = std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab2" ) );
137  auto t2 = at2.get();
138  lw-> addWidget( std::move( at2 ) );
139 
140 } // endTab2( const std::string & _accountGuid )
141 
142 
144 AccountEditor( const std::string & _accountGuid )
145 : m_accountGuid( _accountGuid )
146 {
147  addStyleClass( "AccountEditor" );
148 
149  /*
150  ** Get the accountItem loaded so we can pluck things from it.
151  **
152  */
153  auto accountItem = GCW::Dbo::Accounts::load( m_accountGuid );
154 
155  auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
156 
157  lw-> addWidget( std::make_unique< Wt::WText >( TR("gcw.AccountEditor.editaccount").arg( accountItem-> fullName() ) ) )->
158  setAttributeValue( "style", "margin-bottom:5px" );
159 
160 // auto at1 = std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab1" ) );
161  auto at1 = std::make_unique< Tab1 >( m_accountGuid );
162  m_t1 = at1.get();
163 
164 // auto at2 = std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.tab2" ) );
165  auto at2 = std::make_unique< Tab2 >( m_accountGuid );
166  m_t2 = at2.get();
167 
168  m_tabWidget = lw-> addWidget( std::make_unique< Wt::WTabWidget >(), 1 );
169  auto twt1 = tabWidget()-> addTab( std::move( at1 ), "General" );
170  auto twt2 = tabWidget()-> addTab( std::move( at2 ), "More Properties" );
171 
172  auto model = std::make_shared< Wt::WFormModel >();
173  model-> addField( GCW::Dbo::Accounts::Field::name, "Account Name" );
174 
175  auto footer = lw-> addWidget( std::make_unique< Wt::WTemplate >( TR( "gcw_gui.accounteditor.form.footer" ) ) );
176 
177  footer-> bindNew< Wt::WPushButton >( "help" , "help" )-> clicked().connect( this, &AccountEditor::do_help );
178  footer-> bindNew< Wt::WPushButton >( "cancel" , "cancel" )-> clicked().connect( this, &AccountEditor::do_cancel );
179  footer-> bindNew< Wt::WPushButton >( "ok" , "ok" )-> clicked().connect( this, &AccountEditor::do_ok );
180 
181 // m_placeholder
182 // m_hidden
183 // m_autoTransfer
184 // m_taxRelated
185 // m_openingBalance
186 
187 } // endGCW::AccountEditor::AccountEditor( const std::string & _accountGuid )
188 
189 auto
191 do_help()-> void
192 {
193  wApp-> doJavaScript( "window.open( '/dox/html/AccountEditor.html', '_blank' )" );
194 
195 } // enddo_help()-> void
196 
197 auto
199 do_cancel()-> void
200 {
201  cancel().emit();
202 
203 } // enddo_cancel()-> void
204 
205 auto
207 do_ok()-> void
208 {
209  std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
210 
211 } // enddo_ok()-> void
212 
214 AccountEditorDialog( const std::string & _accountGuid )
215 : Wt::WDialog( "Edit Account" )
216 {
217  rejectWhenEscapePressed( true );
218  setResizable( true );
219  setClosable( true );
220  setMinimumSize( "800px", "600px" );
221 
222  contents()-> addNew< GCW::Gui::AccountEditor >( _accountGuid );
223 
224 }; // endclass GCW::Gui::AccountEditorDialog::AccountEditorDialog( const std::string & _accountGuid )
225 
226 
227 
AccountTypeCombo(const std::string &_initialValue)
AccountEditorDialog(const std::string &_accountGuid)
Tab1(const std::string &_accountGuid)
Tab2(const std::string &_accountGuid)
Wt::WTabWidget * m_tabWidget
Definition: AccountEditor.h:81
auto t1() -> Tab1 *
Definition: AccountEditor.h:66
auto t2() -> Tab2 *
Definition: AccountEditor.h:67
AccountEditor(const std::string &_accountGuid)
Wt::WTabWidget * tabWidget()
Definition: AccountEditor.h:64
#define TR(X)
Definition: define.h:17
const Wt::WFormModel::Field name
Definition: Accounts.cpp:47
const Wt::WFormModel::Field guid
Definition: Accounts.cpp:46
const Wt::WFormModel::Field description
Definition: Accounts.cpp:54
const Wt::WFormModel::Field code
Definition: Accounts.cpp:53
const Wt::WFormModel::Field hidden
Definition: Accounts.cpp:55
const Wt::WFormModel::Field parent_guid
Definition: Accounts.cpp:52
auto load(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
Definition: Accounts.cpp:135
const std::vector< AccountDef_t > s_accountDefs
Definition: Accounts.cpp:20
auto fullName(const std::string &_guid) -> std::string
Account Fullname via GUID.
Definition: Accounts.cpp:282
const Wt::WFormModel::Field parent
Definition: BillTerms.cpp:15
const Wt::WFormModel::Field fraction
Definition: Commodities.cpp:41
const Wt::WFormModel::Field notes
Definition: Definition.h:20
Definition: GncLock.h:6