2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* File: LeftAndMain.EditForm.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
2012-03-04 21:58:00 +01:00
|
|
|
|
|
|
|
// Can't bind this through jQuery
|
|
|
|
window.onbeforeunload = function(e) {
|
|
|
|
var form = $('.cms-edit-form');
|
|
|
|
form.trigger('beforesave');
|
|
|
|
if(form.is('.changed')) return ss.i18n._t('LeftAndMain.CONFIRMUNSAVEDSHORT');
|
|
|
|
};
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$.entwine('ss', function($){
|
|
|
|
|
|
|
|
/**
|
2011-03-31 10:52:29 +02:00
|
|
|
* Class: .cms-edit-form
|
2011-03-23 10:51:00 +01:00
|
|
|
*
|
|
|
|
* Base edit form, provides ajaxified saving
|
|
|
|
* and reloading itself through the ajax return values.
|
|
|
|
* Takes care of resizing tabsets within the layout container.
|
|
|
|
* @name ss.Form_EditForm
|
|
|
|
* @require jquery.changetracker
|
|
|
|
*
|
|
|
|
* Events:
|
|
|
|
* ajaxsubmit - Form is about to be submitted through ajax
|
|
|
|
* validate - Contains validation result
|
|
|
|
* removeform - A form is about to be removed from the DOM
|
|
|
|
* load - Form is about to be loaded through ajax
|
|
|
|
*/
|
2011-03-31 10:52:29 +02:00
|
|
|
$('.cms-edit-form').entwine(/** @lends ss.Form_EditForm */{
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Variable: PlaceholderHtml
|
|
|
|
* (String_ HTML text to show when no form content is chosen.
|
|
|
|
* Will show inside the <form> tag.
|
|
|
|
*/
|
|
|
|
PlaceholderHtml: '',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Variable: ChangeTrackerOptions
|
|
|
|
* (Object)
|
|
|
|
*/
|
2012-02-03 00:59:40 +01:00
|
|
|
ChangeTrackerOptions: {
|
|
|
|
ignoreFieldSelector: '.ss-upload :input'
|
|
|
|
},
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor: onmatch
|
|
|
|
*/
|
|
|
|
onmatch: function() {
|
|
|
|
var self = this;
|
2011-12-15 11:38:29 +01:00
|
|
|
|
|
|
|
// Turn off autocomplete to fix the access tab randomly switching radio buttons in Firefox
|
|
|
|
// when refresh the page with an anchor tag in the URL. E.g: /admin#Root_Access.
|
|
|
|
// Autocomplete in the CMS also causes strangeness in other browsers,
|
|
|
|
// filling out sections of the form that the user does not want to be filled out,
|
|
|
|
// so this turns it off for all browsers.
|
|
|
|
// See the following page for demo and explanation of the Firefox bug:
|
|
|
|
// http://www.ryancramer.com/journal/entries/radio_buttons_firefox/
|
|
|
|
this.attr("autocomplete", "off");
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
this._setupChangeTracker();
|
|
|
|
|
2011-12-15 11:38:29 +01:00
|
|
|
// Catch navigation events before they reach handleStateChange(),
|
|
|
|
// in order to avoid changing the menu state if the action is cancelled by the user
|
2012-02-21 17:46:58 +01:00
|
|
|
// $('.cms-menu')
|
2011-06-08 01:35:56 +02:00
|
|
|
|
|
|
|
// focus input on first form element
|
2011-09-19 21:34:03 +02:00
|
|
|
this.find(':input:visible:not(:submit):first').focus();
|
2011-06-08 01:35:56 +02:00
|
|
|
|
|
|
|
// Optionally get the form attributes from embedded fields, see Form->formHtmlContent()
|
|
|
|
for(var overrideAttr in {'action':true,'method':true,'enctype':true,'name':true}) {
|
|
|
|
var el = this.find(':input[name='+ '_form_' + overrideAttr + ']');
|
|
|
|
if(el) {
|
|
|
|
this.attr(overrideAttr, el.val());
|
|
|
|
el.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// // Rewrite # links
|
|
|
|
// html = html.replace(/(<a[^>]+href *= *")#/g, '$1' + window.location.href.replace(/#.*$/,'') + '#');
|
|
|
|
//
|
|
|
|
// // Rewrite iframe links (for IE)
|
|
|
|
// html = html.replace(/(<iframe[^>]*src=")([^"]+)("[^>]*>)/g, '$1' + $('base').attr('href') + '$2$3');
|
|
|
|
|
|
|
|
// Show validation errors if necessary
|
|
|
|
if(this.hasClass('validationerror')) {
|
|
|
|
// TODO validation shouldnt need a special case
|
|
|
|
statusMessage(ss.i18n._t('ModelAdmin.VALIDATIONERROR', 'Validation Error'), 'bad');
|
|
|
|
}
|
2011-07-21 20:14:33 +02:00
|
|
|
|
|
|
|
// Move navigator to preview if one is available.
|
|
|
|
// If not, just leave the links in the form.
|
|
|
|
var previewEl = $('.cms-preview');
|
|
|
|
if(previewEl.length) {
|
|
|
|
// TODO Relies on DOM element order (the second .cms-navigator is the "old" one)
|
|
|
|
previewEl.find('.cms-preview-controls').html(this.find('.cms-navigator').detach());
|
|
|
|
}
|
2011-06-08 01:35:56 +02:00
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
2011-12-13 14:56:35 +01:00
|
|
|
|
2011-07-21 18:39:26 +02:00
|
|
|
redraw: function() {
|
2011-12-15 20:37:20 +01:00
|
|
|
// Force initialization of tabsets to avoid layout glitches
|
2012-04-17 17:40:37 +02:00
|
|
|
this.add(this.find('.cms-tabset')).redrawTabs();
|
2011-12-15 20:37:20 +01:00
|
|
|
|
2011-12-15 22:04:03 +01:00
|
|
|
var approxWidth = $('.cms-container').width() - $('.cms-menu').width();
|
|
|
|
this.find('.cms-content-actions').width(approxWidth).height('auto');
|
2011-07-21 18:39:26 +02:00
|
|
|
|
|
|
|
this.layout();
|
|
|
|
},
|
2011-09-19 21:01:17 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Function: _setupChangeTracker
|
|
|
|
*/
|
|
|
|
_setupChangeTracker: function() {
|
|
|
|
// Don't bind any events here, as we dont replace the
|
|
|
|
// full <form> tag by any ajax updates they won't automatically reapply
|
|
|
|
this.changetracker(this.getChangeTrackerOptions());
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-12-15 12:23:32 +01:00
|
|
|
* Function: confirmUnsavedChanges
|
2011-03-23 10:51:00 +01:00
|
|
|
*
|
2011-12-15 12:23:32 +01:00
|
|
|
* Checks the jquery.changetracker plugin status for this form,
|
|
|
|
* and asks the user for confirmation via a browser dialog if changes are detected.
|
|
|
|
* Doesn't cancel any unload or form removal events, you'll need to implement this based on the return
|
|
|
|
* value of this message.
|
2011-03-23 10:51:00 +01:00
|
|
|
*
|
|
|
|
* Returns:
|
2011-12-15 12:23:32 +01:00
|
|
|
* (Boolean) FALSE if the user wants to abort with changes present, TRUE if no changes are detected
|
|
|
|
* or the user wants to discard them.
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2011-12-15 12:23:32 +01:00
|
|
|
confirmUnsavedChanges: function() {
|
|
|
|
this.trigger('beforesave');
|
|
|
|
return (this.is('.changed')) ? confirm(ss.i18n._t('LeftAndMain.CONFIRMUNSAVED')) : true;
|
2011-03-23 10:51:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: onsubmit
|
|
|
|
*
|
|
|
|
* Suppress submission unless it is handled through ajaxSubmit().
|
|
|
|
*/
|
2012-04-05 22:12:00 +02:00
|
|
|
onsubmit: function(e, button) {
|
2012-04-10 00:34:04 +02:00
|
|
|
this.closest('.cms-content').submitForm(this, button);
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: validate
|
|
|
|
*
|
|
|
|
* Hook in (optional) validation routines.
|
|
|
|
* Currently clientside validation is not supported out of the box in the CMS.
|
|
|
|
*
|
|
|
|
* Todo:
|
|
|
|
* Placeholder implementation
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* {boolean}
|
|
|
|
*/
|
|
|
|
validate: function() {
|
|
|
|
var isValid = true;
|
|
|
|
this.trigger('validate', {isValid: isValid});
|
|
|
|
|
|
|
|
return isValid;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2011-03-31 10:52:29 +02:00
|
|
|
* Class: .cms-edit-form .Actions :submit
|
2011-03-23 10:51:00 +01:00
|
|
|
*
|
|
|
|
* All buttons in the right CMS form go through here by default.
|
|
|
|
* We need this onclick overloading because we can't get to the
|
|
|
|
* clicked button from a form.onsubmit event.
|
|
|
|
*/
|
2012-03-09 03:40:24 +01:00
|
|
|
$('.cms-edit-form .Actions input.action[type=submit], .cms-edit-form .Actions button.action').entwine({
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*/
|
|
|
|
onclick: function(e) {
|
2012-04-05 22:12:00 +02:00
|
|
|
this.parents('form').trigger('submit', [this]);
|
2012-03-08 18:21:13 +01:00
|
|
|
e.preventDefault();
|
2011-03-23 10:51:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-01-09 17:17:31 +01:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
});
|
2011-12-13 14:56:35 +01:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
}(jQuery));
|