From 8c0aba9458a25266bb52bbc2101a83ed05967722 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Fri, 1 Apr 2016 12:55:45 -0500 Subject: Get pagination options form the view --- app/assets/javascripts/todos.js.coffee | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'app/assets/javascripts/todos.js.coffee') diff --git a/app/assets/javascripts/todos.js.coffee b/app/assets/javascripts/todos.js.coffee index ce44a16e224..f39184777ac 100644 --- a/app/assets/javascripts/todos.js.coffee +++ b/app/assets/javascripts/todos.js.coffee @@ -1,6 +1,11 @@ class @Todos - constructor: (@name) -> - @todos_per_page = gon.todos_per_page || 20 + constructor: (opts = {}) -> + { + @el = $('.js-todos-options') + } = opts + + @perPage = @el.data('perPage') + @clearListeners() @initBtnListeners() @@ -59,26 +64,30 @@ class @Todos $('.todos-pending .badge, .todos-pending-count').text data.count $('.todos-done .badge').text data.done_count - getRenderedPages: -> - $('.gl-pagination .page').length + getTotalPages: -> + @el.data('totalPages') getCurrentPage: -> - parseInt($.trim($('.gl-pagination .page.active').text())) + @el.data('currentPage') + + getTodosPerPage: -> + @el.data('perPage') + redirectIfNeeded: (total) -> - currPages = @getRenderedPages() + currPages = @getTotalPages() currPage = @getCurrentPage() - newPages = Math.ceil(total / @todos_per_page) + newPages = Math.ceil(total / @getTodosPerPage()) url = location.href # Includes query strings # Refresh if no remaining Todos - if !total + if not total location.reload() return # Do nothing if no pagination - return if !currPages + return if not currPages # If new total of pages is different than we have now if newPages isnt currPages -- cgit v1.2.1