{"version":3,"file":"crud.min.js","sources":["https:\/\/amos.ukf.sk\/calendar\/amd\/src\/crud.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 module to handle CRUD operations within the UI.\n *\n * @module core_calendar\/crud\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\/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 'core\/pending',\n 'core\/modal_save_cancel',\n],\nfunction(\n $,\n Str,\n Notification,\n ModalEvents,\n ModalEventForm,\n CalendarRepository,\n CalendarEvents,\n CalendarModalDelete,\n CalendarSelectors,\n Pending,\n ModalSaveCancel,\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 pendingPromise = new Pending('core_calendar\/crud:confirmDeletion');\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 = CalendarModalDelete.create();\n } else {\n deleteStrings.push({\n key: 'confirmeventdelete',\n component: 'calendar',\n param: eventTitle\n });\n\n\n deletePromise = ModalSaveCancel.create();\n }\n\n var stringsPromise = Str.get_strings(deleteStrings);\n\n var finalPromise = $.when(stringsPromise, deletePromise)\n .then(function(strings, deleteModal) {\n deleteModal.setRemoveOnClose(true);\n deleteModal.setTitle(strings[0]);\n deleteModal.setBody(strings[1]);\n if (!isRepeatedEvent) {\n deleteModal.setSaveButtonText(strings[0]);\n }\n\n deleteModal.show();\n\n deleteModal.getRoot().on(ModalEvents.save, function() {\n var pendingPromise = new Pending('calendar\/crud:initModal:deletedevent');\n CalendarRepository.deleteEvent(eventId, false)\n .then(function() {\n $('body').trigger(CalendarEvents.deleted, [eventId, false]);\n return;\n })\n .then(pendingPromise.resolve)\n .catch(Notification.exception);\n });\n\n deleteModal.getRoot().on(CalendarEvents.deleteAll, function() {\n var pendingPromise = new Pending('calendar\/crud:initModal:deletedallevent');\n CalendarRepository.deleteEvent(eventId, true)\n .then(function() {\n $('body').trigger(CalendarEvents.deleted, [eventId, true]);\n return;\n })\n .then(pendingPromise.resolve)\n .catch(Notification.exception);\n });\n\n return deleteModal;\n })\n .then(function(modal) {\n pendingPromise.resolve();\n\n return modal;\n })\n .catch(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 = ModalEventForm.create();\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 .catch(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.setCourseId(eventWrapper.data('courseId'));\n modal.show();\n\n e.stopImmediatePropagation();\n return;\n }).catch(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 var pendingPromise = new Pending('core_calendar\/crud:registerEditListeners');\n\n return 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 target = root.find(`[data-event-id=${eventId}]`),\n calendarWrapper = root.find(CalendarSelectors.wrapper);\n\n modal.setEventId(eventId);\n modal.setContextId(calendarWrapper.data('contextId'));\n modal.setReturnElement(target);\n modal.show();\n\n e.stopImmediatePropagation();\n });\n return modal;\n })\n .then(function(modal) {\n pendingPromise.resolve();\n\n return modal;\n })\n .catch(Notification.exception);\n }\n\n return {\n registerRemove: registerRemove,\n registerEditListeners: registerEditListeners,\n registerEventFormModal: registerEventFormModal\n };\n});\n"],"names":["define","$","Str","Notification","ModalEvents","ModalEventForm","CalendarRepository","CalendarEvents","CalendarModalDelete","CalendarSelectors","Pending","ModalSaveCancel","registerRemove","root","on","actions","remove","e","eventSource","this","closest","eventItem","eventId","eventTitle","eventCount","deletePromise","pendingPromise","deleteStrings","key","component","isRepeatedEvent","parseInt","push","param","name","count","create","stringsPromise","get_strings","when","then","strings","deleteModal","setRemoveOnClose","setTitle","setBody","setSaveButtonText","show","getRoot","save","deleteEvent","trigger","deleted","resolve","catch","exception","deleteAll","modal","confirmDeletion","data","preventDefault","registerEditListeners","eventFormModalPromise","editEvent","target","find","calendarWrapper","wrapper","setEventId","setContextId","setReturnElement","stopImmediatePropagation","registerEventFormModal","eventFormPromise","categoryId","setCategoryId","today","firstDay","day","length","setStartTime","setCourseId","edit","currentTarget","eventWrapper"],"mappings":";;;;;;;AAsBAA,4BAAO,CACH,SACA,WACA,oBACA,oBACA,iCACA,2BACA,uBACA,6BACA,0BACA,eACA,2BAEJ,SACIC,EACAC,IACAC,aACAC,YACAC,eACAC,mBACAC,eACAC,oBACAC,kBACAC,QACAC,uBA+MO,CACHC,wBAjDoBC,MACpBA,KAAKC,GAAG,QAASL,kBAAkBM,QAAQC,QAAQ,SAASC,OAEpDC,YAAcjB,EAAEkB,MAAMC,QAAQX,kBAAkBY,qBAvJnCC,QAASC,WAAYC,gBAUtCC,cATAC,eAAiB,IAAIhB,QAAQ,sCAC7BiB,cAAgB,CAChB,CACIC,IAAK,cACLC,UAAW,aAMfC,iBAFJN,WAAaO,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