Skip to content

Instantly share code, notes, and snippets.

@ivasilov
Created February 10, 2012 12:42
Show Gist options
  • Save ivasilov/1789417 to your computer and use it in GitHub Desktop.
Save ivasilov/1789417 to your computer and use it in GitHub Desktop.
Faulty view
InvoiceListView = require('views/invoiceListView').InvoiceListView
InvoicesTemplate = require('views/templates/invoices')
class exports.InvoicesView extends Backbone.View
events:
'click #next' : 'nextPage'
'click #prev' : 'prevPage'
initialize: ->
app.collections.invoices.on("reset",@reset, @)
reset:->
@render(1)
render:(page) ->
if(app.views.main.rendered==false)
app.views.main.render(->app.views.invoices.subrender(page))
else
app.views.invoices.subrender(page)
@
subrender:(page) ->
@setElement('#rightpanel')
@page = page
$(@el).html InvoicesTemplate()
@renderPagination()
$('#page'+page).addClass('active')
@
renderPagination: ->
pages = Math.ceil(app.collections.invoices.length / 10)
page = 1
$('#last').before('<li id="page'+ page + '"><a href="#invoices/'+ page + '">' + page + '</a></li>') while page++ < pages
@
prevPage: ->
num = '#page' + @page-1
$(num).click()
@
nextPage: ->
$('#page' + @page+1).click()
@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment