Merge branch 'MDL-59384-master-final' of https://github.com/lameze/moodle

This commit is contained in:
David Monllao 2017-07-12 14:12:53 +02:00
commit 9e548756cf
12 changed files with 101 additions and 10 deletions

View File

@ -0,0 +1 @@
define([],function(){return{deleted:"calendar-events:deleted"}});

View File

@ -1 +1 @@
define(["jquery","core/ajax"],function(a,b){var c=function(a){var c={methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}};return b.call([c])[0]};return{getEventById:c}});
define(["jquery","core/ajax"],function(a,b){var c=function(a){var c={methodname:"core_calendar_delete_calendar_events",args:{events:[{eventid:a,repeat:1}]}};return b.call([c])[0]},d=function(a){var c={methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}};return b.call([c])[0]};return{getEventById:d,deleteEvent:c}});

View File

@ -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});

View File

@ -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 <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([], function() {
return {
deleted: 'calendar-events:deleted'
};
});

View File

@ -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.
@ -45,6 +66,7 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
};
return {
getEventById: getEventById
getEventById: getEventById,
deleteEvent: deleteEvent
};
});

View File

@ -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;
});
});

View File

@ -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>

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
define([],function(){return{shown:"modal:shown",hidden:"modal:hidden",destroyed:"modal:destroyed",save:"modal-save-cancel:save",cancel:"modal-save-cancel:cancel",yes:"modal-confirm:yes",no:"modal-confirm:no"}});
define([],function(){return{shown:"modal:shown",hidden:"modal:hidden",destroyed:"modal:destroyed",bodyRendered:"modal:bodyRendered",save:"modal-save-cancel:save",cancel:"modal-save-cancel:cancel",yes:"modal-confirm:yes",no:"modal-confirm:no"}});

View File

@ -240,6 +240,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
// Just set the value if it's a string.
body.html(value);
Event.notifyFilterContentUpdated(body);
this.getRoot().trigger(ModalEvents.bodyRendered, this);
} else {
// Otherwise we assume it's a promise to be resolved with
// html and javascript.
@ -259,6 +260,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
}
}
Event.notifyFilterContentUpdated(body);
this.getRoot().trigger(ModalEvents.bodyRendered, this);
}.bind(this));
}.bind(this));
}

View File

@ -28,6 +28,7 @@ define([], function() {
shown: 'modal:shown',
hidden: 'modal:hidden',
destroyed: 'modal:destroyed',
bodyRendered: 'modal:bodyRendered',
// ModalSaveCancel events.
save: 'modal-save-cancel:save',
cancel: 'modal-save-cancel:cancel',

View File

@ -74,6 +74,7 @@ $functions = array(
'classpath' => 'calendar/externallib.php',
'type' => 'write',
'capabilities' => 'moodle/calendar:manageentries, moodle/calendar:manageownentries, moodle/calendar:managegroupentries',
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_calendar_get_calendar_events' => array(