Simplified implementation
This commit is contained in:
@@ -228,7 +228,7 @@ const Wt::WFormModel::Field DatabaseModel::UpdateStartTimeField = "update-start
|
|||||||
DatabaseView::DatabaseView(Wt::WContainerWidget *parent)
|
DatabaseView::DatabaseView(Wt::WContainerWidget *parent)
|
||||||
: Wt::WTemplateFormView(parent)
|
: Wt::WTemplateFormView(parent)
|
||||||
{
|
{
|
||||||
_model = new DatabaseModel(this);
|
auto model = new DatabaseModel(this);
|
||||||
|
|
||||||
setTemplateText(tr("template-settings-database"));
|
setTemplateText(tr("template-settings-database"));
|
||||||
addFunction("tr", &WTemplate::Functions::tr);
|
addFunction("tr", &WTemplate::Functions::tr);
|
||||||
@@ -241,12 +241,12 @@ DatabaseView::DatabaseView(Wt::WContainerWidget *parent)
|
|||||||
// Update Period
|
// Update Period
|
||||||
Wt::WComboBox *updatePeriodCB = new Wt::WComboBox();
|
Wt::WComboBox *updatePeriodCB = new Wt::WComboBox();
|
||||||
setFormWidget(DatabaseModel::UpdatePeriodField, updatePeriodCB);
|
setFormWidget(DatabaseModel::UpdatePeriodField, updatePeriodCB);
|
||||||
updatePeriodCB->setModel(_model->updatePeriodModel());
|
updatePeriodCB->setModel(model->updatePeriodModel());
|
||||||
|
|
||||||
// Update Start Time
|
// Update Start Time
|
||||||
Wt::WComboBox *updateStartTimeCB = new Wt::WComboBox();
|
Wt::WComboBox *updateStartTimeCB = new Wt::WComboBox();
|
||||||
setFormWidget(DatabaseModel::UpdateStartTimeField, updateStartTimeCB);
|
setFormWidget(DatabaseModel::UpdateStartTimeField, updateStartTimeCB);
|
||||||
updateStartTimeCB->setModel(_model->updateStartTimeModel());
|
updateStartTimeCB->setModel(model->updateStartTimeModel());
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
|
|
||||||
@@ -259,8 +259,30 @@ DatabaseView::DatabaseView(Wt::WContainerWidget *parent)
|
|||||||
Wt::WPushButton *immScanBtn = new Wt::WPushButton(Wt::WString::tr("msg-btn-immediate-scan"));
|
Wt::WPushButton *immScanBtn = new Wt::WPushButton(Wt::WString::tr("msg-btn-immediate-scan"));
|
||||||
bindWidget("immediate-scan-btn", immScanBtn);
|
bindWidget("immediate-scan-btn", immScanBtn);
|
||||||
|
|
||||||
saveBtn->clicked().connect(this, &DatabaseView::processSave);
|
saveBtn->clicked().connect(std::bind([=] ()
|
||||||
discardBtn->clicked().connect(this, &DatabaseView::processDiscard);
|
{
|
||||||
|
updateModel(model);
|
||||||
|
|
||||||
|
if (model->validate())
|
||||||
|
{
|
||||||
|
model->saveData();
|
||||||
|
|
||||||
|
MediaScanner().reschedule();
|
||||||
|
|
||||||
|
notify(Wt::WString::tr("msg-notify-settings-saved"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Udate the view: Delete any validation message in the view, etc.
|
||||||
|
updateView(model);
|
||||||
|
}));
|
||||||
|
|
||||||
|
discardBtn->clicked().connect(std::bind([=] ()
|
||||||
|
{
|
||||||
|
model->loadData();
|
||||||
|
model->validate();
|
||||||
|
updateView(model);
|
||||||
|
}));
|
||||||
|
|
||||||
immScanBtn->clicked().connect(std::bind([=] ()
|
immScanBtn->clicked().connect(std::bind([=] ()
|
||||||
{
|
{
|
||||||
MediaScanner().scheduleImmediateScan();
|
MediaScanner().scheduleImmediateScan();
|
||||||
@@ -268,36 +290,9 @@ DatabaseView::DatabaseView(Wt::WContainerWidget *parent)
|
|||||||
notify(Wt::WString::tr("msg-notify-scan-launched"));
|
notify(Wt::WString::tr("msg-notify-scan-launched"));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateView(_model);
|
updateView(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DatabaseView::processDiscard()
|
|
||||||
{
|
|
||||||
_model->loadData();
|
|
||||||
_model->validate();
|
|
||||||
updateView(_model);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DatabaseView::processSave()
|
|
||||||
{
|
|
||||||
updateModel(_model);
|
|
||||||
|
|
||||||
if (_model->validate())
|
|
||||||
{
|
|
||||||
_model->saveData();
|
|
||||||
|
|
||||||
MediaScanner().reschedule();
|
|
||||||
|
|
||||||
notify(Wt::WString::tr("msg-notify-settings-saved"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Udate the view: Delete any validation message in the view, etc.
|
|
||||||
updateView(_model);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
} // namespace UserInterface
|
} // namespace UserInterface
|
||||||
|
|
||||||
|
|||||||
@@ -25,20 +25,10 @@
|
|||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
class DatabaseModel;
|
|
||||||
|
|
||||||
class DatabaseView : public Wt::WTemplateFormView
|
class DatabaseView : public Wt::WTemplateFormView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DatabaseView(Wt::WContainerWidget *parent = 0);
|
DatabaseView(Wt::WContainerWidget *parent = 0);
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void processSave();
|
|
||||||
void processDiscard();
|
|
||||||
void processImmediateScan();
|
|
||||||
|
|
||||||
DatabaseModel *_model;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user