AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"message_drawer_view_contacts.min.js","sources":["../src/message_drawer_view_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 page of the message drawer.\n *\n * @module core_message/message_drawer_view_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/pubsub',\n 'core/str',\n 'core_message/message_drawer_events',\n 'core_message/message_drawer_view_contacts_section_contacts',\n 'core_message/message_drawer_view_contacts_section_requests'\n],\nfunction(\n $,\n PubSub,\n Str,\n MessageDrawerEvents,\n ContactsSection,\n RequestsSection\n) {\n\n var SELECTORS = {\n ACTION_SHOW_CONTACTS_SECTION: '[data-action=\"show-contacts-section\"]',\n ACTION_SHOW_REQUESTS_SECTION: '[data-action=\"show-requests-section\"]',\n CONTACT_REQUEST_COUNT: '[data-region=\"contact-request-count\"]',\n CONTACTS_SECTION_CONTAINER: '[data-section=\"contacts\"]',\n REQUESTS_SECTION_CONTAINER: '[data-section=\"requests\"]',\n };\n\n /**\n * Get the container element for the contacts section.\n *\n * @param {Object} body Contacts page body element.\n * @return {Object}\n */\n var getContactsSectionCon
tainer = function(body) {\n return body.find(SELECTORS.CONTACTS_SECTION_CONTAINER);\n };\n\n /**\n * Get the container element for the requests section.\n *\n * @param {Object} body Contacts page body element.\n * @return {Object}\n */\n var getRequestsSectionContainer = function(body) {\n return body.find(SELECTORS.REQUESTS_SECTION_CONTAINER);\n };\n\n /**\n * Get the element that triggers showing the contacts section.\n *\n * @param {Object} body Contacts page body element.\n * @return {Object}\n */\n var getShowContactsAction = function(body) {\n return body.find(SELECTORS.ACTION_SHOW_CONTACTS_SECTION);\n };\n\n /**\n * Get the element that triggers showing the requests section.\n *\n * @param {Object} body Contacts page body element.\n * @return {Object}\n */\n var getShowRequestsAction = function(body) {\n return body.find(SELECTORS.ACTION_SHOW_REQUESTS_SECTION);\n };\n\n /**\n *
Check if the given section is visible.\n *\n * @param {Object} sectionRoot The root element for the section\n * @return {Bool}\n */\n var isSectionVisible = function(sectionRoot) {\n return sectionRoot.hasClass('active');\n };\n\n /**\n * Decrement the contact request count. If the count is zero or below then\n * hide the count.\n *\n * @param {Object} body Conversation body container element.\n * @return {Function} A function to handle decrementing the count.\n */\n var decrementContactRequestCount = function(body) {\n return function() {\n var countContainer = body.find(SELECTORS.CONTACT_REQUEST_COUNT);\n var count = parseInt(countContainer.text(), 10);\n count = isNaN(count) ? 0 : count - 1;\n\n if (count <= 0) {\n countContainer.addClass('hidden');\n } else {\n countContainer.text(count);\n }\n };\n };\n\n /**\n * Listen to and
handle events for contacts.\n *\n * @param {Object} body Contacts body container element.\n */\n var registerEventListeners = function(body) {\n var contactsSection = getContactsSectionContainer(body);\n var requestsSection = getRequestsSectionContainer(body);\n var showContactsAction = getShowContactsAction(body);\n var showRequestsAction = getShowRequestsAction(body);\n\n showContactsAction.on('show.bs.tab', function() {\n ContactsSection.show(contactsSection);\n });\n\n showRequestsAction.on('show.bs.tab', function() {\n RequestsSection.show(requestsSection);\n });\n\n PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_ACCEPTED, decrementContactRequestCount(body));\n PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_DECLINED, decrementContactRequestCount(body));\n };\n\n /**\n * Setup the contact page.\n *\n * @param {string} namespace The route namespace.\n * @param {Objec
t} header Contacts header container element.\n * @param {Object} body Contacts body container element.\n * @param {Object} footer Contacts footer container element.\n * @param {String|null} tab Tab to show, either 'requests' or 'contacts', if any.\n * @return {Object} jQuery promise\n */\n var show = function(namespace, header, body, footer, tab) {\n body = $(body);\n\n if (!body.attr('data-contacts-init')) {\n registerEventListeners(body);\n body.attr('data-contacts-init', true);\n }\n\n var contactsSection = getContactsSectionContainer(body);\n var requestsSection = getRequestsSectionContainer(body);\n\n if (tab) {\n var showContactsAction = getShowContactsAction(body);\n var showRequestsAction = getShowRequestsAction(body);\n\n // Unfortunately we need to hardcode the class changes here rather than trigger\n // the bootstrap tab functionality because the bootstrap JS doesn't a
ppear to be\n // loaded by this point which means the tab plugin isn't added and the event listeners\n // haven't been set up so we can't just trigger a click either.\n if (tab == 'requests') {\n showContactsAction.removeClass('active');\n contactsSection.removeClass('show active');\n showRequestsAction.addClass('active');\n requestsSection.addClass('show active');\n } else {\n showRequestsAction.removeClass('active');\n requestsSection.removeClass('show active');\n showContactsAction.addClass('active');\n contactsSection.addClass('show active');\n }\n }\n\n if (isSectionVisible(contactsSection)) {\n ContactsSection.show(contactsSection);\n } else {\n RequestsSection.show(requestsSection);\n }\n\n return $.Deferred().resolve().promise();\n };\n\n /**\n * String describin
g this page used for aria-labels.\n *\n * @return {Object} jQuery promise\n */\n var description = function() {\n return Str.get_string('messagedrawerviewcontacts', 'core_message');\n };\n\n return {\n show: show,\n description: description\n };\n});\n"],"names":["define","$","PubSub","Str","MessageDrawerEvents","ContactsSection","RequestsSection","SELECTORS","getContactsSectionContainer","body","find","getRequestsSectionContainer","getShowContactsAction","getShowRequestsAction","decrementContactRequestCount","countContainer","count","parseInt","text","isNaN","addClass","show","namespace","header","footer","tab","attr","contactsSection","requestsSection","showContactsAction","showRequestsAction","on","subscribe","CONTACT_REQUEST_ACCEPTED","CONTACT_REQUEST_DECLINED","registerEventListeners","removeClass","hasClass","Deferred","resolve","promise","description","get_string"],"mappings":";;;;;;;AAsBAA,mDACA,CACI,SACA,cACA,WACA,qCACA,6DACA,+DAEJ,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