Skip to content

Commit

Permalink
MDL-33946 course dndupload - fixes to dialog when dragging text
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
davosmith committed Mar 6, 2013
1 parent 5efae68 commit 2748d8e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
39 changes: 31 additions & 8 deletions course/dndupload.js
Expand Up @@ -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;
Expand All @@ -814,21 +821,22 @@ M.course_dndupload = {
var uploadid = Math.round(Math.random()*100000)+'-'+timestamp;
var nameid = 'dndupload_handler_name'+uploadid;
var content = '';
content += '<label for="'+nameid+'">'+type.namemessage+'</label>';
content += ' <input type="text" id="'+nameid+'" value="" />';
if (type.handlers.length > 1) {
content += '<div id="dndupload_handlers'+uploadid+'">';
var sel = type.handlers[0].module;
for (var i=0; i<type.handlers.length; i++) {
var id = 'dndupload_handler'+uploadid;
var id = 'dndupload_handler'+uploadid+type.handlers[i].module;
var checked = (type.handlers[i].module == sel) ? 'checked="checked" ' : '';
content += '<input type="radio" name="handler" value="'+type.handlers[i].module+'" id="'+id+'" '+checked+'/>';
content += '<input type="radio" name="handler" value="'+i+'" id="'+id+'" '+checked+'/>';
content += ' <label for="'+id+'">';
content += type.handlers[i].message;
content += '</label><br/>';
}
content += '</div>';
}
var disabled = (type.handlers[0].noname) ? ' disabled = "disabled" ' : '';
content += '<label for="'+nameid+'">'+type.namemessage+'</label>';
content += ' <input type="text" id="'+nameid+'" value="" '+disabled+' />';

var Y = this.Y;
var self = this;
Expand All @@ -846,23 +854,27 @@ 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) {
return;
}
} else {
module = type.handlers[0].module;
noname = type.handlers[0].noname;
}
if (name == '' && !noname) {
return;
}
panel.hide();
// Do the upload
Expand All @@ -887,6 +899,17 @@ M.course_dndupload = {
});
// Focus on the 'name' box
Y.one('#'+nameid).focus();
for (i=0; i<type.handlers.length; i++) {
if (type.handlers[i].noname) {
Y.one('#dndupload_handler'+uploadid+type.handlers[i].module).on('click', function (e) {
Y.one('#'+nameid).set('disabled', 'disabled');
});
} else {
Y.one('#dndupload_handler'+uploadid+type.handlers[i].module).on('click', function (e) {
Y.one('#'+nameid).removeAttribute('disabled');
});
}
}
},

/**
Expand Down
8 changes: 6 additions & 2 deletions course/dnduploadlib.php
Expand Up @@ -151,7 +151,8 @@ public function __construct($course, $modnames = null) {
}
if (isset($resp['types'])) {
foreach ($resp['types'] as $type) {
$this->add_type_handler($type['identifier'], $modname, $type['message']);
$noname = !empty($type['noname']);
$this->add_type_handler($type['identifier'], $modname, $type['message'], $noname);
}
}
}
Expand Down Expand Up @@ -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");
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lang/en/moodle.php
Expand Up @@ -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}\'';
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions mod/label/lib.php
Expand Up @@ -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)
)));
}

Expand Down

0 comments on commit 2748d8e

Please sign in to comment.