Skip to content

Commit

Permalink
[MOODLE-21] Add enabled checkbox for process
Browse files Browse the repository at this point in the history
* Add enabled checkbox for process

* fix label text

* ver.
  • Loading branch information
rs-a-demyanenko authored Mar 22, 2024
1 parent 4a09b0f commit 3658279
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 10 deletions.
10 changes: 8 additions & 2 deletions classes/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ public function exam_data($course, $cm) {
'visibleWarnings' => $conditiondata['warnings'],
'ldb' => $conditiondata['ldb'],
'allowMultipleDisplays' => $conditiondata['allowmultipledisplays'],
'desktopAppForbiddenProcesses' => $desktopAppForbiddenProcesses,
'desktopAppAllowedProcesses' => $desktopAppAllowedProcesses,
'allowVirtualEnvironment' => $conditiondata['allowvirtualenvironment'],
'checkIdPhotoQuality' => $conditiondata['checkidphotoquality'],
'webCameraMainView' => $conditiondata['webcameramainview'],
Expand All @@ -269,6 +267,14 @@ public function exam_data($course, $cm) {
),
];

if($conditiondata['enabledForbiddenProcesses']) {
$data['desktopAppForbiddenProcesses'] = $desktopAppForbiddenProcesses;
}

if($conditiondata['enabledAllowedProcesses']) {
$data['desktopAppAllowedProcesses'] = $desktopAppAllowedProcesses;
}

return $data;
}

Expand Down
13 changes: 12 additions & 1 deletion classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class condition extends \core_availability\condition {
'checkidphotoquality', 'webcameramainview',
'scoring', 'warnings', 'rules', 'customrules', 'groups',
'biometryenabled', 'biometryskipfail', 'biometryflow', 'biometrytheme',
'desktopAppForbiddenProcesses','desktopAppAllowedProcesses',
'desktopAppForbiddenProcesses','desktopAppAllowedProcesses','enabledForbiddenProcesses',
'enabledAllowedProcesses'
];

/** @var array List of default values for visible warnings */
Expand Down Expand Up @@ -243,10 +244,18 @@ public function __construct($structure) {
$this->useragreementurl = $structure->useragreementurl;
}

if (!empty($structure->enabledForbiddenProcesses)) {
$this->enabledForbiddenProcesses = $structure->enabledForbiddenProcesses;
}

if (!empty($structure->desktopAppForbiddenProcesses)) {
$this->desktopAppForbiddenProcesses = $structure->desktopAppForbiddenProcesses;
}

if (!empty($structure->enabledAllowedProcesses)) {
$this->enabledAllowedProcesses = $structure->enabledAllowedProcesses;
}

if (!empty($structure->desktopAppAllowedProcesses)) {
$this->desktopAppAllowedProcesses = $structure->desktopAppAllowedProcesses;
}
Expand Down Expand Up @@ -413,7 +422,9 @@ public function save() {
'identification' => $this->identification,
'useragreementurl' => $this->useragreementurl,
'auxiliarycamera' => (bool) $this->auxiliarycamera,
'enabledForbiddenProcesses' => (bool)$this->enabledForbiddenProcesses,
'desktopAppForbiddenProcesses' => $this->desktopAppForbiddenProcesses,
'enabledAllowedProcesses' => (bool)$this->enabledAllowedProcesses,
'desktopAppAllowedProcesses' => $this->desktopAppAllowedProcesses,
'customrules' => $this->customrules,
];
Expand Down
2 changes: 1 addition & 1 deletion classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function get_javascript_strings() {
'scoring_params_header_desc','desktop_app_forbidden_processes',
'desktop_app_allowed_processes','desktop_app_forbidden_processes_desc',
'desktop_app_allowed_processes_desc','scoring_params_header_desc',
'user_agreement_url_desc',
'user_agreement_url_desc','enabledAllowedProcesses','enabledForbiddenProcesses'
];

foreach (condition::WARNINGS as $key => $value) {
Expand Down
3 changes: 3 additions & 0 deletions lang/en/availability_examus2.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,6 @@
$string['desktop_app_forbidden_processes_desc'] = 'Use line breaks to separate applications';
$string['desktop_app_allowed_processes_desc'] = 'Use line breaks to separate applications';
$string['user_agreement_url_desc'] = 'A link to the exam rules (URL) on any page. Insert a custom rules page before the exam.';

$string['enabledAllowedProcesses'] = 'Enable allowed processes';
$string['enabledForbiddenProcesses'] = 'Enable forbidden processes';
5 changes: 4 additions & 1 deletion lang/ru/availability_examus2.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,7 @@
$string['scoring_params_header_desc'] = 'Для тонкой настройки расчета скоринга и вычисления результата прокторинга для конкретного экзамена можно менять параметры скоринга.<br><b>Важно:</b> если выбор не сделан, то будут использованы значения по умолчанию (показываются все)';
$string['desktop_app_forbidden_processes_desc'] = 'Используйте перенос строки для разделения приложений';
$string['desktop_app_allowed_processes_desc'] = 'Используйте перенос строки для разделения приложений';
$string['user_agreement_url_desc'] = 'Ссылка на правила (URL) на любой странице. Предназначено для вставки собственной страницы с правилами перед прохождением экзамена.';
$string['user_agreement_url_desc'] = 'Ссылка на правила (URL) на любой странице. Предназначено для вставки собственной страницы с правилами перед прохождением экзамена.';

$string['enabledAllowedProcesses'] = 'Включить разрешенные процессы';
$string['enabledForbiddenProcesses'] = 'Включить запрещенные процессы';
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'availability_examus2';
$plugin->version = 2024021401;
$plugin->release = 'v2.0.33';
$plugin->version = 2024031501;
$plugin->release = 'v2.0.34';
$plugin->requires = 2018111800;
$plugin->maturity = MATURITY_STABLE;
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ M.availability_examus2.form.getNode = function(json) {
var biometryThemeId = id + '_biometryTheme';
var userAgreementId = id + '_userAgreement';
var webCameraMainViewId = id + '_webCameraMainView';
var enabledForbiddenProcessesId = id + '_enabledForbiddenProcesses';
var desktopAppForbiddenProcessesId = id + '_desktopAppForbiddenProcesses';
var enabledAllowedProcessesId = id + '_enabledAllowedProcesses';
var desktopAppAllowedProcessesId = id + '_desktopAppAllowedProcesses';

var tabButtonOne, tabButtonTwo, tabOne, tabTwo;
Expand Down Expand Up @@ -220,6 +222,11 @@ M.availability_examus2.form.getNode = function(json) {
'<textarea name="customrules" id="' + customRulesId + '" class="form-control"></textarea>'
);

html += formGroup(enabledForbiddenProcessesId, getString('enabledForbiddenProcesses'), '',
'<input type="checkbox" name="enabledForbiddenProcesses" id="' + enabledForbiddenProcessesId + '" value="0">&nbsp;' +
'<label for="' + enabledForbiddenProcessesId + '">' + getString('enable') + '</label> '
);

html += formGroup(
desktopAppForbiddenProcessesId,
getString('desktop_app_forbidden_processes'),
Expand All @@ -228,6 +235,11 @@ M.availability_examus2.form.getNode = function(json) {
desktopAppForbiddenProcessesId + '" class="form-control"></textarea>'
);

html += formGroup(enabledAllowedProcessesId, getString('enabledAllowedProcesses'), '',
'<input type="checkbox" name="enabledAllowedProcesses" id="' + enabledAllowedProcessesId + '" value="0">&nbsp;' +
'<label for="' + enabledAllowedProcessesId + '">' + getString('enable') + '</label> '
);

html += formGroup(
desktopAppAllowedProcessesId,
getString('desktop_app_allowed_processes'),
Expand Down Expand Up @@ -455,12 +467,22 @@ M.availability_examus2.form.getNode = function(json) {
node.one('#' + customRulesId).set('value', json.customrules);
}

if (json.enabledForbiddenProcesses !== undefined) {
node.one('#' + enabledForbiddenProcessesId).set('checked', json.enabledForbiddenProcesses ? 'checked' : null);
}

if (json.desktopAppForbiddenProcesses !== undefined) {
try {
node.one('#' + desktopAppForbiddenProcessesId).set('value', JSON.parse(json.desktopAppForbiddenProcesses).join('\n'));
} catch (e) {
node.one('#' + desktopAppForbiddenProcessesId).set('value', json.desktopAppForbiddenProcesses);
}
node.one('#' + desktopAppForbiddenProcessesId)
.set('disabled', node.one('#' + enabledForbiddenProcessesId).get('checked') ? null : 'disabled');
}

if (json.enabledAllowedProcesses !== undefined) {
node.one('#' + enabledAllowedProcessesId).set('checked', json.enabledAllowedProcesses ? 'checked' : null);
}

if (json.desktopAppAllowedProcesses !== undefined) {
Expand All @@ -469,6 +491,8 @@ M.availability_examus2.form.getNode = function(json) {
} catch (e) {
node.one('#' + desktopAppAllowedProcessesId).set('value', json.desktopAppAllowedProcesses);
}
node.one('#' + desktopAppAllowedProcessesId)
.set('disabled', node.one('#' + enabledAllowedProcessesId).get('checked') ? null : 'disabled');
}

if (json.useragreementurl !== undefined) {
Expand Down Expand Up @@ -517,10 +541,12 @@ M.availability_examus2.form.fillValue = function(value, node) {
value.scheduling_required = node.one('input[name=scheduling_required]').get('checked');
value.istrial = node.one('input[name=istrial]').get('checked');
value.customrules = node.one('textarea[name=customrules]').get('value').trim();
value.enabledForbiddenProcesses = node.one('input[name=enabledForbiddenProcesses]').get('checked');
value.desktopAppForbiddenProcesses = JSON.stringify(node.one('textarea[name=desktopAppForbiddenProcesses]')
.get('value').split('\n').filter(function(line) {
return line.trim();
}));
value.enabledAllowedProcesses = node.one('input[name=enabledAllowedProcesses]').get('checked');
value.desktopAppAllowedProcesses = JSON.stringify(node.one('textarea[name=desktopAppAllowedProcesses]')
.get('value').split('\n').filter(function(line) {
return line.trim();
Expand Down Expand Up @@ -548,6 +574,23 @@ M.availability_examus2.form.fillValue = function(value, node) {
}
});

document.addEventListener('click', function(e) {
if (e.target.name == 'enabledForbiddenProcesses') {
if (e.target.checked) {
document.querySelector('textarea[name=desktopAppForbiddenProcesses]').disabled = false;
} else {
document.querySelector('textarea[name=desktopAppForbiddenProcesses]').disabled = 'disabled';
}
}
if (e.target.name == 'enabledAllowedProcesses') {
if (e.target.checked) {
document.querySelector('textarea[name=desktopAppAllowedProcesses]').disabled = false;
} else {
document.querySelector('textarea[name=desktopAppAllowedProcesses]').disabled = 'disabled';
}
}
});

value.warnings = {};
warningsInputs = node.all('.warnings input');
Y.each(warningsInputs, function(warningInput) {
Expand Down
Loading

0 comments on commit 3658279

Please sign in to comment.