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