Rerender the Settings view each time the internal path changes
This commit is contained in:
+28
-11
@@ -249,37 +249,54 @@ const Wt::WFormModel::Field SettingsModel::PasswordField = "password";
|
|||||||
const Wt::WFormModel::Field SettingsModel::PasswordConfirmField = "password-confirm";
|
const Wt::WFormModel::Field SettingsModel::PasswordConfirmField = "password-confirm";
|
||||||
|
|
||||||
SettingsView::SettingsView()
|
SettingsView::SettingsView()
|
||||||
: Wt::WTemplateFormView(Wt::WString::tr("Lms.Settings.template"))
|
|
||||||
{
|
{
|
||||||
|
wApp->internalPathChanged().connect(std::bind([=]
|
||||||
|
{
|
||||||
|
refreshView();
|
||||||
|
}));
|
||||||
|
|
||||||
|
refreshView();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SettingsView::refreshView()
|
||||||
|
{
|
||||||
|
if (!wApp->internalPathMatches("/settings"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
clear();
|
||||||
|
|
||||||
|
auto t = addNew<Wt::WTemplateFormView>(Wt::WString::tr("Lms.Settings.template"));
|
||||||
|
|
||||||
auto model = std::make_shared<SettingsModel>();
|
auto model = std::make_shared<SettingsModel>();
|
||||||
|
|
||||||
// Password
|
// Password
|
||||||
auto password = std::make_unique<Wt::WLineEdit>();
|
auto password = std::make_unique<Wt::WLineEdit>();
|
||||||
password->setEchoMode(Wt::EchoMode::Password);
|
password->setEchoMode(Wt::EchoMode::Password);
|
||||||
setFormWidget(SettingsModel::PasswordField, std::move(password));
|
t->setFormWidget(SettingsModel::PasswordField, std::move(password));
|
||||||
|
|
||||||
// Password confirm
|
// Password confirm
|
||||||
auto passwordConfirm = std::make_unique<Wt::WLineEdit>();
|
auto passwordConfirm = std::make_unique<Wt::WLineEdit>();
|
||||||
passwordConfirm->setEchoMode(Wt::EchoMode::Password);
|
passwordConfirm->setEchoMode(Wt::EchoMode::Password);
|
||||||
setFormWidget(SettingsModel::PasswordConfirmField, std::move(passwordConfirm));
|
t->setFormWidget(SettingsModel::PasswordConfirmField, std::move(passwordConfirm));
|
||||||
|
|
||||||
// Bitrate
|
// Bitrate
|
||||||
auto bitrate = std::make_unique<Wt::WComboBox>();
|
auto bitrate = std::make_unique<Wt::WComboBox>();
|
||||||
bitrate->setModel(model->bitrateModel());
|
bitrate->setModel(model->bitrateModel());
|
||||||
setFormWidget(SettingsModel::BitrateField, std::move(bitrate));
|
t->setFormWidget(SettingsModel::BitrateField, std::move(bitrate));
|
||||||
|
|
||||||
// Encoding
|
// Encoding
|
||||||
auto encoding = std::make_unique<Wt::WComboBox>();
|
auto encoding = std::make_unique<Wt::WComboBox>();
|
||||||
encoding->setModel(model->encodingModel());
|
encoding->setModel(model->encodingModel());
|
||||||
setFormWidget(SettingsModel::EncodingField, std::move(encoding));
|
t->setFormWidget(SettingsModel::EncodingField, std::move(encoding));
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
Wt::WPushButton *saveBtn = bindWidget("apply-btn", std::make_unique<Wt::WPushButton>(Wt::WString::tr("Lms.apply")));
|
Wt::WPushButton *saveBtn = t->bindWidget("apply-btn", std::make_unique<Wt::WPushButton>(Wt::WString::tr("Lms.apply")));
|
||||||
Wt::WPushButton *discardBtn = bindWidget("discard-btn", std::make_unique<Wt::WPushButton>(Wt::WString::tr("Lms.discard")));
|
Wt::WPushButton *discardBtn = t->bindWidget("discard-btn", std::make_unique<Wt::WPushButton>(Wt::WString::tr("Lms.discard")));
|
||||||
|
|
||||||
saveBtn->clicked().connect(std::bind([=] ()
|
saveBtn->clicked().connect(std::bind([=] ()
|
||||||
{
|
{
|
||||||
updateModel(model.get());
|
t->updateModel(model.get());
|
||||||
|
|
||||||
if (model->validate())
|
if (model->validate())
|
||||||
{
|
{
|
||||||
@@ -288,17 +305,17 @@ SettingsView::SettingsView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Udate the view: Delete any validation message in the view, etc.
|
// Udate the view: Delete any validation message in the view, etc.
|
||||||
updateView(model.get());
|
t->updateView(model.get());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
discardBtn->clicked().connect(std::bind([=] ()
|
discardBtn->clicked().connect(std::bind([=] ()
|
||||||
{
|
{
|
||||||
model->loadData();
|
model->loadData();
|
||||||
model->validate();
|
model->validate();
|
||||||
updateView(model.get());
|
t->updateView(model.get());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
updateView(model.get());
|
t->updateView(model.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace UserInterface
|
} // namespace UserInterface
|
||||||
|
|||||||
@@ -19,14 +19,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Wt/WTemplateFormView.h>
|
#include <Wt/WContainerWidget.h>
|
||||||
|
|
||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
|
|
||||||
class SettingsView : public Wt::WTemplateFormView
|
class SettingsView : public Wt::WContainerWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SettingsView();
|
SettingsView();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void refreshView();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace UserInterface
|
} // namespace UserInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user