Skip to content

Commit

Permalink
Merge branch 'MDL-59920-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Sep 19, 2017
2 parents 7326663 + 2dbfb48 commit be5d95f
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 30 deletions.
2 changes: 1 addition & 1 deletion calendar/amd/build/events.min.js

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

1 change: 1 addition & 0 deletions calendar/amd/build/modal_delete.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/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.

1 change: 1 addition & 0 deletions calendar/amd/src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ define([], function() {
return {
created: 'calendar-events:created',
deleted: 'calendar-events:deleted',
deleteAll: 'calendar-events:delete_all',
updated: 'calendar-events:updated',
editEvent: 'calendar-events:edit_event',
editActionEvent: 'calendar-events:edit_action_event',
Expand Down
112 changes: 112 additions & 0 deletions calendar/amd/src/modal_delete.js
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;
});
9 changes: 6 additions & 3 deletions calendar/amd/src/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
*
* @method deleteEvent
* @param {int} eventId The event id.
* @arapm {bool} deleteSeries Whether to delete all events in the series
* @return {promise} Resolved with requested calendar event
*/
var deleteEvent = function(eventId) {

var deleteEvent = function(eventId, deleteSeries) {
if (typeof deleteSeries === 'undefined') {
deleteSeries = false;
}
var request = {
methodname: 'core_calendar_delete_calendar_events',
args: {
events: [{
eventid: eventId,
repeat: 1
repeat: deleteSeries,
}]
}
};
Expand Down
119 changes: 97 additions & 22 deletions calendar/amd/src/summary_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions calendar/classes/external/event_exporter_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function __construct(event_interface $event, $related = []) {

if ($repeats = $event->get_repeats()) {
$data->repeatid = $repeats->get_id();
$data->eventcount = $repeats->get_num() + 1;
}

if ($cm = $event->get_course_module()) {
Expand Down Expand Up @@ -136,6 +137,12 @@ protected static function define_properties() {
'default' => null,
'null' => NULL_ALLOWED
],
'eventcount' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'modulename' => [
'type' => PARAM_TEXT,
'optional' => true,
Expand Down
Loading

0 comments on commit be5d95f

Please sign in to comment.