sonarr-repo-only/UI/AddSeries/RootFolders/RootFolderView.js

80 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-03-29 19:17:03 +00:00
"use strict";
define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'Mixins/AutoComplete'], function (app, rootFolders) {
NzbDrone.AddSeries.RootFolderItemView = Backbone.Marionette.ItemView.extend({
template: 'AddSeries/RootFolders/RootFolderItemTemplate',
tagName : 'tr',
events: {
'click .x-remove': 'removeFolder',
'click .x-folder': 'folderSelected'
},
removeFolder: function () {
this.model.destroy({ wait: true });
this.model.collection.remove(this.model);
},
folderSelected: function () {
this.trigger('folderSelected', this.model);
}
});
NzbDrone.AddSeries.RootDirListView = Backbone.Marionette.CollectionView.extend({
itemView: NzbDrone.AddSeries.RootFolderItemView,
tagName : 'table',
2013-02-15 08:18:42 +00:00
className: 'table table-hover'
});
2013-05-27 02:53:56 +00:00
NzbDrone.AddSeries.RootFolders.Layout = Backbone.Marionette.Layout.extend({
template: 'AddSeries/RootFolders/LayoutTemplate',
ui: {
pathInput: '.x-path input'
},
regions: {
2013-02-15 08:18:42 +00:00
currentDirs: '#current-dirs'
},
events: {
2013-02-15 08:18:42 +00:00
'click .x-add': 'addFolder'
},
initialize: function () {
this.collection = rootFolders;
this.rootfolderListView = new NzbDrone.AddSeries.RootDirListView({ collection: rootFolders });
this.rootfolderListView.on('itemview:folderSelected', this._onFolderSelected, this);
},
onRender: function () {
this.currentDirs.show(this.rootfolderListView);
2013-02-15 23:38:53 +00:00
this.ui.pathInput.autoComplete('/directories');
},
_onFolderSelected: function (options) {
this.trigger('folderSelected', options);
},
addFolder: function () {
var newDir = new NzbDrone.AddSeries.RootFolders.RootFolderModel(
{
Path: this.ui.pathInput.val()
});
rootFolders.create(newDir, {
wait: true, success: function () {
rootFolders.fetch();
}
});
2013-02-15 08:18:42 +00:00
}
});
});