AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"message_drawer_view_contacts_section_contacts.min.js","sources":["../src/message_drawer_view_contacts_section_contacts.js"],"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 * Controls the contacts section of the contacts page.\n *\n * @module core_message/message_drawer_view_contacts_section_contacts\n * @copyright 2018
Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'jquery',\n 'core/notification',\n 'core/pubsub',\n 'core/templates',\n 'core_message/message_repository',\n 'core_message/message_drawer_events',\n 'core_message/message_drawer_lazy_load_list'\n],\nfunction(\n $,\n Notification,\n PubSub,\n Templates,\n MessageRepository,\n Events,\n LazyLoadList\n) {\n\n var limit = 100;\n var initialOffset = 0;\n\n var SELECTORS = {\n BLOCK_ICON_CONTAINER: '[data-region=\"block-icon-container\"]',\n CONTACT: '[data-region=\"contact\"]',\n CONTENT_CONTAINER: '[data-region=\"contacts-content-container\"]'\n };\n\n var TEMPLATES = {\n CONTACTS_LIST: 'core_message/message_drawer_contacts_list'\n };\n\n /**\n * Find a contact element.\n *\n * @param {Object} body Contacts body container element.\n * @param {Number} userId User id of contact.\n * @r
eturn {Object} contact element.\n */\n var findContact = function(body, userId) {\n return body.find('[data-contact-user-id=\"' + userId + '\"]');\n };\n\n /**\n * Render the contacts in the content container.\n *\n * @param {Object} contentContainer Content container element.\n * @param {Array} contacts List of contacts.\n * @return {Object} jQuery promise\n */\n var render = function(contentContainer, contacts) {\n var formattedContacts = contacts.map(function(contact) {\n return $.extend(contact, {id: contact.userid});\n });\n return Templates.render(TEMPLATES.CONTACTS_LIST, {contacts: formattedContacts})\n .then(function(html) {\n contentContainer.append(html);\n return html;\n })\n .catch(Notification.exception);\n };\n\n /**\n * Load the user contacts and call the renderer.\n *\n * @param {Number} offset The offset to use for loading contacts\n
* @return {Function} the callback.\n */\n var getLoadFunction = function(offset) {\n return function(listRoot, userId) {\n return MessageRepository.getContacts(userId, (limit + 1), offset)\n .then(function(result) {\n return result;\n })\n .then(function(contacts) {\n if (contacts.length > limit) {\n contacts.pop();\n } else {\n LazyLoadList.setLoadedAll(listRoot, true);\n }\n return contacts;\n })\n .then(function(contacts) {\n offset = offset + limit;\n return contacts;\n })\n .catch(Notification.exception);\n };\n };\n\n /**\n * Remove contact from view.\n *\n * @param {Object} body Contacts body container element.\n * @param {Number} userId Contact userid.\n */\n
var removeContact = function(body, userId) {\n findContact(body, userId).remove();\n };\n\n /**\n * Show the contact has been blocked.\n *\n * @param {Object} body Contacts body container element.\n * @param {Number} userId Contact userid.\n */\n var showContactBlocked = function(body, userId) {\n var contact = findContact(body, userId);\n if (contact.length) {\n contact.find(SELECTORS.BLOCK_ICON_CONTAINER).removeClass('hidden');\n }\n };\n\n /**\n * Show the contact has been unblocked.\n *\n * @param {Object} body Contacts body container element.\n * @param {Number} userId Contact userid.\n */\n var showContactUnblocked = function(body, userId) {\n var contact = findContact(body, userId);\n if (contact.length) {\n contact.find(SELECTORS.BLOCK_ICON_CONTAINER).addClass('hidden');\n }\n };\n\n /**\n * Listen to and handle events for contacts.\n *\n * @param {Objec
t} root Contacts section container element.\n */\n var registerEventListeners = function(root) {\n PubSub.subscribe(Events.CONTACT_ADDED, function(profile) {\n var listContentContainer = LazyLoadList.getContentContainer(root);\n render(listContentContainer, [profile]);\n LazyLoadList.hideEmptyMessage(root);\n LazyLoadList.showContent(root);\n });\n\n PubSub.subscribe(Events.CONTACT_REMOVED, function(userId) {\n removeContact(root, userId);\n var contacts = root.find(SELECTORS.CONTACT);\n\n if (!contacts.length) {\n LazyLoadList.hideContent(root);\n LazyLoadList.showEmptyMessage(root);\n }\n });\n\n PubSub.subscribe(Events.CONTACT_BLOCKED, function(userId) {\n showContactBlocked(root, userId);\n });\n\n PubSub.subscribe(Events.CONTACT_UNBLOCKED, function(userId) {\n showContactUnblocked(root, userId);\n });\n
};\n\n /**\n * Setup the contacts section.\n *\n * @param {Object} root Contacts section container.\n */\n var show = function(root) {\n if (!root.attr('data-contacts-init')) {\n registerEventListeners(root);\n root.attr('data-contacts-init', true);\n }\n\n // The root element is already the lazy loaded list root.\n LazyLoadList.show(root, getLoadFunction(initialOffset), render);\n };\n\n return {\n show: show,\n };\n});\n"],"names":["define","$","Notification","PubSub","Templates","MessageRepository","Events","LazyLoadList","SELECTORS","TEMPLATES","findContact","body","userId","find","render","contentContainer","contacts","formattedContacts","map","contact","extend","id","userid","then","html","append","catch","exception","registerEventListeners","root","subscribe","CONTACT_ADDED","profile","listContentContainer","getContentContainer","hideEmptyMessage","showContent","CONTACT_REMOVED","remove","removeContact","length"
,"hideContent","showEmptyMessage","CONTACT_BLOCKED","removeClass","showContactBlocked","CONTACT_UNBLOCKED","addClass","showContactUnblocked","show","offset","attr","listRoot","getContacts","limit","result","pop","setLoadedAll"],"mappings":";;;;;;;AAsBAA,oEACA,CACI,SACA,oBACA,cACA,iBACA,kCACA,qCACA,+CAEJ,SACIC,EACAC,aACAC,OACAC,UACAC,kBACAC,OACAC,kBAMIC,+BACsB,uCADtBA,kBAES,0BAITC,wBACe,4CAUfC,YAAc,SAASC,KAAMC,eACtBD,KAAKE,KAAK,0BAA4BD,OAAS,OAUtDE,OAAS,SAASC,iBAAkBC,cAChCC,kBAAoBD,SAASE,KAAI,SAASC,gBACnClB,EAAEmB,OAAOD,QAAS,CAACE,GAAIF,QAAQG,mBAEnClB,UAAUU,OAAOL,wBAAyB,CAACO,SAAUC,oBACvDM,MAAK,SAASC,aACXT,iBAAiB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