| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
mw.echo.dm.PaginationModel = function MwEchoDmPaginationModel( config ) { |
| 17 |
config = config || {}; |
| 18 |
|
| 19 |
|
| 20 |
OO.EventEmitter.call( this ); |
| 21 |
|
| 22 |
this.pagesContinue = []; |
| 23 |
this.itemsPerPage = config.itemsPerPage || 25; |
| 24 |
this.currentPageItemCount = config.currentPageItemCount || this.itemsPerPage; |
| 25 |
|
| 26 |
|
| 27 |
this.currPageIndex = 0; |
| 28 |
this.pagesContinue[ 0 ] = ''; |
| 29 |
|
| 30 |
|
| 31 |
if ( config.pageNext ) { |
| 32 |
this.setPageContinue( 1, config.pageNext ); |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
OO.initClass( mw.echo.dm.PaginationModel ); |
| 39 |
OO.mixinClass( mw.echo.dm.PaginationModel, OO.EventEmitter ); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
mw.echo.dm.PaginationModel.prototype.reset = function () { |
| 57 |
this.pagesContinue = []; |
| 58 |
this.currPageIndex = 0; |
| 59 |
this.currentPageItemCount = this.itemsPerPage; |
| 60 |
|
| 61 |
this.emit( 'update' ); |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
mw.echo.dm.PaginationModel.prototype.setPageContinue = function ( page, continueVal ) { |
| 71 |
if ( this.pagesContinue[ page ] !== continueVal ) { |
| 72 |
this.pagesContinue[ page ] = continueVal; |
| 73 |
this.emit( 'update' ); |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
mw.echo.dm.PaginationModel.prototype.getPageContinue = function ( page ) { |
| 84 |
return this.pagesContinue[ page ]; |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
mw.echo.dm.PaginationModel.prototype.getCurrPageIndex = function () { |
| 93 |
return this.currPageIndex; |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
mw.echo.dm.PaginationModel.prototype.setCurrPageIndex = function ( index ) { |
| 103 |
this.currPageIndex = index; |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
mw.echo.dm.PaginationModel.prototype.forwards = function () { |
| 112 |
if ( this.hasNextPage() ) { |
| 113 |
this.setCurrPageIndex( this.currPageIndex + 1 ); |
| 114 |
this.emit( 'update' ); |
| 115 |
} |
| 116 |
}; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
mw.echo.dm.PaginationModel.prototype.backwards = function () { |
| 124 |
if ( this.hasPrevPage() ) { |
| 125 |
this.setCurrPageIndex( this.currPageIndex - 1 ); |
| 126 |
this.emit( 'update' ); |
| 127 |
} |
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
mw.echo.dm.PaginationModel.prototype.getPrevPageContinue = function () { |
| 136 |
return this.pagesContinue[ this.currPageIndex - 1 ] || ''; |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
mw.echo.dm.PaginationModel.prototype.getCurrPageContinue = function () { |
| 145 |
return this.pagesContinue[ this.currPageIndex ] || ''; |
| 146 |
}; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
mw.echo.dm.PaginationModel.prototype.getNextPageContinue = function () { |
| 154 |
return this.pagesContinue[ this.currPageIndex + 1 ] || ''; |
| 155 |
}; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
mw.echo.dm.PaginationModel.prototype.setNextPageContinue = function ( cont ) { |
| 163 |
this.setPageContinue( this.currPageIndex + 1, cont ); |
| 164 |
}; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
mw.echo.dm.PaginationModel.prototype.hasPrevPage = function () { |
| 172 |
return this.currPageIndex > 0; |
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
mw.echo.dm.PaginationModel.prototype.hasNextPage = function () { |
| 181 |
return !!this.pagesContinue[ this.currPageIndex + 1 ]; |
| 182 |
}; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
mw.echo.dm.PaginationModel.prototype.setCurrentPageItemCount = function ( count ) { |
| 191 |
if ( this.currentPageItemCount !== count ) { |
| 192 |
this.currentPageItemCount = count; |
| 193 |
this.emit( 'update' ); |
| 194 |
} |
| 195 |
}; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
mw.echo.dm.PaginationModel.prototype.getCurrentPageItemCount = function () { |
| 203 |
return this.currentPageItemCount; |
| 204 |
}; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
mw.echo.dm.PaginationModel.prototype.setItemsPerPage = function ( count ) { |
| 212 |
this.itemsPerPage = count; |
| 213 |
}; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
mw.echo.dm.PaginationModel.prototype.getItemsPerPage = function () { |
| 221 |
return this.itemsPerPage; |
| 222 |
}; |
| 223 |
}() ); |