mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-22 22:34:53 -04:00
UI Cleanup - Updated Shared and Shims subtrees.
This commit is contained in:
+63
-28
@@ -3,42 +3,52 @@ var Marionette = require('marionette');
|
||||
var Paginator = require('backgrid.paginator');
|
||||
|
||||
module.exports = Paginator.extend({
|
||||
template : 'Shared/Grid/PagerTemplate',
|
||||
events : {
|
||||
"click .pager-btn" : 'changePage',
|
||||
"click .x-page-number" : '_showPageJumper',
|
||||
"change .x-page-select" : '_jumpToPage',
|
||||
"blur .x-page-select" : 'render'
|
||||
template : 'Shared/Grid/PagerTemplate',
|
||||
|
||||
events : {
|
||||
'click .pager-btn' : 'changePage',
|
||||
'click .x-page-number' : '_showPageJumper',
|
||||
'change .x-page-select' : '_jumpToPage',
|
||||
'blur .x-page-select' : 'render'
|
||||
},
|
||||
windowSize : 1,
|
||||
|
||||
windowSize : 1,
|
||||
|
||||
fastForwardHandleLabels : {
|
||||
first : 'icon-fast-backward',
|
||||
prev : 'icon-backward',
|
||||
next : 'icon-forward',
|
||||
last : 'icon-fast-forward'
|
||||
},
|
||||
changePage : function(e){
|
||||
|
||||
changePage : function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var target = this.$(e.target);
|
||||
if(target.closest('li').hasClass('disabled')) {
|
||||
|
||||
if (target.closest('li').hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.closest('li i').addClass('icon-spinner icon-spin');
|
||||
|
||||
var label = target.attr('data-action');
|
||||
var ffLabels = this.fastForwardHandleLabels;
|
||||
|
||||
var collection = this.collection;
|
||||
if(ffLabels) {
|
||||
|
||||
if (ffLabels) {
|
||||
switch (label) {
|
||||
case 'first':
|
||||
collection.getFirstPage();
|
||||
return;
|
||||
case 'prev':
|
||||
if(collection.hasPrevious()) {
|
||||
if (collection.hasPrevious()) {
|
||||
collection.getPreviousPage();
|
||||
}
|
||||
return;
|
||||
case 'next':
|
||||
if(collection.hasNext()) {
|
||||
if (collection.hasNext()) {
|
||||
collection.getNextPage();
|
||||
}
|
||||
return;
|
||||
@@ -47,14 +57,19 @@ module.exports = Paginator.extend({
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var state = collection.state;
|
||||
var pageIndex = target.text();
|
||||
collection.getPage(state.firstPage === 0 ? pageIndex - 1 : pageIndex);
|
||||
},
|
||||
makeHandles : function(){
|
||||
|
||||
makeHandles : function() {
|
||||
var handles = [];
|
||||
|
||||
var collection = this.collection;
|
||||
var state = collection.state;
|
||||
|
||||
// convert all indices to 0-based here
|
||||
var firstPage = state.firstPage;
|
||||
var lastPage = +state.lastPage;
|
||||
lastPage = Math.max(0, firstPage ? lastPage - 1 : lastPage);
|
||||
@@ -62,7 +77,8 @@ module.exports = Paginator.extend({
|
||||
currentPage = firstPage ? currentPage - 1 : currentPage;
|
||||
var windowStart = Math.floor(currentPage / this.windowSize) * this.windowSize;
|
||||
var windowEnd = Math.min(lastPage + 1, windowStart + this.windowSize);
|
||||
if(collection.mode !== 'infinite') {
|
||||
|
||||
if (collection.mode !== 'infinite') {
|
||||
for (var i = windowStart; i < windowEnd; i++) {
|
||||
handles.push({
|
||||
label : i + 1,
|
||||
@@ -73,30 +89,34 @@ module.exports = Paginator.extend({
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var ffLabels = this.fastForwardHandleLabels;
|
||||
if(ffLabels) {
|
||||
if(ffLabels.prev) {
|
||||
if (ffLabels) {
|
||||
if (ffLabels.prev) {
|
||||
handles.unshift({
|
||||
label : ffLabels.prev,
|
||||
className : collection.hasPrevious() ? void 0 : 'disabled',
|
||||
action : 'prev'
|
||||
});
|
||||
}
|
||||
if(ffLabels.first) {
|
||||
|
||||
if (ffLabels.first) {
|
||||
handles.unshift({
|
||||
label : ffLabels.first,
|
||||
className : collection.hasPrevious() ? void 0 : 'disabled',
|
||||
action : 'first'
|
||||
});
|
||||
}
|
||||
if(ffLabels.next) {
|
||||
|
||||
if (ffLabels.next) {
|
||||
handles.push({
|
||||
label : ffLabels.next,
|
||||
className : collection.hasNext() ? void 0 : 'disabled',
|
||||
action : 'next'
|
||||
});
|
||||
}
|
||||
if(ffLabels.last) {
|
||||
|
||||
if (ffLabels.last) {
|
||||
handles.push({
|
||||
label : ffLabels.last,
|
||||
className : collection.hasNext() ? void 0 : 'disabled',
|
||||
@@ -104,44 +124,59 @@ module.exports = Paginator.extend({
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return handles;
|
||||
},
|
||||
render : function(){
|
||||
|
||||
render : function() {
|
||||
this.$el.empty();
|
||||
|
||||
var templateFunction = Marionette.TemplateCache.get(this.template);
|
||||
|
||||
this.$el.html(templateFunction({
|
||||
handles : this.makeHandles(),
|
||||
state : this.collection.state
|
||||
}));
|
||||
|
||||
this.delegateEvents();
|
||||
|
||||
return this;
|
||||
},
|
||||
_showPageJumper : function(e){
|
||||
if($(e.target).is('select')) {
|
||||
|
||||
_showPageJumper : function(e) {
|
||||
if ($(e.target).is('select')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var templateFunction = Marionette.TemplateCache.get('Shared/Grid/JumpToPageTemplate');
|
||||
var state = this.collection.state;
|
||||
var currentPage = Math.max(state.currentPage, state.firstPage);
|
||||
currentPage = state.firstPage ? currentPage - 1 : currentPage;
|
||||
|
||||
var pages = [];
|
||||
|
||||
for (var i = 0; i < this.collection.state.lastPage; i++) {
|
||||
if(i === currentPage) {
|
||||
if (i === currentPage) {
|
||||
pages.push({
|
||||
page : i + 1,
|
||||
current : true
|
||||
});
|
||||
}
|
||||
else {
|
||||
pages.push({page : i + 1});
|
||||
} else {
|
||||
pages.push({ page : i + 1 });
|
||||
}
|
||||
}
|
||||
this.$el.find('.x-page-number').html(templateFunction({pages : pages}));
|
||||
|
||||
this.$el.find('.x-page-number').html(templateFunction({ pages : pages }));
|
||||
},
|
||||
_jumpToPage : function(){
|
||||
|
||||
_jumpToPage : function() {
|
||||
var target = this.$el.find('.x-page-select');
|
||||
|
||||
//Remove event handlers so the blur event is not triggered
|
||||
this.undelegateEvents();
|
||||
|
||||
var selectedPage = parseInt(target.val(), 10);
|
||||
|
||||
this.$el.find('.x-page-number').html('<i class="icon-spinner icon-spin"></i>');
|
||||
this.collection.getPage(selectedPage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user