GnuCashew ~ GnuCash Enabled Web
GCW
MainWidget.cpp
Go to the documentation of this file.
1 #line 2 "src/Gui/BillPay/MainWidget.cpp"
2 
3 #include <Wt/WVBoxLayout.h>
4 #include <Wt/WHBoxLayout.h>
5 #include <Wt/WTable.h>
6 #include <Wt/WPushButton.h>
7 
8 #include "BillPay.h"
9 
11 MainWidget()
12 {
13  buildContent();
14 
15 } // endMainWidget()
16 
17 auto
19 buildContent()-> void
20 {
21  clear();
22 
23  // identify
24  addStyleClass( "BillPay" );
25 
26  // layout
27  m_hlw = setLayout( std::make_unique< Wt::WHBoxLayout >() );
28  auto cw = m_hlw-> addWidget( std::make_unique< Wt::WContainerWidget >() );
29 // auto vlw = m_hlw-> addLayout( std::make_unique< Wt::WVBoxLayout >() );
30 
31  // toolbar
32  {
33  auto u_ = std::make_unique< ToolBar >();
34  m_toolBar = u_.get();
35  cw-> addWidget( std::move( u_ ) );
36 
37  m_toolBar-> addClicked().connect( this, &GCW::Gui::BillPay::MainWidget::addClicked );
38 // m_toolBar-> buttonGroup()-> checkedChanged().connect( this, &MainWidget::buttonChanged );
39  m_toolBar-> disabledButton()-> clicked().connect( this, &MainWidget::disabledClicked );
40 
41  m_toolBar-> importClicked().connect( this, &MainWidget::importClicked );
42  m_toolBar-> exportClicked().connect( this, &MainWidget::exportClicked );
43 
44  } // toolbar
45 
46  // recall
47  m_selectedMonth = configItem()-> getVarInt( "selectedMonth" );
48  if( m_selectedMonth < 1 )
49  m_selectedMonth = 1;
50 
51 // Wt::WVBoxLayout * lw2;
52 // Wt::WContainerWidget * cw;
53 // {
54 // auto u_ = std::make_unique< Wt::WContainerWidget >();
55 // cw = u_.get();
56 // m_gridLayout-> addWidget( std::move( u_ ), 1, 0 );
57 // m_gridLayout-> setRowStretch( 1, 1 );
58 //
59 // lw2 = cw-> setLayout( std::make_unique< Wt::WVBoxLayout >() );
60 // lw2-> setSpacing( 0 );
61 // }
62 
63  // unpaid items
64  {
65  auto u_ = std::make_unique< Table >( m_selectedMonth, Status::Unpaid );
66  m_unpaidView = u_.get();
67  cw-> addWidget( std::move( u_ ) );
68  m_unpaidView->
69  doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
70  {
71  editClicked( m_unpaidView, _index );
72  });
73 
74  /*
75  ** unpaid items has a header, whereas the other two item-tables do not have a
76  ** header and clicking on the header changes the selected month
77  */
78  m_unpaidView->
79  headerClicked().connect( this, &MainWidget::on_headerClicked );
80  }
81 
82  // paid items
83  {
84  auto u_ = std::make_unique< Table >( m_selectedMonth, Status::Paid );
85  m_paidView = u_.get();
86  cw-> addWidget( std::move( u_ ) );
87  m_paidView->
88  doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
89  {
90  editClicked( m_paidView, _index );
91  });
92  }
93 
94  // disabled items
95  if( m_toolBar-> showDisabled() )
96  {
97  auto u_ = std::make_unique< Table >( m_selectedMonth, Status::Disabled );
98  m_disabledView = u_.get();
99  cw-> addWidget( std::move( u_ ) );
100  m_disabledView->
101  doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
102  {
103  editClicked( m_disabledView, _index );
104  });
105 
106  }
107 
108  // fill-up remaining space
109 // vlw-> addWidget( std::make_unique< Wt::WContainerWidget >(), 1 );
110 
111 } // endbuildContent()-> void
112 
113 auto
115 openEditor( const std::string & _bpGuid )-> void
116 {
117 
118  /*
119  ** if the edit widget is open, then we can't do anything.
120  */
121  if( m_editWidget )
122  return;
123 
124  /*
125  ** Split the page to open/edit this item
126  **
127  */
128  auto u_ = std::make_unique< GCW::Gui::BillPay::EditWidget >( _bpGuid );
129  m_editWidget = u_.get();
130 // m_gridLayout-> addWidget( std::move( u_), 1, 1 );
131 // m_gridLayout-> setColumnResizable( 0, true, "30%" );
132 
133  /*
134  ** This splits the page, and sets the first side to 20% width, and the second
135  ** side to 75%. The edit form occupies the 80% width side. The split also
136  ** has a slider, so if the user wants to temporarily slide the detail form
137  ** out of the way, he can do that.
138  **
139  */
140  m_hlw-> addWidget( std::move( u_ ) );
141  m_hlw-> setResizable( 0, true, Wt::WLength( 20, Wt::LengthUnit::Percentage ) );
142 
143  m_editWidget->
144  save().connect( [=]()
145  {
146  refreshViews();
147  m_hlw-> removeWidget( m_editWidget.get() );
148  });
149 
150  m_editWidget->
151  cancel().connect( [=]()
152  {
153  refreshViews();
154  m_hlw-> removeWidget( m_editWidget.get() );
155  });
156 
157 } // endopenEditor( const std::string & _nickname )-> void
158 
159 auto
161 addClicked()-> void
162 {
163  Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
164  openEditor( "" );
165 
166 } // endaddClicked()-> void
167 
168 auto
170 editClicked( Table * _table, Wt::WModelIndex _index )-> void
171 {
172  /*
173  ** Get the 0-col index and use that to get the guid of this
174  ** row, and use that to get the Edit dialog open on that
175  ** guid.
176  **
177  */
178  auto zcolIndex = _index.model()-> index( _index.row(), 0 );
179  auto bpGuid = Wt::asString( zcolIndex.data( Wt::ItemDataRole::User ) ).toUTF8();
180  openEditor( bpGuid );
181 
182 } // endeditClicked( Table * _table, Wt::WModelIndex _index )-> void
183 
184 auto
186 buttonChanged( Wt::WRadioButton * _button )-> void
187 {
188  /*
189  ** If there is a button (sometimes there is not), then there's
190  ** nothing to do.
191  **
192  ** This function can get called from a selection of one of the
193  ** monthly buttons in the tool bar, or it can get called from a
194  ** detailForm .save. event. It shouldn't happen, but it's possible
195  ** to add an item without having a month selected. The button
196  ** is going to get defaulted to 1, to help mitigate the issue, but
197  ** it's still a problem if we pass a nullptr for the button. So,
198  ** to be safe, just deal with it.
199  **
200  */
201  if( !_button )
202  return;
203 
204  setMonth( std::stoi( _button-> text().toUTF8() ) );
205 
206 } // endbuttonChanged( Wt::WRadioButton * _button )-> void
207 
208 auto
210 disabledClicked()-> void
211 {
212  buildContent();
213 
214 } // enddisabledClicked()-> void
215 
216 auto
218 setMonth( int _month )-> void
219 {
220  if( m_unpaidView ) m_unpaidView -> setMonth( _month );
221  if( m_paidView ) m_paidView -> setMonth( _month );
222  if( m_disabledView ) m_disabledView -> setMonth( _month );
223 
224  m_selectedMonth = _month;
225 
226  Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
227  configItem().modify()-> setVar( "selectedMonth", m_selectedMonth );
228 
229 } // endsetMonth( int _month )-> void
230 
231 auto
233 refreshViews()-> void
234 {
235  setMonth( m_selectedMonth );
236 
237 } // endrefreshViews()-> void
238 
239 auto
241 importClicked()-> void
242 {
243  std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
244 
245 } // endimportClicked()-> void
246 
247 auto
249 exportClicked()-> void
250 {
251  std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
252 
253 } // endexportClicked()-> void
254 
255 auto
257 on_headerClicked( int _col, const Wt::WMouseEvent _me )-> void
258 {
259  if( _col >= 9 )
260  setMonth( _col - 8 );
261 
262 } // endon_headerClicked( int _col, const Wt::WMouseEvent _me )-> void
263 
264 
auto buttonChanged(Wt::WRadioButton *_button) -> void
Definition: MainWidget.cpp:186
auto openEditor(const std::string &_bpGuid) -> void
Definition: MainWidget.cpp:115
auto editClicked(Table *_table, Wt::WModelIndex _index) -> void
Definition: MainWidget.cpp:170
auto setMonth(int _month) -> void
Definition: MainWidget.cpp:218
auto on_headerClicked(int _col, const Wt::WMouseEvent _me) -> void
Definition: MainWidget.cpp:257
Table View.
Definition: Table.h:23
std::string asString(Status _status)
Get Status as String.
Definition: Status.cpp:7
@ Disabled
Disabled Status.
@ Unpaid
Unpaid Status.
auto configItem() -> GCW::Dbo::Vars::Item::Ptr
Config Item.
Definition: BillPay.cpp:7
App * app()
Definition: App.cpp:67