From 8cb9ea0dfc4e433c411a99e432210baaf62a06a1 Mon Sep 17 00:00:00 2001 From: Johannes Burk Date: Tue, 7 Jun 2016 20:31:51 +0200 Subject: [PATCH] Improve manage table (select menu for actions and toggle all checkbox) --- amd/build/manage.min.js | 1 + amd/src/manage.js | 38 ++++++++++++++++++++++++++++++++++++++ lang/en/enrol_apply.php | 2 +- manage.php | 19 ++++++++++++------- manage_table.php | 2 ++ renderer.php | 36 +++++++++++++++++++----------------- style.css | 12 ++++++++++-- 7 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 amd/build/manage.min.js create mode 100644 amd/src/manage.js diff --git a/amd/build/manage.min.js b/amd/build/manage.min.js new file mode 100644 index 0000000..764c320 --- /dev/null +++ b/amd/build/manage.min.js @@ -0,0 +1 @@ +define(["jquery"],function(a){return{init:function(){a("#toggleall").on("change",function(){a('input[name="userenrolments[]"]').prop("checked",a("#toggleall").prop("checked"))}),a("#formaction").on("change",function(){a("#enrol_apply_manage_form").submit()})}}}); \ No newline at end of file diff --git a/amd/src/manage.js b/amd/src/manage.js new file mode 100644 index 0000000..f03defa --- /dev/null +++ b/amd/src/manage.js @@ -0,0 +1,38 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * @package enrol_apply + * @copyright 2016 sudile GbR (http://www.sudile.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Johannes Burk + */ + +/** + * @module enrol_apply/manage + */ +define(['jquery'], function($) { + return { + init: function() { + $('#toggleall').on('change', function() { + $('input[name="userenrolments[]"]').prop('checked', $('#toggleall').prop('checked')); + }); + + $('#formaction').on('change', function() { + $('#enrol_apply_manage_form').submit(); + }); + } + }; +}); diff --git a/lang/en/enrol_apply.php b/lang/en/enrol_apply.php index 9eb56d3..9c8e99d 100644 --- a/lang/en/enrol_apply.php +++ b/lang/en/enrol_apply.php @@ -61,7 +61,7 @@ $string['applyuser'] = 'First name / Surname'; $string['applyusermail'] = 'Email'; $string['applydate'] = 'Enrol date'; $string['btnconfirm'] = 'Confirm requests'; -$string['btnwait'] = 'put marked users on waiting list'; +$string['btnwait'] = 'Defer requests'; $string['btncancel'] = 'Cancel requests'; $string['enrolusers'] = 'Enrol users'; diff --git a/manage.php b/manage.php index 5dc7365..35d8e8b 100644 --- a/manage.php +++ b/manage.php @@ -28,6 +28,7 @@ require_once($CFG->dirroot.'/enrol/apply/manage_table.php'); require_once($CFG->dirroot.'/enrol/apply/renderer.php'); $id = optional_param('id', null, PARAM_INT); +$formaction = optional_param('formaction', null, PARAM_TEXT); $userenrolments = optional_param_array('userenrolments', null, PARAM_INT); require_login(); @@ -57,14 +58,18 @@ $PAGE->navbar->add(get_string('confirmusers', 'enrol_apply')); $PAGE->set_title(get_string('confirmusers', 'enrol_apply')); $PAGE->requires->css('/enrol/apply/style.css'); -if ($userenrolments != null) { +if ($formaction != null && $userenrolments != null) { $enrolapply = enrol_get_plugin('apply'); - if (optional_param('confirm', false, PARAM_BOOL)) { - $enrolapply->confirm_enrolment($userenrolments); - } else if (optional_param('wait', false, PARAM_BOOL)) { - $enrolapply->wait_enrolment($userenrolments); - } else if (optional_param('cancel', false, PARAM_BOOL)) { - $enrolapply->cancel_enrolment($userenrolments); + switch ($formaction) { + case 'confirm': + $enrolapply->confirm_enrolment($userenrolments); + break; + case 'wait': + $enrolapply->wait_enrolment($userenrolments); + break; + case 'cancel': + $enrolapply->cancel_enrolment($userenrolments); + break; } redirect($manageurl); } diff --git a/manage_table.php b/manage_table.php index 3c98dd4..fbd1706 100644 --- a/manage_table.php +++ b/manage_table.php @@ -55,6 +55,8 @@ class enrol_apply_manage_table extends table_sql { JOIN {course} c ON c.id = e.courseid", $sqlwhere, $sqlparams); + + $this->no_sorting('checkboxcolumn'); } /** diff --git a/renderer.php b/renderer.php index 7d95c76..9efc772 100644 --- a/renderer.php +++ b/renderer.php @@ -48,22 +48,24 @@ class enrol_apply_renderer extends plugin_renderer_base { $this->manage_table($table); - echo html_writer::start_tag('p', array('align' => 'center')); - - echo html_writer::empty_tag('input', array( - 'type' => 'submit', - 'name' => 'confirm', - 'value' => get_string('btnconfirm', 'enrol_apply'))); - echo html_writer::empty_tag('input', array( - 'type' => 'submit', - 'name' => 'wait', - 'value' => get_string('btnwait', 'enrol_apply'))); - echo html_writer::empty_tag('input', array( - 'type' => 'submit', - 'name' => 'cancel', - 'value' => get_string('btncancel', 'enrol_apply'))); - - echo html_writer::end_tag('p'); + if ($table->totalrows > 0) { + echo html_writer::empty_tag('br'); + echo html_writer::start_tag('div', array('class' => 'formaction')); + + $formactions = array( + 'confirm' => get_string('btnconfirm', 'enrol_apply'), + 'wait' => get_string('btnwait', 'enrol_apply'), + 'cancel' => get_string('btncancel', 'enrol_apply')); + echo html_writer::tag('label', get_string('withselectedusers'), array('for' => 'formaction')); + echo html_writer::select($formactions, 'formaction', '', array('' => 'choosedots'), array('id' => 'formaction')); + echo html_writer::tag('noscript', + html_writer::empty_tag('input', array('type' => 'submit', get_string('submit'))), + array('style' => 'display: inline;')); + + echo html_writer::end_tag('div'); + + $this->page->requires->js_call_amd('enrol_apply/manage', 'init'); + } echo html_writer::end_tag('form'); } @@ -76,7 +78,7 @@ class enrol_apply_renderer extends plugin_renderer_base { 'applydate', 'applycomment'); $headers = array( - '', + html_writer::checkbox('toggleall', 'toggleall', false, '', array('id' => 'toggleall')), get_string('course'), 'fullname', // Magic happens here: The column heading will automatically be set due to column name 'fullname'. get_string('email'), diff --git a/style.css b/style.css index 05b7433..c178bb1 100644 --- a/style.css +++ b/style.css @@ -1,3 +1,11 @@ -.enrol_apply_waitinglist_highlight { - border-left: 6px solid grey; +form#enrol_apply_manage_form tr { + border-left: 3px solid transparent; +} + +form#enrol_apply_manage_form tr.enrol_apply_waitinglist_highlight { + border-color: grey; +} + +.formaction { + text-align: center; }