Commit 654ebc2e authored by Nigel McNie's avatar Nigel McNie
Browse files

Don't always show the 'lose your changes' prompt when clicking 'view profile'...

Don't always show the 'lose your changes' prompt when clicking 'view profile' from the profile page.

It's now only shown if you actually change a field, however:

* The change logic is simple - it's an 'onchange' on the fields themselves, so do not take into account if you make a change and revert it
* It doesn't work for the WYSIWYG boxes, they don't seem to fire onchanges. Would need another way to deal with this
parent 144adb0a
......@@ -118,7 +118,6 @@ $elements = array(
'topsubmit' => array(
'type' => 'submitcancel',
'value' => array(get_string('saveprofile','artefact.internal'), get_string('viewmyprofile', 'artefact.internal')),
'confirm' => array(null, get_string('loseyourchanges', 'artefact.internal')),
'goto' => get_config('wwwroot') . 'user/view.php?id=' . $USER->get('id'),
),
'profile' => array(
......@@ -152,7 +151,6 @@ $elements = array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('saveprofile','artefact.internal'), get_string('viewmyprofile', 'artefact.internal')),
'confirm' => array(null, get_string('loseyourchanges', 'artefact.internal')),
'goto' => get_config('wwwroot') . 'user/view.php?id=' . $USER->get('id'),
)
);
......@@ -387,6 +385,9 @@ $smarty = smarty(array('artefact/internal/js/profile.js'), array(), array(
'cannotremovedefaultemail',
'emailtoolong'
),
'artefact.internal' => array(
'loseyourchanges',
),
));
......
......@@ -54,6 +54,25 @@ addLoadEvent(function() {
getFirstElementByTagAndClassName('table', null, 'profileform')
);
// Connect events to each form element to check if they're changed and set
// a dirty flag
var formDirty = false;
forEach(getElementsByTagAndClassName(null, null, 'profileform'), function(i) {
if (i.tagName != 'INPUT' && i.tagName != 'TEXTAREA') return;
if (!hasElementClass(i, 'text') && !hasElementClass(i, 'textarea')) return;
connect(i, 'onchange', function(e) {
formDirty = true;
});
});
connect('cancel_profileform_submit', 'onclick', function(e) {
if (formDirty) {
if (!confirm(get_string('loseyourchanges'))) {
e.stop();
}
}
});
// Now unhide the profile form
hideElement('profile-loading');
$('profileform').style.position = 'static';
......
Markdown is supported
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