MDL-54698 message: add save/cancel button to processor popup

This commit is contained in:
Ryan Wyllie
2016-10-07 16:26:40 +08:00
committed by Mark Nelson
parent b6cd1c1151
commit a4a804b8f9
5 changed files with 62 additions and 36 deletions
@@ -23,7 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 3.2
*/
define(['jquery', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialogue'], function($, Fragment, Templates, Str, Dialogue) {
define(['jquery', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialogue'],
function($, Fragment, Templates, Str, Dialogue) {
/**
* Constructor for the notification processor settings.
*
@@ -49,12 +50,28 @@ define(['jquery', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialog
})
.done(function(html, js) {
Str.get_string('processorsettings', 'message').done(function(string) {
new Dialogue(string, html, function() {
Templates.runTemplateJS(js);
var dialogue = new Dialogue(
string,
html,
function() {
Templates.runTemplateJS(js);
},
function() {
// Removed dialogue from the DOM after close.
dialogue.close();
}
);
$(document).on('mpp:formsubmitted', function() {
dialogue.close();
});
$(document).on('mpp:formcancelled', function() {
dialogue.close();
});
});
});
}
};
return NotificationProcessorSettings;
});
+16 -3
View File
@@ -23,7 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 3.2
*/
define(['jquery', 'core/ajax', 'core/notification'], function($, ajax, notification) {
define(['jquery', 'core/ajax', 'core/notification', 'core/custom_interaction_events'],
function($, ajax, notification, CustomEvents) {
/**
* Constructor for the ProcessorForm.
*
@@ -35,9 +36,21 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, ajax, notificat
this.userId = this.root.attr('data-user-id');
this.name = this.root.attr('data-processor-name');
this.root.on('change', function(e) {
this.save();
this.root.find('form').on('submit', function(e) {
e.preventDefault();
this.save().done(function() {
$(document).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');
});
};
/**
+20 -3
View File
@@ -2144,6 +2144,23 @@ function get_providers_preferences($providers, $userid) {
return $preferences;
}
function get_all_message_preferences($processors, $providers, $user) {
$preferences = get_providers_preferences($providers, $user->id);
$preferences->userdefaultemail = $user->email;//may be displayed by the email processor
/// For every processors put its options on the form (need to get function from processor's lib.php)
foreach ($processors as $processor) {
$processor->object->load_data($preferences, $user->id);
}
//load general messaging preferences
$preferences->blocknoncontacts = get_user_preferences('message_blocknoncontacts', '', $user->id);
$preferences->mailformat = $user->mailformat;
$preferences->mailcharset = get_user_preferences('mailcharset', '', $user->id);
return $preferences;
}
function message_output_fragment_processor_settings($args = []) {
global $PAGE;
@@ -2161,9 +2178,9 @@ function message_output_fragment_processor_settings($args = []) {
$user = core_user::get_user($userid, '*', MUST_EXIST);
$processor = get_message_processor($type);
$providers = message_get_providers_for_user($userid);
$preferences = get_providers_preferences($providers, $userid);
$processor->load_data($preferences, $userid);
$processorwrapper = new stdClass();
$processorwrapper->object = $processor;
$preferences = get_all_message_preferences([$processorwrapper], $providers, $user);
$processoroutput = new \core_message\output\preferences\processor($processor, $preferences, $user, $type);
$renderer = $PAGE->get_renderer('core', 'message');
+1 -26
View File
@@ -215,31 +215,6 @@ class core_message_renderer extends plugin_renderer_base {
return $output;
}
/**
* Get the preferences for the given user.
*
* @param array $processors list of message processors
* @param array $providers list of message providers
* @param stdClass $user user
* @return stdClass
*/
private function get_all_preferences($processors, $providers, $user) {
$preferences = get_providers_preferences($providers, $user->id);
$preferences->userdefaultemail = $user->email;//may be displayed by the email processor
/// For every processors put its options on the form (need to get function from processor's lib.php)
foreach ($processors as $processor) {
$processor->object->load_data($preferences, $user->id);
}
//load general messaging preferences
$preferences->blocknoncontacts = get_user_preferences('message_blocknoncontacts', '', $user->id);
$preferences->mailformat = $user->mailformat;
$preferences->mailcharset = get_user_preferences('mailcharset', '', $user->id);
return $preferences;
}
/**
* Display the interface for messaging options
*
@@ -253,7 +228,7 @@ class core_message_renderer extends plugin_renderer_base {
});
$providers = message_get_providers_for_user($user->id);
$preferences = $this->get_all_preferences($readyprocessors, $providers, $user);
$preferences = get_all_message_preferences($readyprocessors, $providers, $user);
$notificationlistoutput = new \core_message\output\preferences\notification_list($readyprocessors, $providers, $preferences, $user);
$generalsettingsoutput = new \core_message\output\preferences\general_settings($preferences, $user);
@@ -49,6 +49,10 @@
</div>
<form>
{{{formhtml}}}
<div class="form-actions">
<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}}