{"version":3,"sources":["https:\/\/virtual.arte.unicen.edu.ar\/calendar\/amd\/src\/crud.js"],"names":["define","$","Str","Notification","CustomEvents","Modal","ModalRegistry","ModalFactory","ModalEvents","ModalEventForm","CalendarRepository","CalendarEvents","ModalDelete","CalendarSelectors","confirmDeletion","eventId","eventTitle","eventCount","deleteStrings","key","component","parseInt","deletePromise","isRepeatedEvent","push","param","name","count","create","type","TYPE","types","SAVE_CANCEL","then","deleteModal","show","fail","exception","stringsPromise","get_strings","finalPromise","when","strings","setTitle","setBody","setSaveButtonText","getRoot","on","save","deleteEvent","trigger","deleted","catch","deleteAll","registerRemove","root","actions","remove","e","eventSource","closest","eventItem","data","preventDefault","registerEditListeners","eventFormModalPromise","modal","editEvent","calendarWrapper","find","wrapper","setEventId","setContextId","stopImmediatePropagation","registerEventFormModal","eventFormPromise","large","categoryId","setCategoryId","today","firstDay","day","length","setStartTime","setCourseId","edit","target","currentTarget","eventWrapper"],"mappings":"AAuBAA,OAAM,sBAAC,CACH,QADG,CAEH,UAFG,CAGH,mBAHG,CAIH,gCAJG,CAKH,YALG,CAMH,qBANG,CAOH,oBAPG,CAQH,mBARG,CASH,gCATG,CAUH,0BAVG,CAWH,sBAXG,CAYH,4BAZG,CAaH,yBAbG,CAAD,CAeN,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,CANJ,CAOIC,CAPJ,CAQIC,CARJ,CASIC,CATJ,CAUIC,CAVJ,CAWIC,CAXJ,CAYIC,CAZJ,CAaIC,CAbJ,CAcE,CAUE,QAASC,CAAAA,CAAT,CAAyBC,CAAzB,CAAkCC,CAAlC,CAA8CC,CAA9C,CAA0D,CACtD,GAAIC,CAAAA,CAAa,CAAG,CAChB,CACIC,GAAG,CAAE,aADT,CAEIC,SAAS,CAAE,UAFf,CADgB,CAApB,CAOAH,CAAU,CAAGI,QAAQ,CAACJ,CAAD,CAAa,EAAb,CAArB,CARsD,GASlDK,CAAAA,C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wBAAF,EAEH,CAVD,EAUGrC,IAVH,CAUQjC,CAAY,CAACkC,SAVrB,CAWH,CAjBD,EAoBA,MAAOsC,CAAAA,CACV,CA8CM,CAKV,CA5OK,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 .\n\n\/**\n * A module to handle CRUD operations within the UI.\n *\n * @module core_calendar\/crud\n * @package core_calendar\n * @copyright 2017 Andrew Nicols \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\/modal_event_form',\n 'core_calendar\/repository',\n 'core_calendar\/events',\n 'core_calendar\/modal_delete',\n 'core_calendar\/selectors',\n],\nfunction(\n $,\n Str,\n Notification,\n CustomEvents,\n Modal,\n ModalRegistry,\n ModalFactory,\n ModalEvents,\n ModalEventForm,\n CalendarRepository,\n CalendarEvents,\n ModalDelete,\n CalendarSelectors\n) {\n\n \/**\n * Prepares the action for the summary modal's delete action.\n *\n * @param {Number} eventId The ID of the event.\n * @param {string} eventTitle The event title.\n * @param {Number} eventCount The number of events in the series.\n * @return {Promise}\n *\/\n function confirmDeletion(eventId, eventTitle, eventCount) {\n var deleteStrings = [\n {\n key: 'deleteevent',\n component: 'calendar'\n },\n ];\n\n eventCount = parseInt(eventCount, 10);\n var deletePromise;\n var isRepeatedEvent = eventCount > 1;\n if (isRepeatedEvent) {\n deleteStrings.push({\n key: 'confirmeventseriesdelete',\n component: 'calendar',\n param: {\n name: eventTitle,\n count: eventCount,\n },\n });\n\n deletePromise = ModalFactory.create(\n {\n type: ModalDelete.TYPE\n }\n );\n } else {\n deleteStrings.push({\n key: 'confirmeventdelete',\n component: 'calendar',\n param: eventTitle\n });\n\n\n deletePromise = ModalFactory.create(\n {\n type: ModalFactory.types.SAVE_CANCEL\n }\n );\n }\n\n deletePromise.then(function(deleteModal) {\n deleteModal.show();\n\n return;\n })\n .fail(Notification.exception);\n\n var stringsPromise = Str.get_strings(deleteStrings);\n\n var finalPromise = $.when(stringsPromise, deletePromise)\n .then(function(strings, deleteModal) {\n deleteModal.setTitle(strings[0]);\n deleteModal.setBody(strings[1]);\n if (!isRepeatedEvent) {\n deleteModal.setSaveButtonText(strings[0]);\n }\n\n deleteModal.getRoot().on(ModalEvents.save, function() {\n CalendarRepository.deleteEvent(eventId, false)\n .then(function() {\n $('body').trigger(CalendarEvents.deleted, [eventId, false]);\n return;\n })\n .catch(Notification.exception);\n });\n\n deleteModal.getRoot().on(CalendarEvents.deleteAll, function() {\n CalendarRepository.deleteEvent(eventId, true)\n .then(function() {\n $('body').trigger(CalendarEvents.deleted, [eventId, true]);\n return;\n })\n .catch(Notification.exception);\n });\n\n return deleteModal;\n })\n .fail(Notification.exception);\n\n return finalPromise;\n }\n\n \/**\n * Create the event form modal for creating new events and\n * editing existing events.\n *\n * @method registerEventFormModal\n * @param {object} root The calendar root element\n * @return {object} The create modal promise\n *\/\n var registerEventFormModal = function(root) {\n var eventFormPromise = ModalFactory.create({\n type: ModalEventForm.TYPE,\n large: true\n });\n\n \/\/ Bind click event on the new event button.\n root.on('click', CalendarSelectors.actions.create, function(e) {\n eventFormPromise.then(function(modal) {\n var wrapper = root.find(CalendarSelectors.wrapper);\n\n var categoryId = wrapper.data('categoryid');\n if (typeof categoryId !== 'undefined') {\n modal.setCategoryId(categoryId);\n }\n\n \/\/ Attempt to find the cell for today.\n \/\/ If it can't be found, then use the start time of the first day on the calendar.\n var today = root.find(CalendarSelectors.today);\n var firstDay = root.find(CalendarSelectors.day);\n if (!today.length && firstDay.length) {\n modal.setStartTime(firstDay.data('newEventTimestamp'));\n }\n\n modal.setContextId(wrapper.data('contextId'));\n modal.setCourseId(wrapper.data('courseid'));\n modal.show();\n return;\n })\n .fail(Notification.exception);\n\n e.preventDefault();\n });\n\n root.on('click', CalendarSelectors.actions.edit, function(e) {\n e.preventDefault();\n var target = $(e.currentTarget),\n calendarWrapper = target.closest(CalendarSelectors.wrapper),\n eventWrapper = target.closest(CalendarSelectors.eventItem);\n\n eventFormPromise.then(function(modal) {\n \/\/ When something within the calendar tells us the user wants\n \/\/ to edit an event then show the event form modal.\n modal.setEventId(eventWrapper.data('eventId'));\n\n modal.setContextId(calendarWrapper.data('contextId'));\n modal.show();\n\n e.stopImmediatePropagation();\n return;\n }).fail(Notification.exception);\n });\n\n\n return eventFormPromise;\n };\n \/**\n * Register the listeners required to remove the event.\n *\n * @param {jQuery} root\n *\/\n function registerRemove(root) {\n root.on('click', CalendarSelectors.actions.remove, function(e) {\n \/\/ Fetch the event title, count, and pass them into the new dialogue.\n var eventSource = $(this).closest(CalendarSelectors.eventItem);\n var eventId = eventSource.data('eventId'),\n eventTitle = eventSource.data('eventTitle'),\n eventCount = eventSource.data('eventCount');\n confirmDeletion(eventId, eventTitle, eventCount);\n\n e.preventDefault();\n });\n }\n\n \/**\n * Register the listeners required to edit the event.\n *\n * @param {jQuery} root\n * @param {Promise} eventFormModalPromise\n * @returns {Promise}\n *\/\n function registerEditListeners(root, eventFormModalPromise) {\n eventFormModalPromise\n .then(function(modal) {\n \/\/ When something within the calendar tells us the user wants\n \/\/ to edit an event then show the event form modal.\n $('body').on(CalendarEvents.editEvent, function(e, eventId) {\n var calendarWrapper = root.find(CalendarSelectors.wrapper);\n modal.setEventId(eventId);\n modal.setContextId(calendarWrapper.data('contextId'));\n modal.show();\n\n e.stopImmediatePropagation();\n });\n return;\n })\n .fail(Notification.exception);\n\n return eventFormModalPromise;\n }\n\n return {\n registerRemove: registerRemove,\n registerEditListeners: registerEditListeners,\n registerEventFormModal: registerEventFormModal\n };\n});\n"],"file":"crud.min.js"}