2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* Handle auto-saving. Detects if changes have been made, and if so save everything on the page.
|
|
|
|
* If confirmation is true it will ask for confirmation.
|
|
|
|
*/
|
|
|
|
function autoSave(confirmation, callAfter) {
|
2008-10-28 05:32:30 +01:00
|
|
|
// Note: TinyMCE coupling
|
2007-07-19 12:40:05 +02:00
|
|
|
if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave();
|
|
|
|
|
|
|
|
var __forms = []
|
|
|
|
if($('Form_EditForm')) __forms.push($('Form_EditForm'));
|
|
|
|
if($('Form_SubForm')) __forms.push($('Form_SubForm'));
|
|
|
|
if($('Form_MemberForm')) __forms.push($('Form_MemberForm'));
|
|
|
|
|
|
|
|
var __somethingHasChanged = false;
|
|
|
|
var __callAfter = callAfter;
|
|
|
|
|
|
|
|
__forms.each(function(form) {
|
|
|
|
if(form.isChanged && form.isChanged()) {
|
|
|
|
__somethingHasChanged = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if(__somethingHasChanged) {
|
2007-09-14 21:29:12 +02:00
|
|
|
// Note: discard and cancel options are no longer used since switching to confirm dialog.
|
|
|
|
// save is still used if confirmation = false
|
|
|
|
var options = {
|
|
|
|
save: function() {
|
2008-10-03 02:48:34 +02:00
|
|
|
statusMessage(ss.i18n._t('CMSMAIN.SAVING'), '', true);
|
2007-09-14 21:29:12 +02:00
|
|
|
var i;
|
|
|
|
for(i=0;i<__forms.length;i++) {
|
|
|
|
if(__forms[i].isChanged && __forms[i].isChanged()) {
|
|
|
|
if(i == 0) __forms[i].save(true, __callAfter);
|
|
|
|
else __forms[i].save(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
discard: function() {
|
|
|
|
__forms.each(function(form) { form.resetElements(false); });
|
|
|
|
if(__callAfter) __callAfter();
|
|
|
|
},
|
|
|
|
cancel: function() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-14 21:28:41 +02:00
|
|
|
if(confirmation ) {
|
2009-01-05 07:17:59 +01:00
|
|
|
if(confirm(ss.i18n._t('LeftAndMain.CONFIRMUNSAVED')))
|
2007-09-14 21:28:41 +02:00
|
|
|
{
|
|
|
|
// OK was pressed, call function for what was clicked on
|
2007-07-19 12:40:05 +02:00
|
|
|
if(__callAfter) __callAfter();
|
2007-09-14 21:28:41 +02:00
|
|
|
} else {
|
2007-09-14 21:29:12 +02:00
|
|
|
// Cancel was pressed, stay on the current page
|
2007-09-14 21:30:11 +02:00
|
|
|
return false;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-14 21:28:41 +02:00
|
|
|
} else {
|
|
|
|
options.save();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if(__callAfter) __callAfter();
|
|
|
|
}
|
2009-11-21 03:38:17 +01:00
|
|
|
}
|