Skip to content
Permalink
Browse files
Merge branch 'MDL-59759-master-2' of git://github.com/junpataleta/moodle
  • Loading branch information
David Monllao committed Sep 7, 2017
2 parents 305f38d + 7800e68 commit 0e0e92c5e003ca7003b02ce5f6dacd482cb71c13

Some generated files are not rendered by default. Learn more.

@@ -118,33 +118,11 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even
// Apply parent event listeners.
Modal.prototype.registerEventListeners.call(this);

var confirmPromise = ModalFactory.create(
{
type: ModalFactory.types.CONFIRM
},
this.getDeleteButton()
).then(function(modal) {
modal.getRoot().on(ModalEvents.yes, function() {
var eventId = this.getEventId();

CalendarRepository.deleteEvent(eventId)
.then(function() {
$('body').trigger(CalendarEvents.deleted, [eventId]);
this.hide();
}.bind(this))
.catch(Notification.exception);
}.bind(this));

return modal;
}.bind(this));

// We have to wait for the modal to finish rendering in order to ensure that
// the data-event-title property is available to use as the modal title.
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));
});
prepareDeleteAction(this, eventTitle);
}.bind(this));

CustomEvents.define(this.getEditButton(), [
@@ -173,6 +151,48 @@ define(['jquery', 'core/str', 'core/notification', 'core/custom_interaction_even
}.bind(this));
};

/**
* Prepares the action for the summary modal's delete action.
*
* @param {ModalEventSummary} summaryModal The summary modal instance.
* @param {string} eventTitle The event title.
*/
function prepareDeleteAction(summaryModal, eventTitle) {
var deleteStrings = [
{
key: 'deleteevent',
component: 'calendar'
},
{
key: 'confirmeventdelete',
component: 'calendar',
param: eventTitle
}
];
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) {
deleteModal.setTitle(strings[0]);
deleteModal.setBody(strings[1]);
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);
});
return deleteModal;
}).fail(Notification.exception);
}

// 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) {
@@ -104,7 +104,7 @@ Feature: Perform basic calendar functionality
When I follow "This month"
And I click on "Really awesome event!" "link"
And I click on "Delete" "button"
And I click on "Yes" "button"
And I click on "Delete event" "button"
And I wait to be redirected
Then I should not see "Really awesome event!"

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -14,79 +14,33 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Contain the logic for the save/cancel modal.
* Contain the logic for the yes/no confirmation modal.
* This has been deprecated and should not be used anymore. Please use core/modal_save_cancel instead.
* See MDL-59759.
*
* @module core/modal_save_cancel
* @class modal_save_cancel
* @deprecated Since Moodle 3.4
* @module core/modal_confirm
* @class modal_confirm
* @package core
* @copyright 2016 Ryan Wyllie <ryan@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_events'],
function($, Notification, CustomEvents, Modal, ModalEvents) {

var SELECTORS = {
YES_BUTTON: '[data-action="yes"]',
NO_BUTTON: '[data-action="no"]',
};
define(['jquery', 'core/custom_interaction_events', 'core/modal_events', 'core/modal_save_cancel', 'core/log'],
function($, CustomEvents, ModalEvents, ModalSaveCancel, Log) {

/**
* Constructor for the Modal.
*
* @param {object} root The root jQuery element for the modal
*/
var ModalConfirm = function(root) {
Modal.call(this, root);

if (!this.getFooter().find(SELECTORS.YES_BUTTON).length) {
Notification.exception({message: 'No "yes" button found'});
}

if (!this.getFooter().find(SELECTORS.NO_BUTTON).length) {
Notification.exception({message: 'No "no" button found'});
}
Log.warn("The CONFIRM modal type has been deprecated and should not be used anymore." +
" Please use the SAVE_CANCEL modal type instead.");
ModalSaveCancel.call(this, root);
};

ModalConfirm.prototype = Object.create(Modal.prototype);
ModalConfirm.prototype = Object.create(ModalSaveCancel.prototype);
ModalConfirm.prototype.constructor = ModalConfirm;

/**
* Override parent implementation to prevent changing the footer content.
*/
ModalConfirm.prototype.setFooter = function() {
Notification.exception({message: 'Can not change the footer of a confirm modal'});
return;
};

/**
* Set up all of the event handling for the modal.
*
* @method registerEventListeners
*/
ModalConfirm.prototype.registerEventListeners = function() {
// Apply parent event listeners.
Modal.prototype.registerEventListeners.call(this);

this.getModal().on(CustomEvents.events.activate, SELECTORS.YES_BUTTON, function(e, data) {
var yesEvent = $.Event(ModalEvents.yes);
this.getRoot().trigger(yesEvent, this);

if (!yesEvent.isDefaultPrevented()) {
this.hide();
data.originalEvent.preventDefault();
}
}.bind(this));

this.getModal().on(CustomEvents.events.activate, SELECTORS.NO_BUTTON, function(e, data) {
var noEvent = $.Event(ModalEvents.no);
this.getRoot().trigger(noEvent, this);

if (!noEvent.isDefaultPrevented()) {
this.hide();
data.originalEvent.preventDefault();
}
}.bind(this));
};

return ModalConfirm;
});
@@ -32,8 +32,9 @@ define([], function() {
// ModalSaveCancel events.
save: 'modal-save-cancel:save',
cancel: 'modal-save-cancel:cancel',
// ModalConfirm events.
yes: 'modal-confirm:yes',
no: 'modal-confirm:no',
// ModalConfirm events. Deprecated since Moodle 3.4. See MDL-59759.
// Point core/modal_confirm events to save/cancel events of core/modal_save_cancel.
yes: 'modal-save-cancel:save',
no: 'modal-save-cancel:cancel',
};
});
@@ -32,21 +32,24 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
var TEMPLATES = {
DEFAULT: 'core/modal',
SAVE_CANCEL: 'core/modal_save_cancel',
CONFIRM: 'core/modal_confirm',
// Deprecated since Moodle 3.4. Point template to core/modal_save_cancel instead. See MDL-59759.
CONFIRM: 'core/modal_save_cancel',
CANCEL: 'core/modal_cancel',
};

// The available types of modals.
var TYPES = {
DEFAULT: 'DEFAULT',
SAVE_CANCEL: 'SAVE_CANCEL',
// Deprecated since Moodle 3.4. See MDL-59759.
CONFIRM: 'CONFIRM',
CANCEL: 'CANCEL',
};

// Register the common set of modals.
ModalRegistry.register(TYPES.DEFAULT, Modal, TEMPLATES.DEFAULT);
ModalRegistry.register(TYPES.SAVE_CANCEL, ModalSaveCancel, TEMPLATES.SAVE_CANCEL);
// Deprecated since Moodle 3.4. See MDL-59759.
ModalRegistry.register(TYPES.CONFIRM, ModalConfirm, TEMPLATES.CONFIRM);
ModalRegistry.register(TYPES.CANCEL, ModalCancel, TEMPLATES.CANCEL);

This file was deleted.

0 comments on commit 0e0e92c

Please sign in to comment.