You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/UI/AddSeries/RootFolders/Layout.js

72 lines
2.0 KiB

'use strict';
12 years ago
define(
[
'marionette',
'AddSeries/RootFolders/CollectionView',
'AddSeries/RootFolders/Collection',
'AddSeries/RootFolders/Model',
11 years ago
'Shared/LoadingView',
'Mixins/AsValidatedView',
12 years ago
'Mixins/AutoComplete'
], function (Marionette, RootFolderCollectionView, RootFolderCollection, RootFolderModel, LoadingView, AsValidatedView) {
12 years ago
var layout = Marionette.Layout.extend({
12 years ago
template: 'AddSeries/RootFolders/LayoutTemplate',
ui: {
pathInput: '.x-path input'
},
regions: {
currentDirs: '#current-dirs'
},
events: {
'click .x-add': '_addFolder'
12 years ago
},
initialize: function () {
this.collection = RootFolderCollection;
this.rootfolderListView = new RootFolderCollectionView({ collection: RootFolderCollection });
this.listenTo(this.rootfolderListView, 'itemview:folderSelected', this._onFolderSelected);
12 years ago
},
onRender: function () {
var self = this;
11 years ago
this.currentDirs.show(new LoadingView());
RootFolderCollection.promise.done(function () {
self.currentDirs.show(self.rootfolderListView);
});
12 years ago
this.ui.pathInput.autoComplete('/directories');
},
_onFolderSelected: function (options) {
this.trigger('folderSelected', options);
},
_addFolder: function () {
var self = this;
12 years ago
var newDir = new RootFolderModel({
Path: this.ui.pathInput.val()
});
this.bindToModelValidation(newDir);
newDir.save().done(function () {
RootFolderCollection.add(newDir);
self.trigger('folderSelected', {model: newDir});
12 years ago
});
}
});
return AsValidatedView.apply(layout);
12 years ago
});