Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
{"version":3,"file":"manage_subscriptions.min.js","sources":["../src/manage_subscriptions.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 * A module to handle Delete/Update operations of the manage subscription page.\n *\n * @module core_calendar/manage_subscriptions\n * @copyright 2021 Huong Nguyen <huongnv13@gmail.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.0\n */\n\nimport * as CalendarSelectors from 'core_calendar/selectors';\nimport * as CalendarRepository from 'core_calendar/repository';\nimport ModalSaveCancel from 'core/modal_save_cancel';\nimport * as ModalEvents from 'core/modal_events';\nimport {exception as displayException, addNotification, fetchNotifications} from 'core/notification';\nimport Prefetch from 'core/prefetch';\nimport {getString} from 'core/str';\nimport {eventTypes} from 'core/local/inplace_editable/events';\n\n/**\n * Get subscription id for given element.\n *\n * @param {HTMLElement} element update/delete link\n * @return {Number}\n */\nconst getSubscriptionId = element => {\n    return parseInt(element.closest('tr').dataset.subid);\n};\n\n/**\n * Get subscription name for given element.\n *\n * @param {HTMLElement} element update/delete link\n * @return {String}\n */\nconst getSubscriptionName = element => {\n    return element.closest('tr').dataset.subname;\n};\n\n/**\n * Get subscription table row for subscription id.\n *\n * @param {string} subscriptionId Subscription id\n * @return {Element}\n */\nconst getSubscriptionRow = subscriptionId => {\n    return document.querySelector(`tr[data-subid=\"${subscriptionId}\"]`);\n};\n\n/**\n * Create modal.\n *\n * @param {HTMLElement} element\n * @param {string} messageCode Message code.\n * @return {promise} Promise for modal\n */\nconst createModal = (element, messageCode) => {\n    const subscriptionName = getSubscriptionName(element);\n    return ModalSaveCancel.create({\n        title: getString('confirmation', 'admin'),\n        body: getString(messageCode, 'calendar', subscriptionName),\n        buttons: {\n            save: getString('yes')\n        },\n    }).then(modal => {\n        modal.getRoot().on(ModalEvents.hidden, () => {\n            element.focus();\n        });\n        modal.show();\n        return modal;\n    });\n};\n\n/**\n * Response handler for delete action.\n *\n * @param {HTMLElement} element\n * @param {Object} data\n * @return {Promise}\n */\nconst responseHandlerForDelete = async(element, data) => {\n    const subscriptionName = getSubscriptionName(element);\n    const message = data.status ? await getString('subscriptionremoved', 'calendar', subscriptionName) : data.warnings[0].message;\n    const type = data.status ? 'info' : 'error';\n    return addNotification({message, type});\n};\n\n/**\n * Register events for update/delete links.\n */\nconst registerEventListeners = () => {\n    document.addEventListener('click', e => {\n        const deleteAction = e.target.closest(CalendarSelectors.actions.deleteSubscription);\n        if (deleteAction) {\n            e.preventDefault();\n            const modalPromise = createModal(deleteAction, 'confirmsubscriptiondelete');\n            modalPromise.then(modal => {\n                modal.getRoot().on(ModalEvents.save, () => {\n                    const subscriptionId = getSubscriptionId(deleteAction);\n                    CalendarRepository.deleteSubscription(subscriptionId).then(data => {\n                        const response = responseHandlerForDelete(deleteAction, data);\n                        return response.then(() => {\n                            const subscriptionRow = getSubscriptionRow(subscriptionId);\n                            return subscriptionRow.remove();\n                        });\n                    }).catch(displayException);\n                });\n\n                return modal;\n            }).catch(displayException);\n        }\n    });\n\n    document.addEventListener(eventTypes.elementUpdated, e => {\n        const inplaceEditable = e.target;\n        if (inplaceEditable.getAttribute('data-component') == 'core_calendar') {\n            fetchNotifications();\n        }\n    });\n};\n\n/**\n * Initialises.\n */\nexport const init = () => {\n    Prefetch.prefetchStrings('moodle', ['yes']);\n    Prefetch.prefetchStrings('core_admin', ['confirmation']);\n    Prefetch.prefetchStrings('core_calendar', ['confirmsubscriptiondelete', 'subscriptionremoved']);\n    registerEventListeners();\n};\n"],"names":["getSubscriptionName","element","closest","dataset","subname","registerEventListeners","document","addEventListener","e","deleteAction","target","CalendarSelectors","actions","deleteSubscription","preventDefault","messageCode","subscriptionName","ModalSaveCancel","create","title","body","buttons","save","then","modal","getRoot","on","ModalEvents","hidden","focus","show","createModal","subscriptionId","parseInt","subid","CalendarRepository","data","response","async","message","status","warnings","type","responseHandlerForDelete","subscriptionRow","querySelector","getSubscriptionRow","remove","catch","displayException","eventTypes","elementUpdated","getAttribute","prefetchStrings"],"mappings":";;;;;;;;+WAiDMA,oBAAsBC,SACjBA,QAAQC,QAAQ,MAAMC,QAAQC,QAsDnCC,uBAAyB,KAC3BC,SAASC,iBAAiB,SAASC,UACzBC,aAAeD,EAAEE,OAAOR,QAAQS,kBAAkBC,QAAQC,uBAC5DJ,aAAc,CACdD,EAAEM,iBAtCM,EAACb,QAASc,qBACpBC,iBAAmBhB,oBAAoBC,gBACtCgB,2BAAgBC,OAAO,CAC1BC,OAAO,kBAAU,eAAgB,SACjCC,MAAM,kBAAUL,YAAa,WAAYC,kBACzCK,QAAS,CACLC,MAAM,kBAAU,UAErBC,MAAKC,QACJA,MAAMC,UAAUC,GAAGC,YAAYC,QAAQ,KACnC3B,QAAQ4B,WAEZL,MAAMM,OACCN,UA0BkBO,CAAYtB,aAAc,6BAClCc,MAAKC,QACdA,MAAMC,UAAUC,GAAGC,YAAYL,MAAM,WAC3BU,eAxEfC,SAwEkDxB,aAxEjCP,QAAQ,MAAMC,QAAQ+B,OAyE9BC,mBAAmBtB,mBAAmBmB,gBAAgBT,MAAKa,aACjDC,SApBGC,OAAMrC,QAASmC,cACtCpB,iBAAmBhB,oBAAoBC,SACvCsC,QAAUH,KAAKI,aAAe,kBAAU,sBAAuB,WAAYxB,kBAAoBoB,KAAKK,SAAS,GAAGF,QAChHG,KAAON,KAAKI,OAAS,OAAS,eAC7B,iCAAgB,CAACD,QAAAA,QAASG,KAAAA,QAgBIC,CAAyBlC,aAAc2B,aACjDC,SAASd,MAAK,WACXqB,gBAzDPZ,CAAAA,gBAChB1B,SAASuC,uCAAgCb,sBAwDAc,CAAmBd,uBACpCY,gBAAgBG,eAE5BC,MAAMC,4BAGNzB,SACRwB,MAAMC,6BAIjB3C,SAASC,iBAAiB2C,mBAAWC,gBAAgB3C,IAEK,iBAD9BA,EAAEE,OACN0C,aAAa,4EASrB,uBACPC,gBAAgB,SAAU,CAAC,0BAC3BA,gBAAgB,aAAc,CAAC,mCAC/BA,gBAAgB,gBAAiB,CAAC,4BAA6B,wBACxEhD"}