summaryrefslogtreecommitdiffstats
path: root/module/web/static/js/models
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-08-31 23:25:26 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-08-31 23:25:26 +0200
commitcbd4f4b5375f89362733e10a9b98e5a74c2a5734 (patch)
tree056bb5af9aec5dee164d7f3055819ceb40e92a87 /module/web/static/js/models
parentFixed free space issue closed #676 (diff)
downloadpyload-cbd4f4b5375f89362733e10a9b98e5a74c2a5734.tar.xz
first js models/views
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.js52
-rw-r--r--module/web/static/js/models/TreeCollection.js38
-rw-r--r--module/web/static/js/models/model.js24
4 files changed, 123 insertions, 24 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..e5b0dc5a7
--- /dev/null
+++ b/module/web/static/js/models/Package.js
@@ -0,0 +1,52 @@
+define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) {
+
+ 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/getPackageInfo/' + this.get('pid');
+ options.type = "post";
+
+ return Backbone.Model.prototype.fetch.call(options);
+
+ },
+
+ save: function(options) {
+ // TODO
+ },
+
+ // 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
diff --git a/module/web/static/js/models/model.js b/module/web/static/js/models/model.js
deleted file mode 100644
index cd92e2644..000000000
--- a/module/web/static/js/models/model.js
+++ /dev/null
@@ -1,24 +0,0 @@
-define(['jquery', 'backbone'], function($, Backbone) {
-
- var Model = Backbone.Model.extend({
-
- defaults: {
- message: "You are now using Backbone, Lodash, Require, Modernizr, and jQuery! (Click Me)"
- },
-
- // Model Constructor
- initialize: function() {
-
- },
-
- // Any time a model attribute is set, this method is called
- validate: function(attrs) {
-
- }
-
- });
-
- // Returns the Model class
- return Model;
-
-}); \ No newline at end of file