{"version":3,"file":"summary_modal.min.js","sources":["https:\/\/iie-academy.org\/calendar\/amd\/src\/summary_modal.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 .\n\n\/**\n * A javascript module to handle summary modal.\n *\n * @module core_calendar\/summary_modal\n * @copyright 2017 Simey Lameze \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\ndefine([\n 'jquery',\n 'core\/str',\n 'core\/notification',\n 'core\/custom_interaction_events',\n 'core\/modal',\n 'core\/modal_registry',\n 'core\/modal_factory',\n 'core\/modal_events',\n 'core_calendar\/repository',\n 'core_calendar\/events',\n 'core_calendar\/crud',\n],\nfunction(\n $,\n Str,\n Notification,\n CustomEvents,\n Modal,\n ModalRegistry,\n ModalFactory,\n ModalEvents,\n CalendarRepository,\n CalendarEvents,\n CalendarCrud\n) {\n\n var registered = false;\n var SELECTORS = {\n ROOT: \"[data-region='summary-modal-container']\",\n EDIT_BUTTON: '[data-action=\"edit\"]',\n DELETE_BUTTON: '[data-action=\"delete\"]',\n };\n\n \/**\n * Constructor for the Modal.\n *\n * @param {object} root The root jQuery element for the modal\n *\/\n var ModalEventSummary = function(root) {\n Modal.call(this, root);\n };\n\n ModalEventSummary.TYPE = 'core_calendar-event_summary';\n ModalEventSummary.prototype = Object.create(Modal.prototype);\n ModalEventSummary.prototype.constructor = ModalEventSummary;\n\n \/**\n * Get the edit button element from the footer. The button is cached\n * as it's not expected to change.\n *\n * @method getEditButton\n * @return {object} button element\n *\/\n ModalEventSummary.prototype.getEditButton = function() {\n if (typeof this.editButton == 'undefined') {\n this.editButton = this.getFooter().find(SELECTORS.EDIT_BUTTON);\n }\n\n return this.editButton;\n };\n\n \/**\n * Get the delete button element from the footer. The button is cached\n * as it's not expected to change.\n *\n * @method getDeleteButton\n * @return {object} button element\n *\/\n ModalEventSummary.prototype.getDeleteButton = function() {\n if (typeof this.deleteButton == 'undefined') {\n this.deleteButton = this.getFooter().find(SELECTORS.DELETE_BUTTON);\n }\n\n return this.deleteButton;\n };\n\n \/**\n * Get the id for the event being shown in this modal. This value is\n * not cached because it will change depending on which event is\n * being displayed.\n *\n * @method getEventId\n * @return {int}\n *\/\n ModalEventSummary.prototype.getEventId = function() {\n return this.getBody().find(SELECTORS.ROOT).attr('data-event-id');\n };\n\n \/**\n * Get the title for the event being shown in this modal. This value is\n * not cached because it will change depending on which event is\n * being displayed.\n *\n * @method getEventTitle\n * @return {String}\n *\/\n ModalEventSummary.prototype.getEventTitle = function() {\n return this.getBody().find(SELECTORS.ROOT).attr('data-event-title');\n };\n\n \/**\n * Get the number of events in the series for the event being shown in\n * this modal. This value is not cached because it will change\n * depending on which event is being displayed.\n *\n * @method getEventCount\n * @return {int}\n *\/\n ModalEventSummary.prototype.getEventCount = function() {\n return this.getBody().find(SELECTORS.ROOT).attr('data-event-count');\n };\n\n \/**\n * Get the url for the event being shown in this modal.\n *\n * @method getEventUrl\n * @return {String}\n *\/\n ModalEventSummary.prototype.getEditUrl = function() {\n return this.getBody().find(SELECTORS.ROOT).attr('data-edit-url');\n };\n\n \/**\n * Is this an action event.\n *\n * @method getEventUrl\n * @return {String}\n *\/\n ModalEventSummary.prototype.isActionEvent = function() {\n return (this.getBody().find(SELECTORS.ROOT).attr('data-action-event') == 'true');\n };\n\n \/**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n *\/\n ModalEventSummary.prototype.registerEventListeners = function() {\n \/\/ Apply parent event listeners.\n Modal.prototype.registerEventListeners.call(this);\n\n \/\/ We have to wait for the modal to finish rendering in order to ensure that\n \/\/ the data-event-title property is available to use as the modal title.\n M.util.js_pending('core_calendar\/summary_modal:registerEventListeners:bodyRendered');\n this.getRoot().on(ModalEvents.bodyRendered, function() {\n this.getModal().data({\n eventTitle: this.getEventTitle(),\n eventId: this.getEventId(),\n eventCount: this.getEventCount(),\n })\n .attr('data-type', 'event');\n CalendarCrud.registerRemove(this.getModal());\n M.util.js_complete('core_calendar\/summary_modal:registerEventListeners:bodyRendered');\n }.bind(this));\n\n $('body').on(CalendarEvents.deleted, function() {\n \/\/ Close the dialogue on delete.\n this.hide();\n }.bind(this));\n\n CustomEvents.define(this.getEditButton(), [\n CustomEvents.events.activate\n ]);\n\n this.getEditButton().on(CustomEvents.events.activate, function(e, data) {\n if (this.isActionEvent()) {\n \/\/ Action events cannot be edited on the event form and must be redirected to the module UI.\n $('body').trigger(CalendarEvents.editActionEvent, [this.getEditUrl()]);\n } else {\n \/\/ When the edit button is clicked we fire an event for the calendar UI to handle.\n \/\/ We don't care how the UI chooses to handle it.\n $('body').trigger(CalendarEvents.editEvent, [this.getEventId()]);\n }\n\n \/\/ There is nothing else for us to do so let's hide.\n this.hide();\n\n \/\/ We've handled this event so no need to propagate it.\n e.preventDefault();\n e.stopPropagation();\n data.originalEvent.preventDefault();\n data.originalEvent.stopPropagation();\n }.bind(this));\n };\n\n \/\/ Automatically register with the modal registry the first time this module is imported so that you can create modals\n \/\/ of this type using the modal factory.\n if (!registered) {\n ModalRegistry.register(ModalEventSummary.TYPE, ModalEventSummary, 'core_calendar\/event_summary_modal');\n registered = true;\n }\n\n return ModalEventSummary;\n});\n"],"names":["define","$","Str","Notification","CustomEvents","Modal","ModalRegistry","ModalFactory","ModalEvents","CalendarRepository","CalendarEvents","CalendarCrud","registered","SELECTORS","ModalEventSummary","root","call","this","TYPE","prototype","Object","create","constructor","getEditButton","editButton","getFooter","find","getDeleteButton","deleteButton","getEventId","getBody","attr","getEventTitle","getEventCount","getEditUrl","isActionEvent","registerEventListeners","M","util","js_pending","getRoot","on","bodyRendered","getModal","data","eventTitle","eventId","eventCount","registerRemove","js_complete","bind","deleted","hide","events","activate","e","trigger","editActionEvent","editEvent","preventDefault","stopPropagation","originalEvent","register"],"mappings":";;;;;;;AAsBAA,qCAAO,CACH,SACA,WACA,oBACA,iCACA,aACA,sBACA,qBACA,oBACA,2BACA,uBACA,uBAEJ,SACIC,EACAC,IACAC,aACAC,aACAC,MACAC,cACAC,aACAC,YACAC,mBACAC,eACAC,kBAGIC,YAAa,EACbC,eACM,0CADNA,sBAEa,uBAFbA,wBAGe,yBAQfC,kBAAoB,SAASC,MAC7BV,MAAMW,KAAKC,KAAMF,cAGrBD,kBAAkBI,KAAO,+BACzBJ,kBAAkBK,UAAYC,OAAOC,OAAOhB,MAAMc,YACtBG,YAAcR,kBAS1CA,kBAAkBK,UAAUI,cAAgB,uBACV,IAAnBN,KAAKO,kBACPA,WAAaP,KAAKQ,YAAYC,KAAKb,wBAGrCI,KAAKO,YAUhBV,kBAAkBK,UAAUQ,gBAAkB,uBACV,IAArBV,KAAKW,oBACPA,aAAeX,KAAKQ,YAAYC,KAAKb,0BAGvCI,KAAKW,cAWhBd,kBAAkBK,UAAUU,WAAa,kBAC9BZ,KAAKa,UAAUJ,KAAKb,gBAAgBkB,KAAK,kBAWpDjB,kBAAkBK,UAAUa,cAAgB,kBACjCf,KAAKa,UAAUJ,KAAKb,gBAAgBkB,KAAK,qBAWpDjB,kBAAkBK,UAAUc,cAAgB,kBACjChB,KAAKa,UAAUJ,KAAKb,gBAAgBkB,KAAK,qBASpDjB,kBAAkBK,UAAUe,WAAa,kBAC9BjB,KAAKa,UAAUJ,KAAKb,gBAAgBkB,KAAK,kBASpDjB,kBAAkBK,UAAUgB,cAAgB,iBACiC,QAAjElB,KAAKa,UAAUJ,KAAKb,gBAAgBkB,KAAK,sBAQrDjB,kBAAkBK,UAAUiB,uBAAyB,WAEjD\/B,MA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