MDL-47494 ddmarker: allow for 2,3,4,5,6 drags not just 1 or infinite
This commit is contained in:
@@ -57,7 +57,7 @@ class backup_qtype_ddmarker_plugin extends backup_qtype_plugin {
|
||||
$drags = new backup_nested_element('drags');
|
||||
|
||||
$drag = new backup_nested_element('drag', array('id'),
|
||||
array('no', 'infinite', 'label'));
|
||||
array('no', 'infinite', 'label', 'noofdrags'));
|
||||
$drops = new backup_nested_element('drops');
|
||||
|
||||
$drop = new backup_nested_element('drop', array('id'),
|
||||
|
||||
@@ -1,53 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="question/type/ddmarker/db" VERSION="20111001" COMMENT="XMLDB file for Moodle question/type/ddmarker"
|
||||
<XMLDB PATH="question/type/ddmarker/db" VERSION="20130530" COMMENT="XMLDB file for Moodle question/type/ddmarker"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
<TABLES>
|
||||
<TABLE NAME="qtype_ddmarker" COMMENT="Defines drag and drop (text or images onto a background image) questions" NEXT="qtype_ddmarker_drops">
|
||||
<TABLE NAME="qtype_ddmarker" COMMENT="Defines drag and drop (text or images onto a background image) questions">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="questionid"/>
|
||||
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="shuffleanswers"/>
|
||||
<FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="questionid" NEXT="correctfeedback"/>
|
||||
<FIELD NAME="correctfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any correct response." PREVIOUS="shuffleanswers" NEXT="correctfeedbackformat"/>
|
||||
<FIELD NAME="correctfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="correctfeedback" NEXT="partiallycorrectfeedback"/>
|
||||
<FIELD NAME="partiallycorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any partially correct response." PREVIOUS="correctfeedbackformat" NEXT="partiallycorrectfeedbackformat"/>
|
||||
<FIELD NAME="partiallycorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="partiallycorrectfeedback" NEXT="incorrectfeedback"/>
|
||||
<FIELD NAME="incorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any incorrect response." PREVIOUS="partiallycorrectfeedbackformat" NEXT="incorrectfeedbackformat"/>
|
||||
<FIELD NAME="incorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="incorrectfeedback" NEXT="shownumcorrect"/>
|
||||
<FIELD NAME="shownumcorrect" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="incorrectfeedbackformat" NEXT="showmisplaced"/>
|
||||
<FIELD NAME="showmisplaced" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="shownumcorrect"/>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
|
||||
<FIELD NAME="correctfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any correct response."/>
|
||||
<FIELD NAME="correctfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="partiallycorrectfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any partially correct response."/>
|
||||
<FIELD NAME="partiallycorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="incorrectfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any incorrect response."/>
|
||||
<FIELD NAME="incorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="shownumcorrect" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="showmisplaced" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
|
||||
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="qtype_ddmarker_drops" COMMENT="drop regions" PREVIOUS="qtype_ddmarker" NEXT="qtype_ddmarker_drags">
|
||||
<TABLE NAME="qtype_ddmarker_drops" COMMENT="drop regions">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="questionid"/>
|
||||
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="no"/>
|
||||
<FIELD NAME="no" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="drop number" PREVIOUS="questionid" NEXT="shape"/>
|
||||
<FIELD NAME="shape" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="circle, rectangle, polygon" PREVIOUS="no" NEXT="coords"/>
|
||||
<FIELD NAME="coords" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" PREVIOUS="shape" NEXT="choice"/>
|
||||
<FIELD NAME="choice" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="coords"/>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="no" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="drop number"/>
|
||||
<FIELD NAME="shape" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="circle, rectangle, polygon"/>
|
||||
<FIELD NAME="coords" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="choice" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
|
||||
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="qtype_ddmarker_drags" COMMENT="Labels for markers to drag." PREVIOUS="qtype_ddmarker_drops">
|
||||
<TABLE NAME="qtype_ddmarker_drags" COMMENT="Labels for markers to drag.">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="questionid"/>
|
||||
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="no"/>
|
||||
<FIELD NAME="no" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="drag no" PREVIOUS="questionid" NEXT="label"/>
|
||||
<FIELD NAME="label" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" COMMENT="Alt text label for drag-able image." PREVIOUS="no" NEXT="infinite"/>
|
||||
<FIELD NAME="infinite" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="label"/>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="no" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="drag no"/>
|
||||
<FIELD NAME="label" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Alt text label for drag-able image."/>
|
||||
<FIELD NAME="infinite" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="noofdrags" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="No of drag items, ignored if drag is infinite."/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
|
||||
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* ddmarker question type upgrade code.
|
||||
*
|
||||
* @package qtype_ddmarker
|
||||
* @copyright 2013 The Open University
|
||||
* @author Jamie Pratt [email protected]
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Upgrade code for the ddmarker question type.
|
||||
* @param int $oldversion the version we are upgrading from.
|
||||
* @return bool
|
||||
*/
|
||||
function xmldb_qtype_ddmarker_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// Moodle v2.3.0 release upgrade line
|
||||
// Put any upgrade step following this.
|
||||
|
||||
// Moodle v2.4.0 release upgrade line
|
||||
// Put any upgrade step following this.
|
||||
|
||||
// Moodle v2.5.0 release upgrade line
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2013053000) {
|
||||
|
||||
// Define field noofdrags to be added to qtype_ddmarker_drags.
|
||||
$table = new xmldb_table('qtype_ddmarker_drags');
|
||||
$field = new xmldb_field('noofdrags', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '1', 'infinite');
|
||||
|
||||
// Conditionally launch add field noofdrags.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2013053000, 'qtype', 'ddmarker');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -86,8 +86,12 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
|
||||
array('size'=>30, 'class'=>'tweakcss'));
|
||||
$mform->setType('text', PARAM_RAW_TRIMMED);
|
||||
|
||||
$grouparray[] = $mform->createElement('checkbox', 'infinite', ' ',
|
||||
get_string('infinite', 'qtype_ddmarker'));
|
||||
$noofdragoptions = array(0 => get_string('infinite', 'qtype_ddmarker'));
|
||||
foreach (range(1, 6) as $option) {
|
||||
$noofdragoptions[$option] = $option;
|
||||
}
|
||||
$grouparray[] = $mform->createElement('select', 'noofdrags', get_string('noofdrags', 'qtype_ddmarker'), $noofdragoptions);
|
||||
|
||||
$draggableimageitem[] = $mform->createElement('group', 'drags',
|
||||
get_string('marker_n', 'qtype_ddmarker'), $grouparray);
|
||||
return $draggableimageitem;
|
||||
@@ -165,7 +169,11 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
|
||||
$dragindex = $drag->no -1;
|
||||
$question->drags[$dragindex] = array();
|
||||
$question->drags[$dragindex]['label'] = $drag->label;
|
||||
$question->drags[$dragindex]['infinite'] = $drag->infinite;
|
||||
if ($drag->infinite == 1) {
|
||||
$question->drags[$dragindex]['noofdrags'] = 0;
|
||||
} else {
|
||||
$question->drags[$dragindex]['noofdrags'] = $drag->noofdrags;
|
||||
}
|
||||
$dragids[$dragindex] = $drag->id;
|
||||
}
|
||||
$question->drops = array();
|
||||
|
||||
@@ -66,6 +66,7 @@ $string['marker'] = 'Marker';
|
||||
$string['marker_n'] = 'Marker {no}';
|
||||
$string['markers'] = 'Markers';
|
||||
$string['nolabel'] = 'No label text';
|
||||
$string['noofdrags'] = 'Number';
|
||||
$string['noquestionsfound'] = 'No questions found to convert here.';
|
||||
$string['pleasedragatleastonemarker'] = 'Your answer is not complete, you must place at least one marker on the image.';
|
||||
$string['pluginname'] = 'Drag and drop markers';
|
||||
@@ -93,4 +94,4 @@ $string['shuffleimages'] = 'Shuffle drag items each time question is attempted';
|
||||
$string['stateincorrectlyplaced'] = 'State which markers are incorrectly placed';
|
||||
$string['summariseplace'] = '{$a->no}. {$a->text}';
|
||||
$string['summariseplaceno'] = 'Drop zone {$a}';
|
||||
$string['ytop'] = 'Top';
|
||||
$string['ytop'] = 'Top';
|
||||
|
||||
@@ -403,11 +403,13 @@ class qtype_ddmarker_drag_item {
|
||||
public $text;
|
||||
public $no;
|
||||
public $infinite;
|
||||
public $noofdrags;
|
||||
|
||||
public function __construct($label, $no, $infinite) {
|
||||
public function __construct($label, $no, $infinite, $noofdrags) {
|
||||
$this->text = $label;
|
||||
$this->infinite = $infinite;
|
||||
$this->no = $no;
|
||||
$this->noofdrags = $noofdrags;
|
||||
}
|
||||
public function choice_group() {
|
||||
return 1;
|
||||
|
||||
@@ -127,7 +127,13 @@ class qtype_ddmarker extends qtype_ddtoimage_base {
|
||||
$drag = new stdClass();
|
||||
$drag->questionid = $formdata->id;
|
||||
$drag->no = $dragno + 1;
|
||||
$drag->infinite = empty($formdata->drags[$dragno]['infinite'])? 0 : 1;
|
||||
if ($formdata->drags[$dragno]['noofdrags'] == 0) {
|
||||
$drag->infinite = 1;
|
||||
$drag->noofdrags = 1;
|
||||
} else {
|
||||
$drag->infinite = 0;
|
||||
$drag->noofdrags = $formdata->drags[$dragno]['noofdrags'];
|
||||
}
|
||||
$drag->label = $formdata->drags[$dragno]['label'];
|
||||
|
||||
if (isset($olddragids[$dragno +1])) {
|
||||
@@ -229,7 +235,7 @@ class qtype_ddmarker extends qtype_ddtoimage_base {
|
||||
return question_hint_ddmarker::load_from_record($hint);
|
||||
}
|
||||
protected function make_choice($dragdata) {
|
||||
return new qtype_ddmarker_drag_item($dragdata->label, $dragdata->no, $dragdata->infinite);
|
||||
return new qtype_ddmarker_drag_item($dragdata->label, $dragdata->no, $dragdata->infinite, $dragdata->noofdrags);
|
||||
}
|
||||
|
||||
protected function make_place($dropdata) {
|
||||
@@ -296,6 +302,7 @@ class qtype_ddmarker extends qtype_ddtoimage_base {
|
||||
if ($drag->infinite) {
|
||||
$output .= " <infinite/>\n";
|
||||
}
|
||||
$output .= " <noofdrags>{$drag->no}</noofdrags>\n";
|
||||
$output .= " </drag>\n";
|
||||
}
|
||||
foreach ($question->options->drops as $drop) {
|
||||
@@ -334,8 +341,12 @@ class qtype_ddmarker extends qtype_ddtoimage_base {
|
||||
$question->drags[$dragindex] = array();
|
||||
$question->drags[$dragindex]['label'] =
|
||||
$format->getpath($dragxml, array('#', 'text', 0, '#'), '', true);
|
||||
$question->drags[$dragindex]['infinite'] = array_key_exists('infinite', $dragxml['#']);
|
||||
|
||||
if (array_key_exists('infinite', $dragxml['#'])) {
|
||||
$question->drags[$dragindex]['noofdrags'] = 0; // Means infinite in the form.
|
||||
} else {
|
||||
// Defaults to 1 if 'noofdrags' not set.
|
||||
$question->drags[$dragindex]['noofdrags'] = $format->getpath($dragxml, array('#', 'noofdrags', 0, '#'), 1);
|
||||
}
|
||||
}
|
||||
|
||||
$drops = $data['#']['drop'];
|
||||
|
||||
@@ -67,6 +67,8 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
|
||||
"choice{$choiceno}");
|
||||
if ($drag->infinite) {
|
||||
$classes[] = 'infinite';
|
||||
} else {
|
||||
$classes[] = 'dragno'.$drag->noofdrags;
|
||||
}
|
||||
$targeticonhtml =
|
||||
$OUTPUT->pix_icon('crosshairs', '', $componentname, array('class'=> 'target'));
|
||||
@@ -75,7 +77,7 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
|
||||
$markertext = html_writer::tag('span', $drag->text, $markertextattrs);
|
||||
$draghomesattrs = array('class'=>join(' ', $classes));
|
||||
$draghomes .= html_writer::tag('span', $targeticonhtml.$markertext, $draghomesattrs);
|
||||
$hiddenfields .= $this->hidden_field_choice($qa, $choiceno, $drag->infinite);
|
||||
$hiddenfields .= $this->hidden_field_choice($qa, $choiceno, $drag->infinite, $drag->noofdrags);
|
||||
}
|
||||
|
||||
$dragitemsclass = 'dragitems';
|
||||
@@ -131,9 +133,9 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base {
|
||||
$output .= html_writer::tag('div', $hiddenfields, array('class'=>'ddform'));
|
||||
return $output;
|
||||
}
|
||||
protected function hidden_field_choice(question_attempt $qa, $choiceno, $infinite, $value = null) {
|
||||
protected function hidden_field_choice(question_attempt $qa, $choiceno, $infinite, $noofdrags, $value = null) {
|
||||
$varname = 'c'.$choiceno;
|
||||
$classes = array('choices', 'choice'.$choiceno);
|
||||
$classes = array('choices', 'choice'.$choiceno, 'noofdrags'.$noofdrags);
|
||||
if ($infinite) {
|
||||
$classes[] = 'infinite';
|
||||
}
|
||||
@@ -191,4 +193,4 @@ class qtype_ddmarker_list_renderer extends plugin_renderer_base {
|
||||
}
|
||||
return html_writer::alist($children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2013052000;
|
||||
$plugin->version = 2013053000;
|
||||
$plugin->requires = 2013051400;
|
||||
$plugin->cron = 0;
|
||||
$plugin->component = 'qtype_ddmarker';
|
||||
|
||||
Vendored
+9
-3
@@ -440,13 +440,15 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Return coords of all drag items except any that are currently being dragged
|
||||
* based on contents of hidden inputs and whether drags are 'infinite'
|
||||
* Determine what drag items need to be shown and
|
||||
* return coords of all drag items except any that are currently being dragged
|
||||
* based on contents of hidden inputs and whether drags are 'infinite' or how many drags should be shown.
|
||||
*/
|
||||
get_coords : function (input) {
|
||||
var choiceno = this.get_choiceno_for_node(input);
|
||||
var fv = input.get('value');
|
||||
var infinite = input.hasClass('infinite');
|
||||
var noofdrags = this.get_noofdrags_for_node(input);
|
||||
var dragging = (null !== this.doc.drag_item_being_dragged(choiceno));
|
||||
var coords = [];
|
||||
if (fv !== '') {
|
||||
@@ -455,7 +457,8 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) {
|
||||
coords[coords.length] = this.convert_to_window_xy(coordsstrings[i].split(','));
|
||||
}
|
||||
}
|
||||
if (infinite || (!dragging && fv === '')) {
|
||||
var displayeddrags = coords.length + (dragging ? 1 : 0);
|
||||
if (infinite || (displayeddrags < noofdrags)) {
|
||||
coords[coords.length] = this.drag_home_xy(choiceno);
|
||||
}
|
||||
return coords;
|
||||
@@ -470,6 +473,9 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) {
|
||||
get_itemno_for_node : function(node) {
|
||||
return +this.doc.get_classname_numeric_suffix(node, 'item');
|
||||
},
|
||||
get_noofdrags_for_node : function(node) {
|
||||
return +this.doc.get_classname_numeric_suffix(node, 'noofdrags');
|
||||
},
|
||||
|
||||
//----------- keyboard accessibility stuff below line ---------------------
|
||||
drop_zone_key_press : function (e) {
|
||||
|
||||
+25
-7
@@ -104,6 +104,7 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) {
|
||||
dragitemsoptions[i] = Y.Escape.html(label);
|
||||
}
|
||||
}
|
||||
// Get all the currently selected drags for each drop.
|
||||
var selectedvalues = [];
|
||||
var selector;
|
||||
for (i = 0; i < this.form.get_form_value('nodropzone', []); i++) {
|
||||
@@ -112,7 +113,9 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) {
|
||||
}
|
||||
for (i = 0; i < this.form.get_form_value('nodropzone', []); i++) {
|
||||
selector = Y.one('#id_drops_'+i+'_choice');
|
||||
// Remove all options for drag choice.
|
||||
selector.all('option').remove(true);
|
||||
// And recreate the options.
|
||||
for (var value in dragitemsoptions) {
|
||||
value = +value;
|
||||
var option = '<option value="'+ value +'">'
|
||||
@@ -120,15 +123,25 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) {
|
||||
'</option>';
|
||||
selector.append(option);
|
||||
var optionnode = selector.one('option[value="' + value + '"]');
|
||||
// Is this the currently selected value?
|
||||
if (value === selectedvalues[i]) {
|
||||
optionnode.set('selected', true);
|
||||
} else {
|
||||
if (value !== 0) { // no item option is always selectable
|
||||
var infinite = this.form.get_form_value('drags', [value-1, 'infinite']);
|
||||
if (!infinite) {
|
||||
// It is not the currently selected value, is it selectable?
|
||||
if (value !== 0) { // The 'no item' option is always selectable.
|
||||
// Variables to hold form values about this drag item.
|
||||
var noofdrags = this.form.get_form_value('drags', [value-1, 'noofdrags']);
|
||||
if (noofdrags != 0) { // 'noofdrags == 0' means infinite.
|
||||
// Go through all selected values in drop downs.
|
||||
for (var k in selectedvalues) {
|
||||
// Count down 'noofdrags' and if reach zero then set disabled option for this drag item.
|
||||
if (+selectedvalues[k] === value) {
|
||||
optionnode.set('disabled', true);
|
||||
if (noofdrags == 1) {
|
||||
optionnode.set('disabled', true);
|
||||
break;
|
||||
} else {
|
||||
noofdrags--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,12 +158,17 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) {
|
||||
setup_form_events : function () {
|
||||
//events triggered by changes to form data
|
||||
|
||||
//x and y coordinates
|
||||
// Changes to labels.
|
||||
Y.all('fieldset#id_draggableitemheader input').on('change', function () {
|
||||
this.set_options_for_drag_item_selectors();
|
||||
}, this);
|
||||
|
||||
//change in selected item
|
||||
// Changes to selected drag item.
|
||||
Y.all('fieldset#id_draggableitemheader select').on('change', function () {
|
||||
this.set_options_for_drag_item_selectors();
|
||||
}, this);
|
||||
|
||||
// Change in selected item.
|
||||
Y.all('fieldset#id_dropzoneheader select').on('change', function () {
|
||||
this.set_options_for_drag_item_selectors();
|
||||
}, this);
|
||||
@@ -236,4 +254,4 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) {
|
||||
};
|
||||
}, '@VERSION@', {
|
||||
requires:['moodle-qtype_ddmarker-dd', 'form_filepicker', 'graphics', 'escape']
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user