From 5a90a7cabe6f196d7af639acccea415085e06bfc Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 30 Jun 2017 13:57:48 +0800 Subject: [PATCH] MDL-59368 groups: Add an explicit cancel button Autocomplete already uses Escape keyboard handler - so we can't use it to cancel an edit-inplace thing. Make an obvious cancel button instead. --- group/classes/output/user_groups_editable.php | 2 +- lib/amd/src/inplace_editable.js | 18 ++++++++++++++++-- .../output/icon_system_fontawesome.php | 1 + pix/e/cancel.png | Bin 0 -> 169 bytes pix/e/cancel.svg | 3 +++ 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 pix/e/cancel.png create mode 100644 pix/e/cancel.svg diff --git a/group/classes/output/user_groups_editable.php b/group/classes/output/user_groups_editable.php index c6534ba6dd6..f196529d9cf 100644 --- a/group/classes/output/user_groups_editable.php +++ b/group/classes/output/user_groups_editable.php @@ -159,6 +159,6 @@ class user_groups_editable extends \core\output\inplace_editable { $course = get_course($courseid); $user = core_user::get_user($userid); - return new self($course, $context, $user, $coursegroups, $groupids); + return new self($course, $context, $user, $coursegroups, array_values($groupids)); } } diff --git a/lib/amd/src/inplace_editable.js b/lib/amd/src/inplace_editable.js index 43a89098b79..9734c2a36d5 100644 --- a/lib/amd/src/inplace_editable.js +++ b/lib/amd/src/inplace_editable.js @@ -209,7 +209,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' .attr('for', inputelement.attr('id')), options = args.options, attributes = args.attributes, - saveelement = $(''); + saveelement = $(''), + cancelelement = $(''); for (i in options) { inputelement @@ -228,11 +229,19 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' saveelement.append(html); return; }).fail(notification.exception); + + str.get_string('cancel', 'core').then(function(s) { + return templates.renderPix('e/cancel', 'core', s); + }).then(function(html) { + cancelelement.append(html); + return; + }).fail(notification.exception); el.html('') .append(lbl) .append(inputelement) - .append(saveelement); + .append(saveelement) + .append(cancelelement); inputelement.focus(); inputelement.select(); @@ -254,6 +263,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' var val = JSON.stringify(inputelement.val()); turnEditingOff(el); updateValue(el, val); + e.preventDefault(); + }); + cancelelement.on('click', function(e) { + turnEditingOff(el); + e.preventDefault(); }); }; diff --git a/lib/classes/output/icon_system_fontawesome.php b/lib/classes/output/icon_system_fontawesome.php index 2a2589703f0..28ad0cf2a4f 100644 --- a/lib/classes/output/icon_system_fontawesome.php +++ b/lib/classes/output/icon_system_fontawesome.php @@ -84,6 +84,7 @@ class icon_system_fontawesome extends icon_system_font { 'core:e/backward' => 'fa-undo', 'core:e/bold' => 'fa-bold', 'core:e/bullet_list' => 'fa-list-ul', + 'core:e/cancel' => 'fa-times', 'core:e/cell_props' => 'fa-info', 'core:e/cite' => 'fa-quote-right', 'core:e/cleanup_messy_code' => 'fa-eraser', diff --git a/pix/e/cancel.png b/pix/e/cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..7afe114438f314f9e54de21de3bad0dc871b0ac3 GIT binary patch literal 169 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=%3?!FCJ6-`&q5(c3u0VPw2Dp{>w;CwHRubeF z%plM|fBpIV@@-pyBDS6`jv*C{$q7X%2?B;G0p6ksJl<&q-rOR--iZRf-n`!2DL@f# tpg2QOql^ZtXp2^3Rzrq=lf*IxhJ&&K=jHVI-vJF`@O1TaS?83{1OS-kFz)~W literal 0 HcmV?d00001 diff --git a/pix/e/cancel.svg b/pix/e/cancel.svg new file mode 100644 index 00000000000..b1aab8eae28 --- /dev/null +++ b/pix/e/cancel.svg @@ -0,0 +1,3 @@ + +]> \ No newline at end of file