mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
Added backbone
This commit is contained in:
parent
b366f8fadc
commit
b101758957
28 changed files with 5507 additions and 3 deletions
27
NzbDrone.Web/Scripts/backbone/app.js
Normal file
27
NzbDrone.Web/Scripts/backbone/app.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
NzbDrone = {};
|
||||
|
||||
NzbDrone.Views = {};
|
||||
NzbDrone.Models = {};
|
||||
NzbDrone.Collections = {};
|
||||
|
||||
NzbDrone.App = new Backbone.Marionette.Application();
|
||||
|
||||
// Setup default application views
|
||||
NzbDrone.App.addInitializer(function () {
|
||||
|
||||
NzbDrone.App.addRegions({
|
||||
main: '#main-region'
|
||||
});
|
||||
|
||||
var layout = new NzbDrone.Views.AppLayout();
|
||||
|
||||
NzbDrone.App.Layout = layout;
|
||||
NzbDrone.App.main.show(layout);
|
||||
|
||||
layout.header.show(new NzbDrone.Views.HeaderView());
|
||||
});
|
||||
|
||||
NzbDrone.App.addInitializer(function () {
|
||||
new NzbDrone.AppRouter();
|
||||
Backbone.history.start();
|
||||
});
|
7
NzbDrone.Web/Scripts/backbone/bootstrapper.js
vendored
Normal file
7
NzbDrone.Web/Scripts/backbone/bootstrapper.js
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
$(function () {
|
||||
// Legacy support for templating
|
||||
utils.loadTemplate(['QualityProfilesView', 'QualityProfileView'],
|
||||
function () {
|
||||
NzbDrone.App.start();
|
||||
});
|
||||
});
|
11
NzbDrone.Web/Scripts/backbone/constants.js
Normal file
11
NzbDrone.Web/Scripts/backbone/constants.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
NzbDrone.Constants = {
|
||||
Templates: {
|
||||
AppLayout: '#AppLayout',
|
||||
QualityProfilesView: '#QualityProfilesView',
|
||||
QualityProfileView: '#QualityProfileView'
|
||||
},
|
||||
|
||||
Events: {
|
||||
MenuItemSelected: 'MenuItemSelected'
|
||||
}
|
||||
};
|
57
NzbDrone.Web/Scripts/backbone/controller.js
Normal file
57
NzbDrone.Web/Scripts/backbone/controller.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
(function (nzbDrone) {
|
||||
|
||||
var appController = function () {
|
||||
return {
|
||||
home: function (id) {
|
||||
|
||||
// if (!this.homeView) {
|
||||
// this.homeView = new HomeView();
|
||||
// }
|
||||
// $('#content').html(this.homeView.el);
|
||||
|
||||
nzbDrone.App.Layout.content.show(new nzbDrone.Views.HomeView());
|
||||
|
||||
this.menuItemSelected('home-menu');
|
||||
},
|
||||
|
||||
list: function (page) {
|
||||
|
||||
var p = page ? parseInt(page, 10) : 1;
|
||||
var profileList = new ProfileCollection();
|
||||
profileList.fetch({
|
||||
success: function () {
|
||||
$('#content').html(new QualityProfilesView({ model: profileList, page: p }).el);
|
||||
}
|
||||
});
|
||||
this.menuItemSelected('home-menu');
|
||||
},
|
||||
|
||||
wineDetails: function (id) {
|
||||
var profile = new Profile({ id: id });
|
||||
profile.fetch({
|
||||
success: function () {
|
||||
$('#content').html(new QualityProfileView({ model: profile }).el);
|
||||
}
|
||||
});
|
||||
this.menuItemSelected();
|
||||
},
|
||||
|
||||
addWine: function () {
|
||||
var wine = new Profile();
|
||||
$('#content').html(new QualityProfileView({ model: wine }).el);
|
||||
this.menuItemSelected('add-menu');
|
||||
},
|
||||
|
||||
menuItemSelected: function (item) {
|
||||
|
||||
// Using the application vent object as our global event aggregator
|
||||
nzbDrone.App.vent.trigger(
|
||||
nzbDrone.Constants.Events.MenuItemSelected, // Event name
|
||||
item); // Options
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
nzbDrone.AppController = appController;
|
||||
|
||||
})(window.NodeCellar);
|
18
NzbDrone.Web/Scripts/backbone/models/profileCollection.js
Normal file
18
NzbDrone.Web/Scripts/backbone/models/profileCollection.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
window.ProfileCollection = Backbone.Collection.extend({
|
||||
|
||||
model: Profile,
|
||||
|
||||
url: '/api/qualityprofiles',
|
||||
|
||||
search: function (searchTerm, options) {
|
||||
|
||||
var self = this;
|
||||
this.fetch({
|
||||
success: function () {
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
50
NzbDrone.Web/Scripts/backbone/models/profileModel.js
Normal file
50
NzbDrone.Web/Scripts/backbone/models/profileModel.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
window.Profile = Backbone.Model.extend({
|
||||
|
||||
urlRoot: '/api/qualityprofiles',
|
||||
|
||||
idAttribute: 'id',
|
||||
|
||||
initialize: function () {
|
||||
this.validators = {};
|
||||
|
||||
this.validators.name = function (value) {
|
||||
return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must enter a name' };
|
||||
};
|
||||
|
||||
this.validators.allowed = function (value) {
|
||||
return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' };
|
||||
};
|
||||
|
||||
this.validators.cutoff = function (value) {
|
||||
return value != null ? { isValid: true } : { isValid: false, message: 'You must have a valid cutoff' };
|
||||
};
|
||||
},
|
||||
|
||||
validateItem: function (key) {
|
||||
return (this.validators[key]) ? this.validators[key](this.get(key)) : { isValid: true };
|
||||
},
|
||||
|
||||
// TODO: Implement Backbone's standard validate() method instead.
|
||||
validateAll: function () {
|
||||
|
||||
var messages = {};
|
||||
|
||||
for (var key in this.validators) {
|
||||
if (this.validators.hasOwnProperty(key)) {
|
||||
var check = this.validators[key](this.get(key));
|
||||
if (check.isValid === false) {
|
||||
messages[key] = check.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _.size(messages) > 0 ? { isValid: false, messages: messages } : { isValid: true };
|
||||
},
|
||||
|
||||
defaults: {
|
||||
id: null,
|
||||
name: '',
|
||||
allowed: {},
|
||||
cutoff: null
|
||||
}
|
||||
});
|
16
NzbDrone.Web/Scripts/backbone/router.js
Normal file
16
NzbDrone.Web/Scripts/backbone/router.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
(function (nzbDrone, backbone) {
|
||||
nzbDrone.AppRouter = backbone.Marionette.AppRouter.extend({
|
||||
|
||||
controller: new nzbDrone.AppController(),
|
||||
|
||||
appRoutes: {
|
||||
'': 'home',
|
||||
'wines': 'list',
|
||||
'wines/page/:page': 'list',
|
||||
'wines/add': 'addWine',
|
||||
'wines/:id': 'wineDetails',
|
||||
'about': 'about',
|
||||
'search/:searchTerm': 'handleSearch'
|
||||
}
|
||||
});
|
||||
})(window.NzbDrone, window.Backbone);s
|
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();
|
||||
}
|
||||
|
||||
};
|
37
NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js
Normal file
37
NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
window.QualityProfilesView = Backbone.View.extend({
|
||||
|
||||
initialize: function () {
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var profiles = this.model.models;
|
||||
var len = profiles.length;
|
||||
var startPos = (this.options.page - 1) * 8;
|
||||
var endPos = Math.min(startPos + 8, len);
|
||||
|
||||
$(this.el).html('<ul class="thumbnails"></ul>');
|
||||
|
||||
for (var i = startPos; i < endPos; i++) {
|
||||
$('.thumbnails', this.el).append(new QualityProfileView({ model: profiles[i] }).render().el);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
window.QualityProfileView = Backbone.View.extend({
|
||||
|
||||
tagName: "li",
|
||||
|
||||
initialize: function () {
|
||||
this.model.bind("change", this.render, this);
|
||||
this.model.bind("destroy", this.close, this);
|
||||
},
|
||||
|
||||
render: function () {
|
||||
$(this.el).html(this.template(this.model.toJSON()));
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue