app/assets/javascripts/trestle/components/_form.js in trestle-0.8.6 vs app/assets/javascripts/trestle/components/_form.js in trestle-0.8.7
- old
+ new
@@ -8,18 +8,39 @@
Trestle.init(function(e, root) {
var form = $(root).find('form[data-behavior="trestle-form"]');
form
.on('ajax:complete', function(e, xhr, status) {
- // Find the parent context and replace content
- var context = $(this).closest('[data-context]');
- context.html(xhr.responseText);
+ var contentType = xhr.getResponseHeader("Content-Type").split(";")[0];
- // Initialize replaced elements within the context
- $(Trestle).trigger('init', context);
+ if (contentType == "text/html") {
+ if (/<html/i.test(xhr.responseText)) {
+ // Response is a full HTML page, likely an error page. Render within an iframe.
- // Focus the correct tab
- Trestle.focusActiveTab();
+ var context = $(this).closest('[data-context]');
+ var iframe = $("<iframe>").addClass('error-iframe').get(0);
+ context.html(iframe);
+
+ iframe.contentWindow.document.documentElement.innerHTML = xhr.responseText;
+ } else {
+ // Find the parent context and replace content
+ var context = $(this).closest('[data-context]');
+ context.html(xhr.responseText);
+
+ // Initialize replaced elements within the context
+ $(Trestle).trigger('init', context);
+
+ // Focus the correct tab
+ Trestle.focusActiveTab();
+ }
+ } else {
+ // Assume an error response
+ var title = xhr.status + " (" + xhr.statusText + ")";
+ Trestle.Dialog.showError(title, xhr.responseText);
+
+ // Reset submit button
+ form.find(':submit').prop('disabled', false).removeClass('loading');
+ }
})
.on('ajax:success', function(e, data, status, xhr) {
var context = $(this).closest('[data-context]');
var location = xhr.getResponseHeader("X-Trestle-Location");