Pagination.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.grid.enhanced.plugins.Pagination"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.grid.enhanced.plugins.Pagination"] = true;
  8. dojo.provide("dojox.grid.enhanced.plugins.Pagination");
  9. dojo.require("dijit.form.NumberTextBox");
  10. dojo.require("dijit.form.Button");
  11. dojo.require("dojox.grid.enhanced._Plugin");
  12. dojo.require("dojox.grid.enhanced.plugins.Dialog");
  13. dojo.require("dojox.grid.enhanced.plugins._StoreLayer");
  14. dojo.requireLocalization("dojox.grid.enhanced", "Pagination", null, "ROOT,ar,bg,ca,cs,da,de,el,es,fi,fr,he,hr,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
  15. dojo.declare("dojox.grid.enhanced.plugins.Pagination", dojox.grid.enhanced._Plugin, {
  16. // summary:
  17. // The typical pagination way as an alternative to deal with huge data set besides the default virtual scrolling way
  18. name: "pagination",
  19. // The page size used with the store, default = 25.
  20. pageSize: 25,
  21. defaultRows: 25,
  22. //current page we are at
  23. _currentPage: 0,
  24. //The currently obtained max # of rows to page through.
  25. _maxSize: 0,
  26. init: function(){
  27. this.gh = null;
  28. this.grid.rowsPerPage = this.pageSize = this.grid.rowsPerPage ? this.grid.rowsPerPage : this.pageSize;
  29. this.grid.usingPagination = true;
  30. this.nls = dojo.i18n.getLocalization("dojox.grid.enhanced", "Pagination");
  31. this._wrapStoreLayer();
  32. this._createPaginators(this.option);
  33. this._regApis();
  34. },
  35. _createPaginators: function(paginationArgs){
  36. // summary:
  37. // Function to create the pagination control bar.
  38. this.paginators = [];
  39. if(paginationArgs.position === "both"){
  40. this.paginators = [
  41. new dojox.grid.enhanced.plugins._Paginator(dojo.mixin(paginationArgs, {position: "bottom", plugin: this})),
  42. new dojox.grid.enhanced.plugins._Paginator(dojo.mixin(paginationArgs, {position: "top", plugin: this}))
  43. ];
  44. }else{
  45. this.paginators = [new dojox.grid.enhanced.plugins._Paginator(dojo.mixin(paginationArgs, {plugin: this}))];
  46. }
  47. },
  48. _wrapStoreLayer: function(){
  49. var g = this.grid,
  50. ns = dojox.grid.enhanced.plugins;
  51. this._store = g.store;
  52. this.query = g.query;
  53. this.forcePageStoreLayer = new ns._ForcedPageStoreLayer(this);
  54. ns.wrap(g, "_storeLayerFetch", this.forcePageStoreLayer);
  55. this.connect(g, "setQuery", function(query){
  56. if(query !== this.query){
  57. this.query = query;
  58. }
  59. });
  60. },
  61. _stopEvent: function(event){
  62. try{
  63. dojo.stopEvent(event);
  64. }catch(e){}
  65. },
  66. _onNew: function(item, parentInfo){
  67. var totalPages = Math.ceil(this._maxSize / this.pageSize);
  68. if(((this._currentPage + 1 === totalPages || totalPages === 0) && this.grid.rowCount < this.pageSize) || this.showAll){
  69. dojo.hitch(this.grid, this._originalOnNew)(item, parentInfo);
  70. this.forcePageStoreLayer.endIdx++;
  71. }
  72. this._maxSize++;
  73. if(this.showAll){
  74. this.pageSize++;
  75. }
  76. if(this.showAll && this.grid.autoHeight){
  77. this.grid._refresh();
  78. }else{
  79. dojo.forEach(this.paginators, function(p){
  80. p.update();
  81. });
  82. }
  83. },
  84. _removeSelectedRows: function(){
  85. this._multiRemoving = true;
  86. this._originalRemove();
  87. this._multiRemoving = false;
  88. this.grid.resize();
  89. this.grid._refresh();
  90. },
  91. _onDelete: function(){
  92. if(!this._multiRemoving){
  93. this.grid.resize();
  94. if(this.showAll){
  95. this.grid._refresh();
  96. }
  97. }
  98. if(this.grid.get('rowCount') === 0){
  99. this.prevPage();
  100. }
  101. },
  102. _regApis: function(){
  103. // summary:
  104. // register pagination public APIs to grid.
  105. var g = this.grid;
  106. // New added APIs
  107. g.gotoPage = dojo.hitch(this, this.gotoPage);
  108. g.nextPage = dojo.hitch(this, this.nextPage);
  109. g.prevPage = dojo.hitch(this, this.prevPage);
  110. g.gotoFirstPage = dojo.hitch(this, this.gotoFirstPage);
  111. g.gotoLastPage = dojo.hitch(this, this.gotoLastPage);
  112. g.changePageSize = dojo.hitch(this, this.changePageSize);
  113. g.showGotoPageButton = dojo.hitch(this, this.showGotoPageButton);
  114. g.getTotalRowCount = dojo.hitch(this, this.getTotalRowCount);
  115. // Changed APIs
  116. this.originalScrollToRow = dojo.hitch(g, g.scrollToRow);
  117. g.scrollToRow = dojo.hitch(this, this.scrollToRow);
  118. this._originalOnNew = dojo.hitch(g, g._onNew);
  119. this._originalRemove = dojo.hitch(g, g.removeSelectedRows);
  120. g.removeSelectedRows = dojo.hitch(this, this._removeSelectedRows);
  121. g._onNew = dojo.hitch(this, this._onNew);
  122. this.connect(g, "_onDelete", dojo.hitch(this, this._onDelete));
  123. },
  124. destroy: function(){
  125. this.inherited(arguments);
  126. var g = this.grid;
  127. try{
  128. dojo.forEach(this.paginators, function(p){
  129. p.destroy();
  130. });
  131. g.unwrap(this.forcePageStoreLayer.name());
  132. g._onNew = this._originalOnNew;
  133. g.removeSelectedRows = this._originalRemove;
  134. g.scrollToRow = this.originalScrollToRow;
  135. this.paginators = null;
  136. this.nls = null;
  137. }catch(e){
  138. console.warn("Pagination.destroy() error: ", e);
  139. }
  140. },
  141. nextPage: function(){
  142. // summary:
  143. // Function to handle shifting to the next page in the list.
  144. if(this._maxSize > ((this._currentPage + 1) * this.pageSize)){
  145. //Current page is indexed at 0 and gotoPage expects 1-X. So to go
  146. //up one, pass current page + 2!
  147. this.gotoPage(this._currentPage + 2);
  148. }
  149. },
  150. prevPage: function(){
  151. // summary:
  152. // Function to handle shifting to the previous page in the list.
  153. if(this._currentPage > 0){
  154. //Current page is indexed at 0 and gotoPage expects 1-X. So to go
  155. //back one, pass current page!
  156. this.gotoPage(this._currentPage);
  157. }
  158. },
  159. gotoPage: function(page){
  160. // summary:
  161. // Function to handle shifting to an arbirtary page in the list.
  162. // page:
  163. // The page to go to, starting at 1.
  164. var totalPages = Math.ceil(this._maxSize / this.pageSize);
  165. page--;
  166. if(page < totalPages && page >= 0 && this._currentPage !== page){
  167. this._currentPage = page;
  168. // this._updateSelected();
  169. this.grid.setQuery(this.query);
  170. this.grid.resize();
  171. }
  172. },
  173. gotoFirstPage: function(){
  174. // summary:
  175. // Go to the first page
  176. this.gotoPage(1);
  177. },
  178. gotoLastPage: function(){
  179. // summary:
  180. // Go to the last page
  181. var totalPages = Math.ceil(this._maxSize / this.pageSize);
  182. this.gotoPage(totalPages);
  183. },
  184. changePageSize: function(size){
  185. // summary:
  186. // Change size of items per page.
  187. // This function will only be called by _Paginator
  188. if(typeof size == "string"){
  189. size = parseInt(size, 10);
  190. }
  191. var startIndex = this.pageSize * this._currentPage;
  192. dojo.forEach(this.paginators, function(f){
  193. f.currentPageSize = this.grid.rowsPerPage = this.pageSize = size;
  194. if(size >= this._maxSize){
  195. this.grid.rowsPerPage = this.defaultRows;
  196. this.showAll = true;
  197. this.grid.usingPagination = false;
  198. }else{
  199. this.grid.usingPagination = true;
  200. }
  201. }, this);
  202. var endIndex = startIndex + Math.min(this.pageSize, this._maxSize);
  203. if(endIndex > this._maxSize){
  204. this.gotoLastPage();
  205. }else{
  206. var cp = Math.ceil(startIndex / this.pageSize);
  207. if(cp !== this._currentPage){
  208. this.gotoPage(cp + 1);
  209. }else{
  210. this.grid._refresh(true);
  211. }
  212. }
  213. this.grid.resize();
  214. },
  215. showGotoPageButton: function(flag){
  216. // summary:
  217. // For show/hide the go to page button dynamically
  218. // flag: boolean
  219. // Show the go to page button when flag is true, otherwise hide it
  220. dojo.forEach(this.paginators, function(p){
  221. p._showGotoButton(flag);
  222. });
  223. },
  224. scrollToRow: function(inRowIndex){
  225. // summary:
  226. // Override the grid.scrollToRow(), could jump to the right page
  227. // and scroll to the specific row
  228. // inRowIndex: integer
  229. // The row index
  230. var page = parseInt(inRowIndex / this.pageSize, 10),
  231. totalPages = Math.ceil(this._maxSize / this.pageSize);
  232. if(page > totalPages){
  233. return;
  234. }
  235. this.gotoPage(page + 1);
  236. var rowIdx = inRowIndex % this.pageSize;
  237. this.grid.setScrollTop(this.grid.scroller.findScrollTop(rowIdx) + 1);
  238. },
  239. getTotalRowCount: function(){
  240. // summary:
  241. // Function for get total row count
  242. return this._maxSize;
  243. }
  244. });
  245. dojo.declare("dojox.grid.enhanced.plugins._ForcedPageStoreLayer", dojox.grid.enhanced.plugins._StoreLayer, {
  246. tags: ["presentation"],
  247. constructor: function(plugin){
  248. this._plugin = plugin;
  249. },
  250. _fetch: function(request){
  251. var self = this,
  252. plugin = self._plugin,
  253. grid = plugin.grid,
  254. scope = request.scope || dojo.global,
  255. onBegin = request.onBegin;
  256. request.start = plugin._currentPage * plugin.pageSize + request.start;
  257. self.startIdx = request.start;
  258. self.endIdx = request.start + plugin.pageSize - 1;
  259. if(onBegin && (plugin.showAll || dojo.every(plugin.paginators, function(p){
  260. return plugin.showAll = !p.sizeSwitch && !p.pageStepper && !p.gotoButton;
  261. }))){
  262. request.onBegin = function(size, req){
  263. plugin._maxSize = plugin.pageSize = size;
  264. self.startIdx = 0;
  265. self.endIdx = size - 1;
  266. dojo.forEach(plugin.paginators, function(f){
  267. f.update();
  268. });
  269. req.onBegin = onBegin;
  270. req.onBegin.call(scope, size, req);
  271. };
  272. }else if(onBegin){
  273. request.onBegin = function(size, req){
  274. req.start = 0;
  275. req.count = plugin.pageSize;
  276. plugin._maxSize = size;
  277. self.endIdx = self.endIdx >= size ? (size - 1) : self.endIdx;
  278. if(self.startIdx > size && size !== 0){
  279. grid._pending_requests[req.start] = false;
  280. plugin.gotoFirstPage();
  281. }
  282. dojo.forEach(plugin.paginators, function(f){
  283. f.update();
  284. });
  285. req.onBegin = onBegin;
  286. req.onBegin.call(scope, Math.min(plugin.pageSize, (size - self.startIdx)), req);
  287. };
  288. }
  289. return dojo.hitch(this._store, this._originFetch)(request);
  290. }
  291. });
  292. dojo.declare("dojox.grid.enhanced.plugins._Paginator", [dijit._Widget,dijit._Templated], {
  293. templateString:"<div dojoAttachPoint=\"paginatorBar\">\n\t<table cellpadding=\"0\" cellspacing=\"0\" class=\"dojoxGridPaginator\">\n\t\t<tr>\n\t\t\t<td dojoAttachPoint=\"descriptionTd\" class=\"dojoxGridDescriptionTd\">\n\t\t\t\t<div dojoAttachPoint=\"descriptionDiv\" class=\"dojoxGridDescription\" />\n\t\t\t</td>\n\t\t\t<td dojoAttachPoint=\"sizeSwitchTd\"></td>\n\t\t\t<td dojoAttachPoint=\"pageStepperTd\" class=\"dojoxGridPaginatorFastStep\">\n\t\t\t\t<div dojoAttachPoint=\"pageStepperDiv\" class=\"dojoxGridPaginatorStep\"></div>\n\t\t\t</td>\n\t\t</tr>\n\t</table>\n</div>\n",
  294. // pagination bar position - "bottom"|"top"
  295. position: "bottom",
  296. // max data item size
  297. _maxItemSize: 0,
  298. // description message status params
  299. description: true,
  300. // fast step page status params
  301. pageStepper: true,
  302. maxPageStep: 7,
  303. // items per page size switch params
  304. sizeSwitch: true,
  305. pageSizes: ["10", "25", "50", "100", "All"],
  306. gotoButton: false,
  307. constructor: function(params){
  308. dojo.mixin(this, params);
  309. this.grid = this.plugin.grid;
  310. this.itemTitle = this.itemTitle ? this.itemTitle : this.plugin.nls.itemTitle;
  311. this.descTemplate = this.descTemplate ? this.descTemplate : this.plugin.nls.descTemplate;
  312. },
  313. postCreate: function(){
  314. this.inherited(arguments);
  315. this._setWidthValue();
  316. var self = this;
  317. var g = this.grid;
  318. this.plugin.connect(g, "_resize", dojo.hitch(this, "_resetGridHeight"));
  319. this._originalResize = g.resize;
  320. g.resize = function(changeSize, resultSize){
  321. self._changeSize = changeSize;
  322. self._resultSize = resultSize;
  323. self._originalResize.apply(g, arguments);
  324. };
  325. this._placeSelf();
  326. },
  327. destroy: function(){
  328. this.inherited(arguments);
  329. this.grid.focus.removeArea("pagination" + this.position.toLowerCase());
  330. if(this._gotoPageDialog){
  331. this._gotoPageDialog.destroy();
  332. dojo.destroy(this.gotoPageTd);
  333. delete this.gotoPageTd;
  334. delete this._gotoPageDialog;
  335. }
  336. this.grid.resize = this._originalResize;
  337. this.pageSizes = null;
  338. },
  339. update: function(){
  340. // summary:
  341. // Function to update paging information and update
  342. // pagination bar display.
  343. this.currentPageSize = this.plugin.pageSize;
  344. this._maxItemSize = this.plugin._maxSize;
  345. // update pagination bar display information
  346. this._updateDescription();
  347. this._updatePageStepper();
  348. this._updateSizeSwitch();
  349. this._updateGotoButton();
  350. },
  351. _setWidthValue: function(){
  352. var type = ["description", "sizeSwitch", "pageStepper"];
  353. var endWith = function(str1, str2){
  354. var reg = new RegExp(str2+"$");
  355. return reg.test(str1);
  356. };
  357. dojo.forEach(type, function(t){
  358. var width, flag = this[t];
  359. if(flag === undefined || typeof flag == "boolean"){
  360. return;
  361. }
  362. if(dojo.isString(flag)){
  363. width = endWith(flag, "px") || endWith(flag, "%") || endWith(flag, "em") ? flag : parseInt(flag, 10) > 0 ? parseInt(flag, 10) + "px" : null;
  364. }else if(typeof flag === "number" && flag > 0){
  365. width = flag + "px";
  366. }
  367. this[t] = width ? true : false;
  368. this[t + "Width"] = width;
  369. }, this);
  370. },
  371. _regFocusMgr: function(position){
  372. // summary:
  373. // Function to register pagination bar to focus manager.
  374. this.grid.focus.addArea({
  375. name: "pagination" + position,
  376. onFocus: dojo.hitch(this, this._onFocusPaginator),
  377. onBlur: dojo.hitch(this, this._onBlurPaginator),
  378. onMove: dojo.hitch(this, this._moveFocus),
  379. onKeyDown: dojo.hitch(this, this._onKeyDown)
  380. });
  381. switch(position){
  382. case "top":
  383. this.grid.focus.placeArea("pagination" + position, "before", "header");
  384. break;
  385. case "bottom":
  386. default:
  387. this.grid.focus.placeArea("pagination" + position, "after", "content");
  388. break;
  389. }
  390. },
  391. _placeSelf: function(){
  392. // summary:
  393. // Place pagination bar to a position.
  394. // There are two options, top of the grid, bottom of the grid.
  395. var g = this.grid;
  396. var position = dojo.trim(this.position.toLowerCase());
  397. switch(position){
  398. case "top":
  399. this.placeAt(g.viewsHeaderNode, "before");
  400. this._regFocusMgr("top");
  401. break;
  402. case "bottom":
  403. default:
  404. this.placeAt(g.viewsNode, "after");
  405. this._regFocusMgr("bottom");
  406. break;
  407. }
  408. },
  409. _resetGridHeight: function(changeSize, resultSize){
  410. // summary:
  411. // Function of resize grid height to place this pagination bar.
  412. // Since the grid would be able to add other element in its domNode, we have
  413. // change the grid view size to place the pagination bar.
  414. // This function will resize the grid viewsNode height, scorllboxNode height
  415. var g = this.grid;
  416. changeSize = changeSize || this._changeSize;
  417. resultSize = resultSize || this._resultSize;
  418. delete this._changeSize;
  419. delete this._resultSize;
  420. if(g._autoHeight){
  421. return;
  422. }
  423. var padBorder = g._getPadBorder().h;
  424. if(!this.plugin.gh){
  425. this.plugin.gh = (g.domNode.clientHeight || dojo.style(g.domNode, 'height')) + 2 * padBorder;
  426. }
  427. if(resultSize){
  428. changeSize = resultSize;
  429. }
  430. if(changeSize){
  431. this.plugin.gh = dojo.contentBox(g.domNode).h + 2 * padBorder;
  432. }
  433. var gh = this.plugin.gh,
  434. hh = g._getHeaderHeight(),
  435. ph = dojo.marginBox(this.domNode).h;
  436. ph = this.plugin.paginators[1] ? ph * 2 : ph;
  437. if(typeof g.autoHeight == "number"){
  438. var cgh = gh + ph - padBorder;
  439. dojo.style(g.domNode, "height", cgh + "px");
  440. dojo.style(g.viewsNode, "height", (cgh - ph - hh) + "px");
  441. this._styleMsgNode(hh, dojo.marginBox(g.viewsNode).w, cgh - ph - hh);
  442. }else{
  443. var h = gh - ph - hh - padBorder;
  444. dojo.style(g.viewsNode, "height", h + "px");
  445. var hasHScroller = dojo.some(g.views.views, function(v){
  446. return v.hasHScrollbar();
  447. });
  448. dojo.forEach(g.viewsNode.childNodes, function(c, idx){
  449. dojo.style(c, "height", h + "px");
  450. });
  451. dojo.forEach(g.views.views, function(v, idx){
  452. if(v.scrollboxNode){
  453. if(!v.hasHScrollbar() && hasHScroller){
  454. dojo.style(v.scrollboxNode, "height", (h - dojox.html.metrics.getScrollbar().h) + "px");
  455. }else{
  456. dojo.style(v.scrollboxNode, "height", h + "px");
  457. }
  458. }
  459. });
  460. this._styleMsgNode(hh, dojo.marginBox(g.viewsNode).w, h);
  461. }
  462. },
  463. _styleMsgNode: function(top, width, height){
  464. var messagesNode = this.grid.messagesNode;
  465. dojo.style(messagesNode, {"position": "absolute", "top": top + "px", "width": width + "px", "height": height + "px", "z-Index": "100"});
  466. },
  467. _updateDescription: function(){
  468. // summary:
  469. // Update size information.
  470. var s = this.plugin.forcePageStoreLayer;
  471. if(this.description && this.descriptionDiv){
  472. this.descriptionDiv.innerHTML = this._maxItemSize > 0 ? dojo.string.substitute(this.descTemplate, [this.itemTitle, this._maxItemSize, s.startIdx + 1, s.endIdx + 1]) : "0 " + this.itemTitle;
  473. }
  474. if(this.descriptionWidth){
  475. dojo.style(this.descriptionTd, "width", this.descriptionWidth);
  476. }
  477. },
  478. _updateSizeSwitch: function(){
  479. // summary:
  480. // Update "items per page" information.
  481. if(!this.sizeSwitchTd){
  482. return;
  483. }
  484. if(!this.sizeSwitch || this._maxItemSize <= 0){
  485. dojo.style(this.sizeSwitchTd, "display", "none");
  486. return;
  487. }else{
  488. dojo.style(this.sizeSwitchTd, "display", "");
  489. }
  490. if(this.initializedSizeNode && !this.pageSizeValue){
  491. // do not update page size if page size was not changed
  492. return;
  493. }
  494. if(this.sizeSwitchTd.childNodes.length < 1){
  495. this._createSizeSwitchNodes();
  496. }
  497. this._updateSwitchNodeClass();
  498. // move focus to next activable node
  499. this._moveToNextActivableNode(this._getAllPageSizeNodes(), this.pageSizeValue);
  500. this.pageSizeValue = null;
  501. },
  502. _createSizeSwitchNodes: function(){
  503. // summary:
  504. // The function to create the size switch nodes
  505. var node = null;
  506. if(!this.pageSizes || this.pageSizes.length < 1){
  507. return;
  508. }
  509. dojo.forEach(this.pageSizes, function(size){
  510. // create page size switch node
  511. size = dojo.trim(size);
  512. var labelValue = size.toLowerCase() == "all" ? this.plugin.nls.allItemsLabelTemplate : dojo.string.substitute(this.plugin.nls.pageSizeLabelTemplate, [size]);
  513. node = dojo.create("span", {innerHTML: size, title: labelValue, value: size, tabindex: 0}, this.sizeSwitchTd, "last");
  514. // for accessibility
  515. dijit.setWaiState(node, "label", labelValue);
  516. // connect event
  517. this.plugin.connect(node, "onclick", dojo.hitch(this, "_onSwitchPageSize"));
  518. this.plugin.connect(node, "onmouseover", function(e){
  519. dojo.addClass(e.target, "dojoxGridPageTextHover");
  520. });
  521. this.plugin.connect(node, "onmouseout", function(e){
  522. dojo.removeClass(e.target, "dojoxGridPageTextHover");
  523. });
  524. // create a separation node
  525. node = dojo.create("span", {innerHTML: "|"}, this.sizeSwitchTd, "last");
  526. dojo.addClass(node, "dojoxGridSeparator");
  527. }, this);
  528. // delete last separation node
  529. dojo.destroy(node);
  530. this.initializedSizeNode = true;
  531. if(this.sizeSwitchWidth){
  532. dojo.style(this.sizeSwitchTd, "width", this.sizeSwitchWidth);
  533. }
  534. },
  535. _updateSwitchNodeClass: function(){
  536. // summary:
  537. // Update the switch nodes style
  538. var size = null;
  539. var hasActivedNode = false;
  540. var styleNode = function(node, status){
  541. if(status){
  542. dojo.addClass(node, "dojoxGridActivedSwitch");
  543. dojo.attr(node, "tabindex", "-1");
  544. hasActivedNode = true;
  545. }else{
  546. dojo.addClass(node, "dojoxGridInactiveSwitch");
  547. dojo.attr(node, "tabindex", "0");
  548. }
  549. };
  550. dojo.forEach(this.sizeSwitchTd.childNodes, function(node){
  551. if(node.value){
  552. size = node.value;
  553. dojo.removeClass(node);
  554. if(this.pageSizeValue){
  555. styleNode(node, size === this.pageSizeValue && !hasActivedNode);
  556. }else{
  557. if(size.toLowerCase() == "all"){
  558. size = this._maxItemSize;
  559. }
  560. styleNode(node, this.currentPageSize === parseInt(size, 10) && !hasActivedNode);
  561. }
  562. }
  563. }, this);
  564. },
  565. _updatePageStepper: function(){
  566. // summary:
  567. // Update the page step nodes
  568. if(!this.pageStepperTd){
  569. return;
  570. }
  571. if(!this.pageStepper || this._maxItemSize <= 0){
  572. dojo.style(this.pageStepperTd, "display", "none");
  573. return;
  574. }else{
  575. dojo.style(this.pageStepperTd, "display", "");
  576. }
  577. if(this.pageStepperDiv.childNodes.length < 1){
  578. this._createPageStepNodes();
  579. this._createWardBtns();
  580. }else{
  581. this._resetPageStepNodes();
  582. }
  583. this._updatePageStepNodeClass();
  584. this._moveToNextActivableNode(this._getAllPageStepNodes(), this.pageStepValue);
  585. this.pageStepValue = null;
  586. },
  587. _createPageStepNodes: function(){
  588. // summary:
  589. // Create the page step nodes if they do not exist
  590. var startPage = this._getStartPage(),
  591. stepSize = this._getStepPageSize(),
  592. label = "",
  593. node = null;
  594. for(var i = startPage; i < this.maxPageStep + 1; i++){
  595. label = dojo.string.substitute(this.plugin.nls.pageStepLabelTemplate, [i + ""]);
  596. node = dojo.create("div", {innerHTML: i, value: i, title: label, tabindex: i < startPage + stepSize ? 0 : -1}, this.pageStepperDiv, "last");
  597. dijit.setWaiState(node, "label", label);
  598. // connect event
  599. this.plugin.connect(node, "onclick", dojo.hitch(this, "_onPageStep"));
  600. this.plugin.connect(node, "onmouseover", function(e){
  601. dojo.addClass(e.target, "dojoxGridPageTextHover");
  602. });
  603. this.plugin.connect(node, "onmouseout", function(e){
  604. dojo.removeClass(e.target, "dojoxGridPageTextHover");
  605. });
  606. dojo.style(node, "display", i < startPage + stepSize ? "block" : "none");
  607. }
  608. if(this.pageStepperWidth){
  609. dojo.style(this.pageStepperTd, "width", this.pageStepperWidth);
  610. }
  611. },
  612. _createWardBtns: function(){
  613. // summary:
  614. // Create the previous/next/first/last button
  615. var self = this;
  616. var highContrastLabel = {prevPage: "&#60;", firstPage: "&#171;", nextPage: "&#62;", lastPage: "&#187;"};
  617. var createWardBtn = function(value, label, position){
  618. var node = dojo.create("div", {value: value, title: label, tabindex: 1}, self.pageStepperDiv, position);
  619. self.plugin.connect(node, "onclick", dojo.hitch(self, "_onPageStep"));
  620. dijit.setWaiState(node, "label", label);
  621. // for high contrast
  622. var highConrastNode = dojo.create("span", {value: value, title: label, innerHTML: highContrastLabel[value]}, node, position);
  623. dojo.addClass(highConrastNode, "dojoxGridWardButtonInner");
  624. };
  625. createWardBtn("prevPage", this.plugin.nls.prevTip, "first");
  626. createWardBtn("firstPage", this.plugin.nls.firstTip, "first");
  627. createWardBtn("nextPage", this.plugin.nls.nextTip, "last");
  628. createWardBtn("lastPage", this.plugin.nls.lastTip, "last");
  629. },
  630. _resetPageStepNodes: function(){
  631. // summary:
  632. // The page step nodes might be changed when fetch data, we need to
  633. // update/reset them
  634. var startPage = this._getStartPage(),
  635. stepSize = this._getStepPageSize(),
  636. stepNodes = this.pageStepperDiv.childNodes,
  637. node = null;
  638. for(var i = startPage, j = 2; j < stepNodes.length - 2; j++, i++){
  639. node = stepNodes[j];
  640. if(i < startPage + stepSize){
  641. dojo.attr(node, "innerHTML", i);
  642. dojo.attr(node, "value", i);
  643. dojo.style(node, "display", "block");
  644. dijit.setWaiState(node, "label", dojo.string.substitute(this.plugin.nls.pageStepLabelTemplate, [i + ""]));
  645. }else{
  646. dojo.style(node, "display", "none");
  647. }
  648. }
  649. },
  650. _updatePageStepNodeClass: function(){
  651. // summary:
  652. // Update the style of the page step nodes
  653. var value = null,
  654. curPage = this._getCurrentPageNo(),
  655. pageCount = this._getPageCount(),
  656. visibleNodeLen = 0;
  657. var updateClass = function(node, isWardBtn, status){
  658. var value = node.value,
  659. enableClass = isWardBtn ? "dojoxGrid" + value + "Btn" : "dojoxGridInactived",
  660. disableClass = isWardBtn ? "dojoxGrid" + value + "BtnDisable" : "dojoxGridActived";
  661. if(status){
  662. dojo.addClass(node, disableClass);
  663. dojo.attr(node, "tabindex", "-1");
  664. }else{
  665. dojo.addClass(node, enableClass);
  666. dojo.attr(node, "tabindex", "0");
  667. }
  668. };
  669. dojo.forEach(this.pageStepperDiv.childNodes, function(node){
  670. dojo.removeClass(node);
  671. if(isNaN(parseInt(node.value, 10))){
  672. dojo.addClass(node, "dojoxGridWardButton");
  673. var disablePageNum = node.value == "prevPage" || node.value == "firstPage" ? 1 : pageCount;
  674. updateClass(node, true, (curPage == disablePageNum));
  675. }else{
  676. value = parseInt(node.value, 10);
  677. updateClass(node, false, (value === curPage || dojo.style(node, "display") === "none"));
  678. }
  679. }, this);
  680. },
  681. _showGotoButton: function(flag){
  682. this.gotoButton = flag;
  683. this._updateGotoButton();
  684. },
  685. _updateGotoButton: function(){
  686. // summary:
  687. // Create/destroy the goto page button
  688. if(!this.gotoButton){
  689. if(this.gotoPageTd){
  690. if(this._gotoPageDialog){
  691. this._gotoPageDialog.destroy();
  692. }
  693. dojo.destroy(this.gotoPageDiv);
  694. dojo.destroy(this.gotoPageTd);
  695. delete this.gotoPageDiv;
  696. delete this.gotoPageTd;
  697. }
  698. return;
  699. }
  700. if(!this.gotoPageTd){
  701. this._createGotoNode();
  702. }
  703. dojo.toggleClass(this.gotoPageDiv, "dojoxGridPaginatorGotoDivDisabled", this.plugin.pageSize >= this.plugin._maxSize);
  704. },
  705. _createGotoNode: function(){
  706. // summary:
  707. // Create the goto page button
  708. this.gotoPageTd = dojo.create("td", {}, dojo.query("tr", this.domNode)[0], "last");
  709. dojo.addClass(this.gotoPageTd, "dojoxGridPaginatorGotoTd");
  710. this.gotoPageDiv = dojo.create("div", {tabindex: "0", title: this.plugin.nls.gotoButtonTitle}, this.gotoPageTd, "first");
  711. dojo.addClass(this.gotoPageDiv, "dojoxGridPaginatorGotoDiv");
  712. this.plugin.connect(this.gotoPageDiv, "onclick", dojo.hitch(this, "_openGotopageDialog"));
  713. // for high contrast
  714. var highConrastNode = dojo.create("span", {title: this.plugin.nls.gotoButtonTitle, innerHTML: "&#8869;"}, this.gotoPageDiv, "last");
  715. dojo.addClass(highConrastNode, "dojoxGridWardButtonInner");
  716. },
  717. _openGotopageDialog: function(event){
  718. // summary:
  719. // Show the goto page dialog
  720. if(!this._gotoPageDialog){
  721. this._gotoPageDialog = new dojox.grid.enhanced.plugins.pagination._GotoPageDialog(this.plugin);
  722. }
  723. // focus
  724. if(!this._currentFocusNode){
  725. this.grid.focus.focusArea("pagination" + this.position, event);
  726. }else{
  727. this._currentFocusNode = this.gotoPageDiv;
  728. }
  729. if(this.focusArea != "pageStep"){
  730. this.focusArea = "pageStep";
  731. }
  732. this._gotoPageDialog.updatePageCount();
  733. this._gotoPageDialog.showDialog();
  734. },
  735. // ===== focus handlers ===== //
  736. _onFocusPaginator: function(event, step){
  737. // summary:
  738. // Focus handler
  739. if(!this._currentFocusNode){
  740. if(step > 0){
  741. return this._onFocusPageSizeNode(event) ? true : this._onFocusPageStepNode(event);
  742. }else if(step < 0){
  743. return this._onFocusPageStepNode(event) ? true : this._onFocusPageSizeNode(event);
  744. }else{
  745. return false;
  746. }
  747. }else{
  748. if(step > 0){
  749. return this.focusArea === "pageSize" ? this._onFocusPageStepNode(event) : false;
  750. }else if(step < 0){
  751. return this.focusArea === "pageStep" ? this._onFocusPageSizeNode(event) : false;
  752. }else{
  753. return false;
  754. }
  755. }
  756. },
  757. _onFocusPageSizeNode: function(event){
  758. // summary:
  759. // Focus the page size area, if there is no focusable node, return false
  760. var pageSizeNodes = this._getPageSizeActivableNodes();
  761. if(event && event.type !== "click"){
  762. if(pageSizeNodes[0]){
  763. dijit.focus(pageSizeNodes[0]);
  764. this._currentFocusNode = pageSizeNodes[0];
  765. this.focusArea = "pageSize";
  766. this.plugin._stopEvent(event);
  767. return true;
  768. }else{
  769. return false;
  770. }
  771. }
  772. if(event && event.type == "click"){
  773. if(dojo.indexOf(this._getPageSizeActivableNodes(), event.target) > -1){
  774. this.focusArea = "pageSize";
  775. this.plugin._stopEvent(event);
  776. return true;
  777. }
  778. }
  779. return false;
  780. },
  781. _onFocusPageStepNode: function(event){
  782. // summary:
  783. // Focus the page step area, if there is no focusable node, return false
  784. var pageStepNodes = this._getPageStepActivableNodes();
  785. if(event && event.type !== "click"){
  786. if(pageStepNodes[0]){
  787. dijit.focus(pageStepNodes[0]);
  788. this._currentFocusNode = pageStepNodes[0];
  789. this.focusArea = "pageStep";
  790. this.plugin._stopEvent(event);
  791. return true;
  792. }else if(this.gotoPageDiv){
  793. dijit.focus(this.gotoPageDiv);
  794. this._currentFocusNode = this.gotoPageDiv;
  795. this.focusArea = "pageStep";
  796. this.plugin._stopEvent(event);
  797. return true;
  798. }else{
  799. return false;
  800. }
  801. }
  802. if(event && event.type == "click"){
  803. if(dojo.indexOf(this._getPageStepActivableNodes(), event.target) > -1){
  804. this.focusArea = "pageStep";
  805. this.plugin._stopEvent(event);
  806. return true;
  807. }else if(event.target == this.gotoPageDiv){
  808. dijit.focus(this.gotoPageDiv);
  809. this._currentFocusNode = this.gotoPageDiv;
  810. this.focusArea = "pageStep";
  811. this.plugin._stopEvent(event);
  812. return true;
  813. }
  814. }
  815. return false;
  816. },
  817. _onFocusGotoPageNode: function(event){
  818. // summary:
  819. // Focus the goto page button, if there is no focusable node, return false
  820. if(!this.gotoButton || !this.gotoPageTd){
  821. return false;
  822. }
  823. if(event && event.type !== "click" || (event.type == "click" && event.target == this.gotoPageDiv)){
  824. dijit.focus(this.gotoPageDiv);
  825. this._currentFocusNode = this.gotoPageDiv;
  826. this.focusArea = "gotoButton";
  827. this.plugin._stopEvent(event);
  828. return true;
  829. }
  830. return true;
  831. },
  832. _onBlurPaginator: function(event, step){
  833. var pageSizeNodes = this._getPageSizeActivableNodes(),
  834. pageStepNodes = this._getPageStepActivableNodes();
  835. if(step > 0 && this.focusArea === "pageSize" && (pageStepNodes.length > 1 || this.gotoButton)){
  836. return false;
  837. }else if(step < 0 && this.focusArea === "pageStep" && pageSizeNodes.length > 1){
  838. return false;
  839. }
  840. this._currentFocusNode = null;
  841. this.focusArea = null;
  842. return true;
  843. },
  844. _onKeyDown: function(event, isBubble){
  845. // summary:
  846. // Focus navigation
  847. if(isBubble){
  848. return;
  849. }
  850. if(event.altKey || event.metaKey){
  851. return;
  852. }
  853. var dk = dojo.keys;
  854. if(event.keyCode === dk.ENTER || event.keyCode === dk.SPACE){
  855. if(dojo.indexOf(this._getPageStepActivableNodes(), this._currentFocusNode) > -1){
  856. this._onPageStep(event);
  857. }else if(dojo.indexOf(this._getPageSizeActivableNodes(), this._currentFocusNode) > -1){
  858. this._onSwitchPageSize(event);
  859. }else if(this._currentFocusNode === this.gotoPageDiv){
  860. this._openGotopageDialog(event);
  861. }
  862. }
  863. this.plugin._stopEvent(event);
  864. },
  865. _moveFocus: function(rowDelta, colDelta, evt){
  866. // summary:
  867. // Move focus according row delta&column delta
  868. var nodes;
  869. if(this.focusArea == "pageSize"){
  870. nodes = this._getPageSizeActivableNodes();
  871. }else if(this.focusArea == "pageStep"){
  872. nodes = this._getPageStepActivableNodes();
  873. if(this.gotoPageDiv){
  874. nodes.push(this.gotoPageDiv);
  875. }
  876. }
  877. if(nodes.length < 1){
  878. return;
  879. }
  880. var currentIdx = dojo.indexOf(nodes, this._currentFocusNode);
  881. var focusIdx = currentIdx + colDelta;
  882. if(focusIdx >= 0 && focusIdx < nodes.length){
  883. dijit.focus(nodes[focusIdx]);
  884. this._currentFocusNode = nodes[focusIdx];
  885. }
  886. this.plugin._stopEvent(evt);
  887. },
  888. _getPageSizeActivableNodes: function(){
  889. return dojo.query("span[tabindex='0']", this.sizeSwitchTd);
  890. },
  891. _getPageStepActivableNodes: function(){
  892. return (dojo.query("div[tabindex='0']", this.pageStepperDiv));
  893. },
  894. _getAllPageSizeNodes: function(){
  895. var nodeList = [];
  896. dojo.forEach(this.sizeSwitchTd.childNodes, function(node){
  897. if(node.value){
  898. nodeList.push(node);
  899. }
  900. });
  901. return nodeList;
  902. },
  903. _getAllPageStepNodes: function(){
  904. var nodeList = [];
  905. for(var i = 0, len = this.pageStepperDiv.childNodes.length; i < len; i++){
  906. nodeList.push(this.pageStepperDiv.childNodes[i]);
  907. }
  908. return nodeList;
  909. },
  910. _moveToNextActivableNode: function(nodeList, curNodeValue){
  911. // summary:
  912. // Need to move the focus to next node since current node is inactive and unfocusable
  913. if(!curNodeValue){
  914. return;
  915. }
  916. if(nodeList.length < 2){
  917. this.grid.focus.tab(1);
  918. }
  919. var nl = [],
  920. node = null,
  921. index = 0;
  922. dojo.forEach(nodeList, function(n){
  923. if(n.value == curNodeValue){
  924. nl.push(n);
  925. node = n;
  926. }else if(dojo.attr(n, "tabindex") == "0"){
  927. nl.push(n);
  928. }
  929. });
  930. if(nl.length < 2){
  931. this.grid.focus.tab(1);
  932. }
  933. index = dojo.indexOf(nl, node);
  934. if(dojo.attr(node, "tabindex") != "0"){
  935. node = nl[index + 1] ? nl[index + 1] : nl[index - 1];
  936. }
  937. dijit.focus(node);
  938. this._currentFocusNode = node;
  939. },
  940. // ===== pagination events handlers ===== //
  941. _onSwitchPageSize: function(/*Event*/e){
  942. // summary:
  943. // The handler of switch the page size
  944. var size = this.pageSizeValue = e.target.value;
  945. if(!size){
  946. return;
  947. }
  948. if(dojo.trim(size.toLowerCase()) == "all"){
  949. size = this._maxItemSize;
  950. this.plugin.showAll = true;
  951. }else{
  952. this.plugin.showAll = false;
  953. }
  954. this.plugin.grid.usingPagination = !this.plugin.showAll;
  955. size = parseInt(size, 10);
  956. if(isNaN(size) || size <= 0/* || size == this.currentPageSize*/){
  957. return;
  958. }
  959. if(!this._currentFocusNode){
  960. this.grid.focus.currentArea("pagination" + this.position);
  961. }
  962. if(this.focusArea != "pageSize"){
  963. this.focusArea = "pageSize";
  964. }
  965. this.plugin.changePageSize(size);
  966. },
  967. _onPageStep: function(/*Event*/e){
  968. // summary:
  969. // The handler jump page event
  970. var p = this.plugin,
  971. value = this.pageStepValue = e.target.value;
  972. if(!this._currentFocusNode){
  973. this.grid.focus.currentArea("pagination" + this.position);
  974. }
  975. if(this.focusArea != "pageStep"){
  976. this.focusArea = "pageStep";
  977. }
  978. if(!isNaN(parseInt(value, 10))){
  979. p.gotoPage(value);
  980. }else{
  981. switch(e.target.value){
  982. case "prevPage":
  983. p.prevPage();
  984. break;
  985. case "nextPage":
  986. p.nextPage();
  987. break;
  988. case "firstPage":
  989. p.gotoFirstPage();
  990. break;
  991. case "lastPage":
  992. p.gotoLastPage();
  993. }
  994. }
  995. },
  996. // ===== information getters ===== //
  997. _getCurrentPageNo: function(){
  998. return this.plugin._currentPage + 1;
  999. },
  1000. _getPageCount: function(){
  1001. if(!this._maxItemSize || !this.currentPageSize){
  1002. return 0;
  1003. }
  1004. return Math.ceil(this._maxItemSize / this.currentPageSize);
  1005. },
  1006. _getStartPage: function(){
  1007. var cp = this._getCurrentPageNo();
  1008. var ms = parseInt(this.maxPageStep / 2, 10);
  1009. var pc = this._getPageCount();
  1010. if(cp < ms || (cp - ms) < 1){
  1011. return 1;
  1012. }else if(pc <= this.maxPageStep){
  1013. return 1;
  1014. }else{
  1015. if(pc - cp < ms && cp - this.maxPageStep >= 0){
  1016. return pc - this.maxPageStep + 1;
  1017. }else{
  1018. return (cp - ms);
  1019. }
  1020. }
  1021. },
  1022. _getStepPageSize: function(){
  1023. var sp = this._getStartPage();
  1024. var count = this._getPageCount();
  1025. if((sp + this.maxPageStep) > count){
  1026. return count - sp + 1;
  1027. }else{
  1028. return this.maxPageStep;
  1029. }
  1030. }
  1031. });
  1032. dojo.declare("dojox.grid.enhanced.plugins.pagination._GotoPageDialog", null, {
  1033. pageCount: 0,
  1034. constructor: function(plugin){
  1035. this.plugin = plugin;
  1036. this.pageCount = this.plugin.paginators[0]._getPageCount();
  1037. this._dialogNode = dojo.create("div", {}, dojo.body(), "last");
  1038. this._gotoPageDialog = new dojox.grid.enhanced.plugins.Dialog({
  1039. "refNode": plugin.grid.domNode,
  1040. "title": this.plugin.nls.dialogTitle
  1041. }, this._dialogNode);
  1042. this._createDialogContent();
  1043. this._gotoPageDialog.startup();
  1044. },
  1045. _createDialogContent: function(){
  1046. // summary:
  1047. // Create the dialog content
  1048. this._specifyNode = dojo.create("div", {innerHTML: this.plugin.nls.dialogIndication}, this._gotoPageDialog.containerNode, "last");
  1049. this._pageInputDiv = dojo.create("div", {}, this._gotoPageDialog.containerNode, "last");
  1050. this._pageTextBox = new dijit.form.NumberTextBox();
  1051. this._pageTextBox.constraints = {fractional:false, min:1, max:this.pageCount};
  1052. this.plugin.connect(this._pageTextBox.textbox, "onkeyup", dojo.hitch(this, "_setConfirmBtnState"));
  1053. this._pageInputDiv.appendChild(this._pageTextBox.domNode);
  1054. this._pageLabel = dojo.create("label", {innerHTML: dojo.string.substitute(this.plugin.nls.pageCountIndication, [this.pageCount])}, this._pageInputDiv, "last");
  1055. this._buttonDiv = dojo.create("div", {}, this._gotoPageDialog.containerNode, "last");
  1056. this._confirmBtn = new dijit.form.Button({label: this.plugin.nls.dialogConfirm, onClick: dojo.hitch(this, this._onConfirm)});
  1057. this._confirmBtn.set("disabled", true);
  1058. this._cancelBtn = new dijit.form.Button({label: this.plugin.nls.dialogCancel, onClick: dojo.hitch(this, this._onCancel)});
  1059. this._buttonDiv.appendChild(this._confirmBtn.domNode);
  1060. this._buttonDiv.appendChild(this._cancelBtn.domNode);
  1061. this._styleContent();
  1062. this._gotoPageDialog.onCancel = dojo.hitch(this, this._onCancel);
  1063. this.plugin.connect(this._gotoPageDialog, "_onKey", dojo.hitch(this, "_onKeyDown"));
  1064. },
  1065. _styleContent: function(){
  1066. dojo.addClass(this._specifyNode, "dojoxGridDialogMargin");
  1067. dojo.addClass(this._pageInputDiv, "dojoxGridDialogMargin");
  1068. dojo.addClass(this._buttonDiv, "dojoxGridDialogButton");
  1069. dojo.style(this._pageTextBox.domNode, "width", "50px");
  1070. },
  1071. updatePageCount: function(){
  1072. this.pageCount = this.plugin.paginators[0]._getPageCount();
  1073. this._pageTextBox.constraints = {fractional:false, min:1, max:this.pageCount};
  1074. dojo.attr(this._pageLabel, "innerHTML", dojo.string.substitute(this.plugin.nls.pageCountIndication, [this.pageCount]));
  1075. },
  1076. showDialog: function(){
  1077. this._gotoPageDialog.show();
  1078. },
  1079. _onConfirm: function(event){
  1080. // summary:
  1081. // Jump to the given page
  1082. if(this._pageTextBox.isValid() && this._pageTextBox.getDisplayedValue() !== ""){
  1083. this.plugin.gotoPage(this._pageTextBox.parse(this._pageTextBox.getDisplayedValue()));
  1084. this._gotoPageDialog.hide();
  1085. this._pageTextBox.reset();
  1086. }
  1087. this.plugin._stopEvent(event);
  1088. },
  1089. _onCancel: function(event){
  1090. // summary:
  1091. // Cancel action and hide the dialog
  1092. this._pageTextBox.reset();
  1093. this._gotoPageDialog.hide();
  1094. this.plugin._stopEvent(event);
  1095. },
  1096. _onKeyDown: function(event){
  1097. if(event.altKey || event.metaKey){
  1098. return;
  1099. }
  1100. var dk = dojo.keys;
  1101. if(event.keyCode === dk.ENTER){
  1102. this._onConfirm(event);
  1103. }
  1104. },
  1105. _setConfirmBtnState: function(){
  1106. if(this._pageTextBox.isValid() && this._pageTextBox.getDisplayedValue() !== ""){
  1107. this._confirmBtn.set("disabled", false);
  1108. }else{
  1109. this._confirmBtn.set("disabled", true);
  1110. }
  1111. },
  1112. destroy: function(){
  1113. this._pageTextBox.destroy();
  1114. this._confirmBtn.destroy();
  1115. this._cancelBtn.destroy();
  1116. this._gotoPageDialog.destroy();
  1117. dojo.destroy(this._specifyNode);
  1118. dojo.destroy(this._pageInputDiv);
  1119. dojo.destroy(this._pageLabel);
  1120. dojo.destroy(this._buttonDiv);
  1121. dojo.destroy(this._dialogNode);
  1122. }
  1123. });
  1124. dojox.grid.EnhancedGrid.registerPlugin(dojox.grid.enhanced.plugins.Pagination/*name:'pagination'*/);
  1125. }