Skip to content

Commit

Permalink
MDL-47494 ddimageortext: NOBUG added select drag item type selector a…
Browse files Browse the repository at this point in the history
…nd js code to hide the filepicker.
  • Loading branch information
jamiepratt committed Sep 9, 2011
1 parent 1a17df8 commit 42167fc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
39 changes: 31 additions & 8 deletions question/type/ddimageortext/edit_ddimagetoimage_form.php
Expand Up @@ -151,9 +151,9 @@ protected function drop_zone($mform, $imagerepeats) {
$options[$i] = $i;
}
$grouparray[] = $mform->createElement('static', '', '', ' ' .
get_string('draggableimage', 'qtype_ddimagetoimage').' ');
get_string('draggableitem', 'qtype_ddimagetoimage').' ');
$grouparray[] = $mform->createElement('select', 'choice',
get_string('draggableimage', 'qtype_ddimagetoimage'), $options);
get_string('draggableitem', 'qtype_ddimagetoimage'), $options);
$grouparray[] = $mform->createElement('static', '', '', ' ' .
get_string('label', 'qtype_ddimagetoimage').' ');
$grouparray[] = $mform->createElement('text', 'droplabel',
Expand Down Expand Up @@ -182,10 +182,16 @@ protected function definition_draggable_images($mform, $imagerepeatsatstart) {
protected function draggable_image($mform) {
$draggableimageitem = array();

$draggableimageitem[] = $mform->createElement('header', 'draggableimageheader',
get_string('draggableimageheader', 'qtype_ddimagetoimage', '{no}'));
$draggableimageitem[] = $mform->createElement('header', 'draggableitemheader',
get_string('draggableitemheader', 'qtype_ddimagetoimage', '{no}'));
$dragitemtypes = array(0 => get_string('draggableimage', 'qtype_ddimagetoimage'),
1 => get_string('draggableword', 'qtype_ddimagetoimage'));
$draggableimageitem[] = $mform->createElement('select', 'dragitemtype',
get_string('draggableitemtype', 'qtype_ddimagetoimage'),
$dragitemtypes,
array('class' => 'dragitemtype'));
$draggableimageitem[] = $mform->createElement('filepicker', 'dragitem', '', null,
self::file_picker_options());
self::file_picker_options());

$grouparray = array();
$grouparray[] = $mform->createElement('text', 'draglabel',
Expand All @@ -199,7 +205,9 @@ protected function draggable_image($mform) {
$grouparray[] = $mform->createElement('static', '', '', ' ' .
get_string('group', 'qtype_gapselect').' ');
$grouparray[] = $mform->createElement('select', 'draggroup',
get_string('group', 'qtype_gapselect'), $options);
get_string('group', 'qtype_gapselect'),
$options,
array('class' => 'draggroup'));
$grouparray[] = $mform->createElement('advcheckbox', 'infinite', ' ',
get_string('infinite', 'qtype_ddimagetoimage'));
$draggableimageitem[] = $mform->createElement('group', 'drags',
Expand Down Expand Up @@ -260,7 +268,22 @@ public function data_preprocessing($question) {
'dragimage', $itemid, self::file_picker_options());
$question->dragitem[$imageindex] = $draftitemid;
}

if (!empty($question->options)) {
foreach ($question->options->drags as $drag) {
$dragindex = $drag->no -1;
if (!isset($draftitemids[$dragindex])) {
$fileexists = false;
} else {
$fileexists = self::file_uploaded($draftitemids[$dragindex]);
}
$labelexists = $question->drags[$dragindex]['draglabel'];
if ($labelexists && !$fileexists) {
$question->dragitemtype[$dragindex] = 1;
} else {
$question->dragitemtype[$dragindex] = 0;
}
}
}
$maxsizes =new stdClass();
$maxsizes->bgimage = new stdClass();
$maxsizes->bgimage->width = QTYPE_DDIMAGETOIMAGE_BGIMAGE_MAXWIDTH;
Expand All @@ -275,7 +298,7 @@ public function data_preprocessing($question) {
$PAGE->requires->yui_module('moodle-qtype_ddimagetoimage-form',
'M.qtype_ddimagetoimage.init_form',
array($params));
//$PAGE->requires->css('/lib/yui/3.4.0/build/csscssfonts/fonts-context-min.css');
$PAGE->requires->css('/lib/yui/3.2.0/build/cssfonts/fonts-context-min.css');

return $question;
}
Expand Down
7 changes: 5 additions & 2 deletions question/type/ddimageortext/lang/en/qtype_ddimagetoimage.php
Expand Up @@ -31,8 +31,11 @@
$string['ddimagetoimage'] = 'Drag and drop: images onto image';
$string['ddimagetoimage_help'] = 'Select a background image file, select draggable images and define the drop zones on the background image to which they must be dragged.';
$string['ddimagetoimagesummary'] = 'Images are dragged and dropped into drop zones on a background image.';
$string['draggableimage'] = 'Draggable item';
$string['draggableimageheader'] = 'Draggable item {$a}';
$string['draggableimage'] = 'Draggable image';
$string['draggableitem'] = 'Draggable item';
$string['draggableitemheader'] = 'Draggable item {$a}';
$string['draggableitemtype'] = 'Type';
$string['draggableword'] = 'Draggable word';
$string['dropzone'] = 'Drop zone {$a}';
$string['dropzoneheader'] = 'Drop zones';
$string['editingddimagetoimage'] = 'Editing drag and drop: images onto image';
Expand Down
26 changes: 22 additions & 4 deletions question/type/ddimageortext/yui/form/form.js
Expand Up @@ -45,6 +45,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) {
} else {
this.setup_form_events();
}
this.update_visibility_of_file_pickers();
},

after_all_images_loaded : function () {
Expand Down Expand Up @@ -119,7 +120,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) {
optionnode.set('selected', true);
} else {
if (value !== 0) { // no image option is always selectable
var cbselector = 'fieldset#draggableimageheader_'+(value-1)
var cbselector = 'fieldset#draggableitemheader_'+(value-1)
+' input[type="checkbox"]';
var cbel = Y.one(cbselector);
var infinite = cbel.get('checked');
Expand Down Expand Up @@ -159,17 +160,22 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) {

for (var i=0; i < this.form.get_form_value('noimages', []); i++) {
//change to group selector
Y.all('fieldset#draggableimageheader_'+i+' select').on('change', function (e){
Y.all('fieldset#draggableitemheader_'+i+' select.draggroup')
.on('change', function (e){
this.doc.drag_images().remove(true);
this.draw_dd_area();
}, this);
Y.all('fieldset#draggableimageheader_'+i+' input[type="text"]')
Y.all('fieldset#draggableitemheader_'+i+' select.dragitemtype')
.on('change', function (e){
this.update_visibility_of_file_pickers();
}, this);
Y.all('fieldset#draggableitemheader_'+i+' input[type="text"]')
.on('blur', function (e){
this.doc.drag_images().remove(true);
this.draw_dd_area();
}, this);
//change to infinite checkbox
Y.all('fieldset#draggableimageheader_'+i+' input[type="checkbox"]')
Y.all('fieldset#draggableitemheader_'+i+' input[type="checkbox"]')
.on('change', this.set_options_for_drag_image_selectors, this);
}
//event on file picker new file selection
Expand All @@ -182,6 +188,18 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) {
}, M.form_filepicker, 'callback', this);
},

update_visibility_of_file_pickers : function() {
for (var i=0; i < this.form.get_form_value('noimages', []); i++) {
if ('0' === this.form.get_form_value('dragitemtype', [i])) {
Y.one('input#id_dragitem_'+i).get('parentNode').get('parentNode')
.setStyle('display', 'block');
} else {
Y.one('input#id_dragitem_'+i).get('parentNode').get('parentNode')
.setStyle('display', 'none');
}
}
},

reposition_drags_for_form : function() {
this.doc.drag_images().each(function (drag) {
var draginstanceno = drag.getData('draginstanceno');
Expand Down

0 comments on commit 42167fc

Please sign in to comment.