[ 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 /* global SELECTORS */ 16 17 /** 18 * Messenger manager. 19 * 20 * @module moodle-core_message-messenger 21 * @package core_message 22 * @copyright 2015 Frédéric Massart - FMCorz.net 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 SELECTORS.MANAGER = { 27 SENDMESSAGE: '[data-trigger="core_message-messenger::sendmessage"]' 28 }; 29 30 /** 31 * Messenger manager. 32 * 33 * @namespace M.core_message.messenger 34 * @class MANAGER 35 * @constructor 36 */ 37 var MANAGER = function() { 38 MANAGER.superclass.constructor.apply(this, arguments); 39 }; 40 Y.namespace('M.core_message.messenger').Manager = Y.extend(MANAGER, Y.Base, { 41 42 _sendMessageDialog: null, 43 _events: [], 44 45 /** 46 * Initializer. 47 * 48 * @method initializer 49 */ 50 initializer: function() { 51 this._setEvents(); 52 }, 53 54 /** 55 * Sending a message. 56 * 57 * @method sendMessage 58 * @param {Number} userid The user ID to send a message to. 59 * @param {String} fullname The fullname of the user. 60 * @param {EventFacade} e The event triggered, when any it should be passed to the dialog. 61 */ 62 sendMessage: function(userid, fullname, e) { 63 var Klass; 64 if (!this._sendMessageDialog) { 65 Klass = Y.namespace('M.core_message.messenger.sendMessage'); 66 this._sendMessageDialog = new Klass({ 67 url: this.get('url') 68 }); 69 } 70 71 this._sendMessageDialog.prepareForUser(userid, fullname); 72 this._sendMessageDialog.show(e); 73 }, 74 75 /** 76 * Pop up an alert dialogue to notify the logged in user that they are blocked from 77 * messaging the target user. 78 * 79 * @method alertBlocked 80 * @param {String} blockedString The identifier to retrieve the blocked user message. 81 * @param {String} fullName The target user's full name. 82 */ 83 alertBlocked: function(blockedString, fullName) { 84 new M.core.alert({ 85 title: M.util.get_string('error', 'core'), 86 message: M.util.get_string(blockedString, 'message', fullName) 87 }); 88 }, 89 90 /** 91 * Register the events. 92 * 93 * @method _setEvents. 94 */ 95 _setEvents: function() { 96 var captureEvent = function(e) { 97 var target = e.currentTarget, 98 userid = parseInt(target.getData('userid'), 10), 99 fullname = target.getData('fullname'), 100 blockedString = target.getData('blocked-string'); 101 102 if (!userid || !fullname) { 103 return; 104 } 105 106 // Pass the validation before preventing defaults. 107 e.preventDefault(); 108 if (blockedString) { 109 this.alertBlocked(blockedString, fullname); 110 } else { 111 this.sendMessage(userid, fullname, e); 112 } 113 }; 114 115 this._events.push(Y.delegate('click', captureEvent, 'body', SELECTORS.MANAGER.SENDMESSAGE, this)); 116 this._events.push(Y.one(Y.config.doc).delegate('key', captureEvent, 'space', SELECTORS.MANAGER.SENDMESSAGE, this)); 117 } 118 119 }, { 120 NAME: 'core_message-messenger-manager', 121 ATTRS: { 122 123 /** 124 * URL to the message Ajax actions. 125 * 126 * @attribute url 127 * @default M.cfg.wwwroot + '/message/ajax.php' 128 * @type String 129 */ 130 url: { 131 readonly: true, 132 value: M.cfg.wwwroot + '/message/ajax.php' 133 } 134 } 135 }); 136 137 var MANAGERINST; 138 Y.namespace('M.core_message.messenger').init = function(config) { 139 if (!MANAGERINST) { 140 // Prevent duplicates of the manager if this function is called more than once. 141 MANAGERINST = new MANAGER(config); 142 } 143 return MANAGERINST; 144 };
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 |