Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
solr-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
2b235279
authored
2016-02-09 12:33:09 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refactored, to increase coverage, and remove duplicate code paths.
1 parent
bd7f86a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
19 deletions
src/scripts/solr/model/Pagination.js
src/scripts/solr/model/Pagination.js
View file @
2b23527
...
...
@@ -27,11 +27,18 @@ define(function(require) {
var
currentPage
=
parseInt
(
this
.
get
(
'currentPage'
));
var
pageSize
=
parseInt
(
this
.
get
(
'pageSize'
));
var
totalCount
=
parseInt
(
this
.
get
(
'totalCount'
));
if
(
!
currentPage
||
!
pageSize
||
!
totalCount
)
{
if
(
!
totalCount
)
{
return
;
}
var
pages
=
[];
var
totalPages
=
Math
.
floor
((
totalCount
+
pageSize
-
1
)
/
pageSize
);
if
(
currentPage
<
0
)
{
this
.
set
(
'currentPage'
,
1
);
return
;
}
else
if
(
currentPage
>
totalPages
)
{
this
.
set
(
'currentPage'
,
totalPages
);
return
;
}
function
addPage
(
self
,
i
)
{
pages
.
push
({
current
:
i
===
currentPage
,
...
...
@@ -59,9 +66,7 @@ define(function(require) {
}
for
(
var
i
=
startAt
;
i
<
endAt
;
i
++
)
{
if
(
i
>
0
&&
i
<=
totalPages
)
{
addPage
(
this
,
i
);
}
addPage
(
this
,
i
);
}
var
hasPrevious
=
currentPage
>
1
;
var
hasNext
=
currentPage
<
totalPages
;
...
...
@@ -89,21 +94,6 @@ define(function(require) {
totalPages
:
totalPages
,
});
};
this
.
on
(
'change:pageSize change:currentPage change:totalCount'
,
function
()
{
var
currentPage
=
parseInt
(
this
.
get
(
'currentPage'
));
var
pageSize
=
parseInt
(
this
.
get
(
'pageSize'
));
var
totalCount
=
parseInt
(
this
.
get
(
'totalCount'
));
if
(
!
currentPage
||
!
pageSize
||
!
totalCount
)
{
return
;
}
var
pages
=
[];
var
totalPages
=
Math
.
floor
((
totalCount
+
pageSize
-
1
)
/
pageSize
);
if
(
currentPage
<
0
)
{
this
.
set
(
'currentPage'
,
1
);
}
else
if
(
currentPage
>
totalPages
)
{
this
.
set
(
'currentPage'
,
totalPages
);
}
},
this
);
this
.
on
(
'change:pageSize change:currentPage change:totalCount'
,
buildPages
,
this
);
var
installActions
=
_
.
bind
(
function
installActions
(
eventName
,
nextName
,
hasNextName
,
previousName
,
hasPreviousName
,
pageCount
)
{
this
.
on
(
eventName
,
function
()
{
...
...
Please
register
or
sign in
to post a comment