diff options
author | Alfredo Sumaran <alfredo@gitlab.com> | 2016-04-01 12:55:45 -0500 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-04-01 12:55:45 -0500 |
commit | 8c0aba9458a25266bb52bbc2101a83ed05967722 (patch) | |
tree | 670472f5597ccc858ec7486d09658f6b13e045b3 /app/assets/javascripts/todos.js.coffee | |
parent | f3134c2a7045accd70f6877874c43c3ead134d35 (diff) | |
download | gitlab-ce-8c0aba9458a25266bb52bbc2101a83ed05967722.tar.gz |
Get pagination options form the view
Diffstat (limited to 'app/assets/javascripts/todos.js.coffee')
-rw-r--r-- | app/assets/javascripts/todos.js.coffee | 27 |
1 files changed, 18 insertions, 9 deletions
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 |