MDL-59759 core_calendar: Use SAVE_CANCEL modal for delete dialog
[moodle.git] / calendar / amd / build / summary_modal.min.js
1 define(["jquery","core/str","core/notification","core/custom_interaction_events","core/modal","core/modal_registry","core/modal_factory","core/modal_events","core_calendar/repository","core_calendar/events"],function(a,b,c,d,e,f,g,h,i,j){function k(d,e){var f=[{key:"deleteevent",component:"calendar"},{key:"confirmeventdelete",component:"calendar",param:e}],k=d.getEventId(),l=b.get_strings(f),m=g.create({type:g.types.SAVE_CANCEL},d.getDeleteButton());a.when(l,m).then(function(b,e){return e.setTitle(b[0]),e.setBody(b[1]),e.setSaveButtonText(b[0]),e.getRoot().on(h.save,function(){i.deleteEvent(k).then(function(){a("body").trigger(j.deleted,[k]),d.hide()})["catch"](c.exception)}),e}).fail(c.exception)}var l=!1,m={ROOT:"[data-region='summary-modal-container']",EDIT_BUTTON:'[data-action="edit"]',DELETE_BUTTON:'[data-action="delete"]'},n=function(a){e.call(this,a)};return n.TYPE="core_calendar-event_summary",n.prototype=Object.create(e.prototype),n.prototype.constructor=n,n.prototype.getEditButton=function(){return"undefined"==typeof this.editButton&&(this.editButton=this.getFooter().find(m.EDIT_BUTTON)),this.editButton},n.prototype.getDeleteButton=function(){return"undefined"==typeof this.deleteButton&&(this.deleteButton=this.getFooter().find(m.DELETE_BUTTON)),this.deleteButton},n.prototype.getEventId=function(){return this.getBody().find(m.ROOT).attr("data-event-id")},n.prototype.getEditUrl=function(){return this.getBody().find(m.ROOT).attr("data-edit-url")},n.prototype.isActionEvent=function(){return"true"==this.getBody().find(m.ROOT).attr("data-action-event")},n.prototype.registerEventListeners=function(){e.prototype.registerEventListeners.call(this),this.getRoot().on(h.bodyRendered,function(){var a=this.getBody().find(m.ROOT).attr("data-event-title");k(this,a)}.bind(this)),d.define(this.getEditButton(),[d.events.activate]),this.getEditButton().on(d.events.activate,function(b,c){this.isActionEvent()?a("body").trigger(j.editActionEvent,[this.getEditUrl()]):a("body").trigger(j.editEvent,[this.getEventId()]),this.hide(),b.preventDefault(),b.stopPropagation(),c.originalEvent.preventDefault(),c.originalEvent.stopPropagation()}.bind(this))},l||(f.register(n.TYPE,n,"core_calendar/event_summary_modal"),l=!0),n});