Commit fdb78c81 authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review
Browse files

Enable checking dirty changes for special pages (Bug #1182739)



1. Profile Picture
2. Edit layout
3. Files
4. institution members
5. institution/site staff
6. institution/site admins
7. Edit access (Shared by me)

Change-Id: I9e651134fcc7f9e223a735b31bdae66a2dc64a6f
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent d41927f6
......@@ -55,6 +55,7 @@ $adminusers = get_column_sql('SELECT ui.usr
$form = array(
'name' => 'adminusers',
'checkdirtychange' => false,
'elements' => array(
'users' => array(
'type' => 'userlist',
......@@ -104,7 +105,11 @@ function adminusers_submit(Pieform $form, $values) {
}
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs'] . '
addLoadEvent(function() {
formchangemanager.add(\'adminusers\');
formchangemanager.unbindForm(\'adminusers\');
});');
$smarty->assign('adminusersform', pieform($form));
$smarty->assign('PAGEHEADING', TITLE);
$smarty->display('admin/users/institutionadmins.tpl');
......@@ -55,6 +55,7 @@ $staffusers = get_column_sql('SELECT ui.usr
$form = array(
'name' => 'staffusers',
'checkdirtychange' => false,
'elements' => array(
'users' => array(
'type' => 'userlist',
......@@ -102,7 +103,11 @@ function staffusers_submit(Pieform $form, $values) {
}
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs'] . '
addLoadEvent(function() {
formchangemanager.add(\'staffusers\');
formchangemanager.unbindForm(\'staffusers\');
});');
$smarty->assign('staffusersform', pieform($form));
$smarty->assign('PAGEHEADING', TITLE);
$smarty->display('admin/users/institutionstaff.tpl');
......@@ -86,6 +86,7 @@ if ($usertype == 'lastinstitution') {
$usertypeselector = pieform(array(
'name' => 'usertypeselect',
'checkdirtychange' => false,
'elements' => $usertypeselectorelements,
));
......@@ -153,6 +154,7 @@ $userlistelement['searchparams']['institution'] = $institution;
$userlistform = array(
'name' => 'institutionusers',
'checkdirtychange' => false,
'elements' => array(
'institution' => $institutionelement,
'users' => $userlistelement,
......@@ -296,6 +298,10 @@ addLoadEvent(function() {
if ($('institutionusers_institution')) {
connect($('institutionusers_institution'), 'onchange', reloadUsers);
}
formchangemanager.add('institutionusers');
// Unbind the handler for standard pieform input
// The JS code for updating the userlist will also update the formchangechecker state
formchangemanager.unbindForm('institutionusers');
});
EOF;
......
......@@ -51,6 +51,7 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
if (self.config.edit || self.config.editmeta) {
self.edit_init();
}
}
this.submitform = function () {
......@@ -247,8 +248,12 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
this.hide_edit_form = function () {
var editrow = $(self.id + '_edit_row');
if (!hasElementClass(editrow, 'hidden')) {
if ((typeof formchangemanager !== 'undefined') && !formchangemanager.confirmLeavingForm()) {
return false;
}
addElementClass(editrow, 'hidden');
// Reconnect the old edit button to open the form
if (editrow.previousSibling) {
......@@ -261,13 +266,17 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
});
}
}
return true;
}
this.edit_form = function (e) {
e.stop();
// In IE, this.value is set to the button text
var id = getNodeAttribute(this, 'name').replace(/.*_edit\[(\d+)\]$/, '$1');
self.hide_edit_form();
if (!self.hide_edit_form()) {
return;
}
$(self.id + '_edit_heading').innerHTML = self.filedata[id].artefacttype == 'folder' ? get_string('editfolder') : get_string('editfile');
var descriptionrow = getFirstParentByTagAndClassName($(self.id + '_edit_description'), 'tr');
if (self.filedata[id].artefacttype == 'profileicon') {
......@@ -322,9 +331,12 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
disconnectAll(this);
connect(this, 'onclick', function (e) {
e.stop();
addElementClass(self.id + '_edit_row', 'hidden');
disconnectAll(this);
connect(this, 'onclick', self.edit_form);
// Check if there are some dirty changes before close the edit form
if ((typeof formchangemanager !== 'undefined') && formchangemanager.confirmLeavingForm()) {
addElementClass(self.id + '_edit_row', 'hidden');
disconnectAll(this);
connect(this, 'onclick', self.edit_form);
}
return false;
});
......@@ -437,6 +449,10 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
});
forEach(getElementsByTagAndClassName('a', 'changefolder', self.id + '_upload_browse'), function (elem) {
connect(elem, 'onclick', function (e) {
if ((typeof formchangemanager !== 'undefined') && !formchangemanager.confirmLeavingForm()) {
e.stop();
return false;
}
var href = getNodeAttribute(this, 'href');
var params = parseQueryString(href.substring(href.indexOf('?')+1));
$(self.id + '_changefolder').value = params.folder;
......@@ -837,3 +853,5 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
// This variable = true if the users has updated the field 'Tags' by clicking the tag.
var tags_changed = false;
......@@ -90,6 +90,10 @@ $profileiconattachedtoportfolioitems = json_encode(get_string('profileiconattach
$profileiconappearsinviews = json_encode(get_string('profileiconappearsinviews', 'artefact.file'));
$confirmdeletefile = json_encode(get_string('confirmdeletefile', 'artefact.file'));
$IJS = <<<EOF
formchangemanager.add('settings');
var profileiconschecker = formchangemanager.find('settings');
var table = new TableRenderer(
'profileicons',
'profileicons.json.php',
......@@ -142,6 +146,10 @@ table.updatecallback = function(response) {
}
};
table.postupdatecallback = function(response) {
profileiconschecker.init();
};
var uploadingMessage = TR(null,
TD(null, {$struploadingfile})
);
......@@ -162,6 +170,8 @@ function postSubmit(form, data) {
addLoadEvent( function() {
connect('settings_delete', 'onclick', function(e) {
profileiconschecker.set(FORM_SUBMITTED);
// Find form
var form = getFirstParentByTagAndClassName(e, 'form', 'pieform');
forEach (getElementsByTagAndClassName('input', 'checkbox', form), function (profileicon) {
......
......@@ -77,6 +77,10 @@
collayouts += '_row' + [i+1] + '_' + $('#selectcollayoutrow_' + (i+1)).val();
}
if (typeof formchangemanager !== 'undefined') {
formchangemanager.setFormState($('#viewlayout'), FORM_CHANGED);
}
var pd = {
'id': $('#viewlayout_viewid').val(),
'change': 1
......@@ -227,6 +231,10 @@
$('#custompreview').html(pi);
}
});
if (typeof formchangemanager !== 'undefined') {
formchangemanager.setFormState($('#viewlayout'), FORM_CHANGED);
}
}
$(document).ready(function() {
......
......@@ -198,6 +198,10 @@ function renderAccessListItem(item) {
if (!getFirstElementByTagAndClassName('tr', null, 'accesslistitems')) {
renderAccessListDefault();
}
// Update the formchangechecker state
if (typeof formchangemanager !== 'undefined') {
formchangemanager.setFormStateById('{{$formname}}', FORM_CHANGED);
}
});
appendChildNodes('accesslistitems', row);
addElementClass('accesslisttabledefault', 'hidden');
......@@ -218,6 +222,10 @@ function renderAccessListItem(item) {
$j(row).find('.pieform-calendar-toggle').hide();
}
count++;
// Update the formchangechecker state
if (typeof formchangemanager !== 'undefined') {
formchangemanager.setFormStateById('{{$formname}}', FORM_CHANGED);
}
}
function makeCalendarInput(item, type, disabled) {
......@@ -278,10 +286,17 @@ function setupCalendar(item, type) {
"button" : type + 'date_' + count + '_btn',
//"dateStatusFunc" : dateStatusFunc,
//"onSelect" : selectedFunc
"onUpdate" : updateFormChangeChecker,
"showsTime" : true
});
}
function updateFormChangeChecker() {
if (typeof formchangemanager !== 'undefined') {
formchangemanager.setFormStateById('{{$formname}}', FORM_CHANGED);
}
}
// SETUP
// Left top: public, loggedin, friends
......
......@@ -112,6 +112,10 @@ function get_max_custom_rows() {
return {$maxlayoutrows};
}
addLoadEvent(function () {
formchangemanager.add("viewlayout");
});
JAVASCRIPT;
$elements = array(
......
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