diff --git a/ui/settings/SettingsUsers.cpp b/ui/settings/SettingsUsers.cpp index 6d4b9ab1..8f123a73 100644 --- a/ui/settings/SettingsUsers.cpp +++ b/ui/settings/SettingsUsers.cpp @@ -15,27 +15,55 @@ Users::Users(SessionData& sessionData, Wt::WContainerWidget *parent) : Wt::WContainerWidget(parent), _sessionData(sessionData) { + // Stack two widgets: + _stack = new Wt::WStackedWidget(this); - Wt::WGroupBox *container = new Wt::WGroupBox("Users", this); + // 1/ the user table view + { + Wt::WGroupBox *container = new Wt::WGroupBox("Users", _stack); - _table = new Wt::WTable(container); + _table = new Wt::WTable(container); - _table->addStyleClass("table form-inline"); + _table->addStyleClass("table form-inline"); - _table->toggleStyleClass("table-hover", true); - _table->toggleStyleClass("table-striped", true); + _table->toggleStyleClass("table-hover", true); + _table->toggleStyleClass("table-striped", true); - _table->setHeaderCount(1); + _table->setHeaderCount(1); - _table->elementAt(0, 0)->addWidget(new Wt::WText("#")); - _table->elementAt(0, 1)->addWidget(new Wt::WText("Name")); - _table->elementAt(0, 2)->addWidget(new Wt::WText("e-Mail")); - _table->elementAt(0, 3)->addWidget(new Wt::WText("Admin")); + _table->elementAt(0, 0)->addWidget(new Wt::WText("#")); + _table->elementAt(0, 1)->addWidget(new Wt::WText("Name")); + _table->elementAt(0, 2)->addWidget(new Wt::WText("e-Mail")); + _table->elementAt(0, 3)->addWidget(new Wt::WText("Admin")); - Database::Handler& db = sessionData.getDatabaseHandler(); + Wt::WPushButton* addBtn = new Wt::WPushButton("Add User"); + addBtn->setStyleClass("btn-success"); + container->addWidget( addBtn ); + addBtn->clicked().connect(this, &Users::handleAddUser); + } + + // 2/ the user form + { + new Wt::WText("This is the user form!", _stack); + } + + refresh(); +} + +void +Users::refresh(void) +{ + + assert(_table->rowCount() > 0); + for (int i = _table->rowCount() - 1; i > 0; ++i) + _table->deleteRow(i); + + Database::Handler& db = _sessionData.getDatabaseHandler(); Wt::Dbo::Transaction transaction(db.getSession()); + const Wt::Auth::User& currentUser = db.getLogin().user(); + std::vector users = Database::User::getAll(db.getSession()); for (std::size_t i = 0; i < users.size(); ++i) @@ -60,27 +88,23 @@ _sessionData(sessionData) email->setStyleClass("alert-danger"); email->setText(authUser.unverifiedEmail()); } - _table->elementAt(i + 1, 2)->addWidget( email ) ; - _table->elementAt(i + 1, 3)->addWidget(new Wt::WText( users[i]->isAdmin() ? "Yes" : "No" )); Wt::WPushButton* editBtn = new Wt::WPushButton("Edit"); _table->elementAt(i + 1, 4)->addWidget(editBtn); + editBtn->clicked().connect(boost::bind( &Users::handleEditUser, this, userId)); - Wt::WPushButton* delBtn = new Wt::WPushButton("Delete"); - delBtn->setStyleClass("btn-danger"); - delBtn->setMargin(5, Wt::Left); - - delBtn->clicked().connect(boost::bind( &Users::handleDelUser, this, authUser.identity(Wt::Auth::Identity::LoginName), userId)); - - _table->elementAt(i + 1, 4)->addWidget(delBtn); + if (currentUser != authUser) + { + Wt::WPushButton* delBtn = new Wt::WPushButton("Delete"); + delBtn->setStyleClass("btn-danger"); + delBtn->setMargin(5, Wt::Left); + _table->elementAt(i + 1, 4)->addWidget(delBtn); + delBtn->clicked().connect(boost::bind( &Users::handleDelUser, this, authUser.identity(Wt::Auth::Identity::LoginName), userId)); + } } - Wt::WPushButton* addBtn = new Wt::WPushButton("Add User"); - addBtn->setStyleClass("btn-success"); - - addWidget( addBtn ); } void @@ -91,7 +115,7 @@ Users::handleDelUser(Wt::WString loginNameIdentity, std::string id) Wt::WString( "Deleting user '{1}'?").arg(loginNameIdentity), Wt::Question, Wt::Yes | Wt::No); - messageBox->setModal(false); + messageBox->setModal(true); messageBox->buttonClicked().connect(std::bind([=] () { if (messageBox->buttonResult() == Wt::Yes) @@ -112,10 +136,23 @@ Users::handleDelUser(Wt::WString loginNameIdentity, std::string id) })); messageBox->show(); - - } +void +Users::handleAddUser(void) +{ + // TODO refresh the User Form for a new user + //_stack->setCurrentIndex(1); +} + +void +Users::handleEditUser(std::string id) +{ + //TODO refresh the User Form to edit the given user + //_stack->setCurrentIndex(1); +} + + } // namespace UserInterface } // namespace Settings diff --git a/ui/settings/SettingsUsers.hpp b/ui/settings/SettingsUsers.hpp index c06adf96..a096c679 100644 --- a/ui/settings/SettingsUsers.hpp +++ b/ui/settings/SettingsUsers.hpp @@ -1,6 +1,7 @@ #ifndef UI_SETTINGS_USERS_HPP #define UI_SETTINGS_USERS_HPP +#include #include #include @@ -14,13 +15,18 @@ class Users : public Wt::WContainerWidget public: Users(SessionData& sessioNData, Wt::WContainerWidget *parent = 0); + void refresh(); + private: void handleDelUser(Wt::WString loginNameIdentity, std::string id); + void handleEditUser(std::string id); + void handleAddUser(void); SessionData& _sessionData; - Wt::WTable* _table; + Wt::WStackedWidget* _stack; + Wt::WTable* _table; }; } // namespace UserInterface