parent
aed7b95245
commit
2407e33ea2
@ -1,9 +1,14 @@
|
||||
NzbDrone.Missing.Row = Backgrid.Row.extend({
|
||||
events: {
|
||||
'click .x-search' : 'search'
|
||||
},
|
||||
"use strict";
|
||||
define(['app','backgrid'], function () {
|
||||
NzbDrone.Missing.Row = Backgrid.Row.extend({
|
||||
events: {
|
||||
'click .x-search': 'search'
|
||||
},
|
||||
|
||||
search: function () {
|
||||
window.alert('Episode Search');
|
||||
}
|
||||
});
|
||||
search: function () {
|
||||
window.alert('Episode Search');
|
||||
}
|
||||
});
|
||||
|
||||
return NzbDrone.Missing.Row;
|
||||
});
|
||||
|
@ -1,211 +0,0 @@
|
||||
/*! Backbone.Mutators - v0.4.0
|
||||
------------------------------
|
||||
Build @ 2013-05-01
|
||||
Documentation and Full License Available at:
|
||||
http://asciidisco.github.com/Backbone.Mutators/index.html
|
||||
git://github.com/asciidisco/Backbone.Mutators.git
|
||||
Copyright (c) 2013 Sebastian Golasch <public@asciidisco.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.*/
|
||||
(function (root, factory, undef) {
|
||||
'use strict';
|
||||
|
||||
if (typeof exports === 'object') {
|
||||
// Node. Does not work with strict CommonJS, but
|
||||
// only CommonJS-like enviroments that support module.exports,
|
||||
// like Node.
|
||||
module.exports = factory(require('underscore'), require('Backbone'));
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['underscore', 'backbone'], function (_, Backbone) {
|
||||
// Check if we use the AMD branch of Back
|
||||
_ = _ === undef ? root._ : _;
|
||||
Backbone = Backbone === undef ? root.Backbone : Backbone;
|
||||
return (root.returnExportsGlobal = factory(_, Backbone, root));
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
root.returnExportsGlobal = factory(root._, root.Backbone);
|
||||
}
|
||||
|
||||
// Usage:
|
||||
//
|
||||
// Note: This plugin is UMD compatible, you can use it in node, amd and vanilla js envs
|
||||
//
|
||||
// Vanilla JS:
|
||||
// <script src="underscore.js"></script>
|
||||
// <script src="backbone.js"></script>
|
||||
// <script src="backbone.mutators.js"></script>
|
||||
//
|
||||
// Node:
|
||||
// var _ = require('underscore');
|
||||
// var Backbone = require('backbone');
|
||||
// var Mutators = require('backbone.mutators');
|
||||
//
|
||||
//
|
||||
// AMD:
|
||||
// define(['underscore', 'backbone', 'backbone.mutators'], function (_, Backbone, Mutators) {
|
||||
// // insert sample from below
|
||||
// return User;
|
||||
// });
|
||||
//
|
||||
// var User = Backbone.Model.extend({
|
||||
// mutators: {
|
||||
// fullname: function () {
|
||||
// return this.firstname + ' ' + this.lastname;
|
||||
// }
|
||||
// },
|
||||
//
|
||||
// defaults: {
|
||||
// firstname: 'Sebastian',
|
||||
// lastname: 'Golasch'
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// var user = new User();
|
||||
// user.get('fullname') // returns 'Sebastian Golasch'
|
||||
// user.toJSON() // return '{firstname: 'Sebastian', lastname: 'Golasch', fullname: 'Sebastian Golasch'}'
|
||||
|
||||
}(this, function (_, Backbone, root, undef) {
|
||||
'use strict';
|
||||
|
||||
// check if we use the amd branch of backbone and underscore
|
||||
Backbone = Backbone === undef ? root.Backbone : Backbone;
|
||||
_ = _ === undef ? root._ : _;
|
||||
|
||||
// extend backbones model prototype with the mutator functionality
|
||||
var Mutator = function () {},
|
||||
oldGet = Backbone.DeepModel.prototype.get,
|
||||
oldSet = Backbone.DeepModel.prototype.set,
|
||||
oldToJson = Backbone.DeepModel.prototype.toJSON;
|
||||
|
||||
// This is necessary to ensure that Models declared without the mutators object do not throw and error
|
||||
Mutator.prototype.mutators = {};
|
||||
|
||||
// override get functionality to fetch the mutator props
|
||||
Mutator.prototype.get = function (attr) {
|
||||
var isMutator = this.mutators !== undef;
|
||||
|
||||
// check if we have a getter mutation
|
||||
if (isMutator === true && _.isFunction(this.mutators[attr]) === true) {
|
||||
return this.mutators[attr].call(this);
|
||||
}
|
||||
|
||||
// check if we have a deeper nested getter mutation
|
||||
if (isMutator === true && _.isObject(this.mutators[attr]) === true && _.isFunction(this.mutators[attr].get) === true) {
|
||||
return this.mutators[attr].get.call(this);
|
||||
}
|
||||
|
||||
return oldGet.call(this, attr);
|
||||
};
|
||||
|
||||
// override set functionality to set the mutator props
|
||||
Mutator.prototype.set = function (key, value, options) {
|
||||
var isMutator = this.mutators !== undef,
|
||||
ret = null,
|
||||
attrs = null;
|
||||
|
||||
// seamleassly stolen from backbone core
|
||||
// check if the setter action is triggered
|
||||
// using key <-> value or object
|
||||
if (_.isObject(key) || key === null) {
|
||||
attrs = key;
|
||||
options = value;
|
||||
} else {
|
||||
attrs = {};
|
||||
attrs[key] = value;
|
||||
}
|
||||
|
||||
// check if we have a deeper nested setter mutation
|
||||
if (isMutator === true && _.isObject(this.mutators[key]) === true) {
|
||||
|
||||
// check if we need to set a single value
|
||||
if (_.isFunction(this.mutators[key].set) === true) {
|
||||
ret = this.mutators[key].set.call(this, key, attrs[key], options, _.bind(oldSet, this));
|
||||
} else if(_.isFunction(this.mutators[key])){
|
||||
ret = this.mutators[key].call(this, key, attrs[key], options, _.bind(oldSet, this));
|
||||
}
|
||||
}
|
||||
|
||||
if (_.isObject(attrs)) {
|
||||
_.each(attrs, _.bind(function (attr, attrKey) {
|
||||
var cur_ret = null;
|
||||
if (isMutator === true && _.isObject(this.mutators[attrKey]) === true) {
|
||||
// check if we need to set a single value
|
||||
|
||||
var meth = this.mutators[attrKey];
|
||||
if(_.isFunction(meth.set)){
|
||||
meth = meth.set;
|
||||
}
|
||||
|
||||
if(_.isFunction(meth)){
|
||||
if (options === undef || (_.isObject(options) === true && options.silent !== true && (options.mutators !== undef && options.mutators.silent !== true))) {
|
||||
this.trigger('mutators:set:' + attrKey);
|
||||
}
|
||||
cur_ret = meth.call(this, attrKey, attr, options, _.bind(oldSet, this));
|
||||
}
|
||||
|
||||
}
|
||||
if (cur_ret === null) {
|
||||
cur_ret = _.bind(oldSet, this)(attrKey, attr, options);
|
||||
}
|
||||
|
||||
if (ret !== false) { ret = cur_ret; }
|
||||
|
||||
}, this));
|
||||
}
|
||||
|
||||
//validation purposes
|
||||
if (ret !== null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return oldSet.call(this, key, value, options);
|
||||
};
|
||||
|
||||
// override toJSON functionality to serialize mutator properties
|
||||
Mutator.prototype.toJSON = function () {
|
||||
// fetch ye olde values
|
||||
var attr = oldToJson.call(this);
|
||||
// iterate over all mutators (if there are some)
|
||||
_.each(this.mutators, _.bind(function (mutator, name) {
|
||||
// check if we have some getter mutations
|
||||
if (_.isObject(this.mutators[name]) === true && _.isFunction(this.mutators[name].get)) {
|
||||
attr[name] = _.bind(this.mutators[name].get, this)();
|
||||
} else {
|
||||
attr[name] = _.bind(this.mutators[name], this)();
|
||||
}
|
||||
}, this));
|
||||
|
||||
return attr;
|
||||
};
|
||||
|
||||
// override get functionality to get HTML-escaped the mutator props
|
||||
Mutator.prototype.escape = function (attr){
|
||||
var val = this.get(attr);
|
||||
return _.escape(val == null ? '' : '' + val);
|
||||
};
|
||||
|
||||
// extend the models prototype
|
||||
_.extend(Backbone.DeepModel.prototype, Mutator.prototype);
|
||||
|
||||
// make mutators globally available under the Backbone namespace
|
||||
Backbone.Mutators = Mutator;
|
||||
return Mutator;
|
||||
}));
|
@ -1,9 +1,16 @@
|
||||
NzbDrone.Missing.Row = Backgrid.Row.extend({
|
||||
events: {
|
||||
'click .x-search' : 'search'
|
||||
},
|
||||
|
||||
search: function () {
|
||||
window.alert('Episode Search');
|
||||
}
|
||||
});
|
||||
"use strict";
|
||||
define(['app','backgrid'], function () {
|
||||
|
||||
NzbDrone.Missing.Row = Backgrid.Row.extend({
|
||||
events: {
|
||||
'click .x-search': 'search'
|
||||
},
|
||||
|
||||
search: function () {
|
||||
window.alert('Episode Search');
|
||||
}
|
||||
});
|
||||
return NzbDrone.Mixins.Row;
|
||||
|
||||
});
|
||||
|
||||
|
@ -1,48 +1,49 @@
|
||||
"use strict";
|
||||
define(['app', 'signalR'], function () {
|
||||
|
||||
_.extend(Backbone.Collection.prototype, {BindSignalR: function (options) {
|
||||
_.extend(Backbone.Collection.prototype, {BindSignalR: function (options) {
|
||||
|
||||
if (!options || !options.url) {
|
||||
console.assert(this.url, 'url must be provided or collection must have url');
|
||||
options = {
|
||||
url: this.url.replace('api', 'signalr')
|
||||
};
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
var _getStatus = function (status) {
|
||||
switch (status) {
|
||||
case 0:
|
||||
return 'connecting';
|
||||
case 1:
|
||||
return 'connected';
|
||||
case 2:
|
||||
return 'reconnecting';
|
||||
case 4:
|
||||
return 'disconnected';
|
||||
default:
|
||||
throw 'invalid status ' + status;
|
||||
if (!options || !options.url) {
|
||||
console.assert(this.url, 'url must be provided or collection must have url');
|
||||
options = {
|
||||
url: this.url.replace('api', 'signalr')
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
var self = this;
|
||||
|
||||
var _getStatus = function (status) {
|
||||
switch (status) {
|
||||
case 0:
|
||||
return 'connecting';
|
||||
case 1:
|
||||
return 'connected';
|
||||
case 2:
|
||||
return 'reconnecting';
|
||||
case 4:
|
||||
return 'disconnected';
|
||||
default:
|
||||
throw 'invalid status ' + status;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var connection = $.connection(options.url);
|
||||
|
||||
connection.stateChanged(function (change) {
|
||||
console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState)));
|
||||
});
|
||||
var connection = $.connection(options.url);
|
||||
|
||||
connection.received(function (model) {
|
||||
console.debug(model);
|
||||
self.fetch();
|
||||
});
|
||||
connection.stateChanged(function (change) {
|
||||
console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState)));
|
||||
});
|
||||
|
||||
connection.start({ transport: ['longPolling'] });
|
||||
connection.received(function (model) {
|
||||
console.debug(model);
|
||||
self.fetch();
|
||||
});
|
||||
|
||||
return this;
|
||||
}});
|
||||
connection.start({ transport: ['longPolling'] });
|
||||
|
||||
return this;
|
||||
}});
|
||||
});
|
||||
|
||||
|
||||
|
@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Underscore mixins for deep objects
|
||||
*
|
||||
* Based on https://gist.github.com/echong/3861963
|
||||
*/
|
||||
(function() {
|
||||
var arrays, basicObjects, deepClone, deepExtend, deepExtendCouple, isBasicObject,
|
||||
__slice = [].slice;
|
||||
|
||||
deepClone = function(obj) {
|
||||
var func, isArr;
|
||||
if (!_.isObject(obj) || _.isFunction(obj)) {
|
||||
return obj;
|
||||
}
|
||||
if (obj instanceof Backbone.Collection || obj instanceof Backbone.Model) {
|
||||
return obj;
|
||||
}
|
||||
if (_.isDate(obj)) {
|
||||
return new Date(obj.getTime());
|
||||
}
|
||||
if (_.isRegExp(obj)) {
|
||||
return new RegExp(obj.source, obj.toString().replace(/.*\//, ""));
|
||||
}
|
||||
isArr = _.isArray(obj || _.isArguments(obj));
|
||||
func = function(memo, value, key) {
|
||||
if (isArr) {
|
||||
memo.push(deepClone(value));
|
||||
} else {
|
||||
memo[key] = deepClone(value);
|
||||
}
|
||||
return memo;
|
||||
};
|
||||
return _.reduce(obj, func, isArr ? [] : {});
|
||||
};
|
||||
|
||||
isBasicObject = function(object) {
|
||||
if (object == null) return false;
|
||||
return (object.prototype === {}.prototype || object.prototype === Object.prototype) && _.isObject(object) && !_.isArray(object) && !_.isFunction(object) && !_.isDate(object) && !_.isRegExp(object) && !_.isArguments(object);
|
||||
};
|
||||
|
||||
basicObjects = function(object) {
|
||||
return _.filter(_.keys(object), function(key) {
|
||||
return isBasicObject(object[key]);
|
||||
});
|
||||
};
|
||||
|
||||
arrays = function(object) {
|
||||
return _.filter(_.keys(object), function(key) {
|
||||
return _.isArray(object[key]);
|
||||
});
|
||||
};
|
||||
|
||||
deepExtendCouple = function(destination, source, maxDepth) {
|
||||
var combine, recurse, sharedArrayKey, sharedArrayKeys, sharedObjectKey, sharedObjectKeys, _i, _j, _len, _len1;
|
||||
if (maxDepth == null) {
|
||||
maxDepth = 20;
|
||||
}
|
||||
if (maxDepth <= 0) {
|
||||
console.warn('_.deepExtend(): Maximum depth of recursion hit.');
|
||||
return _.extend(destination, source);
|
||||
}
|
||||
sharedObjectKeys = _.intersection(basicObjects(destination), basicObjects(source));
|
||||
recurse = function(key) {
|
||||
return source[key] = deepExtendCouple(destination[key], source[key], maxDepth - 1);
|
||||
};
|
||||
for (_i = 0, _len = sharedObjectKeys.length; _i < _len; _i++) {
|
||||
sharedObjectKey = sharedObjectKeys[_i];
|
||||
recurse(sharedObjectKey);
|
||||
}
|
||||
sharedArrayKeys = _.intersection(arrays(destination), arrays(source));
|
||||
combine = function(key) {
|
||||
return source[key] = _.union(destination[key], source[key]);
|
||||
};
|
||||
for (_j = 0, _len1 = sharedArrayKeys.length; _j < _len1; _j++) {
|
||||
sharedArrayKey = sharedArrayKeys[_j];
|
||||
combine(sharedArrayKey);
|
||||
}
|
||||
return _.extend(destination, source);
|
||||
};
|
||||
|
||||
deepExtend = function() {
|
||||
var finalObj, maxDepth, objects, _i;
|
||||
objects = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), maxDepth = arguments[_i++];
|
||||
if (!_.isNumber(maxDepth)) {
|
||||
objects.push(maxDepth);
|
||||
maxDepth = 20;
|
||||
}
|
||||
if (objects.length <= 1) {
|
||||
return objects[0];
|
||||
}
|
||||
if (maxDepth <= 0) {
|
||||
return _.extend.apply(this, objects);
|
||||
}
|
||||
finalObj = objects.shift();
|
||||
while (objects.length > 0) {
|
||||
finalObj = deepExtendCouple(finalObj, deepClone(objects.shift()), maxDepth);
|
||||
}
|
||||
return finalObj;
|
||||
};
|
||||
|
||||
_.mixin({
|
||||
deepClone: deepClone,
|
||||
isBasicObject: isBasicObject,
|
||||
basicObjects: basicObjects,
|
||||
arrays: arrays,
|
||||
deepExtend: deepExtend
|
||||
});
|
||||
|
||||
}).call(this);
|
@ -1,27 +1,33 @@
|
||||
"use strict";
|
||||
NzbDrone.Release.DownloadReportCell = Backgrid.Cell.extend({
|
||||
|
||||
className: "download-report-cell",
|
||||
define(['app'], function () {
|
||||
NzbDrone.Release.DownloadReportCell = Backgrid.Cell.extend({
|
||||
|
||||
events: {
|
||||
'click': '_onClick'
|
||||
},
|
||||
className: "download-report-cell",
|
||||
|
||||
_onClick: function () {
|
||||
events: {
|
||||
'click': '_onClick'
|
||||
},
|
||||
|
||||
var self = this;
|
||||
_onClick: function () {
|
||||
|
||||
this.$el.html('<i class ="icon-spinner icon-spin" />');
|
||||
this.model.save()
|
||||
.always(function () {
|
||||
self.$el.html('<i class ="icon-download-alt" />');
|
||||
});
|
||||
},
|
||||
var self = this;
|
||||
|
||||
render: function () {
|
||||
this.$el.html('<i class ="icon-spinner icon-spin" />');
|
||||
this.model.save()
|
||||
.always(function () {
|
||||
self.$el.html('<i class ="icon-download-alt" />');
|
||||
});
|
||||
},
|
||||
|
||||
this.$el.html('<i class ="icon-download-alt" />');
|
||||
return this;
|
||||
render: function () {
|
||||
|
||||
}
|
||||
this.$el.html('<i class ="icon-download-alt" />');
|
||||
return this;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return NzbDrone.Release.DownloadReportCell;
|
||||
});
|
||||
|
@ -1,17 +1,22 @@
|
||||
"use strict";
|
||||
NzbDrone.Series.Index.Table.Row = Backgrid.Row.extend({
|
||||
events: {
|
||||
'click .x-edit' : 'editSeries',
|
||||
'click .x-remove': 'removeSeries'
|
||||
},
|
||||
define(['app','backgrid'], function () {
|
||||
NzbDrone.Series.Index.Table.Row = Backgrid.Row.extend({
|
||||
events: {
|
||||
'click .x-edit' : 'editSeries',
|
||||
'click .x-remove': 'removeSeries'
|
||||
},
|
||||
|
||||
editSeries: function () {
|
||||
var view = new NzbDrone.Series.Edit.EditSeriesView({ model: this.model});
|
||||
NzbDrone.modalRegion.show(view);
|
||||
},
|
||||
editSeries: function () {
|
||||
var view = new NzbDrone.Series.Edit.EditSeriesView({ model: this.model});
|
||||
NzbDrone.modalRegion.show(view);
|
||||
},
|
||||
|
||||
removeSeries: function () {
|
||||
var view = new NzbDrone.Series.Delete.DeleteSeriesView({ model: this.model });
|
||||
NzbDrone.modalRegion.show(view);
|
||||
}
|
||||
});
|
||||
|
||||
return NzbDrone.Series.Table.Row;
|
||||
});
|
||||
|
||||
removeSeries: function () {
|
||||
var view = new NzbDrone.Series.Delete.DeleteSeriesView({ model: this.model });
|
||||
NzbDrone.modalRegion.show(view);
|
||||
}
|
||||
});
|
@ -1,23 +1,27 @@
|
||||
"use strict";
|
||||
Backgrid.SeriesStatusCell = Backgrid.Cell.extend({
|
||||
className: "series-status-cell",
|
||||
define(['app','backgrid'], function () {
|
||||
Backgrid.SeriesStatusCell = Backgrid.Cell.extend({
|
||||
className: "series-status-cell",
|
||||
|
||||
render: function () {
|
||||
this.$el.empty();
|
||||
var monitored = this.model.get('monitored');
|
||||
var status = this.model.get('status');
|
||||
render: function () {
|
||||
this.$el.empty();
|
||||
var monitored = this.model.get('monitored');
|
||||
var status = this.model.get('status');
|
||||
|
||||
if (!monitored) {
|
||||
this.$el.html('<i class="icon-pause grid-icon" title="Not Monitored"></i>');
|
||||
}
|
||||
else if (status === 'continuing') {
|
||||
this.$el.html('<i class="icon-play grid-icon" title="Continuing"></i>');
|
||||
}
|
||||
if (!monitored) {
|
||||
this.$el.html('<i class="icon-pause grid-icon" title="Not Monitored"></i>');
|
||||
}
|
||||
else if (status === 'continuing') {
|
||||
this.$el.html('<i class="icon-play grid-icon" title="Continuing"></i>');
|
||||
}
|
||||
|
||||
else {
|
||||
this.$el.html('<i class="icon-stop grid-icon" title="Ended"></i>');
|
||||
}
|
||||
|
||||
else {
|
||||
this.$el.html('<i class="icon-stop grid-icon" title="Ended"></i>');
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
return Backgrid.SeriesStatusCell;
|
||||
});
|
||||
|
@ -1,106 +1,100 @@
|
||||
"use strict";
|
||||
|
||||
Backgrid.Column.prototype.defaults = {
|
||||
name : undefined,
|
||||
label : undefined,
|
||||
sortable : true,
|
||||
editable : false,
|
||||
renderable: true,
|
||||
formatter : undefined,
|
||||
cell : undefined,
|
||||
headerCell: 'nzbDrone'
|
||||
};
|
||||
|
||||
|
||||
Backgrid.NzbDroneHeaderCell = Backgrid.HeaderCell.extend({
|
||||
events: {
|
||||
'click': 'onClick'
|
||||
},
|
||||
|
||||
render: function () {
|
||||
this.$el.empty();
|
||||
this.$el.append(this.column.get("label"));
|
||||
|
||||
if (this.column.get('sortable')) {
|
||||
this.$el.addClass('clickable');
|
||||
this.$el.append(" <i class='pull-right'></i>");
|
||||
|
||||
if (this.collection.state) {
|
||||
var sortKey = this.collection.state.sortKey;
|
||||
var sortDir = this._convertIntToDirection(this.collection.state.order);
|
||||
|
||||
if (sortKey === this.column.get('name')) {
|
||||
this.$el.children('i').addClass(this._convertDirectionToIcon(sortDir));
|
||||
this._direction = sortDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.delegateEvents();
|
||||
return this;
|
||||
},
|
||||
|
||||
direction: function (dir) {
|
||||
if (arguments.length) {
|
||||
if (this._direction) {
|
||||
this.$el.children('i').removeClass(this._convertDirectionToIcon(this._direction));
|
||||
}
|
||||
if (dir) {
|
||||
this.$el.children('i').addClass(this._convertDirectionToIcon(dir));
|
||||
}
|
||||
this._direction = dir;
|
||||
}
|
||||
define(['app','backgrid'], function () {
|
||||
|
||||
return this._direction;
|
||||
},
|
||||
|
||||
onClick: function (e) {
|
||||
e.preventDefault();
|
||||
Backgrid.NzbDroneHeaderCell = Backgrid.HeaderCell.extend({
|
||||
events: {
|
||||
'click': 'onClick'
|
||||
},
|
||||
|
||||
var columnName = this.column.get("name");
|
||||
render: function () {
|
||||
this.$el.empty();
|
||||
this.$el.append(this.column.get("label"));
|
||||
|
||||
if (this.column.get("sortable")) {
|
||||
if (this.direction() === "ascending") {
|
||||
this.sort(columnName, "descending", function (left, right) {
|
||||
var leftVal = left.get(columnName);
|
||||
var rightVal = right.get(columnName);
|
||||
if (leftVal === rightVal) {
|
||||
return 0;
|
||||
}
|
||||
else if (leftVal > rightVal) {
|
||||
return -1;
|
||||
if (this.column.get('sortable')) {
|
||||
this.$el.addClass('clickable');
|
||||
this.$el.append(" <i class='pull-right'></i>");
|
||||
|
||||
if (this.collection.state) {
|
||||
var sortKey = this.collection.state.sortKey;
|
||||
var sortDir = this._convertIntToDirection(this.collection.state.order);
|
||||
|
||||
if (sortKey === this.column.get('name')) {
|
||||
this.$el.children('i').addClass(this._convertDirectionToIcon(sortDir));
|
||||
this._direction = sortDir;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.sort(columnName, "ascending", function (left, right) {
|
||||
var leftVal = left.get(columnName);
|
||||
var rightVal = right.get(columnName);
|
||||
if (leftVal === rightVal) {
|
||||
return 0;
|
||||
}
|
||||
else if (leftVal < rightVal) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
this.delegateEvents();
|
||||
return this;
|
||||
},
|
||||
|
||||
direction: function (dir) {
|
||||
if (arguments.length) {
|
||||
if (this._direction) {
|
||||
this.$el.children('i').removeClass(this._convertDirectionToIcon(this._direction));
|
||||
}
|
||||
if (dir) {
|
||||
this.$el.children('i').addClass(this._convertDirectionToIcon(dir));
|
||||
}
|
||||
this._direction = dir;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_convertDirectionToIcon: function (dir) {
|
||||
if (dir === 'ascending') {
|
||||
return 'icon-sort-up';
|
||||
}
|
||||
return this._direction;
|
||||
},
|
||||
|
||||
onClick: function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var columnName = this.column.get("name");
|
||||
|
||||
if (this.column.get("sortable")) {
|
||||
if (this.direction() === "ascending") {
|
||||
this.sort(columnName, "descending", function (left, right) {
|
||||
var leftVal = left.get(columnName);
|
||||
var rightVal = right.get(columnName);
|
||||
if (leftVal === rightVal) {
|
||||
return 0;
|
||||
}
|
||||
else if (leftVal > rightVal) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.sort(columnName, "ascending", function (left, right) {
|
||||
var leftVal = left.get(columnName);
|
||||
var rightVal = right.get(columnName);
|
||||
if (leftVal === rightVal) {
|
||||
return 0;
|
||||
}
|
||||
else if (leftVal < rightVal) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_convertDirectionToIcon: function (dir) {
|
||||
if (dir === 'ascending') {
|
||||
return 'icon-sort-up';
|
||||
}
|
||||
|
||||
return 'icon-sort-down';
|
||||
},
|
||||
return 'icon-sort-down';
|
||||
},
|
||||
|
||||
_convertIntToDirection: function (dir) {
|
||||
if (dir === '-1') {
|
||||
return 'ascending';
|
||||
}
|
||||
|
||||
_convertIntToDirection: function (dir) {
|
||||
if (dir === '-1') {
|
||||
return 'ascending';
|
||||
return 'descending';
|
||||
}
|
||||
});
|
||||
|
||||
return 'descending';
|
||||
}
|
||||
return Backgrid.NzbDroneHeaderCell;
|
||||
});
|
||||
|
Loading…
Reference in new issue