Skip to content

Commit

Permalink
MINOR Removed $('.cms-content').loadForm(), its very similar to loadP…
Browse files Browse the repository at this point in the history
…anel() - accepts callbacks, but that's not specific to forms. Listen to 'afterstatechange' rather than 'loadform' events
  • Loading branch information
chillu committed Apr 12, 2012
1 parent b025b95 commit e2df1f4
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 78 deletions.
2 changes: 1 addition & 1 deletion admin/javascript/LeftAndMain.AddForm.js
Expand Up @@ -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() {
Expand Down
72 changes: 0 additions & 72 deletions admin/javascript/LeftAndMain.Content.js
Expand Up @@ -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
*
Expand Down
3 changes: 0 additions & 3 deletions admin/javascript/LeftAndMain.js
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions docs/en/reference/cms-architecture.md
Expand Up @@ -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,
Expand Down

0 comments on commit e2df1f4

Please sign in to comment.