forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-59920-master' of git://github.com/andrewnicols/moodle
- Loading branch information
Showing
12 changed files
with
286 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Contain the logic for the save/cancel modal. | ||
* | ||
* @module core_calendar/modal_delete | ||
* @class modal_delete | ||
* @package core_calendar | ||
* @copyright 2017 Andrew Nicols <[email protected]> | ||
* @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_events', | ||
'core/modal_registry', | ||
'core_calendar/events', | ||
], | ||
function( | ||
$, | ||
Notification, | ||
CustomEvents, | ||
Modal, | ||
ModalEvents, | ||
ModalRegistry, | ||
CalendarEvents | ||
) { | ||
|
||
var registered = false; | ||
var SELECTORS = { | ||
DELETE_ONE_BUTTON: '[data-action="deleteone"]', | ||
DELETE_ALL_BUTTON: '[data-action="deleteall"]', | ||
CANCEL_BUTTON: '[data-action="cancel"]', | ||
}; | ||
|
||
/** | ||
* Constructor for the Modal. | ||
* | ||
* @param {object} root The root jQuery element for the modal | ||
*/ | ||
var ModalDelete = function(root) { | ||
Modal.call(this, root); | ||
}; | ||
|
||
ModalDelete.TYPE = 'core_calendar-modal_delete'; | ||
ModalDelete.prototype = Object.create(Modal.prototype); | ||
ModalDelete.prototype.constructor = ModalDelete; | ||
|
||
/** | ||
* Set up all of the event handling for the modal. | ||
* | ||
* @method registerEventListeners | ||
*/ | ||
ModalDelete.prototype.registerEventListeners = function() { | ||
// Apply parent event listeners. | ||
Modal.prototype.registerEventListeners.call(this); | ||
|
||
this.getModal().on(CustomEvents.events.activate, SELECTORS.DELETE_ONE_BUTTON, function(e, data) { | ||
var saveEvent = $.Event(ModalEvents.save); | ||
this.getRoot().trigger(saveEvent, this); | ||
|
||
if (!saveEvent.isDefaultPrevented()) { | ||
this.hide(); | ||
data.originalEvent.preventDefault(); | ||
} | ||
}.bind(this)); | ||
|
||
this.getModal().on(CustomEvents.events.activate, SELECTORS.DELETE_ALL_BUTTON, function(e, data) { | ||
var saveEvent = $.Event(CalendarEvents.deleteAll); | ||
this.getRoot().trigger(saveEvent, this); | ||
|
||
if (!saveEvent.isDefaultPrevented()) { | ||
this.hide(); | ||
data.originalEvent.preventDefault(); | ||
} | ||
}.bind(this)); | ||
|
||
this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function(e, data) { | ||
var cancelEvent = $.Event(ModalEvents.cancel); | ||
this.getRoot().trigger(cancelEvent, this); | ||
|
||
if (!cancelEvent.isDefaultPrevented()) { | ||
this.hide(); | ||
data.originalEvent.preventDefault(); | ||
} | ||
}.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) { | ||
ModalRegistry.register(ModalDelete.TYPE, ModalDelete, 'calendar/event_delete_modal'); | ||
registered = true; | ||
} | ||
|
||
return ModalDelete; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,32 @@ | |
* @copyright 2017 Simey Lameze <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
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($, Str, Notification, CustomEvents, Modal, ModalRegistry, ModalFactory, ModalEvents, CalendarRepository, | ||
CalendarEvents) { | ||
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', | ||
'core_calendar/modal_delete', | ||
], | ||
function( | ||
$, | ||
Str, | ||
Notification, | ||
CustomEvents, | ||
Modal, | ||
ModalRegistry, | ||
ModalFactory, | ||
ModalEvents, | ||
CalendarRepository, | ||
CalendarEvents, | ||
ModalDelete | ||
) { | ||
|
||
var registered = false; | ||
var SELECTORS = { | ||
|
@@ -89,6 +110,18 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even | |
return this.getBody().find(SELECTORS.ROOT).attr('data-event-id'); | ||
}; | ||
|
||
/** | ||
* Get the number of events in the series for the event being shown in | ||
* this modal. This value is not cached because it will change | ||
* depending on which event is being displayed. | ||
* | ||
* @method getEventCount | ||
* @return {int} | ||
*/ | ||
ModalEventSummary.prototype.getEventCount = function() { | ||
return this.getBody().find(SELECTORS.ROOT).attr('data-event-event-count'); | ||
}; | ||
|
||
/** | ||
* Get the url for the event being shown in this modal. | ||
* | ||
|
@@ -163,34 +196,76 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even | |
key: 'deleteevent', | ||
component: 'calendar' | ||
}, | ||
{ | ||
]; | ||
|
||
var eventCount = parseInt(summaryModal.getEventCount(), 10); | ||
var deletePromise; | ||
var isRepeatedEvent = eventCount > 1; | ||
if (isRepeatedEvent) { | ||
deleteStrings.push({ | ||
key: 'confirmeventseriesdelete', | ||
component: 'calendar', | ||
param: { | ||
name: eventTitle, | ||
count: eventCount, | ||
}, | ||
}); | ||
|
||
deletePromise = ModalFactory.create( | ||
{ | ||
type: ModalDelete.TYPE | ||
}, | ||
summaryModal.getDeleteButton() | ||
); | ||
} else { | ||
deleteStrings.push({ | ||
key: 'confirmeventdelete', | ||
component: 'calendar', | ||
param: eventTitle | ||
} | ||
]; | ||
}); | ||
|
||
deletePromise = ModalFactory.create( | ||
{ | ||
type: ModalFactory.types.SAVE_CANCEL | ||
}, | ||
summaryModal.getDeleteButton() | ||
); | ||
} | ||
|
||
var eventId = summaryModal.getEventId(); | ||
var stringsPromise = Str.get_strings(deleteStrings); | ||
var deletePromise = ModalFactory.create( | ||
{ | ||
type: ModalFactory.types.SAVE_CANCEL | ||
}, | ||
summaryModal.getDeleteButton() | ||
); | ||
|
||
$.when(stringsPromise, deletePromise).then(function(strings, deleteModal) { | ||
$.when(stringsPromise, deletePromise) | ||
.then(function(strings, deleteModal) { | ||
deleteModal.setTitle(strings[0]); | ||
deleteModal.setBody(strings[1]); | ||
deleteModal.setSaveButtonText(strings[0]); | ||
if (!isRepeatedEvent) { | ||
deleteModal.setSaveButtonText(strings[0]); | ||
} | ||
|
||
deleteModal.getRoot().on(ModalEvents.save, function() { | ||
CalendarRepository.deleteEvent(eventId).then(function() { | ||
$('body').trigger(CalendarEvents.deleted, [eventId]); | ||
summaryModal.hide(); | ||
return; | ||
}).catch(Notification.exception); | ||
CalendarRepository.deleteEvent(eventId, false) | ||
.then(function() { | ||
$('body').trigger(CalendarEvents.deleted, [eventId, false]); | ||
summaryModal.hide(); | ||
return; | ||
}) | ||
.catch(Notification.exception); | ||
}); | ||
|
||
deleteModal.getRoot().on(CalendarEvents.deleteAll, function() { | ||
CalendarRepository.deleteEvent(eventId, true) | ||
.then(function() { | ||
$('body').trigger(CalendarEvents.deleted, [eventId, true]); | ||
summaryModal.hide(); | ||
return; | ||
}) | ||
.catch(Notification.exception); | ||
}); | ||
|
||
return deleteModal; | ||
}).fail(Notification.exception); | ||
}) | ||
.fail(Notification.exception); | ||
} | ||
|
||
// Automatically register with the modal registry the first time this module is imported so that you can create modals | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.