Toolbar.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. Ext.define('erp.view.common.datalist.Toolbar', {
  2. extend: 'Ext.toolbar.Paging',
  3. alias: 'widget.erpDatalistToolbar',
  4. doRefresh:function(){
  5. //this.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
  6. window.location.reload();
  7. },
  8. cls: 'u-toolbar',
  9. items: ['-',{
  10. id: 'erpAddButton',
  11. name: 'add',
  12. tooltip: $I18N.common.button.erpAddButton,
  13. iconCls: 'x-button-icon-add',
  14. cls: 'x-btn-tb',
  15. width: 24,
  16. hidden: true,
  17. handler: function(btn){
  18. var g = btn.ownerCt.ownerCt, u = g.BaseUtil;
  19. u.onAdd(caller, u.getActiveTab().title, url);
  20. }
  21. },{
  22. id:'datalistexport',
  23. name: 'export',
  24. tooltip: $I18N.common.button.erpExportButton,
  25. iconCls: 'x-button-icon-excel',
  26. cls: 'x-btn-tb',
  27. width: 24,
  28. hidden:getUrlParam('_noexport')==-1,
  29. handler : function(i) {
  30. var me = i.ownerCt;
  31. me.exportData(me.ownerCt, i);
  32. }
  33. },'-',{
  34. itemId: 'close',
  35. tooltip:$I18N.common.button.erpCloseButton,
  36. iconCls: 'x-button-icon-close',
  37. width: 24,
  38. cls: 'x-btn-tb',
  39. handler: function(){
  40. var main = parent.Ext.getCmp("content-panel");
  41. if(main)
  42. main.getActiveTab().close();
  43. else if(typeof parentDoc !== 'undefined' && parentDoc) {
  44. var doc = parent.Ext.getCmp(parentDoc);
  45. if(doc) {
  46. doc.fireEvent('close', doc);
  47. }
  48. }
  49. }
  50. },'-',{
  51. iconCls: 'x-button-icon-query',
  52. tooltip: $I18N.common.tip.searchlist,
  53. width: 24,
  54. cls: 'x-btn-tb',
  55. id: 'searchlist'
  56. },'-',{
  57. iconCls:'x-button-icon-install',
  58. tooltip: $I18N.common.tip.customize,
  59. width: 24,
  60. cls: 'x-btn-tb',
  61. id: 'customize'
  62. },'-',{
  63. iconCls: 'x-button-icon-detail',
  64. tooltip: $I18N.common.tip.relativelist,
  65. cls: 'x-btn-tb',
  66. width: 24,
  67. id: 'relativelist',
  68. handler: function(btn){
  69. if(relative){
  70. var url = window.location.href.toString().replace(caller, relative);
  71. if(url.indexOf('?') > -1) {
  72. url += '&';
  73. } else {
  74. url += '?';
  75. }
  76. url += '_noc=1';
  77. window.location.href = url;
  78. }
  79. }
  80. }],
  81. exportData : function(grid, btn, title, customFields) {
  82. if(!btn.locked) {
  83. if(dataCount > 6000) {
  84. btn.setDisabled(true);
  85. btn.locked = true;
  86. setTimeout(function(){
  87. btn.setDisabled(false);
  88. btn.locked = false;
  89. }, 8000);
  90. // create xls file by client side, request high RAM
  91. // var w = 400, h = 200, t = (window.screen.availHeight - 30 - h) / 2, l = (window.screen.availWidth - 10 - w) / 2;
  92. // window.open(basePath + 'common/excel/create.action?caller=' + caller + '&type=datalist&condition=' +
  93. // (grid.getCondition() || '') + '&title=' + (title || grid.BaseUtil.pageTitle()) + '&fields=' + (customFields || ''),
  94. // 'export_modal', 'height=' + h + ',width=' + w + ',top=' + t + ',left=' + l +
  95. // ',toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
  96. }
  97. grid.BaseUtil.createExcel(caller, 'datalist', grid.getCondition(), title, null, customFields);
  98. }
  99. },
  100. updateInfo : function(){
  101. var page = this.child('#inputItem').getValue();
  102. var me = this,
  103. displayItem = me.child('#displayItem'), msg,
  104. pageData = me.getPageData();
  105. pageData.fromRecord = (page-1)*pageSize+1;
  106. pageData.toRecord = page*pageSize > dataCount ? dataCount : page*pageSize;//
  107. pageData.total=dataCount;
  108. dataCount;
  109. if (displayItem) {
  110. if (dataCount === 0) {
  111. msg = me.emptyMsg;
  112. } else {
  113. msg = Ext.String.format(
  114. me.displayMsg,
  115. pageData.fromRecord,
  116. pageData.toRecord,
  117. pageData.total
  118. );
  119. }
  120. displayItem.setText(msg);
  121. me.doComponentLayout();
  122. }
  123. },
  124. getPageData : function(){
  125. var store = this.store,
  126. totalCount = store.getTotalCount();
  127. totalCount=dataCount;
  128. return {
  129. total : totalCount,
  130. currentPage : page,
  131. pageCount: Math.ceil(dataCount / pageSize),
  132. fromRecord: ((store.currentPage - 1) * store.pageSize) + 1,
  133. toRecord: Math.min(store.currentPage * store.pageSize, totalCount)
  134. };
  135. },
  136. onPagingKeyDown : function(field, e){
  137. var me = this, k = e.getKey(), grid = me.ownerCt,
  138. pageData = me.getPageData(),
  139. increment = e.shiftKey ? 10 : 1, pageNum = 0, s = Ext.EventObject;
  140. if (k == s.RETURN) {
  141. e.stopEvent();
  142. pageNum = me.readPageFromInput(pageData);
  143. if (pageNum !== false) {
  144. pageNum = Math.min(Math.max(1, pageNum), pageData.pageCount);
  145. me.child('#inputItem').setValue(pageNum);
  146. if(me.fireEvent('beforechange', me, pageNum) !== false){
  147. page = pageNum;
  148. grid.getColumnsAndStore(caller, null, page, pageSize);
  149. }
  150. }
  151. } else if (k == s.HOME || k == s.END) {
  152. e.stopEvent();
  153. pageNum = k == s.HOME ? 1 : pageData.pageCount;
  154. field.setValue(pageNum);
  155. } else if (k == s.UP || k == s.PAGEUP || k == s.DOWN || k == s.PAGEDOWN) {
  156. e.stopEvent();
  157. pageNum = me.readPageFromInput(pageData);
  158. if (pageNum) {
  159. if (k == s.DOWN || k == s.PAGEDOWN) {
  160. increment *= -1;
  161. }
  162. pageNum += increment;
  163. if (pageNum >= 1 && pageNum <= pageData.pages) {
  164. field.setValue(pageNum);
  165. }
  166. }
  167. }
  168. me.updateInfo();
  169. fn(me, pageNum);
  170. },
  171. moveFirst : function(){
  172. var me = this;
  173. me.child('#inputItem').setValue(1);
  174. value = 1;
  175. page = value;
  176. me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
  177. me.updateInfo();
  178. fn(me,value);
  179. },
  180. movePrevious : function(){
  181. var me = this;
  182. me.child('#inputItem').setValue(me.child('#inputItem').getValue()-1);
  183. value = me.child('#inputItem').getValue();
  184. page = value;
  185. me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
  186. me.updateInfo();
  187. fn(me,value);
  188. },
  189. moveNext : function(){
  190. var me = this,
  191. last = me.getPageData().pageCount;
  192. total = last;
  193. me.child('#inputItem').setValue(me.child('#inputItem').getValue()+1);
  194. value = me.child('#inputItem').getValue();
  195. page = value;
  196. me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
  197. me.updateInfo();
  198. fn(me,value);
  199. },
  200. moveLast : function(){
  201. var me = this,
  202. last = me.getPageData().pageCount;
  203. total = last;
  204. me.child('#inputItem').setValue(last);
  205. value = me.child('#inputItem').getValue();
  206. page = value;
  207. me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
  208. me.updateInfo();
  209. fn(me,value);
  210. },
  211. onLoad : function() {
  212. var e = this, d, b, c, a;
  213. if (!e.rendered) {
  214. return
  215. }
  216. d = e.getPageData();
  217. b = d.currentPage;
  218. c = Math.ceil(dataCount / pageSize);
  219. a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
  220. e.child("#afterTextItem").setText(a);
  221. e.child("#inputItem").setValue(b);
  222. e.child("#first").setDisabled(b === 1);
  223. e.child("#prev").setDisabled(b === 1);
  224. e.child("#next").setDisabled(b === c || c===1);//
  225. e.child("#last").setDisabled(b === c || c===1);
  226. e.child("#refresh").enable();
  227. e.updateInfo();
  228. e.fireEvent("change", e, d);
  229. },
  230. onPagingBlur : function(e){
  231. var inputItem = this.child("#inputItem"),
  232. curPage;
  233. if (inputItem) {
  234. curPage = this.getPageData().currentPage;
  235. var e = this, d, b, c, a;
  236. d = e.getPageData();
  237. b = d.currentPage;
  238. c = Math.ceil(dataCount / pageSize);
  239. a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
  240. e.child("#afterTextItem").setText(a);
  241. e.child("#inputItem").setValue(b);
  242. e.child("#first").setDisabled(b === 1);
  243. e.child("#prev").setDisabled(b === 1);
  244. e.child("#next").setDisabled(b === c || c===1);
  245. e.child("#last").setDisabled(b === c || c===1);
  246. }
  247. },
  248. afterOnLoad : function(num) {
  249. var e = this, d, c, a, grid = e.ownerCt;
  250. if (!e.rendered) {
  251. return
  252. }
  253. d = e.getPageData();
  254. b = d.currentPage;
  255. c = Math.ceil(dataCount / pageSize);
  256. a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
  257. e.child("#afterTextItem").setText(a);
  258. //解决抬头筛选 页码不对
  259. if(num && num == 1) e.child("#inputItem").setValue(1);
  260. e.updateInfo();
  261. e.fireEvent("change", e, d);
  262. e.child('#last').setDisabled(c <= 1 || page == c);
  263. e.child('#next').setDisabled(c <= 1 || page == c);
  264. if(grid.noCount) {
  265. var m = e.down('#more');
  266. if(!m) {
  267. m = Ext.create('Ext.panel.Tool', {
  268. id: 'more',
  269. type: 'right',
  270. margin: '0 5 0 5',
  271. handler: function() {
  272. grid.getCount(null, null, true);
  273. m.hide();
  274. grid.noCount = false;
  275. }
  276. });
  277. e.add(m);
  278. } else {
  279. m.show();
  280. }
  281. }
  282. }
  283. });
  284. function fn(me,value){
  285. me.child('#last').setDisabled(value == total);
  286. me.child('#next').setDisabled(value == total);
  287. me.child('#first').setDisabled(value <= 1);
  288. me.child('#prev').setDisabled(value <= 1);
  289. }