1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 '/browse', 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'
|