Skip to content

Commit d6af471

Browse files
committed
Finalize customise buttons in adminapprove step
1 parent c782758 commit d6af471

File tree

8 files changed

+133
-112
lines changed

8 files changed

+133
-112
lines changed

step/adminapprove/amd/build/init.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

step/adminapprove/amd/build/init.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

step/adminapprove/amd/src/init.js

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,57 @@
2222
*/
2323
define(['jquery'], function($) {
2424
return {
25-
init: function(sesskey, url, totalrows) {
25+
init: function(totalrows) {
2626

2727
$('#adminapprove_totalrows').html(totalrows);
2828

2929
$('input[name="checkall"]').click(function() {
3030
$('input[name="c[]"]').prop('checked', $('input[name="checkall"]').prop('checked'));
3131
});
3232

33-
$('.adminapprove-action').each(function() {
34-
$(this).click(function() {
35-
var post = {
36-
'act': $(this).attr('data-action'),
37-
'c[]': $(this).attr('data-content'),
38-
'sesskey': sesskey
39-
};
40-
var form = document.createElement('form');
33+
$('.selectedbutton').click(function() {
34+
const sesskey = this.getAttribute('sesskey');
35+
const stepid = this.getAttribute('stepid');
36+
const action = this.getAttribute('action');
37+
const checkboxes = document.querySelectorAll('input[name="c[]"]');
38+
let data = [];
39+
let input;
40+
for (let i = 0; checkboxes[i]; ++i) {
41+
if (checkboxes[i].checked) {
42+
data.push(checkboxes[i].value);
43+
}
44+
}
45+
let datalength = data.length;
46+
if (datalength > 0) {
47+
let form = document.createElement('form');
4148
form.hidden = true;
4249
form.method = 'post';
43-
form.action = url;
44-
for (var k in post) {
45-
var input = document.createElement('input');
50+
form.action = '';
51+
for (let i = 0; i < datalength; i++) {
52+
input = document.createElement('input');
4653
input.type = 'hidden';
47-
input.name = k;
48-
input.value = post[k];
54+
input.name = 'c[]';
55+
input.value = data[i];
4956
form.append(input);
5057
}
58+
input = document.createElement('input');
59+
input.type = 'hidden';
60+
input.name = 'action';
61+
input.value = action;
62+
form.append(input);
63+
input = document.createElement('input');
64+
input.type = 'hidden';
65+
input.name = 'stepid';
66+
input.value = stepid;
67+
form.append(input);
68+
input = document.createElement('input');
69+
input.type = 'hidden';
70+
input.name = 'sesskey';
71+
input.value = sesskey;
72+
form.append(input);
5173
document.body.append(form);
5274
form.submit();
53-
});
75+
}
5476
});
5577
}
5678
};

step/adminapprove/approvestep.php

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
require_capability('moodle/site:config', context_system::instance());
4040

41-
$action = optional_param('act', null, PARAM_ALPHA);
41+
$action = optional_param('action', null, PARAM_ALPHANUMEXT);
4242
$ids = optional_param_array('c', [], PARAM_INT);
4343
$stepid = required_param('stepid', PARAM_INT);
4444

@@ -110,38 +110,13 @@
110110
if (is_array($ids) && count($ids) > 0 && ($action == PROCEED || $action == ROLLBACK)) {
111111
[$insql, $inparams] = $DB->get_in_or_equal($ids);
112112
$sql = 'UPDATE {lifecyclestep_adminapprove} ' .
113-
'SET status = ' . ($action == PROCEED ? 1 : 2) . ' ' .
114-
'WHERE id ' . $insql . ' ' .
115-
'AND status = 0';
113+
'SET status = ' . ($action == PROCEED ? 1 : 2) . ' ' .
114+
'WHERE id ' . $insql . ' ' .
115+
'AND status = 0';
116116
$DB->execute($sql, $inparams);
117-
} else if ($action == PROCEED_ALL || $action == ROLLBACK_ALL) {
118-
$sql = 'SELECT p.id FROM {lifecyclestep_adminapprove} a ' .
119-
'JOIN {tool_lifecycle_process} p ON p.id = a.processid ' .
120-
'JOIN {tool_lifecycle_step} s ON s.workflowid = p.workflowid AND s.sortindex = p.stepindex ' .
121-
'JOIN {course} c ON p.courseid = c.id ' .
122-
'WHERE s.id = :stepid ';
123-
$params = ['stepid' => $stepid];
124-
125-
if ($courseid) {
126-
$sql .= 'AND c.id = :cid ';
127-
$params['cid'] = $courseid;
128-
}
129-
if ($coursename) {
130-
$sql .= "AND c.fullname LIKE :cname ";
131-
$params['cname'] = '%' . $DB->sql_like_escape($coursename) . '%';
132-
}
133-
134-
$ids = array_keys($DB->get_records_sql_menu($sql, $params));
135-
if (!empty($ids)) {
136-
[$insql, $inparams] = $DB->get_in_or_equal($ids);
137-
$sql = 'UPDATE {lifecyclestep_adminapprove} ' .
138-
'SET status = ' . ($action == PROCEED_ALL ? 1 : 2) . ' ' .
139-
'WHERE status = 0 ' .
140-
'AND processid ' . $insql;
141-
$DB->execute($sql, $inparams);
142-
}
117+
118+
redirect($PAGE->url);
143119
}
144-
redirect($PAGE->url);
145120
}
146121

147122
$renderer = $PAGE->get_renderer('tool_lifecycle');
@@ -165,48 +140,18 @@
165140
echo get_string('courses_waiting', 'lifecyclestep_adminapprove',
166141
['step' => $step->instancename, 'workflow' => $workflow->title]);
167142

168-
$rollbackallcustlabel =
169-
settings_manager::get_settings($step->id, settings_type::STEP)['rollbackallbuttonlabel'] ?? null;
170-
$proceedallcustlabel =
171-
settings_manager::get_settings($step->id, settings_type::STEP)['proceedallbuttonlabel'] ?? null;
172-
$rollbackselectedcustlabel =
173-
settings_manager::get_settings($step->id, settings_type::STEP)['rollbackselectedbuttonlabel'] ?? null;
174-
$proceedselectedcustlabel =
175-
settings_manager::get_settings($step->id, settings_type::STEP)['proceedselectedbuttonlabel'] ?? null;
176-
177-
echo '<div class="mt-2 mb-2">';
178-
echo \html_writer::div('0', 'totalrows badge badge-primary badge-pill mr-2',
143+
echo '<div class="mt-2">';
144+
echo \html_writer::span('0', 'totalrows badge badge-primary badge-pill mr-1 mb-1',
179145
['id' => 'adminapprove_totalrows']);
180-
$button = new \single_button(new moodle_url($PAGE->url, ['act' => ROLLBACK_ALL]),
181-
!empty($rollbackallcustlabel) ? $rollbackallcustlabel :
182-
get_string(ROLLBACK_ALL, 'lifecyclestep_adminapprove'));
183-
echo $OUTPUT->render($button);
184-
185-
$button = new \single_button(new moodle_url($PAGE->url, ['act' => PROCEED_ALL]),
186-
!empty($proceedallcustlabel) ? $proceedallcustlabel :
187-
get_string(PROCEED_ALL, 'lifecyclestep_adminapprove'),
188-
'post', 'primary');
189-
echo $OUTPUT->render($button);
190-
191-
$button = new \single_button(new moodle_url($PAGE->url, ['act' => ROLLBACK]),
192-
!empty($rollbackselectedcustlabel) ? $rollbackselectedcustlabel :
193-
get_string('rollbackselected', 'lifecyclestep_adminapprove'), 'post', 'secondary');
194-
echo $OUTPUT->render($button);
195-
196-
$button = new \single_button(new moodle_url($PAGE->url, ['act' => PROCEED]),
197-
!empty($proceedselectedcustlabel) ? $proceedselectedcustlabel :
198-
get_string('proceedselected', 'lifecyclestep_adminapprove'), 'post', 'primary');
199-
echo $OUTPUT->render($button);
200-
146+
echo \html_writer::span(get_string('courses'));
201147
echo '</div>';
202148

203149
echo '<form action="" method="post"><input type="hidden" name="sesskey" value="' . sesskey() . '">';
204150
$table = new lifecyclestep_adminapprove\decision_table($stepid, $courseid, $category, $coursename);
205151
$table->out(100, false);
206152
echo '</form>';
207153

208-
$PAGE->requires->js_call_amd('lifecyclestep_adminapprove/init', 'init',
209-
[sesskey(), $PAGE->url->out(), $table->totalrows]);
154+
$PAGE->requires->js_call_amd('lifecyclestep_adminapprove/init', 'init', [$table->totalrows]);
210155
} else {
211156
echo get_string('no_courses_waiting', 'lifecyclestep_adminapprove',
212157
['step' => $step->instancename, 'workflow' => $workflow->title]);

0 commit comments

Comments
 (0)