Skip to content

Commit

Permalink
Merge branch 'MDL-59384-master-final' of https://github.com/lameze/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonllao committed Jul 12, 2017
2 parents eff0303 + 38b325a commit 9e54875
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 10 deletions.
1 change: 1 addition & 0 deletions calendar/amd/build/calendar_events.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define([],function(){return{deleted:"calendar-events:deleted"}});
2 changes: 1 addition & 1 deletion calendar/amd/build/calendar_repository.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/summary_modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions calendar/amd/src/calendar_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 events a modal can fire.
*
* @module core_calendar/calendar_events
* @class calendar_events
* @package core_calendar
* @copyright 2017 Simey Lameze <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([], function() {
return {
deleted: 'calendar-events:deleted'
};
});
24 changes: 23 additions & 1 deletion calendar/amd/src/calendar_repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@
*/
define(['jquery', 'core/ajax'], function($, Ajax) {

/**
* Delete a calendar event.
*
* @method deleteEvent
* @param {int} eventId The event id.
* @return {promise} Resolved with requested calendar event
*/
var deleteEvent = function(eventId) {

var request = {
methodname: 'core_calendar_delete_calendar_events',
args: {
events: [{
eventid: eventId,
repeat: 1
}]
}
};

return Ajax.call([request])[0];
};

/**
* Get a calendar event by id.
Expand All @@ -45,6 +66,7 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
};

return {
getEventById: getEventById
getEventById: getEventById,
deleteEvent: deleteEvent
};
});
43 changes: 39 additions & 4 deletions calendar/amd/src/summary_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
* @copyright 2017 Simey Lameze <[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_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"]'
Expand All @@ -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) {
Expand All @@ -60,5 +96,4 @@ define(['jquery', 'core/notification', 'core/custom_interaction_events', 'core/m
}

return ModalEventSummary;

});
});
2 changes: 1 addition & 1 deletion calendar/templates/event_summary_body.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"eventtype": "open",
}
}}
<div>
<div data-region="summary-modal-container" data-event-id="{{id}}" data-event-title="{{name}}">
<h4>{{#str}} when, core_calendar {{/str}}</h4>
{{#userdate}} {{timestart}}, {{#str}} strftimerecentfull {{/str}} {{/userdate}}
<br>
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/build/modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e54875

Please sign in to comment.