diff --git a/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp b/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp index 9491cb1..03bb508 100644 --- a/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp +++ b/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp @@ -6,6 +6,7 @@ ViewerInstructors::ViewerInstructors(ConnectorToServer* connectorToServer, QWidget *parent) : InstructorsView(connectorToServer, CommonView::TypeView::onlyView, parent), dlgRedactor(nullptr), + flTryEditorInstructors(false), ui(new Ui::ViewerInstructors) { ui->setupUi(this); @@ -20,6 +21,8 @@ ViewerInstructors::ViewerInstructors(ConnectorToServer* connectorToServer, QWidg setNotLoggedInVisible(true); ui->btnEditorInstructors->setVisible(false); + + connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, this, &ViewerInstructors::slot_checkTryBlockResult); } ViewerInstructors::~ViewerInstructors() @@ -48,6 +51,8 @@ void ViewerInstructors::deactivate() dlgRedactor = nullptr; } + flTryEditorInstructors = false; + CommonView::deactivate(); updateButtons(); } @@ -75,23 +80,31 @@ void ViewerInstructors::slot_receiveMessage(ClientMessage clientMessage) slot_NeedUpdateUI(true, false); } +void ViewerInstructors::slot_checkTryBlockResult(bool result, QString type) +{ + if(flTryEditorInstructors) + { + if(type == "EditorInstructors") + { + if(result) + {//Одобрено + dialog_EditorInstructors(); + } + else + {//Отказ + SpecMsgBox::WarningClose(this, tr("The server rejected your request to access instructors control.\nAnother instructor is managing instructors.\nPlease try again later.")); + } + + flTryEditorInstructors = false; + } + } +} + void ViewerInstructors::on_btnEditorInstructors_clicked() { + flTryEditorInstructors = true; + connectorToServer->sendQueryBlockAuth(true, "EditorInstructors"); - - dlgRedactor = new DialogRedactorInstructors(connectorToServer, adminMode, this); - dlgRedactor->exec(); - - if(dlgRedactor) - { - delete dlgRedactor; - dlgRedactor = nullptr; - } - - if(authComplited) - loadInstructorsFromDB(); - - connectorToServer->sendQueryBlockAuth(false, "EditorInstructors"); } void ViewerInstructors::on_treeWidgetCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) @@ -143,3 +156,20 @@ void ViewerInstructors::updateButtons() ui->btnEditorInstructors->setEnabled(false); } } + +void ViewerInstructors::dialog_EditorInstructors() +{ + dlgRedactor = new DialogRedactorInstructors(connectorToServer, adminMode, this); + dlgRedactor->exec(); + + if(dlgRedactor) + { + delete dlgRedactor; + dlgRedactor = nullptr; + } + + if(authComplited) + loadInstructorsFromDB(); + + connectorToServer->sendQueryBlockAuth(false, "EditorInstructors"); +} diff --git a/LibInstructorsAndTrainees/instructors/viewerinstructors.h b/LibInstructorsAndTrainees/instructors/viewerinstructors.h index cc65ca1..fc8239b 100644 --- a/LibInstructorsAndTrainees/instructors/viewerinstructors.h +++ b/LibInstructorsAndTrainees/instructors/viewerinstructors.h @@ -29,6 +29,8 @@ protected: public slots: void slot_receiveMessage(ClientMessage clientMessage); + void slot_checkTryBlockResult(bool result, QString type); + public Q_SLOTS: void on_btnEditorInstructors_clicked(); @@ -41,9 +43,13 @@ Q_SIGNALS: private: void updateButtons() override; + void dialog_EditorInstructors(); + private: DialogRedactorInstructors* dlgRedactor; + bool flTryEditorInstructors; + private: Ui::ViewerInstructors *ui; }; diff --git a/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp b/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp index f472fff..f004a84 100644 --- a/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp +++ b/LibInstructorsAndTrainees/instructorsandtraineeswidget.cpp @@ -703,8 +703,6 @@ void InstructorsAndTraineesWidget::on_btnSettings_clicked() connect(dlgSettings, &DialogSettings::signal_LanguageChanged, this, &InstructorsAndTraineesWidget::slot_LanguageChanged); connect(dlgSettings, &DialogSettings::signal_UpdateStyleSheet, this, &InstructorsAndTraineesWidget::slot_UpdateStyleSheet); - connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, dlgSettings, &DialogSettings::slot_checkTryBlockResult); - switch( dlgSettings->exec() ) { case QDialog::Accepted: diff --git a/LibInstructorsAndTrainees/settings/dialogsettings.cpp b/LibInstructorsAndTrainees/settings/dialogsettings.cpp index 3600e3f..1ca7567 100644 --- a/LibInstructorsAndTrainees/settings/dialogsettings.cpp +++ b/LibInstructorsAndTrainees/settings/dialogsettings.cpp @@ -70,6 +70,8 @@ DialogSettings::DialogSettings(ConnectorToServer* connectorToServer, bool instru ui->btnSave->setEnabled(false); flSettingsServerChanged = false; + + connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, this, &DialogSettings::slot_checkTryBlockResult); } DialogSettings::~DialogSettings() @@ -219,9 +221,6 @@ void DialogSettings::on_btnSetVersion_clicked() flTryVersionControl = true; connectorToServer->sendQueryBlockAuth(true, "VersionControl"); - - //TODO пока сразу - //slot_VersionControl(); } } @@ -254,7 +253,7 @@ void DialogSettings::on_DialogSettings_accepted() emit signal_LanguageChanged(language); } -void DialogSettings::slot_VersionControl() +void DialogSettings::dialog_VersionControl() { dlgVersionControl = new DialogVersionControl(connectorToServer, this); dlgVersionControl->initialize(connectorToServer->getLoginName()); @@ -277,7 +276,7 @@ void DialogSettings::slot_checkTryBlockResult(bool result, QString type) { if(result) {//Одобрено - slot_VersionControl(); + dialog_VersionControl(); } else {//Отказ diff --git a/LibInstructorsAndTrainees/settings/dialogsettings.h b/LibInstructorsAndTrainees/settings/dialogsettings.h index 3577d26..2956dc6 100644 --- a/LibInstructorsAndTrainees/settings/dialogsettings.h +++ b/LibInstructorsAndTrainees/settings/dialogsettings.h @@ -47,12 +47,11 @@ private slots: void on_DialogSettings_accepted(); public slots: - void slot_VersionControl(); - void slot_checkTryBlockResult(bool result, QString type); private: bool saveSettings(); + void dialog_VersionControl(); private: Ui::DialogSettings *ui; diff --git a/LibInstructorsAndTrainees/trainees/viewertrainees.cpp b/LibInstructorsAndTrainees/trainees/viewertrainees.cpp index bb88d01..5d4d386 100644 --- a/LibInstructorsAndTrainees/trainees/viewertrainees.cpp +++ b/LibInstructorsAndTrainees/trainees/viewertrainees.cpp @@ -11,6 +11,7 @@ ViewerTrainees::ViewerTrainees(ConnectorToServer* connectorToServer, MessangerCo messangerController(messangerController), dlgRedactor(nullptr), dlgCardTrainee(nullptr), + flTryEditorTrainees(false), ui(new Ui::ViewerTrainees) { ui->setupUi(this); @@ -32,6 +33,8 @@ ViewerTrainees::ViewerTrainees(ConnectorToServer* connectorToServer, MessangerCo setNotLoggedInVisible(true); ui->btnEditorTrainees->setVisible(false); + + connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, this, &ViewerTrainees::slot_checkTryBlockResult); } ViewerTrainees::~ViewerTrainees() @@ -79,6 +82,8 @@ void ViewerTrainees::deactivate() if(dlgCardTrainee) dlgCardTrainee->close(); + flTryEditorTrainees = false; + CommonView::deactivate(); ammTasksWidgetCommon->deactivate(); @@ -109,23 +114,31 @@ void ViewerTrainees::slot_receiveMessage(ClientMessage clientMessage) slot_NeedUpdateUI(false, true); } +void ViewerTrainees::slot_checkTryBlockResult(bool result, QString type) +{ + if(flTryEditorTrainees) + { + if(type == "EditorTrainees") + { + if(result) + {//Одобрено + dialog_EditorTrainees(); + } + else + {//Отказ + SpecMsgBox::WarningClose(this, tr("The server rejected your request to access trainees control.\nAnother instructor is managing trainees.\nPlease try again later.")); + } + + flTryEditorTrainees = false; + } + } +} + void ViewerTrainees::on_btnEditorTrainees_clicked() { - connectorToServer->sendQueryBlockAuth(true, "EditorTrainees"); + flTryEditorTrainees = true; - dlgRedactor = new DialogRedactorTrainees(connectorToServer, adminMode, this); - dlgRedactor->exec(); - - if(dlgRedactor) - { - delete dlgRedactor; - dlgRedactor = nullptr; - } - - if(authComplited) - loadTraineesFromDB(); - - connectorToServer->sendQueryBlockAuth(false, "EditorTrainees"); + connectorToServer->sendQueryBlockAuth(true, "EditorTrainees"); } void ViewerTrainees::on_btnPersonalCard_clicked() @@ -236,3 +249,20 @@ void ViewerTrainees::updateButtons() ui->btnEditorTrainees->setEnabled(false); } } + +void ViewerTrainees::dialog_EditorTrainees() +{ + dlgRedactor = new DialogRedactorTrainees(connectorToServer, adminMode, this); + dlgRedactor->exec(); + + if(dlgRedactor) + { + delete dlgRedactor; + dlgRedactor = nullptr; + } + + if(authComplited) + loadTraineesFromDB(); + + connectorToServer->sendQueryBlockAuth(false, "EditorTrainees"); +} diff --git a/LibInstructorsAndTrainees/trainees/viewertrainees.h b/LibInstructorsAndTrainees/trainees/viewertrainees.h index 742060f..63a5bd9 100644 --- a/LibInstructorsAndTrainees/trainees/viewertrainees.h +++ b/LibInstructorsAndTrainees/trainees/viewertrainees.h @@ -36,6 +36,8 @@ protected: public slots: void slot_receiveMessage(ClientMessage clientMessage); + void slot_checkTryBlockResult(bool result, QString type); + public Q_SLOTS: void on_btnEditorTrainees_clicked(); void on_btnPersonalCard_clicked(); @@ -50,6 +52,8 @@ Q_SIGNALS: private: void updateButtons() override; + void dialog_EditorTrainees(); + private: AMMtasksWidget* ammTasksWidgetCommon; FIMtasksWidget* fimTasksWidgetCommon; @@ -59,6 +63,8 @@ private: DialogRedactorTrainees* dlgRedactor; DialogCardTrainee* dlgCardTrainee; + bool flTryEditorTrainees; + private: Ui::ViewerTrainees *ui; };