mirror of
https://github.com/altlinux/admc.git
synced 2024-10-26 17:25:38 +03:00
Merge pull request #383 from AlexSP0/fix_ok_button_availability_rename_user_dialog
fix: ok button availability in rename user dialog
This commit is contained in:
commit
5b382606a6
@ -39,12 +39,17 @@ void RenameObjectHelper::fail_msg(const QString &old_name) {
|
||||
g_status->add_message(message, StatusType_Error);
|
||||
}
|
||||
|
||||
RenameObjectHelper::RenameObjectHelper(AdInterface &ad, const QString &target_arg, QLineEdit *name_edit_arg, const QList<AttributeEdit *> &edits_arg, QDialog *parent_dialog_arg)
|
||||
RenameObjectHelper::RenameObjectHelper(AdInterface &ad, const QString &target_arg, QLineEdit *name_edit_arg, const QList<AttributeEdit *> &edits_arg, QDialog *parent_dialog_arg, QList<QLineEdit *> required, QDialogButtonBox *button_box)
|
||||
: QObject(parent_dialog_arg) {
|
||||
name_edit = name_edit_arg;
|
||||
edits = edits_arg;
|
||||
target = target_arg;
|
||||
parent_dialog = parent_dialog_arg;
|
||||
required_list = required;
|
||||
ok_button = nullptr;
|
||||
if(button_box != nullptr) {
|
||||
ok_button = button_box->button(QDialogButtonBox::Ok);
|
||||
}
|
||||
|
||||
const QString name = dn_get_name(target);
|
||||
name_edit->setText(name);
|
||||
@ -53,6 +58,13 @@ RenameObjectHelper::RenameObjectHelper(AdInterface &ad, const QString &target_ar
|
||||
|
||||
const AdObject object = ad.search_object(target);
|
||||
AttributeEdit::load(edits, ad, object);
|
||||
|
||||
if(!required_list.isEmpty() && ok_button != nullptr) {
|
||||
for(QLineEdit *edit : required_list) {
|
||||
connect(edit, &QLineEdit::textChanged, this, &RenameObjectHelper::on_edited);
|
||||
}
|
||||
on_edited();
|
||||
}
|
||||
}
|
||||
|
||||
bool RenameObjectHelper::accept() const {
|
||||
@ -116,3 +128,18 @@ QString RenameObjectHelper::get_new_dn() const {
|
||||
|
||||
return new_dn;
|
||||
}
|
||||
|
||||
void RenameObjectHelper::on_edited()
|
||||
{
|
||||
const bool all_required_filled = [this]() {
|
||||
for (QLineEdit *edit : required_list) {
|
||||
if (edit->text().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}();
|
||||
|
||||
ok_button->setEnabled(all_required_filled);
|
||||
}
|
||||
|
@ -21,7 +21,9 @@
|
||||
#ifndef RENAME_OBJECT_HELPER_H
|
||||
#define RENAME_OBJECT_HELPER_H
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QObject>
|
||||
#include <QPushButton>
|
||||
|
||||
class QLineEdit;
|
||||
class QDialog;
|
||||
@ -32,7 +34,7 @@ class RenameObjectHelper : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RenameObjectHelper(AdInterface &ad, const QString &target_arg, QLineEdit *name_edit_arg, const QList<AttributeEdit *> &edits_arg, QDialog *parent_dialog);
|
||||
RenameObjectHelper(AdInterface &ad, const QString &target_arg, QLineEdit *name_edit_arg, const QList<AttributeEdit *> &edits_arg, QDialog *parent_dialog, QList<QLineEdit *> required = QList<QLineEdit *>(), QDialogButtonBox *button_box = nullptr);
|
||||
|
||||
static void success_msg(const QString &old_name);
|
||||
static void fail_msg(const QString &old_name);
|
||||
@ -41,11 +43,16 @@ public:
|
||||
QString get_new_name() const;
|
||||
QString get_new_dn() const;
|
||||
|
||||
private slots:
|
||||
void on_edited();
|
||||
|
||||
private:
|
||||
QString target;
|
||||
QLineEdit *name_edit;
|
||||
QList<AttributeEdit *> edits;
|
||||
QDialog *parent_dialog;
|
||||
QList<QLineEdit *> required_list;
|
||||
QPushButton *ok_button;
|
||||
};
|
||||
|
||||
#endif /* RENAME_OBJECT_HELPER_H */
|
||||
|
@ -51,7 +51,13 @@ RenameUserDialog::RenameUserDialog(AdInterface &ad, const QString &target_arg, Q
|
||||
sam_name_edit,
|
||||
};
|
||||
|
||||
helper = new RenameObjectHelper(ad, target_arg, ui->name_edit, edit_list, this);
|
||||
const QList<QLineEdit *> required_list = {
|
||||
ui->name_edit,
|
||||
ui->upn_prefix_edit,
|
||||
ui->sam_name_edit
|
||||
};
|
||||
|
||||
helper = new RenameObjectHelper(ad, target_arg, ui->name_edit, edit_list, this, required_list, ui->button_box);
|
||||
|
||||
setup_lineedit_autofill(ui->upn_prefix_edit, ui->sam_name_edit);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user