diff --git a/course/dndupload.js b/course/dndupload.js
index 35ded979e36..b1dbc632f06 100644
--- a/course/dndupload.js
+++ b/course/dndupload.js
@@ -239,7 +239,7 @@ M.course_dndupload = {
* Look through the event data, checking it against the registered data types
* (in order of priority) and return details of the first matching data type
* @param e the event details
- * @return mixed false if not found or an object {
+ * @return object|false - false if not found or an object {
* realtype: the type as given by the browser
* addmessage: the message to show to the user during dragging
* namemessage: the message for requesting a name for the resource from the user
@@ -284,6 +284,7 @@ M.course_dndupload = {
realtype: dttypes[j],
addmessage: types[i].addmessage,
namemessage: types[i].namemessage,
+ handlermessage: types[i].handlermessage,
type: types[i].identifier,
handlers: types[i].handlers
};
@@ -417,7 +418,7 @@ M.course_dndupload = {
var modsel = section.one(this.modslistselector);
if (!modsel) {
// Create the above 'ul' if it doesn't exist
- var modsel = document.createElement('ul');
+ modsel = document.createElement('ul');
modsel.className = 'section img-text';
var contentel = section.get('children').pop();
var brel = contentel.get('children').pop();
@@ -489,6 +490,7 @@ M.course_dndupload = {
*/
hide_preview_element: function() {
this.Y.all('li.dndupload-preview').addClass('dndupload-hidden');
+ this.Y.all('.dndupload-over').removeClass('dndupload-over');
},
/**
@@ -500,7 +502,11 @@ M.course_dndupload = {
show_preview_element: function(section, type) {
this.hide_preview_element();
var preview = section.one('li.dndupload-preview').removeClass('dndupload-hidden');
- preview.one('span').setContent(type.addmessage);
+ section.addClass('dndupload-over');
+
+ // Horrible work-around to allow the 'Add X here' text to be a drop target in Firefox.
+ var node = preview.one('span').getDOMNode();
+ node.firstChild.nodeValue = type.addmessage;
},
/**
@@ -616,44 +622,16 @@ M.course_dndupload = {
var Y = this.Y;
var self = this;
- var panel = new Y.Panel({
+ var panel = new M.core.dialogue({
bodyContent: content,
- width: 350,
- zIndex: 5,
- centered: true,
+ width: '350px',
modal: true,
visible: true,
render: true,
- buttons: [{
- value: M.util.get_string('upload', 'moodle'),
- action: function(e) {
- e.preventDefault();
- // Find out which module was selected
- var module = false;
- var div = Y.one('#dndupload_handlers'+uploadid);
- div.all('input').each(function(input) {
- if (input.get('checked')) {
- module = input.get('value');
- }
- });
- if (!module) {
- return;
- }
- panel.hide();
- // Remember this selection for next time
- self.lastselected[extension] = module;
- // Do the upload
- self.upload_file(file, section, sectionnumber, module);
- },
- section: Y.WidgetStdMod.FOOTER
- },{
- value: M.util.get_string('cancel', 'moodle'),
- action: function(e) {
- e.preventDefault();
- panel.hide();
- },
- section: Y.WidgetStdMod.FOOTER
- }]
+ align: {
+ node: null,
+ points: [Y.WidgetPositionAlign.CC, Y.WidgetPositionAlign.CC]
+ }
});
// When the panel is hidden - destroy it and then check for other pending uploads
panel.after("visibleChange", function(e) {
@@ -662,6 +640,39 @@ M.course_dndupload = {
self.check_upload_queue();
}
});
+
+ // Add the submit/cancel buttons to the bottom of the dialog.
+ panel.addButton({
+ label: M.util.get_string('upload', 'moodle'),
+ action: function(e) {
+ e.preventDefault();
+ // Find out which module was selected
+ var module = false;
+ var div = Y.one('#dndupload_handlers'+uploadid);
+ div.all('input').each(function(input) {
+ if (input.get('checked')) {
+ module = input.get('value');
+ }
+ });
+ if (!module) {
+ return;
+ }
+ panel.hide();
+ // Remember this selection for next time
+ self.lastselected[extension] = module;
+ // Do the upload
+ self.upload_file(file, section, sectionnumber, module);
+ },
+ section: Y.WidgetStdMod.FOOTER
+ });
+ panel.addButton({
+ label: M.util.get_string('cancel', 'moodle'),
+ action: function(e) {
+ e.preventDefault();
+ panel.hide();
+ },
+ section: Y.WidgetStdMod.FOOTER
+ });
},
/**
@@ -822,6 +833,7 @@ M.course_dndupload = {
var nameid = 'dndupload_handler_name'+uploadid;
var content = '';
if (type.handlers.length > 1) {
+ content += '
'+type.handlermessage+'
';
content += '';
var sel = type.handlers[0].module;
for (var i=0; i 1) {
- // Find out which module was selected
- var div = Y.one('#dndupload_handlers'+uploadid);
- div.all('input').each(function(input) {
- if (input.get('checked')) {
- 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
- self.upload_item(name, type.type, contents, section, sectionnumber, module);
- },
- section: Y.WidgetStdMod.FOOTER
- },{
- value: M.util.get_string('cancel', 'moodle'),
- action: function(e) {
- e.preventDefault();
- panel.hide();
- },
- section: Y.WidgetStdMod.FOOTER
- }]
+ align: {
+ node: null,
+ points: [Y.WidgetPositionAlign.CC, Y.WidgetPositionAlign.CC]
+ }
});
+
// When the panel is hidden - destroy it and then check for other pending uploads
panel.after("visibleChange", function(e) {
if (!panel.get('visible')) {
@@ -897,19 +871,86 @@ M.course_dndupload = {
self.check_upload_queue();
}
});
- // Focus on the 'name' box
- Y.one('#'+nameid).focus();
+
+ var namefield = Y.one('#'+nameid);
+ var submit = function(e) {
+ e.preventDefault();
+ var name = Y.Lang.trim(namefield.get('value'));
+ 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')) {
+ 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;
+ }
+ if (noname) {
+ name = '';
+ }
+ panel.hide();
+ // Do the upload
+ self.upload_item(name, type.type, contents, section, sectionnumber, module);
+ };
+
+ // Add the submit/cancel buttons to the bottom of the dialog.
+ panel.addButton({
+ label: M.util.get_string('upload', 'moodle'),
+ action: submit,
+ section: Y.WidgetStdMod.FOOTER,
+ name: 'submit'
+ });
+ panel.addButton({
+ label: M.util.get_string('cancel', 'moodle'),
+ action: function(e) {
+ e.preventDefault();
+ panel.hide();
+ },
+ section: Y.WidgetStdMod.FOOTER
+ });
+ var submitbutton = panel.getButton('submit').button;
+ namefield.on('key', submit, 'enter'); // Submit the form if 'enter' pressed
+ namefield.after('keyup', function() {
+ if (Y.Lang.trim(namefield.get('value')) == '') {
+ submitbutton.disable();
+ } else {
+ submitbutton.enable();
+ }
+ });
+
+ // Enable / disable the 'name' box, depending on the handler selected.
for (i=0; i array('node', 'event', 'panel', 'json', 'anim')
+ 'requires' => array('node', 'event', 'json', 'anim')
);
$vars = array(
array('courseid' => $course->id,
@@ -112,12 +112,12 @@ class dndupload_handler {
// Add some default types to handle.
// Note: 'Files' type is hard-coded into the Javascript as this needs to be ...
// ... treated a little differently.
- $this->add_type('url', array('url', 'text/uri-list', 'text/x-moz-url'), get_string('addlinkhere', 'moodle'),
- get_string('nameforlink', 'moodle'), 10);
- $this->add_type('text/html', array('text/html'), get_string('addpagehere', 'moodle'),
- get_string('nameforpage', 'moodle'), 20);
- $this->add_type('text', array('text', 'text/plain'), get_string('addpagehere', 'moodle'),
- get_string('nameforpage', 'moodle'), 30);
+ $this->add_type_internal('url', array('url', 'text/uri-list', 'text/x-moz-url'), get_string('addlinkhere', 'moodle'),
+ get_string('nameforlink', 'moodle'), get_string('whatforlink', 'moodle'), 10);
+ $this->add_type_internal('text/html', array('text/html'), get_string('addpagehere', 'moodle'),
+ get_string('nameforpage', 'moodle'), get_string('whatforpage', 'moodle'), 20);
+ $this->add_type_internal('text', array('text', 'text/plain'), get_string('addpagehere', 'moodle'),
+ get_string('nameforpage', 'moodle'), get_string('whatforpage', 'moodle'), 30);
// Loop through all modules to find handlers.
$mods = get_plugin_list_with_function('mod', 'dndupload_register');
@@ -145,8 +145,11 @@ class dndupload_handler {
} else {
$priority = 100;
}
- $this->add_type($type['identifier'], $type['datatransfertypes'],
- $type['addmessage'], $type['namemessage'], $priority);
+ if (!isset($type['handlermessage'])) {
+ $type['handlermessage'] = '';
+ }
+ $this->add_type_internal($type['identifier'], $type['datatransfertypes'],
+ $type['addmessage'], $type['namemessage'], $type['handlermessage'], $priority);
}
}
if (isset($resp['types'])) {
@@ -158,6 +161,21 @@ class dndupload_handler {
}
}
+ /**
+ * No external code should be directly adding new types - they should be added via a 'addtypes' array, returned
+ * by MODNAME_dndupload_register.
+ *
+ * @deprecated deprecated since Moodle 2.5
+ * @param string $identifier
+ * @param array $datatransfertypes
+ * @param string $addmessage
+ * @param string $namemessage
+ * @param int $priority
+ */
+ public function add_type($identifier, $datatransfertypes, $addmessage, $namemessage, $priority=100) {
+ $this->add_type_internal($identifier, $datatransfertypes, $addmessage, $namemessage, '', $priority);
+ }
+
/**
* Used to add a new mime type that can be drag and dropped onto a
* course displayed in a browser window
@@ -169,10 +187,11 @@ class dndupload_handler {
* dragged onto the page
* @param string $namemessage The message to pop up when asking for the name to give the
* course module instance when it is created
+ * @param string $handlermessage The message to pop up when asking which module should handle this type
* @param int $priority Controls the order in which types are checked by the browser (mainly
* needed to check for 'text' last as that is usually given as fallback)
*/
- public function add_type($identifier, $datatransfertypes, $addmessage, $namemessage, $priority=100) {
+ protected function add_type_internal($identifier, $datatransfertypes, $addmessage, $namemessage, $handlermessage, $priority=100) {
if ($this->is_known_type($identifier)) {
throw new coding_exception("Type $identifier is already registered");
}
@@ -182,6 +201,7 @@ class dndupload_handler {
$add->datatransfertypes = $datatransfertypes;
$add->addmessage = $addmessage;
$add->namemessage = $namemessage;
+ $add->handlermessage = $handlermessage;
$add->priority = $priority;
$add->handlers = array();
diff --git a/lang/en/moodle.php b/lang/en/moodle.php
index 46237a90999..fe13216d6b8 100644
--- a/lang/en/moodle.php
+++ b/lang/en/moodle.php
@@ -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 text?';
+$string['nameforpage'] = 'Name';
$string['navigation'] = 'Navigation';
$string['needed'] = 'Needed';
$string['never'] = 'Never';
@@ -1806,6 +1806,8 @@ $string['welcometocoursetext'] = 'Welcome to {$a->coursename}!
If you have not done so already, you should edit your profile page so that we can learn more about you:
{$a->profileurl}';
+$string['whatforlink'] = 'What do you want to do with the link?';
+$string['whatforpage'] = 'What do you want to do with the text?';
$string['whattocallzip'] = 'What do you want to call the zip file?';
$string['whattodo'] = 'What to do';
$string['windowclosing'] = 'This window should close automatically. If not, please close it now.';
diff --git a/mod/label/lang/en/label.php b/mod/label/lang/en/label.php
index 55787fcadb5..5731413cea0 100644
--- a/mod/label/lang/en/label.php
+++ b/mod/label/lang/en/label.php
@@ -31,7 +31,7 @@ $string['dndmedia'] = 'Media drag and drop';
$string['dndresizeheight'] = 'Resize drag and drop height';
$string['dndresizewidth'] = 'Resize drag and drop width';
$string['dnduploadlabel'] = 'Add image to course page';
-$string['dnduploadlabeltext'] = 'Add text to course page';
+$string['dnduploadlabeltext'] = 'Add a label to the course page';
$string['label:addinstance'] = 'Add a new label';
$string['labeltext'] = 'Label text';
$string['modulename'] = 'Label';
diff --git a/mod/page/lang/en/page.php b/mod/page/lang/en/page.php
index 3dd3d3c6fb5..d7fbf9a6495 100644
--- a/mod/page/lang/en/page.php
+++ b/mod/page/lang/en/page.php
@@ -26,7 +26,7 @@
$string['configdisplayoptions'] = 'Select all options that should be available, existing settings are not modified. Hold CTRL key to select multiple fields.';
$string['content'] = 'Page content';
$string['contentheader'] = 'Content';
-$string['createpage'] = 'Create a new page';
+$string['createpage'] = 'Create a new page resource';
$string['displayoptions'] = 'Available display options';
$string['displayselect'] = 'Display';
$string['displayselectexplain'] = 'Select display type.';