Older/WebApplication/view/EditUsers.cpp

41 lines
1.6 KiB
C++
Raw Normal View History

2024-11-01 19:05:20 +08:00
#include "EditUsers.h"
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
EditUsers::EditUsers(Wt::Dbo::Session &aSession, const std::string &basePath)
: m_session(aSession), m_basePath(basePath) {
setStyleClass("user-editor");
setTemplateText(tr("edit-users-list"));
auto limitEdit = std::make_unique<Wt::WLineEdit>();
auto goLimit = std::make_unique<Wt::WPushButton>(tr("go-limit"));
goLimit->clicked().connect(this, &EditUsers::limitList);
m_limitEdit = bindWidget("limit-edit", std::move(limitEdit));
bindWidget("limit-button", std::move(goLimit));
limitList();
}
void EditUsers::limitList() {
auto listPtr = std::make_unique<Wt::WContainerWidget>();
auto list = listPtr.get();
bindWidget("user-list", std::move(listPtr));
typedef Wt::Dbo ::collection<Wt::Dbo ::ptr<User>> UserList;
Wt::Dbo ::Transaction t(m_session);
UserList users = m_session.find<User>().where("name like ?").bind("%" + m_limitEdit->text() + "%").orderBy("name");
for (auto user : users) {
Wt::WText *t = list->addWidget(std::make_unique<Wt::WText>(user->name));
t->setStyleClass("link");
list->addWidget(std::make_unique<Wt::WBreak>());
t->clicked().connect(std::bind(&EditUsers::onUserClicked, this, user.id()));
}
if (!users.size()) list->addWidget(std::make_unique<Wt::WText>(tr("no-users-found")));
}
EditUser::EditUser(Wt::Dbo::Session &aSession) : WTemplate(tr("edit-user")), session_(aSession) {
auto roleButton = std::make_unique<Wt::WPushButton>();
roleButton_ = bindWidget("role-button", std::move(roleButton));
roleButton_->clicked().connect(this, &EditUser::switchRole);
}