summaryrefslogtreecommitdiffstats
path: root/module/web/static/js
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
parentFixed free space issue closed #676 (diff)
downloadpyload-cbd4f4b5375f89362733e10a9b98e5a74c2a5734.tar.xz
first js models/views
Diffstat (limited to 'module/web/static/js')
-rw-r--r--module/web/static/js/collections/FileList.js17
-rw-r--r--module/web/static/js/collections/PackageList.js16
-rw-r--r--module/web/static/js/default.js13
-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
-rw-r--r--module/web/static/js/views/packageTreeView.js54
8 files changed, 221 insertions, 26 deletions
diff --git a/module/web/static/js/collections/FileList.js b/module/web/static/js/collections/FileList.js
new file mode 100644
index 000000000..e91088867
--- /dev/null
+++ b/module/web/static/js/collections/FileList.js
@@ -0,0 +1,17 @@
+define(['jquery', 'backbone', 'underscore', 'models/File'], function($, Backbone, _, File) {
+
+ return Backbone.Collection.extend({
+
+ model: File,
+
+ comparator: function(file) {
+ return file.get('fileorder');
+ },
+
+ initialize: function() {
+
+ }
+
+ });
+
+}); \ No newline at end of file
diff --git a/module/web/static/js/collections/PackageList.js b/module/web/static/js/collections/PackageList.js
new file mode 100644
index 000000000..cb8abe22f
--- /dev/null
+++ b/module/web/static/js/collections/PackageList.js
@@ -0,0 +1,16 @@
+define(['jquery', 'backbone', 'underscore', 'models/Package'], function($, Backbone, _, Package) {
+
+ return Backbone.Collection.extend({
+
+ model: Package,
+
+ comparator: function(pack) {
+ return pack.get('packageorder');
+ },
+
+ initialize: function() {
+
+ }
+
+ });
+}); \ No newline at end of file
diff --git a/module/web/static/js/default.js b/module/web/static/js/default.js
index 3ec133a87..bed397712 100644
--- a/module/web/static/js/default.js
+++ b/module/web/static/js/default.js
@@ -31,12 +31,21 @@ require.config({
});
-define('default', ['jquery', 'backbone', 'routers/defaultRouter', 'views/headerView'], function ($, Backbone, DefaultRouter, HeaderView) {
+define('default', ['jquery', 'backbone', 'routers/defaultRouter', 'views/headerView', 'views/packageTreeView'],
+ function ($, Backbone, DefaultRouter, HeaderView, TreeView) {
+
var init = function(){
var view = new HeaderView();
view.render();
};
- return {"init":init};
+ var initPackageTree = function() {
+ $(function() {
+ var view = new TreeView();
+ view.init();
+ });
+ };
+
+ return {"init":init, "initPackageTree": initPackageTree};
}); \ No newline at end of file
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
diff --git a/module/web/static/js/views/packageTreeView.js b/module/web/static/js/views/packageTreeView.js
new file mode 100644
index 000000000..79527b394
--- /dev/null
+++ b/module/web/static/js/views/packageTreeView.js
@@ -0,0 +1,54 @@
+define(['jquery', 'backbone', 'underscore', 'models/TreeCollection'], function($, Backbone, _, TreeCollection){
+
+ // Renders whole PackageView
+ return Backbone.View.extend({
+
+ el: '#content',
+
+ events: {
+
+ },
+
+ initialize: function() {
+ _.bindAll(this, 'render');
+
+ this.tree = new TreeCollection();
+
+ },
+
+ init: function() {
+ var self = this;
+ this.tree.fetch({success: function(){
+ self.render();
+ }});
+ },
+
+
+ render: function() {
+
+ var packs = this.tree.get('packages'),
+ files = this.tree.get('files'),
+ html = 'Root: ' + this.tree.get('root').get('name') + '<br>';
+
+ html += 'Packages: ' + packs.size();
+ html += '<br><ul>';
+
+ packs.each(function(pack){
+ html += '<li>'+ pack.get('pid') + pack.get('name') + '</li>';
+ });
+
+ html += '</ul><br> Files: ' + files.size() + '<br><ul>';
+ files.each(function(file){
+ html += '<li>'+ file.get('fid') + file.get('name') + '</li>';
+ });
+
+ html += '</ul>';
+
+
+ this.$el.html(html);
+
+ return this;
+ }
+
+ });
+}); \ No newline at end of file