mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Removed $('.cms-content').loadForm(), its very similar to loadPanel() - accepts callbacks, but that's not specific to forms. Listen to 'afterstatechange' rather than 'loadform' events
This commit is contained in:
parent
b025b95ede
commit
e2df1f4c5f
@ -89,7 +89,7 @@
|
||||
data.push({name:button.attr('name'),value:button.val()});
|
||||
|
||||
// TODO Should be set by hiddenfield already
|
||||
jQuery('.cms-content').entwine('ss').loadForm(
|
||||
jQuery('.cms-content').entwine('ss').submitForm(
|
||||
this.attr('action'),
|
||||
null,
|
||||
function() {
|
||||
|
@ -26,78 +26,6 @@
|
||||
this.layout();
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: loadForm
|
||||
*
|
||||
* See $('.cms-container').loadPanel() on a frequently used alternative
|
||||
* to direct ajax loading of content, with support for the window.History object.
|
||||
*
|
||||
* Parameters:
|
||||
* (String) url - ..
|
||||
* (Function) callback - (Optional) Called after the form content as been loaded
|
||||
* (Object) ajaxOptions - Object literal merged into the jQuery.ajax() call (Optional)
|
||||
*
|
||||
* Returns:
|
||||
* (XMLHTTPRequest)
|
||||
*/
|
||||
loadForm: function(url, form, callback, ajaxOptions) {
|
||||
var self = this;
|
||||
if(!form || !form.length) {
|
||||
var form = $('.cms-content-fields form:first', self);
|
||||
if(form.length == 0) form = $('.cms-content-fields').parents("form").eq(0);
|
||||
}
|
||||
|
||||
// Alert when unsaved changes are present
|
||||
if(!form.confirmUnsavedChanges()) return false;
|
||||
|
||||
// hide existing form - shown again through _loadResponse()
|
||||
form.addClass('loading');
|
||||
|
||||
this.trigger('loadform', {form: form, url: url});
|
||||
|
||||
var opts = jQuery.extend({}, {
|
||||
// Ensure that form view is loaded (rather than whole "Content" template)
|
||||
headers: {"X-Pjax" : "CurrentForm"},
|
||||
url: url,
|
||||
complete: function(xmlhttp, status) {
|
||||
self.loadForm_responseHandler(form, xmlhttp.responseText, status, xmlhttp);
|
||||
if(callback) callback.apply(self, arguments);
|
||||
},
|
||||
dataType: 'html'
|
||||
}, ajaxOptions);
|
||||
|
||||
return jQuery.ajax(opts);
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: loadForm_responseHandler
|
||||
*
|
||||
* Loads the response into the DOM provided. Assumes oldForm is contains
|
||||
* the form tag to replace. If oldForm isn't present in the DOM, such as
|
||||
* if this form is only shown after click, append the whole form.
|
||||
*
|
||||
* Parameters:
|
||||
* (String) oldForm - HTML or eval'd javascript
|
||||
* (String) html - HTML to replace oldForm
|
||||
* (String) status
|
||||
* (XMLHTTPRequest) xmlhttp
|
||||
*/
|
||||
loadForm_responseHandler: function(oldForm, html, status, xmlhttp) {
|
||||
if(!html) return;
|
||||
|
||||
if(oldForm.length > 0) {
|
||||
oldForm.replaceWith(html); // triggers onmatch() on form
|
||||
} else {
|
||||
$('.cms-content').append(html);
|
||||
}
|
||||
|
||||
// redraw the layout.
|
||||
jQuery('.cms-container').entwine('ss').redraw();
|
||||
|
||||
// set status message based on response
|
||||
var _statusMessage = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.statusText;
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: ajaxSubmit
|
||||
*
|
||||
|
@ -194,9 +194,6 @@ jQuery.noConflict();
|
||||
* For example, a ModelAdmin search event should contain the search terms
|
||||
* as URL parameters, and the result display should automatically appear
|
||||
* if the URL is loaded without ajax.
|
||||
*
|
||||
* Alternatively, you can load new content via $('.cms-content').loadForm(<url>).
|
||||
* In this case, the action won't be recorded in the browser history.
|
||||
*/
|
||||
handleStateChange: function() {
|
||||
var self = this, h = window.History, state = h.getState();
|
||||
|
@ -176,8 +176,7 @@ should be placed in jQuery.entinwe `onmatch()` rules which apply to the newly cr
|
||||
See `$('.cms-container').handleStateChange()` in `LeftAndMain.js` for details.
|
||||
|
||||
Alternatively, form-related Ajax calls can be invoked through their own wrappers,
|
||||
which don't cause history events and hence allow callbacks: `$('.cms-content').loadForm()`
|
||||
and `$('.cms-content').submitForm()`.
|
||||
which don't cause history events and hence allow callbacks: `$('.cms-content').submitForm()`.
|
||||
|
||||
Within the PHP logic, the `[api:PjaxResponseNegotiator]` class determines which view is rendered.
|
||||
Through a custom `X-Pjax` HTTP header, the client can declare which view he's expecting,
|
||||
|
Loading…
x
Reference in New Issue
Block a user