* @param section the DOM element reperesenting the course section
* @return DOM element containing the new item
*/
- add_resource_element: function(name, section) {
+ add_resource_element: function(name, section, module) {
var modsel = this.get_mods_element(section);
var resel = {
progress: document.createElement('span')
};
- resel.li.className = 'activity resource modtype_resource';
+ resel.li.className = 'activity ' + module + ' modtype_' + module;
resel.indentdiv.className = 'mod-indent';
resel.li.appendChild(resel.indentdiv);
}
// Add the file to the display
- var resel = this.add_resource_element(file.name, section);
+ var resel = this.add_resource_element(file.name, section, module);
// Update the progress bar as the file is uploaded
xhr.upload.addEventListener('progress', function(e) {
if (result) {
if (result.error == 0) {
// All OK - update the dummy element
- resel.icon.src = result.icon;
- resel.a.href = result.link;
- resel.namespan.innerHTML = result.name;
- if (!parseInt(result.visible, 10)) {
- resel.a.className = 'dimmed';
- }
-
- if (result.groupingname) {
- resel.groupingspan.innerHTML = '(' + result.groupingname + ')';
+ if (result.content) {
+ // A label
+ resel.indentdiv.innerHTML = '<div class="activityinstance" ></div>' + result.content + result.commands;
} else {
- resel.div.removeChild(resel.groupingspan);
+ // Not a label
+ resel.icon.src = result.icon;
+ resel.a.href = result.link;
+ resel.namespan.innerHTML = result.name;
+
+ if (!parseInt(result.visible, 10)) {
+ resel.a.className = 'dimmed';
+ }
+
+ if (result.groupingname) {
+ resel.groupingspan.innerHTML = '(' + result.groupingname + ')';
+ } else {
+ resel.div.removeChild(resel.groupingspan);
+ }
+
+ resel.div.removeChild(resel.progressouter);
+ resel.indentdiv.innerHTML += result.commands;
+ if (result.onclick) {
+ resel.a.onclick = result.onclick;
+ }
+ if (self.Y.UA.gecko > 0) {
+ // Fix a Firefox bug which makes sites with a '~' in their wwwroot
+ // log the user out when clicking on the link (before refreshing the page).
+ resel.div.innerHTML = unescape(resel.div.innerHTML);
+ }
}
-
- resel.div.removeChild(resel.progressouter);
resel.li.id = result.elementid;
- resel.indentdiv.innerHTML += result.commands;
- if (result.onclick) {
- resel.a.onclick = result.onclick;
- }
- if (self.Y.UA.gecko > 0) {
- // Fix a Firefox bug which makes sites with a '~' in their wwwroot
- // log the user out when clicking on the link (before refreshing the page).
- resel.div.innerHTML = unescape(resel.div.innerHTML);
- }
self.add_editing(result.elementid);
} else {
// Error - remove the dummy element
var self = this;
// Add the item to the display
- var resel = this.add_resource_element(name, section);
+ var resel = this.add_resource_element(name, section, module);
// Wait for the AJAX call to complete, then update the
// dummy element with the returned details
if (result) {
if (result.error == 0) {
// All OK - update the dummy element
- resel.icon.src = result.icon;
- resel.a.href = result.link;
- resel.namespan.innerHTML = result.name;
- if (!parseInt(result.visible, 10)) {
- resel.a.className = 'dimmed';
- }
-
- if (result.groupingname) {
- resel.groupingspan.innerHTML = '(' + result.groupingname + ')';
+ if (result.content) {
+ // A label
+ resel.indentdiv.innerHTML = '<div class="activityinstance" ></div>' + result.content + result.commands;
} else {
- resel.div.removeChild(resel.groupingspan);
+ // Not a label
+ resel.icon.src = result.icon;
+ resel.a.href = result.link;
+ resel.namespan.innerHTML = result.name;
+
+ if (!parseInt(result.visible, 10)) {
+ resel.a.className = 'dimmed';
+ }
+
+ if (result.groupingname) {
+ resel.groupingspan.innerHTML = '(' + result.groupingname + ')';
+ } else {
+ resel.div.removeChild(resel.groupingspan);
+ }
+
+ resel.div.removeChild(resel.progressouter);
+ resel.div.innerHTML += result.commands;
+ if (result.onclick) {
+ resel.a.onclick = result.onclick;
+ }
+ if (self.Y.UA.gecko > 0) {
+ // Fix a Firefox bug which makes sites with a '~' in their wwwroot
+ // log the user out when clicking on the link (before refreshing the page).
+ resel.div.innerHTML = unescape(resel.div.innerHTML);
+ }
}
-
- resel.div.removeChild(resel.progressouter);
resel.li.id = result.elementid;
- resel.div.innerHTML += result.commands;
- if (result.onclick) {
- resel.a.onclick = result.onclick;
- }
- if (self.Y.UA.gecko > 0) {
- // Fix a Firefox bug which makes sites with a '~' in their wwwroot
- // log the user out when clicking on the link (before refreshing the page).
- resel.div.innerHTML = unescape(resel.div.innerHTML);
- }
self.add_editing(result.elementid, sectionnumber);
} else {
// Error - remove the dummy element
}
}
+/**
+ * Register the ability to handle drag and drop file uploads
+ * @return array containing details of the files / types the mod can handle
+ */
+function label_dndupload_register() {
+ if (get_config('label', 'dndmedia')) {
+ $mediaextensions = file_get_typegroup('extension', 'web_image');
+ $strdnd = get_string('dnduploadlabel', 'mod_label');
+ $files = array();
+ foreach ($mediaextensions as $extn) {
+ $extn = trim($extn, '.');
+ $files[] = array('extension' => $extn, 'message' => $strdnd);
+ }
+ return array('files' => $files);
+ } else {
+ return array();
+ }
+}
+
+/**
+ * Handle a file that has been uploaded
+ * @param object $uploadinfo details of the file / content that has been uploaded
+ * @return int instance id of the newly created mod
+ */
+function label_dndupload_handle($uploadinfo) {
+ global $USER;
+
+ // Gather the required info.
+ $data = new stdClass();
+ $data->course = $uploadinfo->course->id;
+ $data->name = $uploadinfo->displayname;
+ $data->intro = '';
+ $data->introformat = FORMAT_HTML;
+ $data->coursemodule = $uploadinfo->coursemodule;
+
+ if (!empty($uploadinfo->draftitemid)) {
+ $fs = get_file_storage();
+ $draftcontext = context_user::instance($USER->id);
+ $context = context_module::instance($uploadinfo->coursemodule);
+ $files = $fs->get_area_files($draftcontext->id, 'user', 'draft', $uploadinfo->draftitemid, '', false);
+ if ($file = reset($files)) {
+ $filelink = moodle_url::make_draftfile_url($uploadinfo->draftitemid, $file->get_filepath(), $file->get_filename());
+ if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) {
+ $data->intro = html_writer::empty_tag('img', array('src' => $filelink, 'alt' => $file->get_filename()));
+ $data->intro = file_save_draft_area_files($uploadinfo->draftitemid, $context->id, 'mod_label', 'intro', 0,
+ null, $data->intro);
+ }
+ }
+ }
+
+ return label_add_instance($data, null);
+}
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Resource module admin settings and defaults
+ *
+ * @package mod_label
+ * @copyright 2013 Davo Smith, Synergy Learning
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+if ($ADMIN->fulltree) {
+ $settings->add(new admin_setting_configcheckbox('label/dndmedia',
+ get_string('dndmedia', 'mod_label'), get_string('configdndmedia', 'mod_label'), 1));
+}