mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
Added backbone
This commit is contained in:
parent
b366f8fadc
commit
b101758957
28 changed files with 5507 additions and 3 deletions
53
NzbDrone.Web/Scripts/backbone/utils.js
Normal file
53
NzbDrone.Web/Scripts/backbone/utils.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
window.utils = {
|
||||
|
||||
// Asynchronously load templates located in separate .html files
|
||||
loadTemplate: function (views, callback) {
|
||||
|
||||
var deferreds = [];
|
||||
|
||||
$.each(views, function (index, view) {
|
||||
if (window[view]) {
|
||||
deferreds.push($.get('tpl/' + view + '.html', function (data) {
|
||||
window[view].prototype.template = _.template(data);
|
||||
}));
|
||||
} else {
|
||||
alert(view + ' not found');
|
||||
}
|
||||
});
|
||||
|
||||
$.when.apply(null, deferreds).done(callback);
|
||||
},
|
||||
|
||||
displayValidationErrors: function (messages) {
|
||||
for (var key in messages) {
|
||||
if (messages.hasOwnProperty(key)) {
|
||||
this.addValidationError(key, messages[key]);
|
||||
}
|
||||
}
|
||||
this.showAlert('Warning!', 'Fix validation errors and try again', 'alert-warning');
|
||||
},
|
||||
|
||||
addValidationError: function (field, message) {
|
||||
var controlGroup = $('#' + field).parent().parent();
|
||||
controlGroup.addClass('error');
|
||||
$('.help-inline', controlGroup).html(message);
|
||||
},
|
||||
|
||||
removeValidationError: function (field) {
|
||||
var controlGroup = $('#' + field).parent().parent();
|
||||
controlGroup.removeClass('error');
|
||||
$('.help-inline', controlGroup).html('');
|
||||
},
|
||||
|
||||
showAlert: function (title, text, klass) {
|
||||
$('.alert').removeClass('alert-error alert-warning alert-success alert-info');
|
||||
$('.alert').addClass(klass);
|
||||
$('.alert').html('<strong>' + title + '</strong> ' + text);
|
||||
$('.alert').show();
|
||||
},
|
||||
|
||||
hideAlert: function () {
|
||||
$('.alert').hide();
|
||||
}
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue