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/File.js33
-rw-r--r--module/web/static/js/models/Package.js76
-rw-r--r--module/web/static/js/models/TreeCollection.js38
3 files changed, 147 insertions, 0 deletions
diff --git a/module/web/static/js/models/File.js b/module/web/static/js/models/File.js
new file mode 100644
index 000000000..71aa2b84f
--- /dev/null
+++ b/module/web/static/js/models/File.js
@@ -0,0 +1,33 @@
+define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) {
+
+ 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
+ },
+
+
+ // Model Constructor
+ initialize: function() {
+
+ },
+
+ // 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/Package.js b/module/web/static/js/models/Package.js
new file mode 100644
index 000000000..5a2940c66
--- /dev/null
+++ b/module/web/static/js/models/Package.js
@@ -0,0 +1,76 @@
+define(['jquery', 'backbone', 'underscore', 'collections/FileList', 'require'],
+ function($, Backbone, _, FileList, require) {
+
+ return Backbone.Model.extend({
+
+ idAttribute: 'pid',
+
+ defaults: {
+ pid: -1,
+ name: null,
+ folder: "",
+ root: -1,
+ owner: -1,
+ site: "",
+ comment: "",
+ password: "",
+ added: -1,
+ status: -1,
+ packageorder: -1,
+ stats: null,
+ fids: null,
+ pids: null,
+ files: null, // Collection
+ packs: null // Collection
+ },
+
+ // Model Constructor
+ initialize: function() {
+ },
+
+ // Changes url + method and delegates call to super class
+ fetch: function(options) {
+ options || (options = {});
+ options.url = 'api/getFileTree/' + this.get('pid') + '/false';
+ options.type = "post";
+
+ return Backbone.Model.prototype.fetch.call(this, options);
+ },
+
+ save: function(options) {
+ // TODO
+ },
+
+ destroy: function(options) {
+ options || (options = {});
+ // TODO: as post data
+ options.url = 'api/deletePackages/[' + this.get('pid') + ']';
+ options.type = "post";
+
+ return Backbone.Model.prototype.destroy.call(this, options);
+ },
+
+ parse: function(resp, xhr) {
+ // Package is loaded from tree collection
+ if (_.has(resp, 'root')) {
+ resp.root.files = new FileList(_.values(resp.files));
+ // circular dependencies needs to be avoided
+ var PackageList = require('collections/PackageList');
+ resp.root.packs = new PackageList(_.values(resp.packages));
+ return resp.root;
+ }
+ return Backbone.model.prototype.fetch.call(this, resp, xhr);
+ },
+
+ // Package data is complete when it contains collection for containing files or packs
+ isLoaded: function() {
+ return this.has('files');
+ },
+
+ // 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/TreeCollection.js b/module/web/static/js/models/TreeCollection.js
new file mode 100644
index 000000000..6476ea7b5
--- /dev/null
+++ b/module/web/static/js/models/TreeCollection.js
@@ -0,0 +1,38 @@
+define(['jquery', 'backbone', 'underscore', 'models/Package', 'collections/FileList', 'collections/PackageList'],
+ function($, Backbone, _, 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;
+
+ // TODO: more options possible
+ options.url = 'api/getFileTree/' + pid + '/false';
+ options.type = "post";
+
+ return Backbone.Model.prototype.fetch.call(this, options);
+ },
+
+ parse: function(resp, xhr) {
+ return {
+ root: new Package(resp.root),
+ packages: new PackageList(_.values(resp.packages)),
+ files: new FileList(_.values(resp.files))
+ };
+ }
+
+ });
+}); \ No newline at end of file