mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-61575 message_notification: replace lp/dialogue with core/modal
This commit is contained in:
parent
c092f75791
commit
cd03a6fe88
@ -1 +1 @@
|
||||
define(["jquery","core/ajax","core/notification","core/fragment","core/templates","core/str","tool_lp/dialogue"],function(a,b,c,d,e,f,g){var h={PROCESSOR:"[data-processor-name]",PREFERENCE_ROW:'[data-region="preference-row"]'},i=function(b){this.root=a(b),this.name=this.root.attr("data-name"),this.userId=this.root.attr("data-user-id"),this.contextId=this.root.attr("data-context-id")};return i.prototype.show=function(){d.loadFragment("message","processor_settings",this.contextId,{userid:this.userId,type:this.name}).done(function(b,c){f.get_string("processorsettings","message").done(function(d){var f=new g(d,b,function(){e.runTemplateJS(c)},function(){f.close()});a(document).on("mpp:formsubmitted",function(){f.close(),this.updateConfiguredStatus()}.bind(this)),a(document).on("mpp:formcancelled",function(){f.close()})}.bind(this))}.bind(this))},i.prototype.updateConfiguredStatus=function(){var d=this.root.closest(h.PROCESSOR);if(!d.hasClass("unconfigured"))return!1;var e=d.attr("data-processor-name"),f={methodname:"core_message_get_message_processor",args:{name:e,userid:this.userId}};return b.call([f])[0].fail(c.exception).done(function(b){if(b.userconfigured){var c=a(h.PREFERENCE_ROW+' [data-processor-name="'+e+'"]');d.removeClass("unconfigured"),c.removeClass("disabled")}})},i});
|
||||
define(["jquery","core/ajax","core/str","core/notification","core/custom_interaction_events","core/modal","core/modal_registry","core/fragment"],function(a,b,c,d,e,f,g,h){var i=!1,j={SAVE_BUTTON:'[data-action="save"]',CANCEL_BUTTON:'[data-action="cancel"]',PROCESSOR:"[data-processor-name]",PREFERENCE_ROW:'[data-region="preference-row"]'},k=function(a){f.call(this,a),this.name=null,this.userId=null,this.contextId=null,this.element=null,this.saveButton=this.getFooter().find(j.SAVE_BUTTON),this.cancelButton=this.getFooter().find(j.CANCEL_BUTTON)};return k.TYPE="core_message-notification_processor_settings",k.prototype=Object.create(f.prototype),k.prototype.constructor=k,k.prototype.setUserId=function(a){this.userId=a},k.prototype.getUserId=function(){return this.userId},k.prototype.setElement=function(a){this.element=a},k.prototype.getElement=function(){return this.element},k.prototype.setName=function(a){this.name=a},k.prototype.getName=function(){return this.name},k.prototype.setContextId=function(a){this.contextId=a},k.prototype.getContextId=function(){return this.contextId},k.prototype.getForm=function(){return this.getBody().find("form")},k.prototype.disableButtons=function(){this.saveButton.prop("disabled",!0),this.cancelButton.prop("disabled",!0)},k.prototype.enableButtons=function(){this.saveButton.prop("disabled",!1),this.cancelButton.prop("disabled",!1)},k.prototype.loadTitleContent=function(){return this.titlePromise=c.get_string("processorsettings","message"),this.setTitle(this.titlePromise),this.titlePromise},k.prototype.loadBodyContent=function(){this.disableButtons();var a={userid:this.getUserId(),type:this.getName()};return this.bodyPromise=h.loadFragment("message","processor_settings",this.getContextId(),a),this.setBody(this.bodyPromise),this.bodyPromise.then(function(){this.enableButtons()}.bind(this)).fail(d.exception),this.bodyPromise},k.prototype.loadAllContent=function(){return a.when(this.loadTitleContent(),this.loadBodyContent())},k.prototype.show=function(){this.loadAllContent(),f.prototype.show.call(this)},k.prototype.hide=function(){f.prototype.hide.call(this),this.setContextId(null),this.setName(null),this.setUserId(null)},k.prototype.updateConfiguredStatus=function(){var c=a(this.getElement()).closest(j.PROCESSOR);if(!c.hasClass("unconfigured"))return!1;var e=c.attr("data-processor-name"),f={methodname:"core_message_get_message_processor",args:{name:e,userid:this.userId}};return b.call([f])[0].fail(d.exception).done(function(b){if(b.userconfigured){var d=a(j.PREFERENCE_ROW+' [data-processor-name="'+e+'"]');c.removeClass("unconfigured"),d.removeClass("disabled")}})},k.prototype.registerEventListeners=function(){f.prototype.registerEventListeners.call(this),this.getModal().on(e.events.activate,j.SAVE_BUTTON,function(a,b){this.getForm().submit(),b.originalEvent.preventDefault()}.bind(this)),this.getModal().on("mpp:formsubmitted",function(a){this.hide(),this.updateConfiguredStatus(),a.stopPropagation()}.bind(this)),this.getModal().on(e.events.activate,j.CANCEL_BUTTON,function(a,b){this.hide(),b.originalEvent.preventDefault(),a.stopPropagation()}.bind(this))},i||(g.register(k.TYPE,k,"core/modal_save_cancel"),i=!0),k});
|
@ -1 +1 @@
|
||||
define(["jquery","core/ajax","core/notification","core/custom_interaction_events","core_message/notification_preference","core_message/notification_processor_settings"],function(a,b,c,d,e,f){var g={DISABLE_NOTIFICATIONS:'[data-region="disable-notification-container"] [data-disable-notifications]',DISABLE_NOTIFICATIONS_CONTAINER:'[data-region="disable-notification-container"]',PREFERENCE:"[data-state]",PREFERENCE_ROW:'[data-region="preference-row"]',PREFERENCE_INPUT:"[data-state] input",PROCESSOR_SETTING:"[data-processor-setting]"},h=function(b){this.root=a(b),this.userId=this.root.attr("data-user-id"),this.registerEventListeners()};return h.prototype.isDisabled=function(){return this.root.hasClass("disabled")},h.prototype.setDisabled=function(){this.root.addClass("disabled"),this.root.find(g.PREFERENCE_INPUT).prop("disabled",!0)},h.prototype.setEnabled=function(){this.root.removeClass("disabled"),this.root.find(g.PREFERENCE_INPUT).prop("disabled",!1)},h.prototype.toggleDisableAllStatus=function(){var d=a(g.DISABLE_NOTIFICATIONS),e=a(g.DISABLE_NOTIFICATIONS_CONTAINER),f=d.prop("checked");if(e.hasClass("loading"))return a.Deferred().resolve();e.addClass("loading");var h={methodname:"core_user_update_user_preferences",args:{userid:this.userId,emailstop:f?1:0}};return b.call([h])[0].done(function(){f?this.setDisabled():this.setEnabled()}.bind(this)).always(function(){e.removeClass("loading")}).fail(c.exception)},h.prototype.registerEventListeners=function(){var b=a(g.DISABLE_NOTIFICATIONS);d.define(this.root,[d.events.activate]),this.root.on("change",function(b){if(!this.isDisabled()){var c=a(b.target).closest(g.PREFERENCE),d=a(b.target).closest(g.PREFERENCE_ROW),f=new e(d,this.userId);c.addClass("loading"),f.save().always(function(){c.removeClass("loading")})}}.bind(this)),this.root.on(d.events.activate,g.PROCESSOR_SETTING,function(b,c){var d=a(b.target).closest(g.PROCESSOR_SETTING),e=new f(d);e.show(),c.originalEvent.preventDefault()}),d.define(b,[d.events.activate]),b.on(d.events.activate,function(){this.toggleDisableAllStatus()}.bind(this))},h});
|
||||
define(["jquery","core/ajax","core/notification","core/custom_interaction_events","core_message/notification_preference","core_message/notification_processor_settings","core/modal_factory"],function(a,b,c,d,e,f,g){var h={DISABLE_NOTIFICATIONS:'[data-region="disable-notification-container"] [data-disable-notifications]',DISABLE_NOTIFICATIONS_CONTAINER:'[data-region="disable-notification-container"]',PREFERENCE:"[data-state]",PREFERENCE_ROW:'[data-region="preference-row"]',PREFERENCE_INPUT:"[data-state] input",PROCESSOR_SETTING:"[data-processor-setting]"},i=function(b){this.root=a(b),this.userId=this.root.attr("data-user-id"),this.registerEventListeners()};return i.prototype.isDisabled=function(){return this.root.hasClass("disabled")},i.prototype.setDisabled=function(){this.root.addClass("disabled"),this.root.find(h.PREFERENCE_INPUT).prop("disabled",!0)},i.prototype.setEnabled=function(){this.root.removeClass("disabled"),this.root.find(h.PREFERENCE_INPUT).prop("disabled",!1)},i.prototype.toggleDisableAllStatus=function(){var d=a(h.DISABLE_NOTIFICATIONS),e=a(h.DISABLE_NOTIFICATIONS_CONTAINER),f=d.prop("checked");if(e.hasClass("loading"))return a.Deferred().resolve();e.addClass("loading");var g={methodname:"core_user_update_user_preferences",args:{userid:this.userId,emailstop:f?1:0}};return b.call([g])[0].done(function(){f?this.setDisabled():this.setEnabled()}.bind(this)).always(function(){e.removeClass("loading")}).fail(c.exception)},i.prototype.registerEventListeners=function(){var b=a(h.DISABLE_NOTIFICATIONS);d.define(this.root,[d.events.activate]),this.root.on("change",function(b){if(!this.isDisabled()){var c=a(b.target).closest(h.PREFERENCE),d=a(b.target).closest(h.PREFERENCE_ROW),f=new e(d,this.userId);c.addClass("loading"),f.save().always(function(){c.removeClass("loading")})}}.bind(this));var i=g.create({type:f.TYPE});this.root.on(d.events.activate,h.PROCESSOR_SETTING,function(b){var d=a(b.target).closest(h.PROCESSOR_SETTING);b.preventDefault(),i.then(function(c){c.setUserId(a(d).attr("data-user-id")),c.setName(a(d).attr("data-name")),c.setContextId(a(d).attr("data-context-id")),c.setElement(d),c.show(),b.stopImmediatePropagation()}).fail(c.exception)}),d.define(b,[d.events.activate]),b.on(d.events.activate,function(){this.toggleDisableAllStatus()}.bind(this))},i});
|
@ -1 +1 @@
|
||||
define(["jquery","core/ajax","core/notification","core/custom_interaction_events"],function(a,b,c,d){var e=function(b){this.root=a(b),this.userId=this.root.attr("data-user-id"),this.name=this.root.attr("data-processor-name"),this.root.find("form").on("submit",function(b){b.preventDefault(),this.save().done(function(){a(document).trigger("mpp:formsubmitted")})}.bind(this));var c=this.root.find("[data-cancel-button]");d.define(c,[d.events.activate]),c.on(d.events.activate,function(){a(document).trigger("mpp:formcancelled")})};return e.prototype.startLoading=function(){this.root.addClass("loading")},e.prototype.stopLoading=function(){this.root.removeClass("loading")},e.prototype.isLoading=function(){return this.root.hasClass("loading")},e.prototype.save=function(){if(this.isLoading())return a.Deferred();this.startLoading();var d=this.root.find("form").serializeArray(),e={methodname:"core_message_message_processor_config_form",args:{userid:this.userId,name:this.name,formvalues:d}};return b.call([e])[0].fail(c.exception).always(function(){this.stopLoading()}.bind(this))},e});
|
||||
define(["jquery","core/ajax","core/notification"],function(a,b,c){var d=function(b){this.root=a(b),this.userId=this.root.attr("data-user-id"),this.name=this.root.attr("data-processor-name"),this.root.find("form").on("submit",function(c){c.preventDefault(),this.save().done(function(){a(b).trigger("mpp:formsubmitted")})}.bind(this))};return d.prototype.startLoading=function(){this.root.addClass("loading")},d.prototype.stopLoading=function(){this.root.removeClass("loading")},d.prototype.isLoading=function(){return this.root.hasClass("loading")},d.prototype.save=function(){if(this.isLoading())return a.Deferred();this.startLoading();var d=this.root.find("form").serializeArray(),e={methodname:"core_message_message_processor_config_form",args:{userid:this.userId,name:this.name,formvalues:d}};return b.call([e])[0].fail(c.exception).always(function(){this.stopLoading()}.bind(this))},d});
|
@ -22,60 +22,237 @@
|
||||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/notification', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialogue'],
|
||||
function($, Ajax, Notification, Fragment, Templates, Str, Dialogue) {
|
||||
define([
|
||||
'jquery',
|
||||
'core/ajax',
|
||||
'core/str',
|
||||
'core/notification',
|
||||
'core/custom_interaction_events',
|
||||
'core/modal',
|
||||
'core/modal_registry',
|
||||
'core/fragment',
|
||||
],
|
||||
function(
|
||||
$,
|
||||
Ajax,
|
||||
Str,
|
||||
Notification,
|
||||
CustomEvents,
|
||||
Modal,
|
||||
ModalRegistry,
|
||||
Fragment
|
||||
) {
|
||||
|
||||
var registered = false;
|
||||
var SELECTORS = {
|
||||
SAVE_BUTTON: '[data-action="save"]',
|
||||
CANCEL_BUTTON: '[data-action="cancel"]',
|
||||
PROCESSOR: '[data-processor-name]',
|
||||
PREFERENCE_ROW: '[data-region="preference-row"]',
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor for the notification processor settings.
|
||||
* Constructor for the Modal.
|
||||
*
|
||||
* @param {object} element jQuery object root element of the processor
|
||||
* @param {object} root The root jQuery element for the modal.
|
||||
*/
|
||||
var NotificationProcessorSettings = function(element) {
|
||||
this.root = $(element);
|
||||
this.name = this.root.attr('data-name');
|
||||
this.userId = this.root.attr('data-user-id');
|
||||
this.contextId = this.root.attr('data-context-id');
|
||||
var NotificationProcessorSettings = function(root) {
|
||||
Modal.call(this, root);
|
||||
this.name = null;
|
||||
this.userId = null;
|
||||
this.contextId = null;
|
||||
this.element = null;
|
||||
this.saveButton = this.getFooter().find(SELECTORS.SAVE_BUTTON);
|
||||
this.cancelButton = this.getFooter().find(SELECTORS.CANCEL_BUTTON);
|
||||
};
|
||||
|
||||
NotificationProcessorSettings.TYPE = 'core_message-notification_processor_settings';
|
||||
NotificationProcessorSettings.prototype = Object.create(Modal.prototype);
|
||||
NotificationProcessorSettings.prototype.constructor = NotificationProcessorSettings;
|
||||
|
||||
/**
|
||||
* Set the userid to the given value.
|
||||
*
|
||||
* @method setUserId
|
||||
* @param {int} id The notification userid
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.setUserId = function(id) {
|
||||
this.userId = id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the notification processor settings dialogue.
|
||||
* Retrieve the current userid, if any.
|
||||
*
|
||||
* @method getUserId
|
||||
* @return {int|null} The notification userid
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.getUserId = function() {
|
||||
return this.userId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the object to the given value.
|
||||
*
|
||||
* @method setElement
|
||||
* @param {object} element The notification node element.
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.setElement = function(element) {
|
||||
this.element = element;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the current element, if any.
|
||||
*
|
||||
* @method getElement
|
||||
* @return {object|null} The notification node element.
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.getElement = function() {
|
||||
return this.element;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the name to the given value.
|
||||
*
|
||||
* @method setName
|
||||
* @param {string} name The notification name.
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.setName = function(name) {
|
||||
this.name = name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the current name, if any.
|
||||
*
|
||||
* @method getName
|
||||
* @return {string|null} The notification name.
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.getName = function() {
|
||||
return this.name;
|
||||
};
|
||||
/**
|
||||
* Set the context id to the given value.
|
||||
*
|
||||
* @method setContextId
|
||||
* @param {Number} id The notification context id
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.setContextId = function(id) {
|
||||
this.contextId = id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the current context id, if any.
|
||||
*
|
||||
* @method getContextId
|
||||
* @return {Number|null} The notification context id
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.getContextId = function() {
|
||||
return this.contextId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the form element from the modal.
|
||||
*
|
||||
* @method getForm
|
||||
* @return {object}
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.getForm = function() {
|
||||
return this.getBody().find('form');
|
||||
};
|
||||
|
||||
/**
|
||||
* Disable the buttons in the footer.
|
||||
*
|
||||
* @method disableButtons
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.disableButtons = function() {
|
||||
this.saveButton.prop('disabled', true);
|
||||
this.cancelButton.prop('disabled', true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable the buttons in the footer.
|
||||
*
|
||||
* @method enableButtons
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.enableButtons = function() {
|
||||
this.saveButton.prop('disabled', false);
|
||||
this.cancelButton.prop('disabled', false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the title for the modal to the appropriate value
|
||||
* depending on message outputs.
|
||||
*
|
||||
* @method loadTitleContent
|
||||
* @return {object} A promise resolved with the new title text.
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.loadTitleContent = function() {
|
||||
this.titlePromise = Str.get_string('processorsettings', 'message');
|
||||
this.setTitle(this.titlePromise);
|
||||
|
||||
return this.titlePromise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the body for the modal to the appropriate value
|
||||
* depending on message outputs.
|
||||
*
|
||||
* @method loadBodyContent
|
||||
* @return {object} A promise resolved with the fragment html and js from
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.loadBodyContent = function() {
|
||||
this.disableButtons();
|
||||
|
||||
var args = {
|
||||
userid: this.getUserId(),
|
||||
type: this.getName(),
|
||||
};
|
||||
|
||||
this.bodyPromise = Fragment.loadFragment('message', 'processor_settings', this.getContextId(), args);
|
||||
this.setBody(this.bodyPromise);
|
||||
|
||||
this.bodyPromise.then(function() {
|
||||
this.enableButtons();
|
||||
return;
|
||||
}.bind(this))
|
||||
.fail(Notification.exception);
|
||||
|
||||
return this.bodyPromise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Load both the title and body content.
|
||||
*
|
||||
* @method loadAllContent
|
||||
* @return {object} promise
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.loadAllContent = function() {
|
||||
return $.when(this.loadTitleContent(), this.loadBodyContent());
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the modal content before showing it. This
|
||||
* is to allow us to re-use the same modal for creating and
|
||||
* editing different message outputs within the page.
|
||||
*
|
||||
* @method show
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.show = function() {
|
||||
Fragment.loadFragment('message', 'processor_settings', this.contextId, {
|
||||
userid: this.userId,
|
||||
type: this.name,
|
||||
})
|
||||
.done(function(html, js) {
|
||||
Str.get_string('processorsettings', 'message').done(function(string) {
|
||||
var dialogue = new Dialogue(
|
||||
string,
|
||||
html,
|
||||
function() {
|
||||
Templates.runTemplateJS(js);
|
||||
},
|
||||
function() {
|
||||
// Removed dialogue from the DOM after close.
|
||||
dialogue.close();
|
||||
}
|
||||
);
|
||||
this.loadAllContent();
|
||||
Modal.prototype.show.call(this);
|
||||
};
|
||||
|
||||
$(document).on('mpp:formsubmitted', function() {
|
||||
dialogue.close();
|
||||
this.updateConfiguredStatus();
|
||||
}.bind(this));
|
||||
|
||||
$(document).on('mpp:formcancelled', function() {
|
||||
dialogue.close();
|
||||
});
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
/**
|
||||
* Clear the notification from the modal when it's closed so
|
||||
* that it is loaded fresh next time it's displayed.
|
||||
*
|
||||
* @method hide
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.hide = function() {
|
||||
Modal.prototype.hide.call(this);
|
||||
this.setContextId(null);
|
||||
this.setName(null);
|
||||
this.setUserId(null);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -86,7 +263,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/fragment', 'core/templ
|
||||
* @return {Promise|boolean}
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.updateConfiguredStatus = function() {
|
||||
var processorHeader = this.root.closest(SELECTORS.PROCESSOR);
|
||||
var processorHeader = $(this.getElement()).closest(SELECTORS.PROCESSOR);
|
||||
|
||||
if (!processorHeader.hasClass('unconfigured')) {
|
||||
return false;
|
||||
@ -114,5 +291,44 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/fragment', 'core/templ
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Set up all of the event handling for the modal.
|
||||
*
|
||||
* @method registerEventListeners
|
||||
*/
|
||||
NotificationProcessorSettings.prototype.registerEventListeners = function() {
|
||||
// Apply parent event listeners.
|
||||
Modal.prototype.registerEventListeners.call(this);
|
||||
|
||||
// When the user clicks the save button we trigger the form submission.
|
||||
this.getModal().on(CustomEvents.events.activate, SELECTORS.SAVE_BUTTON, function(e, data) {
|
||||
this.getForm().submit();
|
||||
data.originalEvent.preventDefault();
|
||||
}.bind(this));
|
||||
|
||||
this.getModal().on('mpp:formsubmitted', function(e) {
|
||||
this.hide();
|
||||
this.updateConfiguredStatus();
|
||||
e.stopPropagation();
|
||||
}.bind(this));
|
||||
|
||||
this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function(e, data) {
|
||||
this.hide();
|
||||
data.originalEvent.preventDefault();
|
||||
e.stopPropagation();
|
||||
}.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(
|
||||
NotificationProcessorSettings.TYPE,
|
||||
NotificationProcessorSettings,
|
||||
'core/modal_save_cancel');
|
||||
registered = true;
|
||||
}
|
||||
|
||||
return NotificationProcessorSettings;
|
||||
});
|
||||
|
@ -23,9 +23,23 @@
|
||||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_events', 'core_message/notification_preference',
|
||||
'core_message/notification_processor_settings'],
|
||||
function($, Ajax, Notification, CustomEvents, NotificationPreference, NotificationProcessorSettings) {
|
||||
define(['jquery',
|
||||
'core/ajax',
|
||||
'core/notification',
|
||||
'core/custom_interaction_events',
|
||||
'core_message/notification_preference',
|
||||
'core_message/notification_processor_settings',
|
||||
'core/modal_factory',
|
||||
],
|
||||
function(
|
||||
$,
|
||||
Ajax,
|
||||
Notification,
|
||||
CustomEvents,
|
||||
NotificationPreference,
|
||||
NotificationProcessorSettings,
|
||||
ModalFactory
|
||||
) {
|
||||
|
||||
var SELECTORS = {
|
||||
DISABLE_NOTIFICATIONS: '[data-region="disable-notification-container"] [data-disable-notifications]',
|
||||
@ -143,11 +157,25 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
this.root.on(CustomEvents.events.activate, SELECTORS.PROCESSOR_SETTING, function(e, data) {
|
||||
var eventFormPromise = ModalFactory.create({
|
||||
type: NotificationProcessorSettings.TYPE,
|
||||
});
|
||||
|
||||
this.root.on(CustomEvents.events.activate, SELECTORS.PROCESSOR_SETTING, function(e) {
|
||||
var element = $(e.target).closest(SELECTORS.PROCESSOR_SETTING);
|
||||
var processorSettings = new NotificationProcessorSettings(element);
|
||||
processorSettings.show();
|
||||
data.originalEvent.preventDefault();
|
||||
|
||||
e.preventDefault();
|
||||
eventFormPromise.then(function(modal) {
|
||||
// Configure modal with element settings.
|
||||
modal.setUserId($(element).attr('data-user-id'));
|
||||
modal.setName($(element).attr('data-name'));
|
||||
modal.setContextId($(element).attr('data-context-id'));
|
||||
modal.setElement(element);
|
||||
modal.show();
|
||||
|
||||
e.stopImmediatePropagation();
|
||||
return;
|
||||
}).fail(Notification.exception);
|
||||
});
|
||||
|
||||
CustomEvents.define(disabledNotificationsElement, [
|
||||
|
@ -22,8 +22,8 @@
|
||||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_events'],
|
||||
function($, Ajax, Notification, CustomEvents) {
|
||||
define(['jquery', 'core/ajax', 'core/notification'],
|
||||
function($, Ajax, Notification) {
|
||||
/**
|
||||
* Constructor for the ProcessorForm.
|
||||
*
|
||||
@ -37,18 +37,9 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_eve
|
||||
this.root.find('form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
this.save().done(function() {
|
||||
$(document).trigger('mpp:formsubmitted');
|
||||
$(element).trigger('mpp:formsubmitted');
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
var cancelButton = this.root.find('[data-cancel-button]');
|
||||
CustomEvents.define(cancelButton, [
|
||||
CustomEvents.events.activate
|
||||
]);
|
||||
|
||||
cancelButton.on(CustomEvents.events.activate, function() {
|
||||
$(document).trigger('mpp:formcancelled');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -51,10 +51,6 @@
|
||||
</div>
|
||||
<form>
|
||||
{{{formhtml}}}
|
||||
<div class="form-actions m-t-1">
|
||||
<button type="submit" class="btn btn-primary">{{#str}} savechanges {{/str}}</button>
|
||||
<button type="button" class="btn" data-cancel-button>{{#str}} cancel {{/str}}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{{#js}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user