Your IP : 216.73.216.95


Current Path : /var/www/ljmtc/cbt/message/amd/build/
Upload File :
Current File : /var/www/ljmtc/cbt/message/amd/build/toggle_contact_button.min.js.map

{"version":3,"sources":["../src/toggle_contact_button.js"],"names":["define","$","Ajax","Templates","Notification","CustomEvents","isContact","element","attr","setContact","setNotContact","getUserId","getCurrentUserId","isLoading","hasClass","sendRequest","request","Deferred","addClass","call","fail","exception","always","removeClass","removeAttr","addContact","methodname","args","userid","requesteduserid","done","render","html","js","replaceNodeContents","removeContact","userids","enhance","children","length","append","events","activate","on","e","data","preventDefault","originalEvent"],"mappings":"AAwBAA,OAAM,sCAAC,CAAC,QAAD,CAAW,WAAX,CAAwB,gBAAxB,CAA0C,mBAA1C,CAA+D,gCAA/D,CAAD,CACE,SAASC,CAAT,CAAYC,CAAZ,CAAkBC,CAAlB,CAA6BC,CAA7B,CAA2CC,CAA3C,CAAyD,IASzDC,CAAAA,CAAS,CAAG,SAASC,CAAT,CAAkB,CAC9B,MAA0C,GAAnC,EAAAA,CAAO,CAACC,IAAR,CAAa,iBAAb,CACV,CAX4D,CAmBzDC,CAAU,CAAG,SAASF,CAAT,CAAkB,CAC/BA,CAAO,CAACC,IAAR,CAAa,iBAAb,CAAgC,GAAhC,CACH,CArB4D,CA6BzDE,CAAa,CAAG,SAASH,CAAT,CAAkB,CAClCA,CAAO,CAACC,IAAR,CAAa,iBAAb,CAAgC,GAAhC,CACH,CA/B4D,CAwCzDG,CAAS,CAAG,SAASJ,CAAT,CAAkB,CAC9B,MAAOA,CAAAA,CAAO,CAACC,IAAR,CAAa,aAAb,CACV,CA1C4D,CAmDzDI,CAAgB,CAAG,SAASL,CAAT,CAAkB,CACrC,MAAOA,CAAAA,CAAO,CAACC,IAAR,CAAa,oBAAb,CACV,CArD4D,CA8DzDK,CAAS,CAAG,SAASN,CAAT,CAAkB,CAC9B,MAAOA,CAAAA,CAAO,CAACO,QAAR,CAAiB,SAAjB,GAA+BP,CAAO,CAACC,IAAR,CAAa,UAA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AnB,EACH,CARD,CASH,CAEyD,CAG7D,CArLK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to add/remove contact using ajax.\n *\n * @module     core_message/toggle_contact_button\n * @class      toggle_contact_button\n * @package    message\n * @copyright  2016 Ryan Wyllie <ryan@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/custom_interaction_events'],\n        function($, Ajax, Templates, Notification, CustomEvents) {\n\n    /**\n     * Check the state of the element, if the current user is a contact or not.\n     *\n     * @method isContact\n     * @param {object} element jQuery object for the button\n     * @return {bool}\n     */\n    var isContact = function(element) {\n        return element.attr('data-is-contact') == '1';\n    };\n\n    /**\n     * Record that the user is a contact.\n     *\n     * @method setContact\n     * @param {object} element jQuery object for the button\n     */\n    var setContact = function(element) {\n        element.attr('data-is-contact', '1');\n    };\n\n    /**\n     * Record that the user is not a contact.\n     *\n     * @method setNotContact\n     * @param {object} element jQuery object for the button\n     */\n    var setNotContact = function(element) {\n        element.attr('data-is-contact', '0');\n    };\n\n    /**\n     * Get the id for the user being viewed.\n     *\n     * @method getUserId\n     * @param {object} element jQuery object for the button\n     * @return {int}\n     */\n    var getUserId = function(element) {\n        return element.attr('data-userid');\n    };\n\n    /**\n     * Get the id for the logged in user.\n     *\n     * @method getUserId\n     * @param {object} element jQuery object for the button\n     * @return {int}\n     */\n    var getCurrentUserId = function(element) {\n        return element.attr('data-currentuserid');\n    };\n\n    /**\n     * Check if this element is currently loading.\n     *\n     * @method isLoading\n     * @param {object} element jQuery object for the button\n     * @return {bool}\n     */\n    var isLoading = function(element) {\n        return element.hasClass('loading') || element.attr('disabled');\n    };\n\n    /**\n     * Sends an ajax request to the server and handles the element state\n     * while the request is being performed.\n     *\n     * @method sendRequest\n     * @param {object} element jQuery object for the button\n     * @param {object} request Request hash to send\n     * @return {object} jQuery promise\n     */\n    var sendRequest = function(element, request) {\n        if (isLoading(element)) {\n            return $.Deferred();\n        }\n\n        element.addClass('loading');\n        element.attr('disabled', 'disabled');\n\n        return Ajax.call([request])[0]\n            .fail(Notification.exception)\n            .always(function() {\n                element.removeClass('loading');\n                element.removeAttr('disabled');\n            });\n    };\n\n    /**\n     * Send a request to the server to add the current user as\n     * a contact. The contents of the button are changed to the\n     * remove contact button upon success.\n     *\n     * @method addContact\n     * @param {object} element jQuery object for the button\n     */\n    var addContact = function(element) {\n        if (isLoading(element)) {\n            return;\n        }\n\n        var request = {\n            methodname: 'core_message_create_contact_request',\n            args: {\n                userid: getCurrentUserId(element),\n                requesteduserid: getUserId(element),\n            }\n        };\n        sendRequest(element, request).done(function() {\n            setContact(element);\n            Templates.render('message/remove_contact_button', {}).done(function(html, js) {\n                Templates.replaceNodeContents(element, html, js);\n            });\n        });\n    };\n\n    /**\n     * Send a request to the server to remove the current user as\n     * a contact. The contents of the button are changed to the\n     * add contact button upon success.\n     *\n     * @method removeContact\n     * @param {object} element jQuery object for the button\n     */\n    var removeContact = function(element) {\n        if (isLoading(element)) {\n            return;\n        }\n\n        var request = {\n            methodname: 'core_message_delete_contacts',\n            args: {\n                userids: [getUserId(element)],\n            }\n        };\n\n        sendRequest(element, request).done(function() {\n            setNotContact(element);\n            Templates.render('message/add_contact_button', {}).done(function(html, js) {\n                Templates.replaceNodeContents(element, html, js);\n            });\n        });\n    };\n\n    /**\n     * Enhances the given element with a loading gif and event handles to make\n     * ajax requests to add or remove a contact where appropriate.\n     *\n     * @method enhance\n     * @param {object} element jQuery object for the button\n     */\n    var enhance = function(element) {\n        element = $(element);\n\n        if (!element.children('.loading-icon').length) {\n            // Add the loading gif if it isn't already there.\n            Templates.render('core/loading', {}).done(function(html, js) {\n                element.append(html, js);\n            });\n        }\n\n        CustomEvents.define(element, [CustomEvents.events.activate]);\n\n        element.on(CustomEvents.events.activate, function(e, data) {\n            if (isContact(element)) {\n                removeContact(element);\n            } else {\n                addContact(element);\n            }\n            e.preventDefault();\n            data.originalEvent.preventDefault();\n        });\n    };\n\n    return /** @alias module:message/toggle_contact_button */ {\n        enhance: enhance\n    };\n});\n"],"file":"toggle_contact_button.min.js"}