From 2748d8efdb55248e32b51b0aca487fc535162276 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Wed, 6 Mar 2013 22:38:01 +0000 Subject: [PATCH] MDL-33946 course dndupload - fixes to dialog when dragging text Radio buttons have unique IDs, matching the label IDs 'What do you want to call this text' input moved down and disabled when 'label' selected 'Add page here' changed to 'Add text here' --- course/dndupload.js | 39 +++++++++++++++++++++++++++++++-------- course/dnduploadlib.php | 8 ++++++-- lang/en/moodle.php | 4 ++-- mod/label/lib.php | 4 ++-- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/course/dndupload.js b/course/dndupload.js index 291583c55a706..35ded979e3646 100644 --- a/course/dndupload.js +++ b/course/dndupload.js @@ -798,6 +798,13 @@ M.course_dndupload = { return; } + if (type.handlers.length == 1 && type.handlers[0].noname) { + // Only one handler and it doesn't need a name (i.e. a label). + this.upload_item('', type.type, contents, section, sectionnumber, type.handlers[0].module); + this.check_upload_queue(); + return; + } + if (this.uploaddialog) { var details = new Object(); details.isfile = false; @@ -814,21 +821,22 @@ M.course_dndupload = { var uploadid = Math.round(Math.random()*100000)+'-'+timestamp; var nameid = 'dndupload_handler_name'+uploadid; var content = ''; - content += ''; - content += ' '; if (type.handlers.length > 1) { content += '
'; var sel = type.handlers[0].module; for (var i=0; i'; + content += ''; content += '
'; } content += '
'; } + var disabled = (type.handlers[0].noname) ? ' disabled = "disabled" ' : ''; + content += ''; + content += ' '; var Y = this.Y; var self = this; @@ -846,16 +854,16 @@ M.course_dndupload = { e.preventDefault(); var name = Y.one('#dndupload_handler_name'+uploadid).get('value'); name = name.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); // Trim - if (name == '') { - return; - } var module = false; + var noname = false; if (type.handlers.length > 1) { // Find out which module was selected var div = Y.one('#dndupload_handlers'+uploadid); div.all('input').each(function(input) { if (input.get('checked')) { - module = input.get('value'); + var idx = input.get('value'); + module = type.handlers[idx].module; + noname = type.handlers[idx].noname; } }); if (!module) { @@ -863,6 +871,10 @@ M.course_dndupload = { } } else { module = type.handlers[0].module; + noname = type.handlers[0].noname; + } + if (name == '' && !noname) { + return; } panel.hide(); // Do the upload @@ -887,6 +899,17 @@ M.course_dndupload = { }); // Focus on the 'name' box Y.one('#'+nameid).focus(); + for (i=0; iadd_type_handler($type['identifier'], $modname, $type['message']); + $noname = !empty($type['noname']); + $this->add_type_handler($type['identifier'], $modname, $type['message'], $noname); } } } @@ -195,8 +196,10 @@ public function add_type($identifier, $datatransfertypes, $addmessage, $namemess * @param string $module The name of the module to handle this type * @param string $message The message to show the user if more than one handler is registered * for a type and the user needs to make a choice between them + * @param bool $noname If true, the 'name' dialog should be disabled in the pop-up. + * @throws coding_exception */ - public function add_type_handler($type, $module, $message) { + public function add_type_handler($type, $module, $message, $noname) { if (!$this->is_known_type($type)) { throw new coding_exception("Trying to add handler for unknown type $type"); } @@ -205,6 +208,7 @@ public function add_type_handler($type, $module, $message) { $add->type = $type; $add->module = $module; $add->message = $message; + $add->noname = $noname ? 1 : 0; $this->types[$type]->handlers[] = $add; } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 93361fe8571ff..eb847566386d5 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -65,7 +65,7 @@ $string['addnewcourse'] = 'Add a new course'; $string['addnewuser'] = 'Add a new user'; $string['addnousersrecip'] = 'Add users who haven\'t accessed this {$a} to recipient list'; -$string['addpagehere'] = 'Add page here'; +$string['addpagehere'] = 'Add text here'; $string['addresource'] = 'Add a resource...'; $string['addresourceoractivity'] = 'Add an activity or resource'; $string['addresourcetosection'] = 'Add a resource to section \'{$a}\''; @@ -1097,7 +1097,7 @@ $string['myprofile'] = 'My profile'; $string['name'] = 'Name'; $string['nameforlink'] = 'What do you want to call this link?'; -$string['nameforpage'] = 'What do you want to call this page?'; +$string['nameforpage'] = 'What do you want to call this text?'; $string['navigation'] = 'Navigation'; $string['needed'] = 'Needed'; $string['never'] = 'Never'; diff --git a/mod/label/lib.php b/mod/label/lib.php index 64208d4bd9460..b9149050b828a 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -222,8 +222,8 @@ function label_dndupload_register() { $strdndtext = get_string('dnduploadlabeltext', 'mod_label'); return array_merge($ret, array('types' => array( - array('identifier' => 'text/html', 'message' => $strdndtext), - array('identifier' => 'text', 'message' => $strdndtext) + array('identifier' => 'text/html', 'message' => $strdndtext, 'noname' => true), + array('identifier' => 'text', 'message' => $strdndtext, 'noname' => true) ))); }