Commit 36bbb0b7 authored by Ankit Agarwal's avatar Ankit Agarwal
Browse files

MDL-49931 preferences: Add cancel button to forms

parent 24a2babd
......@@ -135,7 +135,8 @@ if (($form = data_submitted()) && confirm_sesskey()) {
}
user_update_user($user, false, false);
redirect("$CFG->wwwroot/message/edit.php?id=$user->id");
$redirect = new moodle_url("/user/preferences.php", array('userid' => $userid));
redirect($redirect);
}
/// Load preferences
......@@ -180,7 +181,8 @@ $renderer = $PAGE->get_renderer('core', 'message');
// Fetch default (site) preferences
$defaultpreferences = get_message_output_default_preferences();
$messagingoptions = $renderer->manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $user->emailstop);
$messagingoptions = $renderer->manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences,
$user->emailstop, $user->id);
echo $OUTPUT->header();
echo $messagingoptions;
......
......@@ -223,9 +223,15 @@ class core_message_renderer extends plugin_renderer_base {
* @param array $preferences Array of objects containing current preferences
* @param array $defaultpreferences Array of objects containing site default preferences
* @param bool $notificationsdisabled Indicate if the user's "emailstop" flag is set (shouldn't receive any non-forced notifications)
* @param null|int $userid User id, or null if current user.
* @return string The text to render
*/
public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $notificationsdisabled = false) {
public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences,
$notificationsdisabled = false, $userid = null) {
global $USER;
if (empty($userid)) {
$userid = $USER->id;
}
// Filter out enabled, available system_configured and user_configured processors only.
$readyprocessors = array_filter($processors, create_function('$a', 'return $a->enabled && $a->configured && $a->object->is_user_configured();'));
......@@ -379,10 +385,13 @@ class core_message_renderer extends plugin_renderer_base {
$disableallcheckbox .= $this->output->help_icon('disableall', 'message');
$output .= html_writer::nonempty_tag('div', $disableallcheckbox, array('class'=>'disableall'));
$redirect = new moodle_url("/user/preferences.php", array('userid' => $userid));
$output .= html_writer::end_tag('fieldset');
$output .= html_writer::start_tag('div', array('class' => 'mdl-align'));
$output .= html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('savechanges'), 'class' => 'form-submit'));
$output .= html_writer::link($redirect, html_writer::empty_tag('input', array('type' => 'button',
'value' => get_string('cancel'), 'class' => 'btn-cancel')));
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('form');
......
This files describes API changes in /message/ messaging system,
information provided here is intended especially for developers.
=== 2.9 ===
* Renderer method \core_message_renderer::manage_messagingoptions now accepts a user id parameter as well.
=== 2.6 ===
* Message processor extending message_output, should return true in can_send_to_any_users()
if it supports message sending to internal (noreply/support) users.
......
......@@ -41,7 +41,10 @@ $editorform = new user_edit_editor_form(null, array('userid' => $user->id));
$user->preference_htmleditor = get_user_preferences( 'htmleditor', '', $user->id);
$editorform->set_data($user);
if ($data = $editorform->get_data()) {
$redirect = new moodle_url("/user/preferences.php", array('userid' => $user->id));
if ($editorform->is_cancelled()) {
redirect($redirect);
} else if ($data = $editorform->get_data()) {
$user->preference_htmleditor = $data->preference_htmleditor;
......@@ -49,7 +52,7 @@ if ($data = $editorform->get_data()) {
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
redirect($redirect);
}
// Display page header.
......
......@@ -63,7 +63,7 @@ class user_edit_editor_form extends moodleform {
$mform->setType('preference_htmleditor', PARAM_PLUGIN);
}
$this->add_action_buttons(false, get_string('savechanges'));
$this->add_action_buttons(true, get_string('savechanges'));
}
}
......
......@@ -40,7 +40,10 @@ $forumform = new user_edit_forum_form(null, array('userid' => $user->id));
$forumform->set_data($user);
if ($data = $forumform->get_data()) {
$redirect = new moodle_url("/user/preferences.php", array('userid' => $user->id));
if ($forumform->is_cancelled()) {
redirect($redirect);
} else if ($data = $forumform->get_data()) {
$user->maildigest = $data->maildigest;
$user->autosubscribe = $data->autosubscribe;
......@@ -50,7 +53,7 @@ if ($data = $forumform->get_data()) {
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
redirect($redirect);
}
// Display page header.
......
......@@ -75,7 +75,7 @@ class user_edit_forum_form extends moodleform {
$mform->addElement('hidden', 'course', $COURSE->id);
$mform->setType('course', PARAM_INT);
$this->add_action_buttons(false, get_string('savechanges'));
$this->add_action_buttons(true, get_string('savechanges'));
}
}
......
......@@ -39,7 +39,10 @@ list($user, $course) = useredit_setup_preference_page($userid, $courseid);
$languageform = new user_edit_language_form(null, array('userid' => $user->id));
$languageform->set_data($user);
if ($data = $languageform->get_data()) {
$redirect = new moodle_url("/user/preferences.php", array('userid' => $user->id));
if ($languageform->is_cancelled()) {
redirect($redirect);
} else if ($data = $languageform->get_data()) {
$lang = $data->lang;
// If the specified language does not exist, use the site default.
if (!get_string_manager()->translation_exists($lang, false)) {
......@@ -53,7 +56,7 @@ if ($data = $languageform->get_data()) {
// Trigger event.
\core\event\user_updated::create_from_userid($user->id)->trigger();
redirect("$CFG->wwwroot/user/preferences.php?userid=$user->id");
redirect($redirect);
}
// Display page header.
......
......@@ -60,7 +60,7 @@ class user_edit_language_form extends moodleform {
$mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
$mform->setDefault('lang', $CFG->lang);
$this->add_action_buttons(false, get_string('savechanges'));
$this->add_action_buttons(true, get_string('savechanges'));
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment