diff options
author | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2012-08-10 17:06:32 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2012-08-10 17:07:14 +0000 |
commit | 2a029fb35f22ddf03326ec1f9c6b7ef413c2c293 (patch) | |
tree | aede021a2c03540b222aa24d8b221e4fa0cf4c6f /web | |
parent | b1a5a0dd5dc0a7910c305b90c7084766f5a0d729 (diff) | |
download | labitrack-2a029fb35f22ddf03326ec1f9c6b7ef413c2c293.tar.gz labitrack-2a029fb35f22ddf03326ec1f9c6b7ef413c2c293.tar.xz labitrack-2a029fb35f22ddf03326ec1f9c6b7ef413c2c293.zip |
convert 43-browse to coffee
Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>
Diffstat (limited to 'web')
-rw-r--r-- | web/js/labitrack.d/.gitignore | 1 | ||||
-rw-r--r-- | web/js/labitrack.d/43-browse.coffee | 66 | ||||
-rw-r--r-- | web/js/labitrack.d/43-browse.js | 83 |
3 files changed, 67 insertions, 83 deletions
diff --git a/web/js/labitrack.d/.gitignore b/web/js/labitrack.d/.gitignore index cf1c2ca..fc7aaf7 100644 --- a/web/js/labitrack.d/.gitignore +++ b/web/js/labitrack.d/.gitignore @@ -1 +1,2 @@ 39-pagination.js +43-browse.js diff --git a/web/js/labitrack.d/43-browse.coffee b/web/js/labitrack.d/43-browse.coffee new file mode 100644 index 0000000..b0d3358 --- /dev/null +++ b/web/js/labitrack.d/43-browse.coffee @@ -0,0 +1,66 @@ +hdl_add = -> + console.log 'add' + +hdl_remove = -> + console.log 'remove' + +hdl_reset = -> + console.log 'reset' + @render() + +collection = Backbone.Collection.extend { + model: λ.o, + url: -> '/browse/'+(@nextpage++)+'.json' + comparator: (object) -> object.id + fetchpage: (page) -> + if page + @nextpage = page + @fetch() + parse: (data) -> + @stats = {count: data.count} + console.log data + return data.objects +} + +browse = Backbone.View.extend { + initialize: () -> + messages = @collection + messages.bind "reset", hdl_reset, @ + messages.bind "add", hdl_add, @ + messages.bind "remove", hdl_remove, @ + render: (page) -> + if page then @page = page + page = @page + stats = @collection.stats + pages = [] + if stats != undefined + pgcnt = Math.ceil(stats.count / 10) + pages = λ.pagination page, pgcnt + + data = { + rows: @collection.toJSON(), + pages: pages + } + console.log data + $(@el).html λ.template 'objecttable', data +} + +collection = new collection() + +view = λ.routableview.extend { + initialize: () -> + λ.routableview.prototype.initialize.call(@) + @browse = new browse({collection: collection}) + render: (page) -> + page || (page = 1) + page = parseInt page, 10 + console.log 'page', page + λ.setcontent 'browse', {page} + @browse.el = $(@el).find('#objecttable_ph')[0] + console.log @browse.render + @browse.render page + @browse.collection.fetchpage page +} + +view.route 'browse' +view.route 'browse/page/:page' diff --git a/web/js/labitrack.d/43-browse.js b/web/js/labitrack.d/43-browse.js deleted file mode 100644 index 14399ac..0000000 --- a/web/js/labitrack.d/43-browse.js +++ /dev/null @@ -1,83 +0,0 @@ -(function(){ - - function hdl_add(){ - console.log('add'); - } - - function hdl_remove(){ - console.log('remove'); - } - - function hdl_reset(){ - console.log('reset'); - this.render(); - } - - var collection = Backbone.Collection.extend({ - model: λ.o, - url: function(){ - return '/browse/'+(this.nextpage++)+'.json'; - }, - fetchpage: function(page){ - if (page) { - this.nextpage = page; - } - this.fetch();; - }, - comparator: function(object){ - return object.id; - }, - parse: function(data){ - this.stats = {count: data.count}; - console.log(data); - return data.objects; - } - }); - - var browse = Backbone.View.extend({ - initialize: function() { - var messages = this.collection; - messages.bind("reset", hdl_reset, this); - messages.bind("add", hdl_add, this); - messages.bind("remove", hdl_remove, this); - }, - render: function(page){ - if (page) this.page = page; - page = this.page; - var stats = this.collection.stats; - var pages = []; - if (stats !== undefined) { - var pgcnt = Math.ceil(stats.count / 10); - pages = λ.pagination(page, pgcnt); - } - var data = { - rows: this.collection.toJSON(), - pages: pages - }; - console.log(data); - $(this.el).html(λ.template('objecttable', data)); - } - }); - - var collection = new collection(); - - var view = λ.routableview.extend({ - initialize: function() { - λ.routableview.prototype.initialize.call(this); - this.browse = new browse({collection: collection}); - }, - render: function (page) { - page || (page = 1); - page = parseInt(page, 10); - console.log('page', page); - λ.setcontent('browse', {page: page}); - this.browse.el = $(this.el).find('#objecttable_ph')[0]; - console.log(this.browse.render); - this.browse.render(page); - this.browse.collection.fetchpage(page); - } - }); - - view.route('browse'); - view.route('browse/page/:page'); -}()); |