Commit 195f646d authored by Jake Dallimore's avatar Jake Dallimore
Browse files

MDL-57368 mod_feeback: fix drag and drop question reordering in boost

parent a1f95d48
......@@ -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 {
......
......@@ -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, '', '<hr class="feedback_pagebreak">']);
['static',
$item->typ.'_'.$item->id,
'',
html_writer::empty_tag('hr', ['class' => 'feedback_pagebreak', 'id' => 'feedback_item_' . $item->id])
]);
}
/**
......
......@@ -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;
......
......@@ -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);
......
......@@ -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 ? ' ' : '<br>';
$class .= ' multichoicerated-' . ($info->horizontal ? 'horizontal' : 'vertical');
$el = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class);
......
......@@ -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);
}
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment