[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 // This file is part of Moodle - http://moodle.org/ 2 // 3 // Moodle is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // Moodle is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 15 16 /** 17 * Javascript controller for the "Actions" panel at the bottom of the page. 18 * 19 * @module mod_assign/grading_actions 20 * @package mod_assign 21 * @class GradingActions 22 * @copyright 2016 Damyon Wiese <damyon@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 * @since 3.1 25 */ 26 define(['jquery', 'mod_assign/grading_events'], function($, GradingEvents) { 27 28 /** 29 * GradingActions class. 30 * 31 * @class GradingActions 32 * @param {String} selector The selector for the page region containing the actions panel. 33 */ 34 var GradingActions = function(selector) { 35 this._regionSelector = selector; 36 this._region = $(selector); 37 38 this.registerEventListeners(); 39 }; 40 41 /** @type {String} Selector for the page region containing the user navigation. */ 42 GradingActions.prototype._regionSelector = null; 43 44 /** @type {Integer} Remember the last user id to prevent unnessecary reloads. */ 45 GradingActions.prototype._lastUserId = 0; 46 47 /** @type {JQuery} JQuery node for the page region containing the user navigation. */ 48 GradingActions.prototype._region = null; 49 50 /** 51 * Show the actions if there is valid user. 52 * 53 * @method _showActionsForm 54 * @private 55 * @param {Event} event 56 * @param {Integer} userid 57 */ 58 GradingActions.prototype._showActionsForm = function(event, userid) { 59 var form = this._region.find('[data-region=grading-actions-form]'); 60 61 if (userid != this._lastUserId && userid > 0) { 62 this._lastUserId = userid; 63 } 64 if (userid > 0) { 65 form.removeClass('hide'); 66 } else { 67 form.addClass('hide'); 68 } 69 70 }; 71 72 /** 73 * Trigger the named action. 74 * 75 * @method _trigger 76 * @private 77 * @param {String} action 78 */ 79 GradingActions.prototype._trigger = function(action) { 80 $(document).trigger(action); 81 }; 82 83 /** 84 * Get the review panel element. 85 * 86 * @method getReviewPanelElement 87 * @return {jQuery} 88 */ 89 GradingActions.prototype.getReviewPanelElement = function() { 90 return $('[data-region="review-panel"]'); 91 }; 92 93 /** 94 * Check if the page has a review panel. 95 * 96 * @method hasReviewPanelElement 97 * @return {bool} 98 */ 99 GradingActions.prototype.hasReviewPanelElement = function() { 100 return this.getReviewPanelElement().length > 0; 101 }; 102 103 /** 104 * Get the collapse grade panel button. 105 * 106 * @method getCollapseGradePanelButton 107 * @return {jQuery} 108 */ 109 GradingActions.prototype.getCollapseGradePanelButton = function() { 110 return $('[data-region="grade-actions"] .collapse-grade-panel'); 111 }; 112 113 /** 114 * Get the collapse review panel button. 115 * 116 * @method getCollapseReviewPanelButton 117 * @return {jQuery} 118 */ 119 GradingActions.prototype.getCollapseReviewPanelButton = function() { 120 return $('[data-region="grade-actions"] .collapse-review-panel'); 121 }; 122 123 /** 124 * Get the expand all panels button. 125 * 126 * @method getExpandAllPanelsButton 127 * @return {jQuery} 128 */ 129 GradingActions.prototype.getExpandAllPanelsButton = function() { 130 return $('[data-region="grade-actions"] .collapse-none'); 131 }; 132 133 /** 134 * Remove the active state from all layout buttons. 135 * 136 * @method resetLayoutButtons 137 */ 138 GradingActions.prototype.resetLayoutButtons = function() { 139 this.getCollapseGradePanelButton().removeClass('active'); 140 this.getCollapseReviewPanelButton().removeClass('active'); 141 this.getExpandAllPanelsButton().removeClass('active'); 142 }; 143 144 /** 145 * Hide the review panel. 146 * 147 * @method collapseReviewPanel 148 */ 149 GradingActions.prototype.collapseReviewPanel = function() { 150 $(document).trigger(GradingEvents.COLLAPSE_REVIEW_PANEL); 151 $(document).trigger(GradingEvents.EXPAND_GRADE_PANEL); 152 this.resetLayoutButtons(); 153 this.getCollapseReviewPanelButton().addClass('active'); 154 }; 155 156 /** 157 * Show/Hide the grade panel. 158 * 159 * @method collapseGradePanel 160 */ 161 GradingActions.prototype.collapseGradePanel = function() { 162 $(document).trigger(GradingEvents.COLLAPSE_GRADE_PANEL); 163 $(document).trigger(GradingEvents.EXPAND_REVIEW_PANEL); 164 this.resetLayoutButtons(); 165 this.getCollapseGradePanelButton().addClass('active'); 166 }; 167 168 /** 169 * Return the layout to default. 170 * 171 * @method expandAllPanels 172 */ 173 GradingActions.prototype.expandAllPanels = function() { 174 $(document).trigger(GradingEvents.EXPAND_GRADE_PANEL); 175 $(document).trigger(GradingEvents.EXPAND_REVIEW_PANEL); 176 this.resetLayoutButtons(); 177 this.getExpandAllPanelsButton().addClass('active'); 178 }; 179 180 /** 181 * Register event listeners for the grade panel. 182 * 183 * @method registerEventListeners 184 */ 185 GradingActions.prototype.registerEventListeners = function() { 186 // Don't need layout controls if there is no review panel. 187 if (this.hasReviewPanelElement()) { 188 var collapseReviewPanelButton = this.getCollapseReviewPanelButton(); 189 collapseReviewPanelButton.click(function(e) { 190 this.collapseReviewPanel(); 191 e.preventDefault(); 192 }.bind(this)); 193 194 collapseReviewPanelButton.keydown(function(e) { 195 if (!e.metaKey && !e.shiftKey && !e.altKey && !e.ctrlKey) { 196 if (e.keyCode === 13 || e.keyCode === 32) { 197 this.collapseReviewPanel(); 198 e.preventDefault(); 199 } 200 } 201 }.bind(this)); 202 203 var collapseGradePanelButton = this.getCollapseGradePanelButton(); 204 collapseGradePanelButton.click(function(e) { 205 this.collapseGradePanel(); 206 e.preventDefault(); 207 }.bind(this)); 208 209 collapseGradePanelButton.keydown(function(e) { 210 if (!e.metaKey && !e.shiftKey && !e.altKey && !e.ctrlKey) { 211 if (e.keyCode === 13 || e.keyCode === 32) { 212 this.collapseGradePanel(); 213 e.preventDefault(); 214 } 215 } 216 }.bind(this)); 217 218 var expandAllPanelsButton = this.getExpandAllPanelsButton(); 219 expandAllPanelsButton.click(function(e) { 220 this.expandAllPanels(); 221 e.preventDefault(); 222 }.bind(this)); 223 224 expandAllPanelsButton.keydown(function(e) { 225 if (!e.metaKey && !e.shiftKey && !e.altKey && !e.ctrlKey) { 226 if (e.keyCode === 13 || e.keyCode === 32) { 227 this.expandAllPanels(); 228 e.preventDefault(); 229 } 230 } 231 }.bind(this)); 232 } 233 234 $(document).on('user-changed', this._showActionsForm.bind(this)); 235 236 this._region.find('[name="savechanges"]').on('click', this._trigger.bind(this, 'save-changes')); 237 this._region.find('[name="resetbutton"]').on('click', this._trigger.bind(this, 'reset')); 238 this._region.find('form').on('submit', function(e) { 239 e.preventDefault(); 240 }); 241 }; 242 243 return GradingActions; 244 });
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 |