summaryrefslogtreecommitdiffstats
path: root/module/web/static/js/models
diff options
context:
space:
mode:
Diffstat (limited to 'module/web/static/js/models')
-rw-r--r--module/web/static/js/models/Account.js50
-rw-r--r--module/web/static/js/models/ConfigHolder.js67
-rw-r--r--module/web/static/js/models/ConfigItem.js39
-rw-r--r--module/web/static/js/models/File.js91
-rw-r--r--module/web/static/js/models/InteractionTask.js40
-rw-r--r--module/web/static/js/models/Package.js118
-rw-r--r--module/web/static/js/models/Progress.js49
-rw-r--r--module/web/static/js/models/ServerStatus.js46
-rw-r--r--module/web/static/js/models/TreeCollection.js49
9 files changed, 0 insertions, 549 deletions
diff --git a/module/web/static/js/models/Account.js b/module/web/static/js/models/Account.js
deleted file mode 100644
index c6e023578..000000000
--- a/module/web/static/js/models/Account.js
+++ /dev/null
@@ -1,50 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($, Backbone, _, App, Api) {
-
- return Backbone.Model.extend({
-
- // TODO
- // generated, not submitted
- idAttribute: 'user',
-
- defaults: {
- plugin: null,
- loginname: null,
- owner: -1,
- valid: false,
- validuntil: -1,
- trafficleft: -1,
- maxtraffic: -1,
- premium: false,
- activated: false,
- shared: false,
- options: null
- },
-
- // Model Constructor
- initialize: function() {
- },
-
- // Any time a model attribute is set, this method is called
- validate: function(attrs) {
-
- },
-
- save: function(options) {
- options = App.apiRequest('updateAccountInfo', {account: this.toJSON()}, options);
- return $.ajax(options);
- },
-
- destroy: function(options) {
- options = App.apiRequest('removeAccount', {account: this.toJSON()}, options);
- var self = this;
- options.success = function() {
- self.trigger('destroy', self, self.collection, options);
- };
-
- // TODO request is not dispatched
-// return Backbone.Model.prototype.destroy.call(this, options);
- return $.ajax(options);
- }
- });
-
-}); \ No newline at end of file
diff --git a/module/web/static/js/models/ConfigHolder.js b/module/web/static/js/models/ConfigHolder.js
deleted file mode 100644
index b05b1e14b..000000000
--- a/module/web/static/js/models/ConfigHolder.js
+++ /dev/null
@@ -1,67 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'app', './ConfigItem'],
- function($, Backbone, _, App, ConfigItem) {
-
- return Backbone.Model.extend({
-
- defaults: {
- name: "",
- label: "",
- description: "",
- long_description: null,
- // simple list but no collection
- items: null,
- info: null
- },
-
- // Model Constructor
- initialize: function() {
-
- },
-
- // Loads it from server by name
- fetch: function(options) {
- options = App.apiRequest('loadConfig/"' + this.get('name') + '"', null, options);
- return Backbone.Model.prototype.fetch.call(this, options);
- },
-
- save: function(options) {
- var config = this.toJSON();
- var items = [];
- // Convert changed items to json
- _.each(config.items, function(item) {
- if (item.isChanged()) {
- items.push(item.prepareSave());
- }
- });
- config.items = items;
- // TODO: only set new values on success
-
- options = App.apiRequest('saveConfig', {config: config}, options);
-
- return $.ajax(options);
- },
-
- parse: function(resp) {
- // Create item models
- resp.items = _.map(resp.items, function(item) {
- return new ConfigItem(item);
- });
-
- return Backbone.Model.prototype.parse.call(this, resp);
- },
-
- isLoaded: function() {
- return this.has('items') || this.has('long_description');
- },
-
- // check if any of the items has changes
- hasChanges: function() {
- var items = this.get('items');
- if (!items) return false;
- return _.reduce(items, function(a, b) {
- return a || b.isChanged();
- }, false);
- }
-
- });
- }); \ No newline at end of file
diff --git a/module/web/static/js/models/ConfigItem.js b/module/web/static/js/models/ConfigItem.js
deleted file mode 100644
index 01a85c6cc..000000000
--- a/module/web/static/js/models/ConfigItem.js
+++ /dev/null
@@ -1,39 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
- function($, Backbone, _, App, Api) {
-
- return Backbone.Model.extend({
-
- defaults: {
- name: "",
- label: "",
- description: "",
- input: null,
- default_value: null,
- value: null,
- // additional attributes
- inputView: null
- },
-
- // Model Constructor
- initialize: function() {
-
- },
-
- isChanged: function() {
- return this.get('inputView') && this.get('inputView').getVal() !== this.get('value');
- },
-
- // set new value and return json
- prepareSave: function() {
- // set the new value
- if (this.get('inputView'))
- this.set('value', this.get('inputView').getVal());
-
- var data = this.toJSON();
- delete data.inputView;
- delete data.description;
-
- return data;
- }
- });
- }); \ No newline at end of file
diff --git a/module/web/static/js/models/File.js b/module/web/static/js/models/File.js
deleted file mode 100644
index 524637cb4..000000000
--- a/module/web/static/js/models/File.js
+++ /dev/null
@@ -1,91 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($, Backbone, _, App, Api) {
-
- var Finished = [Api.DownloadStatus.Finished, Api.DownloadStatus.Skipped];
- var Failed = [Api.DownloadStatus.Failed, Api.DownloadStatus.Aborted, Api.DownloadStatus.TempOffline, Api.DownloadStatus.Offline];
- // Unfinished - Other
-
- return Backbone.Model.extend({
-
- idAttribute: 'fid',
-
- defaults: {
- fid: -1,
- name: null,
- package: -1,
- owner: -1,
- size: -1,
- status: -1,
- media: -1,
- added: -1,
- fileorder: -1,
- download: null,
-
- // UI attributes
- selected: false,
- visible: true,
- progress: 0,
- eta: 0
- },
-
- // Model Constructor
- initialize: function() {
-
- },
-
- fetch: function(options) {
- options = App.apiRequest(
- 'getFileInfo',
- {fid: this.get('fid')},
- options);
-
- return Backbone.Model.prototype.fetch.call(this, options);
- },
-
- destroy: function(options) {
- // also not working when using data
- options = App.apiRequest(
- 'deleteFiles/[' + this.get('fid') + ']',
- null, options);
- options.method = "post";
-
- return Backbone.Model.prototype.destroy.call(this, options);
- },
-
- // Does not send a request to the server
- destroyLocal: function(options) {
- this.trigger('destroy', this, this.collection, options);
- },
-
- restart: function(options) {
- options = App.apiRequest(
- 'restartFile',
- {fid: this.get('fid')},
- options);
-
- return $.ajax(options);
- },
-
- // Any time a model attribute is set, this method is called
- validate: function(attrs) {
-
- },
-
- isDownload: function() {
- return this.has('download');
- },
-
- isFinished: function() {
- return _.indexOf(Finished, this.get('download').status) > -1;
- },
-
- isUnfinished: function() {
- return _.indexOf(Finished, this.get('download').status) === -1 && _.indexOf(Failed, this.get('download').status) === -1;
- },
-
- isFailed: function() {
- return _.indexOf(Failed, this.get('download').status) > -1;
- }
-
- });
-
-}); \ No newline at end of file
diff --git a/module/web/static/js/models/InteractionTask.js b/module/web/static/js/models/InteractionTask.js
deleted file mode 100644
index 56fdbf8bf..000000000
--- a/module/web/static/js/models/InteractionTask.js
+++ /dev/null
@@ -1,40 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
- function($, Backbone, _, App, Api) {
-
- return Backbone.Model.extend({
-
- idAttribute: 'iid',
-
- defaults: {
- iid: -1,
- type: null,
- input: null,
- default_value: null,
- title: "",
- description: "",
- plugin: "",
- // additional attributes
- result: ""
- },
-
- // Model Constructor
- initialize: function() {
-
- },
-
- save: function(options) {
- options = App.apiRequest('setInteractionResult/' + this.get('iid'),
- {result: this.get('result')}, options);
-
- return $.ajax(options);
- },
-
- isNotification: function() {
- return this.get('type') === Api.Interaction.Notification;
- },
-
- isCaptcha: function() {
- return this.get('type') === Api.Interaction.Captcha;
- }
- });
- }); \ No newline at end of file
diff --git a/module/web/static/js/models/Package.js b/module/web/static/js/models/Package.js
deleted file mode 100644
index 1b050d735..000000000
--- a/module/web/static/js/models/Package.js
+++ /dev/null
@@ -1,118 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'collections/FileList', 'require'],
- function($, Backbone, _, App, FileList, require) {
-
- return Backbone.Model.extend({
-
- idAttribute: 'pid',
-
- defaults: {
- pid: -1,
- name: null,
- folder: "",
- root: -1,
- owner: -1,
- site: "",
- comment: "",
- password: "",
- added: -1,
- tags: null,
- status: -1,
- shared: false,
- packageorder: -1,
- stats: null,
- fids: null,
- pids: null,
- files: null, // Collection
- packs: null, // Collection
-
- selected: false // For Checkbox
- },
-
- // Model Constructor
- initialize: function() {
- },
-
- toJSON: function(options) {
- var obj = Backbone.Model.prototype.toJSON.call(this, options);
- obj.percent = Math.round(obj.stats.linksdone * 100 / obj.stats.linkstotal);
-
- return obj;
- },
-
- // Changes url + method and delegates call to super class
- fetch: function(options) {
- options = App.apiRequest(
- 'getFileTree/' + this.get('pid'),
- {full: false},
- options);
-
- return Backbone.Model.prototype.fetch.call(this, options);
- },
-
- // Create a pseudo package und use search to populate data
- search: function(qry, options) {
- options = App.apiRequest(
- 'findFiles',
- {pattern: qry},
- options);
-
- return Backbone.Model.prototype.fetch.call(this, options);
- },
-
- save: function(options) {
- // TODO
- },
-
- destroy: function(options) {
- // TODO: Not working when using data?, array seems to break it
- options = App.apiRequest(
- 'deletePackages/[' + this.get('pid') + ']',
- null, options);
- options.method = 'post';
-
- console.log(options);
-
- return Backbone.Model.prototype.destroy.call(this, options);
- },
-
- restart: function(options) {
- options = App.apiRequest(
- 'restartPackage',
- {pid: this.get('pid')},
- options);
-
- var self = this;
- options.success = function() {
- self.fetch();
- };
- return $.ajax(options);
- },
-
- parse: function(resp) {
- // Package is loaded from tree collection
- if (_.has(resp, 'root')) {
- if (!this.has('files'))
- resp.root.files = new FileList(_.values(resp.files));
- else
- this.get('files').update(_.values(resp.files));
-
- // circular dependencies needs to be avoided
- var PackageList = require('collections/PackageList');
-
- if (!this.has('packs'))
- resp.root.packs = new PackageList(_.values(resp.packages));
- else
- this.get('packs').update(_.values(resp.packages));
-
- return resp.root;
- }
- return Backbone.model.prototype.parse.call(this, resp);
- },
-
- // Any time a model attribute is set, this method is called
- validate: function(attrs) {
-
- }
-
- });
- }); \ No newline at end of file
diff --git a/module/web/static/js/models/Progress.js b/module/web/static/js/models/Progress.js
deleted file mode 100644
index 96beb0198..000000000
--- a/module/web/static/js/models/Progress.js
+++ /dev/null
@@ -1,49 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'utils/apitypes'], function($, Backbone, _, Api) {
-
- return Backbone.Model.extend({
-
- // generated, not submitted
- idAttribute: 'pid',
-
- defaults: {
- pid: -1,
- plugin: null,
- name: null,
- statusmsg: -1,
- eta: -1,
- done: -1,
- total: -1,
- download: null
- },
-
- getPercent: function() {
- if (this.get('total') > 0)
- return Math.round(this.get('done') * 100 / this.get('total'));
- return 0;
- },
-
- // Model Constructor
- initialize: function() {
-
- },
-
- // Any time a model attribute is set, this method is called
- validate: function(attrs) {
-
- },
-
- toJSON: function(options) {
- var obj = Backbone.Model.prototype.toJSON.call(this, options);
- obj.percent = this.getPercent();
- obj.downloading = this.isDownload() && this.get('download').status === Api.DownloadStatus.Downloading;
-
- return obj;
- },
-
- isDownload : function() {
- return this.has('download');
- }
-
- });
-
-}); \ No newline at end of file
diff --git a/module/web/static/js/models/ServerStatus.js b/module/web/static/js/models/ServerStatus.js
deleted file mode 100644
index 9242bdf95..000000000
--- a/module/web/static/js/models/ServerStatus.js
+++ /dev/null
@@ -1,46 +0,0 @@
-define(['jquery', 'backbone', 'underscore'],
- function($, Backbone, _) {
-
- return Backbone.Model.extend({
-
- defaults: {
- speed: 0,
- linkstotal: 0,
- linksqueue: 0,
- sizetotal: 0,
- sizequeue: 0,
- notifications: -1,
- paused: false,
- download: false,
- reconnect: false
- },
-
- // Model Constructor
- initialize: function() {
-
- },
-
- fetch: function() {
- options || (options = {});
- options.url = 'api/getServerStatus';
-
- return Backbone.Model.prototype.fetch.call(this, options);
- },
-
- toJSON: function(options) {
- var obj = Backbone.Model.prototype.toJSON.call(this, options);
-
- obj.linksdone = obj.linkstotal - obj.linksqueue;
- obj.sizedone = obj.sizetotal - obj.sizequeue;
- if (obj.speed && obj.speed > 0)
- obj.eta = Math.round(obj.sizequeue / obj.speed);
- else if (obj.sizequeue > 0)
- obj.eta = Infinity;
- else
- obj.eta = 0;
-
- return obj;
- }
-
- });
- }); \ No newline at end of file
diff --git a/module/web/static/js/models/TreeCollection.js b/module/web/static/js/models/TreeCollection.js
deleted file mode 100644
index bf14478ce..000000000
--- a/module/web/static/js/models/TreeCollection.js
+++ /dev/null
@@ -1,49 +0,0 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'models/Package', 'collections/FileList', 'collections/PackageList'],
- function($, Backbone, _, App, Package, FileList, PackageList) {
-
- // TreeCollection
- // A Model and not a collection, aggregates other collections
- return Backbone.Model.extend({
-
- defaults : {
- root: null,
- packages: null,
- files: null
- },
-
- initialize: function() {
-
- },
-
- fetch: function(options) {
- options || (options = {});
- var pid = options.pid || -1;
-
- options = App.apiRequest(
- 'getFileTree/' + pid,
- {full: false},
- options);
-
- console.log('Fetching package tree ' + pid);
- return Backbone.Model.prototype.fetch.call(this, options);
- },
-
- // Parse the response and updates the collections
- parse: function(resp) {
- var ret = {};
- if (!this.has('packages'))
- ret.packages = new PackageList(_.values(resp.packages));
- else
- this.get('packages').update(_.values(resp.packages));
-
- if (!this.has('files'))
- ret.files = new FileList(_.values(resp.files));
- else
- this.get('files').update(_.values(resp.files));
-
- ret.root = new Package(resp.root);
- return ret;
- }
-
- });
-}); \ No newline at end of file