From ac58037d5dbc9d2ad8dc05cf609f90176aebb2b0 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 19 Aug 2012 11:36:29 +0200 Subject: boilerplate for js code --- module/web/static/js/models/model.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 module/web/static/js/models/model.js (limited to 'module/web/static/js/models') diff --git a/module/web/static/js/models/model.js b/module/web/static/js/models/model.js new file mode 100644 index 000000000..2ea2db616 --- /dev/null +++ b/module/web/static/js/models/model.js @@ -0,0 +1,24 @@ +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 -- cgit v1.2.3 From 459f4291cb7ae4174d7c7dfa6a06bf89e3538338 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 26 Aug 2012 17:46:04 +0200 Subject: dependency updates --- module/web/static/js/models/model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/web/static/js/models') diff --git a/module/web/static/js/models/model.js b/module/web/static/js/models/model.js index 2ea2db616..cd92e2644 100644 --- a/module/web/static/js/models/model.js +++ b/module/web/static/js/models/model.js @@ -3,7 +3,7 @@ define(['jquery', 'backbone'], function($, Backbone) { var Model = Backbone.Model.extend({ defaults: { - message: "You are now using Backbone, Lodash, Require, Modernizr, and jQuery! (Click Me)" + message: "You are now using Backbone, Lodash, Require, Modernizr, and jQuery! (Click Me)" }, // Model Constructor -- cgit v1.2.3 From cbd4f4b5375f89362733e10a9b98e5a74c2a5734 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 31 Aug 2012 23:25:26 +0200 Subject: first js models/views --- module/web/static/js/models/File.js | 33 +++++++++++++++++ module/web/static/js/models/Package.js | 52 +++++++++++++++++++++++++++ module/web/static/js/models/TreeCollection.js | 38 ++++++++++++++++++++ module/web/static/js/models/model.js | 24 ------------- 4 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 module/web/static/js/models/File.js create mode 100644 module/web/static/js/models/Package.js create mode 100644 module/web/static/js/models/TreeCollection.js delete mode 100644 module/web/static/js/models/model.js (limited to 'module/web/static/js/models') 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 -- cgit v1.2.3 From a03ece96ae83e8fedb27fdb297c52a8e6b111d55 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 1 Sep 2012 21:00:38 +0200 Subject: some functionality for the views --- module/web/static/js/models/Package.js | 102 ++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 39 deletions(-) (limited to 'module/web/static/js/models') diff --git a/module/web/static/js/models/Package.js b/module/web/static/js/models/Package.js index e5b0dc5a7..5a2940c66 100644 --- a/module/web/static/js/models/Package.js +++ b/module/web/static/js/models/Package.js @@ -1,52 +1,76 @@ -define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { +define(['jquery', 'backbone', 'underscore', 'collections/FileList', 'require'], + function($, Backbone, _, FileList, require) { - return Backbone.Model.extend({ + return Backbone.Model.extend({ - idAttribute: 'pid', + 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 - }, + 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() { + // 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"; - // 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(this, options); + }, - return Backbone.Model.prototype.fetch.call(options); + save: function(options) { + // TODO + }, - }, + destroy: function(options) { + options || (options = {}); + // TODO: as post data + options.url = 'api/deletePackages/[' + this.get('pid') + ']'; + options.type = "post"; - save: function(options) { - // TODO - }, + return Backbone.Model.prototype.destroy.call(this, options); + }, - // Any time a model attribute is set, this method is called - validate: function(attrs) { + 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 + } + + }); + }); \ No newline at end of file -- cgit v1.2.3