Trestle.Dialog = function(options) { options = options || {}; this.el = Trestle.Dialog.createElement(); if (options.modalClass) { this.el.find('.modal-dialog').addClass(options.modalClass); } }; Trestle.Dialog.TEMPLATE = '
').addClass('exception').text(errorText));
dialog.show();
return dialog;
};
Trestle.Dialog.prototype.load = function(url, callback) {
var dialog = this;
dialog.show();
dialog.setLoading(true);
$.ajax({
url: url,
dataType: 'html',
headers: {
"X-Trestle-Dialog": true
},
complete: function() {
dialog.setLoading(false);
},
success: function(content) {
dialog.setContent(content);
if (callback) {
callback.apply(dialog);
}
},
error: function(xhr, status, error) {
var errorMessage = Trestle.i18n['trestle.dialog.error'] || 'The request could not be completed.';
var title = error || errorMessage;
var content = $('').text(errorMessage);
dialog.showError(title, content);
}
});
};
Trestle.Dialog.prototype.setLoading = function(loading) {
if (loading) {
this.el.addClass('loading');
} else {
this.el.removeClass('loading');
}
}
Trestle.Dialog.prototype.setContent = function(content) {
this.el.find('.modal-content').html(content);
$(Trestle).trigger('init', this.el);
};
Trestle.Dialog.prototype.showError = function(title, content) {
this.el.addClass('error');
var container = this.el.find('.modal-content').empty();
$('
')
.append('')
.append('').find('h4').text(title).end()
.appendTo(container);
$('')
.append(content)
.appendTo(container);
$('