diff --git a/course/format/topics/format.php b/course/format/topics/format.php index b8ce8f2286241..d1cacdd15d1d4 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -55,8 +55,8 @@ $editing = $PAGE->user_is_editing(); if ($editing) { - $strtopichide = get_string('hidetopicfromothers'); - $strtopicshow = get_string('showtopicfromothers'); + $strtopichide = get_string('hidefromothers', 'format_topics'); + $strtopicshow = get_string('showfromothers', 'format_topics'); $strmarkthistopic = get_string('markthistopic'); $strmarkedthistopic = get_string('markedthistopic'); $strmoveup = get_string('moveup'); @@ -189,16 +189,16 @@ if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) { if ($course->marker == $section) { // Show the "light globe" on/off - echo ''.''.$strmarkedthistopic.'
'; + echo ''.''.$strmarkedthistopic.'
'; } else { - echo ''.''.$strmarkthistopic.'
'; + echo ''.''.$strmarkthistopic.'
'; } if ($thissection->visible) { // Show the hide/show eye - echo ''. + echo ''. ''.$strtopichide.'
'; } else { - echo ''. + echo ''. ''.$strtopicshow.'
'; } if ($section > 1) { // Add a arrow to move section up diff --git a/course/format/topics/lang/en/format_topics.php b/course/format/topics/lang/en/format_topics.php index fed2cefc9c5c9..2a62a7a4c3dc0 100644 --- a/course/format/topics/lang/en/format_topics.php +++ b/course/format/topics/lang/en/format_topics.php @@ -28,3 +28,5 @@ $string['section0name'] = 'General'; $string['page-course-view-topics'] = 'Any course main page in topics format'; $string['page-course-view-topics-x'] = 'Any course page in topics format'; +$string['hidefromothers'] = 'Hide topic'; +$string['showfromothers'] = 'Show topic'; diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index c5c78faf139ed..091ad1885514d 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -47,8 +47,8 @@ $editing = $PAGE->user_is_editing(); if ($editing) { - $strweekhide = get_string('hideweekfromothers'); - $strweekshow = get_string('showweekfromothers'); + $strweekhide = get_string('hidefromothers', 'format_topics'); + $strweekshow = get_string('showfromothers', 'format_topics'); $strmoveup = get_string('moveup'); $strmovedown = get_string('movedown'); } @@ -194,10 +194,10 @@ if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) { if ($thissection->visible) { // Show the hide/show eye - echo ''. + echo ''. ''.$strweekhide.'
'; } else { - echo ''. + echo ''. ''.$strweekshow.'
'; } if ($section > 1) { // Add a arrow to move section up diff --git a/course/format/weeks/lang/en/format_weeks.php b/course/format/weeks/lang/en/format_weeks.php index 87c52aa9c4a46..02de087623b8b 100644 --- a/course/format/weeks/lang/en/format_weeks.php +++ b/course/format/weeks/lang/en/format_weeks.php @@ -28,3 +28,5 @@ $string['section0name'] = 'General'; $string['page-course-view-weeks'] = 'Any course main page in weeks format'; $string['page-course-view-weeks-x'] = 'Any course page in weeks format'; +$string['hidefromothers'] = 'Hide week'; +$string['showfromothers'] = 'Show week'; diff --git a/course/lib.php b/course/lib.php index 42edb6a256244..91e31bdb74448 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1355,10 +1355,16 @@ function course_set_marker($courseid, $marker) { /** * For a given course section, marks it visible or hidden, * and does the same for every activity in that section + * + * @param int $courseid course id + * @param int $sectionnumber The section number to adjust + * @param int $visibility The new visibility + * @return array A list of resources which were hidden in the section */ function set_section_visible($courseid, $sectionnumber, $visibility) { global $DB; + $resourcestotoggle = array(); if ($section = $DB->get_record("course_sections", array("course"=>$courseid, "section"=>$sectionnumber))) { $DB->set_field("course_sections", "visible", "$visibility", array("id"=>$section->id)); if (!empty($section->sequence)) { @@ -1368,7 +1374,19 @@ function set_section_visible($courseid, $sectionnumber, $visibility) { } } rebuild_course_cache($courseid); + + // Determine which modules are visible for AJAX update + if (!empty($modules)) { + list($insql, $params) = $DB->get_in_or_equal($modules); + $select = 'id ' . $insql . ' AND visible = ?'; + array_push($params, $visibility); + if (!$visibility) { + $select .= ' AND visibleold = 1'; + } + $resourcestotoggle = $DB->get_fieldset_select('course_modules', 'id', $select, $params); + } } + return $resourcestotoggle; } /** @@ -4386,3 +4404,97 @@ function course_page_type_list($pagetype, $parentcontext, $currentcontext) { ); } } + +/** + * Include the relevant javascript and language strings for the resource + * toolbox YUI module + * + * @param integer $id The ID of the course being applied to + * @param array $modules An array containing the names of the modules in + * use on the page + * @param object $config An object containing configuration parameters for ajax modules including: + * * resourceurl The URL to post changes to for resource changes + * * sectionurl The URL to post changes to for section changes + * * pageparams Additional parameters to pass through in the post + * @return void + */ +function include_course_ajax($course, $modules = array(), $config = null) { + global $PAGE, $CFG, $USER; + + // Ensure that ajax should be included + $courseformatajaxsupport = course_format_ajax_support($course->format); + if (!$CFG->enablecourseajax + || !$PAGE->theme->enablecourseajax + || !$CFG->enableajax + || empty($USER->editing) + || !$PAGE->user_is_editing() + || ($course->id != SITEID && !$courseformatajaxsupport->capable)) { + return; + } + + if (!$config) { + $config = new stdClass(); + } + + // The URL to use for resource changes + if (!isset($config->resourceurl)) { + $config->resourceurl = '/course/rest.php'; + } + + // The URL to use for section changes + if (!isset($config->sectionurl)) { + $config->sectionurl = '/course/rest.php'; + } + + // Any additional parameters which need to be included on page submission + if (!isset($config->pageparams)) { + $config->pageparams = array(); + } + + // Include toolboxes + $PAGE->requires->yui_module('moodle-course-toolboxes', + 'M.course.init_resource_toolbox', + array(array( + 'courseid' => $course->id, + 'ajaxurl' => $config->resourceurl, + 'config' => $config, + )) + ); + $PAGE->requires->yui_module('moodle-course-toolboxes', + 'M.course.init_section_toolbox', + array(array( + 'courseid' => $course->id, + 'format' => $course->format, + 'ajaxurl' => $config->sectionurl, + 'config' => $config, + )) + ); + + // Require various strings for the command toolbox + $PAGE->requires->strings_for_js(array( + 'moveleft', + 'deletechecktype', + 'deletechecktypename', + 'show', + 'hide', + 'groupsnone', + 'groupsvisible', + 'groupsseparate', + 'clicktochangeinbrackets', + 'markthistopic', + 'markedthistopic', + ), 'moodle'); + + // Include format-specific strings + if ($course->id != SITEID) { + $PAGE->requires->strings_for_js(array( + 'showfromothers', + 'hidefromothers', + ), 'format_' . $course->format); + } + + // For confirming resource deletion we need the name of the module in question + foreach ($modules as $module => $modname) { + $PAGE->requires->string_for_js('pluginname', $module); + } +} diff --git a/course/rest.php b/course/rest.php index 5125ffb72d3f0..ec9956ee2b326 100644 --- a/course/rest.php +++ b/course/rest.php @@ -87,7 +87,8 @@ switch ($field) { case 'visible': - set_section_visible($course->id, $id, $value); + $resourcestotoggle = set_section_visible($course->id, $id, $value); + echo json_encode(array('resourcestotoggle' => $resourcestotoggle)); break; case 'move': @@ -115,20 +116,14 @@ set_coursemodule_groupmode($cm->id, $value); break; - case 'indentleft': + case 'indent': require_capability('moodle/course:manageactivities', $modcontext); - if ($cm->indent > 0) { - $cm->indent--; + $cm->indent = $value; + if ($cm->indent >= 0) { $DB->update_record('course_modules', $cm); } break; - case 'indentright': - require_capability('moodle/course:manageactivities', $modcontext); - $cm->indent++; - $DB->update_record('course_modules', $cm); - break; - case 'move': require_capability('moodle/course:manageactivities', $modcontext); if (!$section = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>$sectionid))) { diff --git a/course/view.php b/course/view.php index 49bbbe87c9258..8254ad3546a4c 100644 --- a/course/view.php +++ b/course/view.php @@ -162,32 +162,6 @@ redirect($CFG->wwwroot .'/'); } - // AJAX-capable course format? - $useajax = false; - $formatajax = course_format_ajax_support($course->format); - - if (!empty($CFG->enablecourseajax) - and $formatajax->capable - and !empty($USER->editing) - and ajaxenabled($formatajax->testedbrowsers) - and $PAGE->theme->enablecourseajax - and has_capability('moodle/course:manageactivities', $context)) { - $PAGE->requires->yui2_lib('dragdrop'); - $PAGE->requires->yui2_lib('connection'); - $PAGE->requires->yui2_lib('selector'); - $PAGE->requires->js('/lib/ajax/block_classes.js', true); - $PAGE->requires->js('/lib/ajax/section_classes.js', true); - - // Okay, global variable alert. VERY UGLY. We need to create - // this object here before the _print_block() - // function is called, since that function needs to set some - // stuff in the javascriptportal object. - $COURSE->javascriptportal = new jsportal(); - $useajax = true; - } - - $CFG->blocksdrag = $useajax; // this will add a new class to the header so we can style differently - $completion = new completion_info($course); if ($completion->is_enabled() && ajaxenabled()) { $PAGE->requires->string_for_js('completion-title-manual-y', 'completion'); @@ -257,16 +231,7 @@ echo html_writer::end_tag('div'); - // Use AJAX? - if ($useajax && has_capability('moodle/course:manageactivities', $context)) { - // At the bottom because we want to process sections and activities - // after the relevant html has been generated. We're forced to do this - // because of the way in which lib/ajax/ajaxcourse.js is written. - echo html_writer::script(false, new moodle_url('/lib/ajax/ajaxcourse.js')); - $COURSE->javascriptportal->print_javascript($course->id); - } - + // Include the command toolbox YUI module + include_course_ajax($course, $modnamesused); echo $OUTPUT->footer(); - - diff --git a/course/yui/toolboxes/toolboxes.js b/course/yui/toolboxes/toolboxes.js new file mode 100644 index 0000000000000..fd67cfec270c2 --- /dev/null +++ b/course/yui/toolboxes/toolboxes.js @@ -0,0 +1,691 @@ +YUI.add('moodle-course-toolboxes', function(Y) { + WAITICON = {'pix':"i/loading_small",'component':'moodle'}; + // The CSS selectors we use + var CSS = { + ACTIVITYLI : 'li.activity', + COMMANDSPAN : 'span.commands', + DELETE : 'a.editing_delete', + DIMCLASS : 'dimmed', + DIMMEDLABELCLASS : 'dimmed_text', + EDITTITLECLASS : 'edittitle', + GENERICICONCLASS : 'iconsmall', + GROUPSNONE : 'a.editing_groupsnone', + GROUPSSEPARATE : 'a.editing_groupsseparate', + GROUPSVISIBLE : 'a.editing_groupsvisible', + HASLABEL : 'label', + HIDE : 'a.editing_hide', + HIGHLIGHT : 'a.editing_highlight', + INSTANCENAME : 'span.instancename', + LIGHTBOX : 'lightbox', + MODINDENTCOUNT : 'mod-indent-', + MODINDENTDIV : 'div.mod-indent', + MODULEIDPREFIX : 'module-', + MOVELEFT : 'a.editing_moveleft', + MOVELEFTCLASS : 'editing_moveleft', + MOVERIGHT : 'a.editing_moveright', + PAGECONTENT : 'div#page-content', + RIGHTDIV : 'div.right', + SECTIONHIDDENCLASS : 'hidden', + SECTIONIDPREFIX : 'section-', + SECTIONLI : 'li.section', + SHOW : 'a.editing_show', + SHOWHIDE : 'a.editing_showhide' + }; + + /** + * The toolbox classes + * + * TOOLBOX is a generic class which should never be directly instantiated + * RESOURCETOOLBOX is a class extending TOOLBOX containing code specific to resources + * SECTIONTOOLBOX is a class extending TOOLBOX containing code specific to sections + */ + var TOOLBOX = function() { + TOOLBOX.superclass.constructor.apply(this, arguments); + } + + Y.extend(TOOLBOX, Y.Base, { + /** + * Replace the button click at the selector with the specified + * callback + * + * @param toolboxtarget The selector of the working area + * @param selector The 'button' to replace + * @param callback The callback to apply + * @param cursor An optional cursor style to apply + */ + replace_button : function(toolboxtarget, selector, callback, cursor) { + if (!cursor) { + // Set the default cursor type to pointer to match the + // anchor + cursor = 'pointer'; + } + var button = Y.one(toolboxtarget).all(selector) + .removeAttribute('href') + .setStyle('cursor', cursor); + + // on isn't chainable and will return an event + button.on('click', callback, this); + + return button; + }, + /** + * Toggle the visibility and availability for the specified + * resource show/hide button + */ + toggle_hide_resource_ui : function(button) { + var element = button.ancestor(CSS.ACTIVITYLI); + var hideicon = button.one('img'); + + var dimarea; + var toggle_class; + if (this.is_label(element)) { + toggle_class = CSS.DIMMEDLABELCLASS; + dimarea = element.one(CSS.MODINDENTDIV + ' div'); + } else { + toggle_class = CSS.DIMCLASS; + dimarea = element.one('a'); + } + + var status = ''; + var value; + if (dimarea.hasClass(toggle_class)) { + status = 'hide'; + value = 1; + } else { + status = 'show'; + value = 0; + } + + // Change the UI + dimarea.toggleClass(toggle_class); + var newstring = M.util.get_string(status, 'moodle'); + hideicon.setAttrs({ + 'alt' : newstring, + 'title' : newstring, + 'src' : M.util.image_url('t/' + status) + }); + button.set('title', newstring); + button.set('className', 'editing_'+status); + + return value; + }, + /** + * Send a request using the REST API + * + * @param data The data to submit + * @param loadingiconat (optional) Show the loading icon spinner at the specified location (replaces text) + * @param lightbox (optional) A lightbox which may contain a section loader + * @param optionalconfig (optional) Any additional configuration to submit + * @return response responseText field from responce + */ + send_request : function(data, loadingiconat, lightbox, optionalconfig) { + // Default data structure + if (!data) { + data = {}; + } + // Handle any variables which we must pass back through to + var pageparams = this.get('config').pageparams; + for (varname in pageparams) { + data[varname] = pageparams[varname]; + } + + // Make a note of the icon for displaying the loadingicon spinner + var originalicon; + if (loadingiconat) { + originalicon = loadingiconat.getAttribute('src'); + } + + data.sesskey = M.cfg.sesskey; + data.courseId = this.get('courseid'); + + var uri = M.cfg.wwwroot + this.get('ajaxurl'); + + // Define the configuration to send with the request + var responsetext = []; + var config = { + method: 'POST', + data: data, + on: { + success: function(tid, response) { + try { + responsetext = Y.JSON.parse(response.responseText); + if (responsetext.error) { + new M.core.ajaxException(responsetext); + } + } catch (e) {} + if (originalicon) { + // Replace the spinner with the original icon We use a pause to give + // positive feedback that something is happening + window.setTimeout(function(e) { + loadingiconat.setAttribute('src', originalicon); + }, 250); + } + if (lightbox) { + window.setTimeout(function(e) { + lightbox.hide(); + }, 250); + } + }, + failure : function(tid, response) { + if (originalicon) { + loadingiconat.setAttribute('src', originalicon); + } + if (lightbox) { + lightbox.hide(); + } + new M.core.ajaxException(response); + } + }, + context: this, + sync: true + } + + // Apply optional config + if (optionalconfig) { + for (varname in optionalconfig) { + config[varname] = optionalconfig[varname]; + } + } + + if (loadingiconat) { + loadingiconat.removeAttribute('innerHTML'); + loadingiconat.set('src', M.util.image_url(WAITICON.pix, WAITICON.component)); + } + + // Send the request + Y.io(uri, config); + return responsetext; + }, + is_label : function(target) { + return target.hasClass(CSS.HASLABEL); + }, + /** + * Return the module ID for the specified element + * + * @param element The
  • element to determine a module-id number for + * @return string The module ID + */ + get_element_id : function(element) { + return element.get('id').replace(CSS.MODULEIDPREFIX, ''); + }, + /** + * Return the module ID for the specified element + * + * @param element The
  • element to determine a module-id number for + * @return string The module ID + */ + get_section_id : function(section) { + return section.get('id').replace(CSS.SECTIONIDPREFIX, ''); + }, + add_lightbox: function(node) { + node.setStyle('position', 'relative'); + var waiticon = Y.Node.create('') + .setAttrs({ + 'src' : M.util.image_url(WAITICON.pix, WAITICON.component), + 'title' : M.str.moodle.move, + 'hspace' : '3' + }) + .setStyles({ + 'position' : 'relative', + 'top' : '50%' + }); + + var lightbox = Y.Node.create('
    ') + .setStyles({ + 'opacity' : '.75', + 'position' : 'absolute', + 'width' : '100%', + 'height' : '100%', + 'top' : 0, + 'left' : 0, + 'backgroundColor' : 'white', + 'text-align' : 'center' + }) + .setAttribute('class', 'lightbox') + .hide(); + lightbox.appendChild(waiticon); + node.append(lightbox); + return lightbox; + } + }, + { + NAME : 'course-toolbox', + ATTRS : { + // The ID of the current course + courseid : { + 'value' : 0 + }, + ajaxurl : { + 'value' : 0 + }, + config : { + 'value' : 0 + } + } + } + ); + + + var RESOURCETOOLBOX = function() { + RESOURCETOOLBOX.superclass.constructor.apply(this, arguments); + } + + Y.extend(RESOURCETOOLBOX, TOOLBOX, { + // Variables + GROUPS_NONE : 0, + GROUPS_SEPARATE : 1, + GROUPS_VISIBLE : 2, + + /** + * Initialize the resource toolbox + * + * Updates all span.commands with relevant handlers and other required changes + */ + initializer : function(config) { + this.setup_for_resource(); + M.course.coursebase.register_module(this); + }, + + /** + * Update any span.commands within the scope of the specified + * selector with AJAX equivelants + * + * @param baseselector The selector to limit scope to + * @return void + */ + setup_for_resource : function(baseselector) { + if (!baseselector) { + var baseselector = CSS.PAGECONTENT; + } + + Y.all(baseselector).each(this._setup_for_resource, this); + }, + _setup_for_resource : function(toolboxtarget) { + // Move left and right + this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVELEFT, this.move_left); + this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.MOVERIGHT, this.move_right); + + // Delete + this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.DELETE, this.delete_resource); + + // Show/Hide + var showhide = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.HIDE, this.toggle_hide_resource); + var shown = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.SHOW, this.toggle_hide_resource); + + showhide = showhide.concat(shown); + showhide.each(function(node) { + var section = node.ancestor(CSS.SECTIONLI); + if (section && section.hasClass(CSS.SECTIONHIDDENCLASS)) { + node.setStyle('cursor', 'auto'); + } + }); + + // Change Group Mode + var groups; + groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSNONE, this.toggle_groupmode); + groups.setAttribute('groupmode', this.GROUPS_NONE); + + groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSSEPARATE, this.toggle_groupmode); + groups.setAttribute('groupmode', this.GROUPS_SEPARATE); + + groups = this.replace_button(toolboxtarget, CSS.COMMANDSPAN + ' ' + CSS.GROUPSVISIBLE, this.toggle_groupmode); + groups.setAttribute('groupmode', this.GROUPS_VISIBLE); + }, + move_left : function(e) { + this.move_leftright(e, -1, CSS.MOVELEFT); + }, + move_right : function(e) { + this.move_leftright(e, 1, CSS.MOVERIGHT); + }, + move_leftright : function(e, direction, buttonselector) { + // Get the element we're working on + var element = e.target.ancestor(CSS.ACTIVITYLI); + + // And we need to determine the current and new indent level + var indentdiv = element.one(CSS.MODINDENTDIV); + var indent = indentdiv.getAttribute('class').match(/mod-indent-(\d{1,})/); + + if (indent) { + var oldindent = parseInt(indent[1]); + var newindent = Math.max(0, (oldindent + parseInt(direction))); + indentdiv.removeClass(indent[0]); + } else { + var oldindent = 0; + var newindent = 1; + } + + // Perform the move + indentdiv.addClass(CSS.MODINDENTCOUNT + newindent); + var data = { + 'class' : 'resource', + 'field' : 'indent', + 'value' : newindent, + 'id' : this.get_element_id(element) + }; + var editbutton = element.one(buttonselector + ' img'); + this.send_request(data, editbutton); + + // Handle removal/addition of the moveleft button + if (newindent == 0) { + window.setTimeout(function(e) { + element.one(CSS.MOVELEFT).remove(); + }, 250); + } else if (newindent == 1 && oldindent == 0) { + this.add_moveleft(element); + } + }, + delete_resource : function(e) { + // Get the element we're working on + var element = e.target.ancestor(CSS.ACTIVITYLI); + + var confirmstring = ''; + if (this.is_label(element)) { + // Labels are slightly different to other activities + var plugindata = { + type : M.util.get_string('pluginname', 'label') + } + confirmstring = M.util.get_string('deletechecktype', 'moodle', plugindata) + } else { + var plugindata = { + type : M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1]), + name : element.one(CSS.INSTANCENAME).get('firstChild').get('data') + } + confirmstring = M.util.get_string('deletechecktypename', 'moodle', plugindata); + } + + // Confirm element removal + if (!confirm(confirmstring)) { + return false; + } + + // Actually remove the element + element.remove(); + var data = { + 'class' : 'resource', + 'action' : 'DELETE', + 'id' : this.get_element_id(element) + }; + this.send_request(data); + }, + toggle_hide_resource : function(e) { + // Return early if the current section is hidden + var section = e.target.ancestor(CSS.SECTIONLI); + if (section && section.hasClass(CSS.SECTIONHIDDENCLASS)) { + return; + } + + // Get the element we're working on + var element = e.target.ancestor(CSS.ACTIVITYLI); + + var button = e.target.ancestor('a', true); + + var value = this.toggle_hide_resource_ui(button); + + // Send the request + var data = { + 'class' : 'resource', + 'field' : 'visible', + 'value' : value, + 'id' : this.get_element_id(element) + }; + this.send_request(data, button.one('img')); + }, + toggle_groupmode : function(e) { + // Get the element we're working on + var element = e.target.ancestor(CSS.ACTIVITYLI); + + var button = e.target.ancestor('a', true); + var icon = button.one('img'); + + // Current Mode + var groupmode = button.getAttribute('groupmode'); + groupmode++; + if (groupmode > 2) { + groupmode = 0; + } + button.setAttribute('groupmode', groupmode); + + var newtitle = ''; + var iconsrc = ''; + switch (groupmode) { + case this.GROUPS_NONE: + newtitle = 'groupsnone'; + iconsrc = M.util.image_url('t/groupn'); + break; + case this.GROUPS_SEPARATE: + newtitle = 'groupsseparate'; + iconsrc = M.util.image_url('t/groups'); + break; + case this.GROUPS_VISIBLE: + newtitle = 'groupsvisible'; + iconsrc = M.util.image_url('t/groupv'); + break; + } + newtitle = M.util.get_string('clicktochangeinbrackets', 'moodle', + M.util.get_string(newtitle, 'moodle')); + + // Change the UI + icon.setAttrs({ + 'alt' : newtitle, + 'title' : newtitle, + 'src' : iconsrc + }); + button.setAttribute('title', newtitle); + + // And send the request + var data = { + 'class' : 'resource', + 'field' : 'groupmode', + 'value' : groupmode, + 'id' : this.get_element_id(element) + }; + this.send_request(data, icon); + }, + /** + * Add the moveleft button + * This is required after moving left from an initial position of 0 + * + * @param target The encapsulating
  • element + */ + add_moveleft : function(target) { + var left_string = M.util.get_string('moveleft', 'moodle'); + var newicon = Y.Node.create('') + .addClass(CSS.GENERICICONCLASS) + .setAttrs({ + 'src' : M.util.image_url('t/left', 'moodle'), + 'title' : left_string, + 'alt' : left_string + }); + var anchor = new Y.Node.create('') + .setStyle('cursor', 'pointer') + .addClass(CSS.MOVELEFTCLASS) + .set('title', left_string); + anchor.appendChild(newicon); + anchor.on('click', this.move_left, this); + target.one(CSS.MOVERIGHT).insert(anchor, 'before'); + } + }, { + NAME : 'course-resource-toolbox', + ATTRS : { + courseid : { + 'value' : 0 + }, + format : { + 'value' : 'topics' + } + } + }); + + var SECTIONTOOLBOX = function() { + SECTIONTOOLBOX.superclass.constructor.apply(this, arguments); + } + + Y.extend(SECTIONTOOLBOX, TOOLBOX, { + /** + * Initialize the toolboxes module + * + * Updates all span.commands with relevant handlers and other required changes + */ + initializer : function(config) { + this.setup_for_section(); + M.course.coursebase.register_module(this); + }, + /** + * Update any section areas within the scope of the specified + * selector with AJAX equivelants + * + * @param baseselector The selector to limit scope to + * @return void + */ + setup_for_section : function(baseselector) { + if (!baseselector) { + var baseselector = CSS.PAGECONTENT; + } + + Y.all(baseselector).each(this._setup_for_section, this); + }, + _setup_for_section : function(toolboxtarget) { + // Section Highlighting + this.replace_button(toolboxtarget, CSS.RIGHTDIV + ' ' + CSS.HIGHLIGHT, this.toggle_highlight); + + // Section Visibility + this.replace_button(toolboxtarget, CSS.RIGHTDIV + ' ' + CSS.SHOWHIDE, this.toggle_hide_section); + }, + toggle_hide_section : function(e) { + // Get the section we're working on + var section = e.target.ancestor(CSS.SECTIONLI); + var button = e.target.ancestor('a', true); + var hideicon = button.one('img'); + + // The value to submit + var value; + // The status text for strings and images + var status; + + if (!section.hasClass(CSS.SECTIONHIDDENCLASS)) { + section.addClass(CSS.SECTIONHIDDENCLASS); + value = 0; + status = 'show'; + + } else { + section.removeClass(CSS.SECTIONHIDDENCLASS); + value = 1; + status = 'hide'; + } + + var newstring = M.util.get_string(status + 'fromothers', 'format_' + this.get('format')); + hideicon.setAttrs({ + 'alt' : newstring, + 'title' : newstring, + 'src' : M.util.image_url('i/' + status) + }); + button.set('title', newstring); + + // Change the highlight status + var data = { + 'class' : 'section', + 'field' : 'visible', + 'id' : this.get_section_id(section), + 'value' : value + }; + + var lightbox = this.add_lightbox(section); + lightbox.show(); + + var response = this.send_request(data, null, lightbox); + + var activities = section.all(CSS.ACTIVITYLI); + activities.each(function(node) { + if (node.one(CSS.SHOW)) { + var button = node.one(CSS.SHOW); + } else { + var button = node.one(CSS.HIDE); + } + var activityid = this.get_element_id(node); + + if (Y.Array.indexOf(response.resourcestotoggle, activityid) != -1) { + this.toggle_hide_resource_ui(button); + } + + if (value == 0) { + button.setStyle('cursor', 'auto'); + } else { + button.setStyle('cursor', 'pointer'); + } + }, this); + }, + toggle_highlight : function(e) { + // Get the section we're working on + var section = e.target.ancestor(CSS.SECTIONLI); + var button = e.target.ancestor('a', true); + var buttonicon = button.one('img'); + + // Determine whether the marker is currently set + var togglestatus = section.hasClass('current'); + var value = 0; + + // Set the current highlighted item text + var old_string = M.util.get_string('markthistopic', 'moodle'); + Y.one(CSS.PAGECONTENT) + .all(CSS.SECTIONLI + '.current ' + CSS.HIGHLIGHT) + .set('title', old_string); + Y.one(CSS.PAGECONTENT) + .all(CSS.SECTIONLI + '.current ' + CSS.HIGHLIGHT + ' img') + .set('title', old_string) + .set('alt', old_string) + .set('src', M.util.image_url('i/marker')); + + // Remove the highlighting from all sections + var allsections = Y.one(CSS.PAGECONTENT).all(CSS.SECTIONLI) + .removeClass('current'); + + // Then add it if required to the selected section + if (!togglestatus) { + section.addClass('current'); + value = this.get_section_id(section); + var new_string = M.util.get_string('markedthistopic', 'moodle'); + button + .set('title', new_string); + buttonicon + .set('title', new_string) + .set('alt', new_string) + .set('src', M.util.image_url('i/marked')); + } + + // Change the highlight status + var data = { + 'class' : 'course', + 'field' : 'marker', + 'value' : value + }; + var lightbox = this.add_lightbox(section); + lightbox.show(); + this.send_request(data, null, lightbox); + } + }, { + NAME : 'course-section-toolbox', + ATTRS : { + courseid : { + 'value' : 0 + }, + format : { + 'value' : 'topics' + } + } + }); + + M.course = M.course || {}; + + M.course.init_resource_toolbox = function(config) { + return new RESOURCETOOLBOX(config); + }; + + M.course.init_section_toolbox = function(config) { + return new SECTIONTOOLBOX(config); + }; + +}, +'@VERSION@', { + requires : ['base', 'node', 'io', 'moodle-course-coursebase'] +} +); diff --git a/index.php b/index.php index e18d2c928836a..e07f11ad685f2 100644 --- a/index.php +++ b/index.php @@ -95,6 +95,7 @@ echo $OUTPUT->header(); /// Print Section or custom info + get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); if (!empty($CFG->customfrontpageinclude)) { include($CFG->customfrontpageinclude); @@ -138,7 +139,6 @@ " class=\"iconsmall\" alt=\"$streditsummary\" />

    "; } - get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); print_section($SITE, $section, $mods, $modnamesused, true); if ($editing) { @@ -147,6 +147,8 @@ echo $OUTPUT->box_end(); } } + include_course_ajax($SITE, $modnamesused); + if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) { $frontpagelayout = $CFG->frontpageloggedin; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index d76e8115b841e..618e6b15c72fc 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -430,6 +430,8 @@ $string['deletedcourse'] = '{$a} has been completely deleted'; $string['deletednot'] = 'Could not delete {$a} !'; $string['deletecheck'] = 'Delete {$a} ?'; +$string['deletechecktype'] = 'Are you sure that you want to delete this {$a->type}?'; +$string['deletechecktypename'] = 'Are you sure that you want to delete the {$a->type} "{$a->name}"?'; $string['deletecheckfiles'] = 'Are you absolutely sure you want to delete these files?'; $string['deletecheckfull'] = 'Are you absolutely sure you want to completely delete {$a} ?'; $string['deletecheckwarning'] = 'You are about to delete these files'; @@ -806,8 +808,6 @@ $string['hidesection'] = 'Hide section {$a}'; $string['hidesettings'] = 'Hide settings'; $string['hideshowblocks'] = 'Hide or show blocks'; -$string['hidetopicfromothers'] = 'Hide topic'; -$string['hideweekfromothers'] = 'Hide week'; $string['hits'] = 'Hits'; $string['hitsoncourse'] = 'Hits on {$a->coursename} by {$a->username}'; $string['hitsoncoursetoday'] = 'Today\'s hits on {$a->coursename} by {$a->username}'; @@ -1506,8 +1506,6 @@ $string['showsettings'] = 'Show settings'; $string['showtheselogs'] = 'Show these logs'; $string['showthishelpinlanguage'] = 'Show this help in language: {$a}'; -$string['showtopicfromothers'] = 'Show topic'; -$string['showweekfromothers'] = 'Show week'; $string['schedule'] = 'Schedule'; $string['since'] = 'Since'; $string['sincelast'] = 'since last login'; diff --git a/lib/ajax/ajaxcourse.js b/lib/ajax/ajaxcourse.js deleted file mode 100644 index f130e86b486fe..0000000000000 --- a/lib/ajax/ajaxcourse.js +++ /dev/null @@ -1,314 +0,0 @@ -/** - * Contains Main class and supporting functions for ajax course layout - */ - - -//hide content body until done loading (manipulation looks ugly elsewise) -//document.getElementById('content').style.display = 'none'; - -// If firebug console is undefined, define a fake one here -if (window.console) { - console.vardump = function(data) { - retval = ''; - for (key in data) { - retval += key+' = '+data[key] + "\n"; - } - console.log(retval); - }; -} - -//onload object for handling scripts on page load, this insures they run in my order -function onload_class() { - this.scripts = new Array(); - this.debug = true; -} - - -onload_class.prototype.add = function(script) { - if (this.debug) { - YAHOO.log("onloadobj.add - adding "+script, "junk"); - } - this.scripts[this.scripts.length] = script; -}; - - -onload_class.prototype.load = function() { - var scriptcount = this.scripts.length; - if (this.debug) { - YAHOO.log("onloadobj.load - loading "+scriptcount+" scripts", "info"); - } - for (i=0; i 0) && (ct <= this.portal.numsections)); - this.sections[ct] = new section_class('section-'+ct, "sections", null, dragable); - this.sections[ct].addToGroup('resources'); - if (ct > 0) { - var sectiontitle = YAHOO.util.Selector.query('#section-'+ct+' h3.weekdates')[0]; - if (undefined !== sectiontitle) { // Only save date for weekly format - this.sectiondates[ct] = sectiontitle.innerHTML; - } - } - } else { - this.sections[ct] = null; - } - //ct++; - } - if (this.debug) { - YAHOO.log("Processed "+ct+" sections"); - } - - this.adminBlock = YAHOO.util.Dom.getElementsByClassName('block_adminblock')[0]; - this.tempBlock = YAHOO.util.Dom.getElementsByClassName('tempblockhandler')[0]; -}; - - -main_class.prototype.mk_safe_for_transport = function(input) { - return input.replace(/&/i, '_.amp._'); -}; - - -//return block by id -main_class.prototype.get_block_index = function(el) { - var blockcount = this.blocks.length; - for (i=0; i= main.connectQueue.length) { - return; - } - var callback = { - success: function(){ - main.connectQueue_fireNext(); - } - }; - main.connectQueueConnection = main.connect(main.connectQueue[head]['method'], - main.connectQueue[head]['urlStub'], - callback, - main.connectQueue[head]['body']); - main.connectQueueHead++; -}; - - -main_class.prototype.update_marker = function(newMarker) { - if (this.marker != null) { - this.marker.toggle_highlight(); - } - this.marker = newMarker; - this.marker.toggle_highlight(); - - this.connect('post', 'class=course&field=marker', null, 'value='+this.marker.sectionId); -}; - - -main_class.prototype.getString = function(identifier, variable) { - if (this.portal.strings[identifier]) { - return this.portal.strings[identifier].replace(/_var_/, variable); - } -}; - -main_class.prototype.hasString = function(identifier) { - if (this.portal.strings[identifier]) { - return true; - } - return false; -}; - -main_class.prototype.is_ie = function() { - var agent = navigator.userAgent.toLowerCase(); - if ((agent.indexOf('msie') != -1)) { - return true; - } - return false; -}; - - -var main = new main_class(); - - -function php_portal_class() { - //portal to php data - this.id = null; - this.debug = null; - - //array of id's of blocks set at end of page load by php - this.blocks = new Array(); - this.imagePath = null; - - //flag for week fomat - this.isWeek = false; - - //strings - this.strings = []; - - //icons - this.icons = []; - - YAHOO.log("Instantiated php_portal_class", "info"); -} diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index 9148561a43488..098c4966f9fa0 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -82,107 +82,4 @@ function ajaxenabled(array $browsers = null) { } else { return false; } -} - - - -// ============================================================================== -// TODO: replace this with something more up-to-date with our coding standards - -/** - * Used to create view of document to be passed to JavaScript on pageload. - * We use this class to pass data from PHP to JavaScript. - */ -class jsportal { - - var $currentblocksection = null; - var $blocks = array(); - - - /** - * Takes id of block and adds it - */ - function block_add($id, $hidden=false){ - $hidden_binary = 0; - - if ($hidden) { - $hidden_binary = 1; - } - $this->blocks[count($this->blocks)] = array($this->currentblocksection, $id, $hidden_binary); - } - - - /** - * Prints the JavaScript code needed to set up AJAX for the course. - */ - function print_javascript($courseid, $return=false) { - global $CFG, $USER, $OUTPUT, $COURSE, $DB; - - $blocksoutput = $output = ''; - for ($i=0; $iblocks); $i++) { - $blocksoutput .= "['".$this->blocks[$i][0]."', - '".$this->blocks[$i][1]."', - '".$this->blocks[$i][2]."']"; - - if ($i != (count($this->blocks) - 1)) { - $blocksoutput .= ','; - } - } - $output .= ""; - if ($return) { - return $output; - } else { - echo $output; - } - } - -} +} \ No newline at end of file diff --git a/lib/ajax/section_classes.js b/lib/ajax/section_classes.js deleted file mode 100644 index ab127f3165487..0000000000000 --- a/lib/ajax/section_classes.js +++ /dev/null @@ -1,1063 +0,0 @@ -/** - * library for ajaxcourse formats, the classes and related functions for - * sections and resources. - * - * This library requires a 'main' object created in calling document. - * - * Drag and drop notes: - * - * Dropping an activity or resource on a section will always add the activity - * or resource at the end of that section. - * - * Dropping an activity or resource on another activity or resource will - * always move the former just above the latter. - */ - - -/** - * section_class - */ -function section_class(id, group, config, isDraggable) { - this.init_section(id, group, config, isDraggable); -} - -YAHOO.extend(section_class, YAHOO.util.DDProxy); - - -section_class.prototype.debug = false; - - -section_class.prototype.init_section = function(id, group, config, isDraggable) { - - if (!id) { - return; - } - - this.is = 'section'; - this.sectionId = null; // Section number. This is NOT the section id from - // the database. - - if (!isDraggable) { - this.initTarget(id, group, config); - this.removeFromGroup('sections'); - } else { - this.init(id, group, config); - this.handle = null; - } - - this.createFrame(); - this.isTarget = true; - - this.resources = []; - this.numberDisplay = null; // Used to display the section number on the top left - // of the section. Not used in all course formats. - this.summary = null; - this.content_div = null; - this.hidden = false; - this.highlighted = false; - this.showOnly = false; - this.resources_ul = null; - this.process_section(); - - this.viewButton = null; - this.highlightButton = null; - this.showOnlyButton = null; - this.init_buttons(); - - if (isDraggable) { - this.add_handle(); - } - if (this.debug) { - YAHOO.log("init_section "+id+" draggable="+isDraggable); - } - if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) { - this.toggle_hide(null,null,true); - } -}; - - -section_class.prototype.init_buttons = function() { - if (this.sectionId > main.portal.numsections) { - // no need to do anything in orphaned sections - return; - } - - var commandContainer = YAHOO.util.Dom.getElementsByClassName('right',null,this.getEl())[0]; - - //clear all but show only button - var commandContainerCount = commandContainer.childNodes.length; - - for (var i=(commandContainerCount-1); i>0; i--) { - commandContainer.removeChild(commandContainer.childNodes[i]) - } - - if (main.getString('courseformat', this.sectionId) != "weeks" && this.sectionId > 0) { - var highlightbutton = ''; - //If current topic, then initalised as marked else marker - if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) { - highlightbutton = main.mk_button('div', main.portal.icons['marked'], main.getString('marked', this.sectionId)); - } else { - highlightbutton = main.mk_button('div', main.portal.icons['marker'], main.getString('marker', this.sectionId)); - } - YAHOO.util.Event.addListener(highlightbutton, 'click', this.mk_marker, this, true); - commandContainer.appendChild(highlightbutton); - this.highlightButton = highlightbutton; - } - if (this.sectionId > 0) { - var viewbutton = main.mk_button('div', main.portal.icons['hide'], main.getString('hidesection', this.sectionId), - [['title', main.portal.strings['hide'] ]]); - YAHOO.util.Event.addListener(viewbutton, 'click', this.toggle_hide, this,true); - commandContainer.appendChild(viewbutton); - this.viewButton = viewbutton; - } -}; - - -section_class.prototype.add_handle = function() { - var handleRef = main.mk_button('a', main.portal.icons['move_2d'], main.getString('movesection', this.sectionId), - [['title', main.portal.strings['move'] ], ['style','cursor:move']]); - - YAHOO.util.Dom.generateId(handleRef, 'sectionHandle'); - - this.handle = handleRef; - - this.getEl().childNodes[0].appendChild(handleRef); - this.setHandleElId(this.handle.id); -}; - - -section_class.prototype.process_section = function() { - this.content_div = YAHOO.util.Dom.getElementsByClassName('content',null,this.getEl())[0]; - - if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) { - this.highlighted = true; - main.marker = this; - } - - // Create holder for display number for access later - - this.numberDisplay = document.createElement('div'); - this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML; - this.getEl().childNodes[0].innerHTML = ''; - this.getEl().childNodes[0].appendChild(this.numberDisplay); - - this.sectionId = this.id.replace(/section-/i, ''); // Okay, we will have to change this if we - // ever change the id attributes format - // for the sections. - if (this.debug) { - YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId); - } - - // Find/edit resources - this.resources_ul = this.content_div.getElementsByTagName('ul')[0]; - var i=0; - while (this.resources_ul && this.resources_ul.className != 'section img-text') { - i++; - this.resources_ul = this.content_div.getElementsByTagName('ul')[i]; i++; - } - if (!this.resources_ul) { - this.resources_ul = document.createElement('ul'); - this.resources_ul.className='section'; - this.content_div.insertBefore(this.resources_ul, this.content_div.lastChild); - } - var resource_count = this.resources_ul.getElementsByTagName('li').length; - - for (var i=0;i main.portal.numsections) { - // no need to do anything in orphaned sections - return; - } - - var strhide = main.portal.strings['hide']; - var strshow = main.portal.strings['show']; - if (this.hidden) { - YAHOO.util.Dom.removeClass(this.getEl(), 'hidden'); - this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show/i, 'hide'); - this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide); - // mk_button set title only in ie, so check before setting it - if (this.viewButton.childNodes[0].title) { - this.viewButton.childNodes[0].title = this.viewButton.childNodes[0].title.replace(strshow, strhide); //IE hack. - } - this.viewButton.title = this.viewButton.title.replace(strshow, strhide); - this.hidden = false; - - if (!superficial) { - main.connect('POST', 'class=section&field=visible', null, 'value=1&id='+this.sectionId); - for (var x=0; x 0) { - oldindent = oldindent[1]; - } else { - return false; - } - var newindent = parseFloat(oldindent) - 1; - YAHOO.util.Dom.replaceClass(indentdiv, 'mod-indent-'+oldindent, 'mod-indent-'+newindent); - main.connect('POST', 'class=resource&field=indentleft', null, 'id='+this.id); - - if (newindent == 0) { - // Remove the indent left button as well. - var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands', - 'span', this.getEl())[0]; - commandContainer.removeChild(this.indentLeftButton); - this.indentLeftButton = null; - } - - return true; -}; - - -resource_class.prototype.indent_right = function() { - - var indentdiv = YAHOO.util.Dom.getElementsByClassName('mod-indent', 'div', this.getEl())[0]; - if (!indentdiv) { - if (this.debug) { - YAHOO.log('Could not indent left: intending div does not exist', 'error'); - } - return false; - } - var oldindent = indentdiv.className.match(/mod-indent-(\d{1,})/); - if (oldindent && oldindent[1] >= 0) { - oldindent = oldindent[1]; - var newindent = parseFloat(oldindent) + 1; - YAHOO.util.Dom.replaceClass(indentdiv, 'mod-indent-'+oldindent, 'mod-indent-'+newindent); - } else { - YAHOO.util.Dom.addClass(indentdiv, 'mod-indent-1'); - } - main.connect('POST', 'class=resource&field=indentright', null, 'id='+this.id); - - if (!this.indentLeftButton) { - // Add a indent left button if none is present. - var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands', 'span', this.getEl())[0]; - var button = main.mk_button('a', main.portal.icons['backwards'], main.portal.strings['moveleft'], - [['class', 'editing_moveleft']], [['class', 'iconsmall']]); - YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true); - commandContainer.insertBefore(button, this.indentRightButton); - this.indentLeftButton = button; - } - - return true; -}; - - -resource_class.prototype.toggle_hide = function(target, e, superficial, force) { - var strhide = main.portal.strings['hide']; - var strshow = main.portal.strings['show']; - if (force != null) { - if (this.debug) { - YAHOO.log("Resource "+this.getEl().id+" forced to "+force); - } - this.hidden = !force; - } - if (this.hidden) { - YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed'); - YAHOO.util.Dom.removeClass(this.divContainer, 'dimmed_text'); - this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show/i, 'hide'); - this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide); - this.viewButton.title = this.viewButton.title.replace(strshow, strhide); - this.hidden = false; - - if (!superficial) { - main.connect('POST', 'class=resource&field=visible', null, 'value=1&id='+this.id); - } - } else { - YAHOO.util.Dom.addClass(this.linkContainer, 'dimmed'); - YAHOO.util.Dom.addClass(this.divContainer, 'dimmed_text'); - this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide/i, 'show'); - this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strhide, strshow); - this.viewButton.title = this.viewButton.title.replace(strhide, strshow); - this.hidden = true; - - if (!superficial) { - main.connect('POST', 'class=resource&field=visible', null, 'value=0&id='+this.id); - } - } -}; - - -resource_class.prototype.groupImages = ['groupn', 'groups', 'groupv']; - - -resource_class.prototype.toggle_groupmode = function() { - this.groupmode++; - if (this.groupmode > 2) { - this.groupmode = 0; - } - - var newtitle = this.groupButton.title; - - switch (this.groupmode) { - case 0: - newtitle = main.portal.strings['groupsnone']; - break; - case 1: - newtitle = main.portal.strings['groupsseparate']; - break; - case 2: - newtitle = main.portal.strings['groupsvisible']; - break; - } - - this.groupButton.getElementsByTagName('img')[0].alt = newtitle; - this.groupButton.title = newtitle; - - this.groupButton.getElementsByTagName('img')[0].src = main.portal.icons[this.groupImages[this.groupmode]]; - main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id); -}; - - -resource_class.prototype.delete_button = function() { - if (this.debug) { - YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id); - } - - // default fallback to something like 'Resource 42' - var modtype = main.getString(this.is); - var modname = this.id; - - // try to get less cryptic instance name from DOM - if (YAHOO.util.Dom.hasClass(this.getEl(), 'activity')) { - if (YAHOO.util.Dom.hasClass(this.getEl(), 'label')) { - // mod_label instance - modtype = main.getString('modtype_label'); - modname = ''; - } else { - // other mod instance, get the type first - matches = new RegExp(/modtype_(\w+)/).exec(this.getEl().className); - if (matches[1] && main.hasString('modtype_' + matches[1])) { - modtype = main.getString('modtype_' + matches[1]); - } - // look for span.instancename content to get the module instance name from it - instancename = YAHOO.util.Selector.query('.instancename', this.getEl(), true); - if (instancename) { - // remove the span.accesshide - accesshides = YAHOO.util.Selector.query('.accesshide', instancename); - for (x in accesshides) { - instancename.removeChild(accesshides[x]); - } - // strip HTML tags - instancenametext = instancename.innerHTML.replace(/<[^>]+>/g, ''); - // and if anything survived, consider it the instance name - if (instancenametext) { - modname = instancenametext; - } - // put span.accesshides back - for (x in accesshides) { - instancename.appendChild(accesshides[x]); - } - } - } - } - - if (modname) { - modname = "'" + modname + "'"; - } - if (!confirm(main.getString('deletecheck', modtype + ' ' + modname))) { - return false; - } - this.parentObj.remove_resource(this); - main.connect('POST', 'class=resource&action=DELETE&id='+this.id); -}; - - -resource_class.prototype.update_index = function(index) { - if (this.debug) { - YAHOO.log("Updating Index for resource "+this.getEl().id+" to "+index); - } -}; - - -resource_class.prototype.startDrag = function(x, y) { - YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT; - - //reinitialize dd element - this.getDragEl().innerHTML = ''; - - var targets = YAHOO.util.DDM.getRelated(this, true); - if (this.debug) { - YAHOO.log(this.id + " startDrag "+targets.length + " targets"); - } -}; - - -resource_class.prototype.clear_move_markers = function(target) { - if (target.is == 'section') { - resources = target.resources; - } else { - resources = target.parentObj.resources; - } - for (var i=0; i 0) { - // We need to have a border at the bottom of the last activity in - // that section. - if (target.resources[target.resources.length - 1].getEl() != null) { - YAHOO.util.Dom.setStyle(target.resources[target.resources.length - 1].getEl().id, - 'border-bottom', '1px solid #BBB'); - } - } -}; - - -resource_class.prototype.onDragOut = function(e, ids) { - var target = YAHOO.util.DDM.getBestMatch(ids); - if (target) { - this.clear_move_markers(target); - } -}; - - -resource_class.prototype.onDragDrop = function(e, ids) { - var target = YAHOO.util.DDM.getBestMatch(ids); - if (!target) { - YAHOO.log('onDragDrop: Target is not valid!', 'error'); - } - - if (this.debug) { - YAHOO.log("Dropped on section id="+target.sectionId - +", el="+this.getEl().id - +", x="+YAHOO.util.Dom.getXY( this.getDragEl() )); - } - this.parentObj.remove_resource(this); - - if (target.is == 'resource' || target.is == 'activity') { - target.parentObj.insert_resource(this, target); - } else if (target.is == 'section') { - target.insert_resource(this); - } - this.clear_move_markers(target); - return; -}; - - -resource_class.prototype.endDrag = function() { - // Eliminates default action -}; - -section_class.prototype.swap_dates = function(el){ - var i=1; - var divs = YAHOO.util.Selector.query('div .weekdates'); - - for (div in divs) { - divs[div].innerHTML = main.sectiondates[i]; - i++; - } -}; -