From a1f95d48b96f44b4300e01ce94364d9b6a470375 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Thu, 12 Jan 2017 09:54:40 +0800 Subject: [PATCH 1/2] MDL-57368 templates: add example context to core_form/element-template --- .../core_form/element-template.mustache | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/theme/boost/templates/core_form/element-template.mustache b/theme/boost/templates/core_form/element-template.mustache index 1af0c25fd93..e51b1a1afec 100644 --- a/theme/boost/templates/core_form/element-template.mustache +++ b/theme/boost/templates/core_form/element-template.mustache @@ -1,3 +1,46 @@ +{{! + 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 . +}} +{{! + @template core_form/element-template + + Template for the form element wrapper template. + + Context variables required for this template: + * label + * required + * advanced + * helpbutton + * error + * element + * id + * name + + Example context (json): + { + "label": "Course full name", + "required": true, + "advanced": false, + "error": null, + "element": { + "id": "id_fullname", + "name": "fullname" + } + } +}}
From 195f646dfc4a0dd02d7de277f857728c9ee488cb Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Thu, 12 Jan 2017 09:56:09 +0800 Subject: [PATCH 2/2] MDL-57368 mod_feeback: fix drag and drop question reordering in boost --- mod/feedback/item/captcha/lib.php | 3 ++- mod/feedback/item/feedback_item_class.php | 6 +++++- mod/feedback/item/label/lib.php | 1 + mod/feedback/item/multichoice/lib.php | 4 ++++ mod/feedback/item/multichoicerated/lib.php | 2 ++ mod/feedback/yui/dragdrop/dragdrop.js | 14 +++++++++++--- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/mod/feedback/item/captcha/lib.php b/mod/feedback/item/captcha/lib.php index 3e19008286b..fa39c782835 100644 --- a/mod/feedback/item/captcha/lib.php +++ b/mod/feedback/item/captcha/lib.php @@ -120,8 +120,9 @@ class feedback_item_captcha extends feedback_item_base { $inputname = $item->typ . '_' . $item->id; if ($form->get_mode() != mod_feedback_complete_form::MODE_COMPLETE) { + // Span to hold the element id. The id is used for drag and drop reordering. $form->add_form_element($item, - ['static', $inputname, $name], + ['static', $inputname, $name, html_writer::span('', '', ['id' => 'feedback_item_' . $item->id])], false, false); } else { diff --git a/mod/feedback/item/feedback_item_class.php b/mod/feedback/item/feedback_item_class.php index ddb3c432354..92eb10a4265 100644 --- a/mod/feedback/item/feedback_item_class.php +++ b/mod/feedback/item/feedback_item_class.php @@ -294,7 +294,11 @@ class feedback_item_pagebreak extends feedback_item_base { */ public function complete_form_element($item, $form) { $form->add_form_element($item, - ['static', $item->typ.'_'.$item->id, '', '']); + ['static', + $item->typ.'_'.$item->id, + '', + html_writer::empty_tag('hr', ['class' => 'feedback_pagebreak', 'id' => 'feedback_item_' . $item->id]) + ]); } /** diff --git a/mod/feedback/item/label/lib.php b/mod/feedback/item/label/lib.php index 4ea3ae45261..6fa83bf5472 100644 --- a/mod/feedback/item/label/lib.php +++ b/mod/feedback/item/label/lib.php @@ -194,6 +194,7 @@ class feedback_item_label extends feedback_item_base { $context->id, 'mod_feedback', $filearea, $item->id); $formatoptions = array('overflowdiv' => true, 'noclean' => true); $output = format_text($output, FORMAT_HTML, $formatoptions); + $output = html_writer::div($output, '', ['id' => 'feedback_item_' . $item->id]); $inputname = $item->typ . '_' . $item->id; diff --git a/mod/feedback/item/multichoice/lib.php b/mod/feedback/item/multichoice/lib.php index 8e47ca0feee..d3b628bc16a 100644 --- a/mod/feedback/item/multichoice/lib.php +++ b/mod/feedback/item/multichoice/lib.php @@ -342,6 +342,8 @@ class feedback_item_multichoice extends feedback_item_base { $objs[] = ['advcheckbox', $inputname.'['.$idx.']', '', $label, null, array(0, $idx)]; $form->set_element_type($inputname.'['.$idx.']', PARAM_INT); } + // Span to hold the element id. The id is used for drag and drop reordering. + $objs[] = ['static', '', '', html_writer::span('', '', ['id' => 'feedback_item_' . $item->id])]; $element = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class); if ($tmpvalue) { foreach (explode(FEEDBACK_MULTICHOICE_LINE_SEP, $tmpvalue) as $v) { @@ -357,6 +359,8 @@ class feedback_item_multichoice extends feedback_item_base { foreach ($options as $idx => $label) { $objs[] = ['radio', $inputname.'[0]', '', $label, $idx]; } + // Span to hold the element id. The id is used for drag and drop reordering. + $objs[] = ['static', '', '', html_writer::span('', '', ['id' => 'feedback_item_' . $item->id])]; $element = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class); $form->set_element_default($inputname.'[0]', $tmpvalue); $form->set_element_type($inputname.'[0]', PARAM_INT); diff --git a/mod/feedback/item/multichoicerated/lib.php b/mod/feedback/item/multichoicerated/lib.php index 5eb16e37b1d..8be2faa97e8 100644 --- a/mod/feedback/item/multichoicerated/lib.php +++ b/mod/feedback/item/multichoicerated/lib.php @@ -312,6 +312,8 @@ class feedback_item_multichoicerated extends feedback_item_base { foreach ($options as $idx => $label) { $objs[] = ['radio', $inputname, '', $label, $idx]; } + // Span to hold the element id. The id is used for drag and drop reordering. + $objs[] = ['static', '', '', html_writer::span('', '', ['id' => 'feedback_item_' . $item->id])]; $separator = $info->horizontal ? ' ' : '
'; $class .= ' multichoicerated-' . ($info->horizontal ? 'horizontal' : 'vertical'); $el = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class); diff --git a/mod/feedback/yui/dragdrop/dragdrop.js b/mod/feedback/yui/dragdrop/dragdrop.js index 31f117fab7e..ac4af8ff6d7 100644 --- a/mod/feedback/yui/dragdrop/dragdrop.js +++ b/mod/feedback/yui/dragdrop/dragdrop.js @@ -167,12 +167,20 @@ YUI.add('moodle-mod_feedback-dragdrop', function(Y) { if (!drop.contains(drag)) { drop.appendChild(drag); } - myElements = ''; + var childElement; + var elementId; + var elements = []; drop.all(CSS.DRAGITEM).each(function(v) { - myElements = myElements + ',' + this.get_node_id(v.get('id')); + childElement = v.one('.felement').one('[id^="feedback_item_"]'); + if (childElement) { + elementId = this.get_node_id(childElement.get('id')); + if (elements.indexOf(elementId) == -1) { + elements.push(elementId); + } + } }, this); var spinner = M.util.add_spinner(Y, dragnode); - this.save_item_order(this.cmid, myElements, spinner); + this.save_item_order(this.cmid, elements.toString(), spinner); } },