From 2a029fb35f22ddf03326ec1f9c6b7ef413c2c293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 10 Aug 2012 17:06:32 +0000 Subject: convert 43-browse to coffee MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- web/js/labitrack.d/.gitignore | 1 + web/js/labitrack.d/43-browse.coffee | 66 +++++++++++++++++++++++++++++ web/js/labitrack.d/43-browse.js | 83 ------------------------------------- 3 files changed, 67 insertions(+), 83 deletions(-) create mode 100644 web/js/labitrack.d/43-browse.coffee delete mode 100644 web/js/labitrack.d/43-browse.js (limited to 'web') 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'); -}()); -- cgit v1.2.1