Commit 41208c92 by Andy Armstrong

Convert to RequireJS text for templates

parent 16890041
define(["underscore", "js/views/baseview"], function(_, BaseView) { define(["underscore", "backbone", "text!common/templates/components/paging-footer.underscore"],
function(_, Backbone, paging_footer_template) {
var PagingFooter = BaseView.extend({ var PagingFooter = Backbone.View.extend({
events : { events : {
"click .next-page-link": "nextPage", "click .next-page-link": "nextPage",
"click .previous-page-link": "previousPage", "click .previous-page-link": "previousPage",
"change .page-number-input": "changePage" "change .page-number-input": "changePage"
}, },
initialize: function(options) { initialize: function(options) {
var view = options.view, var view = options.view,
collection = view.collection; collection = view.collection;
this.view = view; this.view = view;
this.template = this.loadTemplate('paging-footer'); collection.bind('add', _.bind(this.render, this));
collection.bind('add', _.bind(this.render, this)); collection.bind('remove', _.bind(this.render, this));
collection.bind('remove', _.bind(this.render, this)); collection.bind('reset', _.bind(this.render, this));
collection.bind('reset', _.bind(this.render, this)); this.render();
this.render(); },
},
render: function() { render: function() {
var view = this.view, var view = this.view,
collection = view.collection, collection = view.collection,
currentPage = collection.currentPage, currentPage = collection.currentPage,
lastPage = collection.totalPages - 1; lastPage = collection.totalPages - 1;
this.$el.html(this.template({ this.$el.html(_.template(paging_footer_template, {
current_page: collection.currentPage, current_page: collection.currentPage,
total_pages: collection.totalPages total_pages: collection.totalPages
})); }));
this.$(".previous-page-link").toggleClass("is-disabled", currentPage === 0).attr('aria-disabled', currentPage === 0);; this.$(".previous-page-link").toggleClass("is-disabled", currentPage === 0).attr('aria-disabled', currentPage === 0);;
this.$(".next-page-link").toggleClass("is-disabled", currentPage === lastPage).attr('aria-disabled', currentPage === lastPage); this.$(".next-page-link").toggleClass("is-disabled", currentPage === lastPage).attr('aria-disabled', currentPage === lastPage);
return this; return this;
}, },
changePage: function() { changePage: function() {
var view = this.view, var view = this.view,
collection = view.collection, collection = view.collection,
currentPage = collection.currentPage + 1, currentPage = collection.currentPage + 1,
pageInput = this.$("#page-number-input"), pageInput = this.$("#page-number-input"),
pageNumber = parseInt(pageInput.val(), 10); pageNumber = parseInt(pageInput.val(), 10);
if (pageNumber > collection.totalPages) { if (pageNumber > collection.totalPages) {
pageNumber = false; pageNumber = false;
} }
if (pageNumber <= 0) { if (pageNumber <= 0) {
pageNumber = false; pageNumber = false;
} }
// If we still have a page number by this point, // If we still have a page number by this point,
// and it's not the current page, load it. // and it's not the current page, load it.
if (pageNumber && pageNumber !== currentPage) { if (pageNumber && pageNumber !== currentPage) {
view.setPage(pageNumber - 1); view.setPage(pageNumber - 1);
} }
pageInput.val(""); // Clear the value as the label will show beneath it pageInput.val(""); // Clear the value as the label will show beneath it
}, },
nextPage: function() { nextPage: function() {
this.view.nextPage(); this.view.nextPage();
}, },
previousPage: function() { previousPage: function() {
this.view.previousPage(); this.view.previousPage();
} }
}); });
return PagingFooter; return PagingFooter;
}); // end define(); }); // end define();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment