Merge branch 'MDL-33946_label_dndupload_text' of git://github.com/davosmith/moodle
This commit is contained in:
+31
-8
@@ -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 += '<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;
|
||||
@@ -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; 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');
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,8 @@ class dndupload_handler {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,8 +196,10 @@ class dndupload_handler {
|
||||
* @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 @@ class dndupload_handler {
|
||||
$add->type = $type;
|
||||
$add->module = $module;
|
||||
$add->message = $message;
|
||||
$add->noname = $noname ? 1 : 0;
|
||||
|
||||
$this->types[$type]->handlers[] = $add;
|
||||
}
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ $string['addnewcategory'] = 'Add new category';
|
||||
$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['mymoodledashboard'] = 'My Moodle dashboard';
|
||||
$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';
|
||||
|
||||
+2
-2
@@ -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)
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user