rjs -> webpack

This commit is contained in:
Keivan Beigi
2015-02-02 17:18:45 -08:00
parent 344f3d66ef
commit 428a1439e5
399 changed files with 11591 additions and 16139 deletions
+2 -10
View File
@@ -1,11 +1,3 @@
'use strict';
var Marionette = require('marionette');
define(
[
'marionette'
], function (Marionette) {
return Marionette.CompositeView.extend({
template: 'Shared/FileBrowser/EmptyViewTemplate'
});
});
module.exports = Marionette.CompositeView.extend({template : 'Shared/FileBrowser/EmptyViewTemplate'});
@@ -1,39 +1,27 @@
'use strict';
define(
[
'jquery',
'backbone',
'Shared/FileBrowser/FileBrowserModel'
], function ($, Backbone, FileBrowserModel) {
var $ = require('jquery');
var Backbone = require('backbone');
var FileBrowserModel = require('./FileBrowserModel');
return Backbone.Collection.extend({
model: FileBrowserModel,
url : window.NzbDrone.ApiRoot + '/filesystem',
parse: function(response) {
var contents = [];
if (response.parent || response.parent === '') {
var type = 'parent';
var name = '...';
if (response.parent === '') {
type = 'computer';
name = 'My Computer';
}
contents.push({
type : type,
name : name,
path : response.parent
});
}
$.merge(contents, response.directories);
$.merge(contents, response.files);
return contents;
module.exports = Backbone.Collection.extend({
model : FileBrowserModel,
url : window.NzbDrone.ApiRoot + '/filesystem',
parse : function(response){
var contents = [];
if(response.parent || response.parent === '') {
var type = 'parent';
var name = '...';
if(response.parent === '') {
type = 'computer';
name = 'My Computer';
}
});
});
contents.push({
type : type,
name : name,
path : response.parent
});
}
$.merge(contents, response.directories);
$.merge(contents, response.files);
return contents;
}
});
+117 -169
View File
@@ -1,171 +1,119 @@
'use strict';
define(
[
'underscore',
'vent',
'marionette',
'backgrid',
'Shared/FileBrowser/FileBrowserCollection',
'Shared/FileBrowser/EmptyView',
'Shared/FileBrowser/FileBrowserRow',
'Shared/FileBrowser/FileBrowserTypeCell',
'Shared/FileBrowser/FileBrowserNameCell',
'Cells/RelativeDateCell',
'Cells/FileSizeCell',
'Shared/LoadingView',
'Mixins/DirectoryAutoComplete'
], function (_,
vent,
Marionette,
Backgrid,
FileBrowserCollection,
EmptyView,
FileBrowserRow,
FileBrowserTypeCell,
FileBrowserNameCell,
RelativeDateCell,
FileSizeCell,
LoadingView) {
var _ = require('underscore');
var vent = require('../../vent');
var Marionette = require('marionette');
var Backgrid = require('backgrid');
var FileBrowserCollection = require('./FileBrowserCollection');
var EmptyView = require('./EmptyView');
var FileBrowserRow = require('./FileBrowserRow');
var FileBrowserTypeCell = require('./FileBrowserTypeCell');
var FileBrowserNameCell = require('./FileBrowserNameCell');
var RelativeDateCell = require('../../Cells/RelativeDateCell');
var FileSizeCell = require('../../Cells/FileSizeCell');
var LoadingView = require('../LoadingView');
require('../../Mixins/DirectoryAutoComplete');
return Marionette.Layout.extend({
template: 'Shared/FileBrowser/FileBrowserLayoutTemplate',
regions: {
browser : '#x-browser'
},
ui: {
path : '.x-path',
indicator : '.x-indicator'
},
events: {
'typeahead:selected .x-path' : '_pathChanged',
'typeahead:autocompleted .x-path' : '_pathChanged',
'keyup .x-path' : '_inputChanged',
'click .x-ok' : '_selectPath'
},
initialize: function (options) {
this.collection = new FileBrowserCollection();
this.collection.showFiles = options.showFiles || false;
this.collection.showLastModified = options.showLastModified || false;
this.input = options.input;
this._setColumns();
this.listenTo(this.collection, 'sync', this._showGrid);
this.listenTo(this.collection, 'filebrowser:folderselected', this._rowSelected);
},
onRender: function () {
this.browser.show(new LoadingView());
this.ui.path.directoryAutoComplete();
this._fetchCollection(this.input.val());
this._updatePath(this.input.val());
},
_setColumns: function () {
this.columns = [
{
name : 'type',
label : '',
sortable : false,
cell : FileBrowserTypeCell
},
{
name : 'name',
label : 'Name',
sortable : false,
cell : FileBrowserNameCell
}
];
if (this.collection.showLastModified) {
this.columns.push({
name : 'lastModified',
label : 'Last Modified',
sortable : false,
cell : RelativeDateCell
});
}
if (this.collection.showFiles) {
this.columns.push({
name : 'size',
label : 'Size',
sortable : false,
cell : FileSizeCell
});
}
},
_fetchCollection: function (path) {
this.ui.indicator.show();
var data = {
includeFiles : this.collection.showFiles
};
if (path) {
data.path = path;
}
this.collection.fetch({
data: data
});
},
_showGrid: function () {
this.ui.indicator.hide();
if (this.collection.models.length === 0) {
this.browser.show(new EmptyView());
return;
}
var grid = new Backgrid.Grid({
row : FileBrowserRow,
collection : this.collection,
columns : this.columns,
className : 'table table-hover'
});
this.browser.show(grid);
},
_rowSelected: function (model) {
var path = model.get('path');
this._updatePath(path);
this._fetchCollection(path);
},
_pathChanged: function (e, path) {
this._fetchCollection(path.value);
this._updatePath(path.value);
},
_inputChanged: function () {
var path = this.ui.path.val();
if (path === '' || path.endsWith('\\') || path.endsWith('/')) {
this._fetchCollection(path);
}
},
_updatePath: function (path) {
if (path !== undefined || path !== null) {
this.ui.path.val(path);
}
},
_selectPath: function () {
this.input.val(this.ui.path.val());
this.input.trigger('change');
vent.trigger(vent.Commands.CloseFileBrowser);
}
module.exports = Marionette.Layout.extend({
template : "Shared/FileBrowser/FileBrowserLayoutTemplate",
regions : {browser : "#x-browser"},
ui : {
path : ".x-path",
indicator : ".x-indicator"
},
events : {
"typeahead:selected .x-path" : "_pathChanged",
"typeahead:autocompleted .x-path" : "_pathChanged",
"keyup .x-path" : "_inputChanged",
"click .x-ok" : "_selectPath"
},
initialize : function(options){
this.collection = new FileBrowserCollection();
this.collection.showFiles = options.showFiles || false;
this.collection.showLastModified = options.showLastModified || false;
this.input = options.input;
this._setColumns();
this.listenTo(this.collection, "sync", this._showGrid);
this.listenTo(this.collection, "filebrowser:folderselected", this._rowSelected);
},
onRender : function(){
this.browser.show(new LoadingView());
this.ui.path.directoryAutoComplete();
this._fetchCollection(this.input.val());
this._updatePath(this.input.val());
},
_setColumns : function(){
this.columns = [{
name : "type",
label : "",
sortable : false,
cell : FileBrowserTypeCell
}, {
name : "name",
label : "Name",
sortable : false,
cell : FileBrowserNameCell
}];
if(this.collection.showLastModified) {
this.columns.push({
name : "lastModified",
label : "Last Modified",
sortable : false,
cell : RelativeDateCell
});
}
if(this.collection.showFiles) {
this.columns.push({
name : "size",
label : "Size",
sortable : false,
cell : FileSizeCell
});
}
},
_fetchCollection : function(path){
this.ui.indicator.show();
var data = {includeFiles : this.collection.showFiles};
if(path) {
data.path = path;
}
this.collection.fetch({data : data});
},
_showGrid : function(){
this.ui.indicator.hide();
if(this.collection.models.length === 0) {
this.browser.show(new EmptyView());
return;
}
var grid = new Backgrid.Grid({
row : FileBrowserRow,
collection : this.collection,
columns : this.columns,
className : "table table-hover"
});
});
this.browser.show(grid);
},
_rowSelected : function(model){
var path = model.get("path");
this._updatePath(path);
this._fetchCollection(path);
},
_pathChanged : function(e, path){
this._fetchCollection(path.value);
this._updatePath(path.value);
},
_inputChanged : function(){
var path = this.ui.path.val();
if(path === "" || path.endsWith("\\") || path.endsWith("/")) {
this._fetchCollection(path);
}
},
_updatePath : function(path){
if(path !== undefined || path !== null) {
this.ui.path.val(path);
}
},
_selectPath : function(){
this.input.val(this.ui.path.val());
this.input.trigger("change");
vent.trigger(vent.Commands.CloseFileBrowser);
}
});
@@ -1,63 +1,46 @@
'use strict';
define(
[
'jquery',
'backbone',
'marionette',
'bootstrap'
], function ($, Backbone, Marionette) {
var region = Marionette.Region.extend({
el: '#file-browser-modal-region',
var $ = require('jquery');
var Backbone = require('backbone');
var Marionette = require('marionette');
require('bootstrap');
constructor: function () {
Backbone.Marionette.Region.prototype.constructor.apply(this, arguments);
this.on('show', this.showModal, this);
},
getEl: function (selector) {
var $el = $(selector);
$el.on('hidden', this.close);
return $el;
},
showModal: function () {
this.$el.addClass('modal fade');
//need tab index so close on escape works
//https://github.com/twitter/bootstrap/issues/4663
this.$el.attr('tabindex', '-1');
this.$el.css('z-index', '1060');
this.$el.modal({
show : true,
keyboard : true,
backdrop : true
});
this.$el.on('hide.bs.modal', $.proxy(this._closing, this));
this.$el.on('shown.bs.modal', function () {
$('.modal-backdrop:last').css('z-index', 1059);
});
this.currentView.$el.addClass('modal-dialog');
},
closeModal: function () {
$(this.el).modal('hide');
this.reset();
},
_closing: function () {
if (this.$el) {
this.$el.off('hide.bs.modal');
this.$el.off('shown.bs.modal');
}
this.reset();
module.exports = (function(){
var region = Marionette.Region.extend({
el : '#file-browser-modal-region',
constructor : function(){
Backbone.Marionette.Region.prototype.constructor.apply(this, arguments);
this.on('show', this.showModal, this);
},
getEl : function(selector){
var $el = $(selector);
$el.on('hidden', this.close);
return $el;
},
showModal : function(){
this.$el.addClass('modal fade');
this.$el.attr('tabindex', '-1');
this.$el.css('z-index', '1060');
this.$el.modal({
show : true,
keyboard : true,
backdrop : true
});
this.$el.on('hide.bs.modal', $.proxy(this._closing, this));
this.$el.on('shown.bs.modal', function(){
$('.modal-backdrop:last').css('z-index', 1059);
});
this.currentView.$el.addClass('modal-dialog');
},
closeModal : function(){
$(this.el).modal('hide');
this.reset();
},
_closing : function(){
if(this.$el) {
this.$el.off('hide.bs.modal');
this.$el.off('shown.bs.modal');
}
});
return region;
this.reset();
}
});
return region;
}).call(this);
@@ -1,10 +1,3 @@
'use strict';
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
});
});
var Backbone = require('backbone');
module.exports = Backbone.Model.extend({});
@@ -1,23 +1,13 @@
'use strict';
var vent = require('../../vent');
var NzbDroneCell = require('../../Cells/NzbDroneCell');
define(
[
'vent',
'Cells/NzbDroneCell'
], function (vent, NzbDroneCell) {
return NzbDroneCell.extend({
className: 'file-browser-name-cell',
render: function () {
this.$el.empty();
var name = this.model.get(this.column.get('name'));
this.$el.html(name);
this.delegateEvents();
return this;
}
});
});
module.exports = NzbDroneCell.extend({
className : 'file-browser-name-cell',
render : function(){
this.$el.empty();
var name = this.model.get(this.column.get('name'));
this.$el.html(name);
this.delegateEvents();
return this;
}
});
+18 -30
View File
@@ -1,31 +1,19 @@
'use strict';
define(
[
'underscore',
'backgrid'
], function (_, Backgrid) {
var _ = require('underscore');
var Backgrid = require('backgrid');
return Backgrid.Row.extend({
className: 'file-browser-row',
events: {
'click': '_selectRow'
},
_originalInit: Backgrid.Row.prototype.initialize,
initialize: function () {
this._originalInit.apply(this, arguments);
},
_selectRow: function () {
if (this.model.get('type') === 'file') {
this.model.collection.trigger('filebrowser:fileselected', this.model);
}
else {
this.model.collection.trigger('filebrowser:folderselected', this.model);
}
}
});
});
module.exports = Backgrid.Row.extend({
className : 'file-browser-row',
events : {"click" : '_selectRow'},
_originalInit : Backgrid.Row.prototype.initialize,
initialize : function(){
this._originalInit.apply(this, arguments);
},
_selectRow : function(){
if(this.model.get('type') === 'file') {
this.model.collection.trigger('filebrowser:fileselected', this.model);
}
else {
this.model.collection.trigger('filebrowser:folderselected', this.model);
}
}
});
@@ -1,40 +1,26 @@
'use strict';
var vent = require('../../vent');
var NzbDroneCell = require('../../Cells/NzbDroneCell');
define(
[
'vent',
'Cells/NzbDroneCell'
], function (vent, NzbDroneCell) {
return NzbDroneCell.extend({
className: 'file-browser-type-cell',
render: function () {
this.$el.empty();
var type = this.model.get(this.column.get('name'));
var icon = 'icon-hdd';
if (type === 'computer') {
icon = 'icon-desktop';
}
else if (type === 'parent') {
icon = 'icon-level-up';
}
else if (type === 'folder') {
icon = 'icon-folder-close-alt';
}
else if (type === 'file') {
icon = 'icon-file-alt';
}
this.$el.html('<i class="{0}"></i>'.format(icon));
this.delegateEvents();
return this;
}
});
});
module.exports = NzbDroneCell.extend({
className : 'file-browser-type-cell',
render : function(){
this.$el.empty();
var type = this.model.get(this.column.get('name'));
var icon = 'icon-hdd';
if(type === 'computer') {
icon = 'icon-desktop';
}
else if(type === 'parent') {
icon = 'icon-level-up';
}
else if(type === 'folder') {
icon = 'icon-folder-close-alt';
}
else if(type === 'file') {
icon = 'icon-file-alt';
}
this.$el.html('<i class="{0}"></i>'.format(icon));
this.delegateEvents();
return this;
}
});