mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
MDL-59384 core_calendar: add delete event logic to modal
Part of MDL-59333.
This commit is contained in:
parent
ea0368d599
commit
38b325a3e6
2
calendar/amd/build/summary_modal.min.js
vendored
2
calendar/amd/build/summary_modal.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery","core/notification","core/custom_interaction_events","core/modal","core/modal_registry"],function(a,b,c,d,e){var f=!1,g={EDIT_BUTTON:'[data-action="edit"]',DELETE_BUTTON:'[data-action="delete"]',EVENT_LINK:'[data-action="event-link"]'},h=function(a){d.call(this,a),this.getFooter().find(g.EDIT_BUTTON).length||b.exception({message:"No edit button found"}),this.getFooter().find(g.DELETE_BUTTON).length||b.exception({message:"No delete button found"})};return h.TYPE="core_calendar-event_summary",h.prototype=Object.create(d.prototype),h.prototype.constructor=h,f||(e.register(h.TYPE,h,"core_calendar/event_summary_modal"),f=!0),h});
|
||||
define(["jquery","core/str","core/notification","core/custom_interaction_events","core/modal","core/modal_registry","core/modal_factory","core/modal_events","core_calendar/calendar_repository","core_calendar/calendar_events"],function(a,b,c,d,e,f,g,h,i,j){var k=!1,l={ROOT:"[data-region='summary-modal-container']",EDIT_BUTTON:'[data-action="edit"]',DELETE_BUTTON:'[data-action="delete"]',EVENT_LINK:'[data-action="event-link"]'},m=function(a){e.call(this,a),this.getFooter().find(l.EDIT_BUTTON).length||c.exception({message:"No edit button found"}),this.getFooter().find(l.DELETE_BUTTON).length||c.exception({message:"No delete button found"})};return m.TYPE="core_calendar-event_summary",m.prototype=Object.create(e.prototype),m.prototype.constructor=m,m.prototype.registerEventListeners=function(){e.prototype.registerEventListeners.call(this);var a=g.create({type:g.types.CONFIRM},this.getFooter().find(l.DELETE_BUTTON)).then(function(a){return b.get_string("confirm").then(function(b){a.setTitle(b)}.bind(this))["catch"](c.exception),a.getRoot().on(h.yes,function(){var b=this.getBody().find(l.ROOT).attr("data-event-id");i.deleteEvent(b).done(function(){a.getRoot().trigger(j.deleted,b),window.location.reload()}).fail(c.exception)}.bind(this)),a}.bind(this));this.getRoot().on(h.bodyRendered,function(){var c=this.getBody().find(l.ROOT).attr("data-event-title");a.then(function(a){a.setBody(b.get_string("confirmeventdelete","core_calendar",c))})}.bind(this))},k||(f.register(m.TYPE,m,"core_calendar/event_summary_modal"),k=!0),m});
|
@ -21,11 +21,15 @@
|
||||
* @copyright 2017 Simey Lameze <simey@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/modal', 'core/modal_registry'],
|
||||
function($, Notification, CustomEvents, Modal, ModalRegistry) {
|
||||
define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_events', 'core/modal',
|
||||
'core/modal_registry', 'core/modal_factory', 'core/modal_events', 'core_calendar/calendar_repository',
|
||||
'core_calendar/calendar_events'],
|
||||
function($, Str, Notification, CustomEvents, Modal, ModalRegistry, ModalFactory, ModalEvents, CalendarRepository,
|
||||
CalendarEvents) {
|
||||
|
||||
var registered = false;
|
||||
var SELECTORS = {
|
||||
ROOT: "[data-region='summary-modal-container']",
|
||||
EDIT_BUTTON: '[data-action="edit"]',
|
||||
DELETE_BUTTON: '[data-action="delete"]',
|
||||
EVENT_LINK: '[data-action="event-link"]'
|
||||
@ -52,6 +56,38 @@ define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/m
|
||||
ModalEventSummary.prototype = Object.create(Modal.prototype);
|
||||
ModalEventSummary.prototype.constructor = ModalEventSummary;
|
||||
|
||||
/**
|
||||
* Set up all of the event handling for the modal.
|
||||
*
|
||||
* @method registerEventListeners
|
||||
*/
|
||||
ModalEventSummary.prototype.registerEventListeners = function() {
|
||||
// Apply parent event listeners.
|
||||
Modal.prototype.registerEventListeners.call(this);
|
||||
var confirmPromise = ModalFactory.create({
|
||||
type: ModalFactory.types.CONFIRM,
|
||||
}, this.getFooter().find(SELECTORS.DELETE_BUTTON)).then(function(modal) {
|
||||
Str.get_string('confirm').then(function(languagestring) {
|
||||
modal.setTitle(languagestring);
|
||||
}.bind(this)).catch(Notification.exception);
|
||||
modal.getRoot().on(ModalEvents.yes, function() {
|
||||
var eventId = this.getBody().find(SELECTORS.ROOT).attr('data-event-id');
|
||||
CalendarRepository.deleteEvent(eventId).done(function() {
|
||||
modal.getRoot().trigger(CalendarEvents.deleted, eventId);
|
||||
window.location.reload();
|
||||
}).fail(Notification.exception);
|
||||
}.bind(this));
|
||||
return modal;
|
||||
}.bind(this));
|
||||
|
||||
this.getRoot().on(ModalEvents.bodyRendered, function() {
|
||||
var eventTitle = this.getBody().find(SELECTORS.ROOT).attr('data-event-title');
|
||||
confirmPromise.then(function(modal) {
|
||||
modal.setBody(Str.get_string('confirmeventdelete', 'core_calendar', eventTitle));
|
||||
});
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
// Automatically register with the modal registry the first time this module is imported so that you can create modals
|
||||
// of this type using the modal factory.
|
||||
if (!registered) {
|
||||
@ -60,5 +96,4 @@ define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/m
|
||||
}
|
||||
|
||||
return ModalEventSummary;
|
||||
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user