[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 /** 2 * Resource and activity toolbox class. 3 * 4 * This class is responsible for managing AJAX interactions with activities and resources 5 * when viewing a course in editing mode. 6 * 7 * @module moodle-course-toolboxes 8 * @namespace M.course.toolboxes 9 */ 10 11 /** 12 * Section toolbox class. 13 * 14 * This class is responsible for managing AJAX interactions with sections 15 * when viewing a course in editing mode. 16 * 17 * @class section 18 * @constructor 19 * @extends M.course.toolboxes.toolbox 20 */ 21 var SECTIONTOOLBOX = function() { 22 SECTIONTOOLBOX.superclass.constructor.apply(this, arguments); 23 }; 24 25 Y.extend(SECTIONTOOLBOX, TOOLBOX, { 26 /** 27 * Initialize the section toolboxes module. 28 * 29 * Updates all span.commands with relevant handlers and other required changes. 30 * 31 * @method initializer 32 * @protected 33 */ 34 initializer : function() { 35 M.course.coursebase.register_module(this); 36 37 // Section Highlighting. 38 Y.delegate('click', this.toggle_highlight, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.HIGHLIGHT, this); 39 40 // Section Visibility. 41 Y.delegate('click', this.toggle_hide_section, SELECTOR.PAGECONTENT, SELECTOR.SECTIONLI + ' ' + SELECTOR.SHOWHIDE, this); 42 }, 43 44 toggle_hide_section : function(e) { 45 // Prevent the default button action. 46 e.preventDefault(); 47 48 // Get the section we're working on. 49 var section = e.target.ancestor(M.course.format.get_section_selector(Y)), 50 button = e.target.ancestor('a', true), 51 hideicon = button.one('img'), 52 53 // The value to submit 54 value, 55 56 // The text for strings and images. Also determines the icon to display. 57 action, 58 nextaction; 59 60 if (!section.hasClass(CSS.SECTIONHIDDENCLASS)) { 61 section.addClass(CSS.SECTIONHIDDENCLASS); 62 value = 0; 63 action = 'hide'; 64 nextaction = 'show'; 65 } else { 66 section.removeClass(CSS.SECTIONHIDDENCLASS); 67 value = 1; 68 action = 'show'; 69 nextaction = 'hide'; 70 } 71 72 var newstring = M.util.get_string(nextaction + 'fromothers', 'format_' + this.get('format')); 73 hideicon.setAttrs({ 74 'alt' : newstring, 75 'src' : M.util.image_url('i/' + nextaction) 76 }); 77 button.set('title', newstring); 78 79 // Change the highlight status 80 var data = { 81 'class' : 'section', 82 'field' : 'visible', 83 'id' : Y.Moodle.core_course.util.section.getId(section.ancestor(M.course.format.get_section_wrapper(Y), true)), 84 'value' : value 85 }; 86 87 var lightbox = M.util.add_lightbox(Y, section); 88 lightbox.show(); 89 90 this.send_request(data, lightbox, function(response) { 91 var activities = section.all(SELECTOR.ACTIVITYLI); 92 activities.each(function(node) { 93 var button; 94 if (node.one(SELECTOR.SHOW)) { 95 button = node.one(SELECTOR.SHOW); 96 } else { 97 button = node.one(SELECTOR.HIDE); 98 } 99 var activityid = Y.Moodle.core_course.util.cm.getId(node); 100 101 // NOTE: resourcestotoggle is returned as a string instead 102 // of a Number so we must cast our activityid to a String. 103 if (Y.Array.indexOf(response.resourcestotoggle, "" + activityid) !== -1) { 104 M.course.resource_toolbox.handle_resource_dim(button, node, action); 105 } 106 }, this); 107 }); 108 }, 109 110 /** 111 * Toggle highlighting the current section. 112 * 113 * @method toggle_highlight 114 * @param {EventFacade} e 115 */ 116 toggle_highlight : function(e) { 117 // Prevent the default button action. 118 e.preventDefault(); 119 120 // Get the section we're working on. 121 var section = e.target.ancestor(M.course.format.get_section_selector(Y)); 122 var button = e.target.ancestor('a', true); 123 var buttonicon = button.one('img'); 124 125 // Determine whether the marker is currently set. 126 var togglestatus = section.hasClass('current'); 127 var value = 0; 128 129 // Set the current highlighted item text. 130 var old_string = M.util.get_string('markthistopic', 'moodle'); 131 Y.one(SELECTOR.PAGECONTENT) 132 .all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT) 133 .set('title', old_string); 134 Y.one(SELECTOR.PAGECONTENT) 135 .all(M.course.format.get_section_selector(Y) + '.current ' + SELECTOR.HIGHLIGHT + ' img') 136 .set('alt', old_string) 137 .set('src', M.util.image_url('i/marker')); 138 139 // Remove the highlighting from all sections. 140 Y.one(SELECTOR.PAGECONTENT).all(M.course.format.get_section_selector(Y)) 141 .removeClass('current'); 142 143 // Then add it if required to the selected section. 144 if (!togglestatus) { 145 section.addClass('current'); 146 value = Y.Moodle.core_course.util.section.getId(section.ancestor(M.course.format.get_section_wrapper(Y), true)); 147 var new_string = M.util.get_string('markedthistopic', 'moodle'); 148 button 149 .set('title', new_string); 150 buttonicon 151 .set('alt', new_string) 152 .set('src', M.util.image_url('i/marked')); 153 } 154 155 // Change the highlight status. 156 var data = { 157 'class' : 'course', 158 'field' : 'marker', 159 'value' : value 160 }; 161 var lightbox = M.util.add_lightbox(Y, section); 162 lightbox.show(); 163 this.send_request(data, lightbox); 164 } 165 }, { 166 NAME : 'course-section-toolbox', 167 ATTRS : { 168 } 169 }); 170 171 M.course.init_section_toolbox = function(config) { 172 return new SECTIONTOOLBOX(config); 173 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |