123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- Ext.define('erp.view.common.datalist.Toolbar', {
- extend: 'Ext.toolbar.Paging',
- alias: 'widget.erpDatalistToolbar',
- doRefresh:function(){
- //this.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
- window.location.reload();
- },
- cls: 'u-toolbar',
- items: ['-',{
- id: 'erpAddButton',
- name: 'add',
- tooltip: $I18N.common.button.erpAddButton,
- iconCls: 'x-button-icon-add',
- cls: 'x-btn-tb',
- width: 24,
- hidden: true,
- handler: function(btn){
- var g = btn.ownerCt.ownerCt, u = g.BaseUtil;
- u.onAdd(caller, u.getActiveTab().title, url);
- }
- },{
- id:'datalistexport',
- name: 'export',
- tooltip: $I18N.common.button.erpExportButton,
- iconCls: 'x-button-icon-excel',
- cls: 'x-btn-tb',
- width: 24,
- hidden:getUrlParam('_noexport')==-1,
- handler : function(i) {
- var me = i.ownerCt;
- me.exportData(me.ownerCt, i);
- }
- },'-',{
- itemId: 'close',
- tooltip:$I18N.common.button.erpCloseButton,
- iconCls: 'x-button-icon-close',
- width: 24,
- cls: 'x-btn-tb',
- handler: function(){
- var main = parent.Ext.getCmp("content-panel");
- if(main)
- main.getActiveTab().close();
- else if(typeof parentDoc !== 'undefined' && parentDoc) {
- var doc = parent.Ext.getCmp(parentDoc);
- if(doc) {
- doc.fireEvent('close', doc);
- }
- }
- }
- },'-',{
- iconCls: 'x-button-icon-query',
- tooltip: $I18N.common.tip.searchlist,
- width: 24,
- cls: 'x-btn-tb',
- id: 'searchlist'
- },'-',{
- iconCls:'x-button-icon-install',
- tooltip: $I18N.common.tip.customize,
- width: 24,
- cls: 'x-btn-tb',
- id: 'customize'
- },'-',{
- iconCls: 'x-button-icon-detail',
- tooltip: $I18N.common.tip.relativelist,
- cls: 'x-btn-tb',
- width: 24,
- id: 'relativelist',
- handler: function(btn){
- if(relative){
- var url = window.location.href.toString().replace(caller, relative);
- if(url.indexOf('?') > -1) {
- url += '&';
- } else {
- url += '?';
- }
- url += '_noc=1';
- window.location.href = url;
- }
- }
- }],
- exportData : function(grid, btn, title, customFields) {
- if(!btn.locked) {
- if(dataCount > 6000) {
- btn.setDisabled(true);
- btn.locked = true;
- setTimeout(function(){
- btn.setDisabled(false);
- btn.locked = false;
- }, 8000);
- // create xls file by client side, request high RAM
- // var w = 400, h = 200, t = (window.screen.availHeight - 30 - h) / 2, l = (window.screen.availWidth - 10 - w) / 2;
- // window.open(basePath + 'common/excel/create.action?caller=' + caller + '&type=datalist&condition=' +
- // (grid.getCondition() || '') + '&title=' + (title || grid.BaseUtil.pageTitle()) + '&fields=' + (customFields || ''),
- // 'export_modal', 'height=' + h + ',width=' + w + ',top=' + t + ',left=' + l +
- // ',toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
- }
- grid.BaseUtil.createExcel(caller, 'datalist', grid.getCondition(), title, null, customFields);
- }
- },
- updateInfo : function(){
- var page = this.child('#inputItem').getValue();
- var me = this,
- displayItem = me.child('#displayItem'), msg,
- pageData = me.getPageData();
- pageData.fromRecord = (page-1)*pageSize+1;
- pageData.toRecord = page*pageSize > dataCount ? dataCount : page*pageSize;//
- pageData.total=dataCount;
- dataCount;
- if (displayItem) {
- if (dataCount === 0) {
- msg = me.emptyMsg;
- } else {
- msg = Ext.String.format(
- me.displayMsg,
- pageData.fromRecord,
- pageData.toRecord,
- pageData.total
- );
- }
- displayItem.setText(msg);
- me.doComponentLayout();
- }
- },
- getPageData : function(){
- var store = this.store,
- totalCount = store.getTotalCount();
- totalCount=dataCount;
- return {
- total : totalCount,
- currentPage : page,
- pageCount: Math.ceil(dataCount / pageSize),
- fromRecord: ((store.currentPage - 1) * store.pageSize) + 1,
- toRecord: Math.min(store.currentPage * store.pageSize, totalCount)
- };
- },
- onPagingKeyDown : function(field, e){
- var me = this, k = e.getKey(), grid = me.ownerCt,
- pageData = me.getPageData(),
- increment = e.shiftKey ? 10 : 1, pageNum = 0, s = Ext.EventObject;
- if (k == s.RETURN) {
- e.stopEvent();
- pageNum = me.readPageFromInput(pageData);
- if (pageNum !== false) {
- pageNum = Math.min(Math.max(1, pageNum), pageData.pageCount);
- me.child('#inputItem').setValue(pageNum);
- if(me.fireEvent('beforechange', me, pageNum) !== false){
- page = pageNum;
- grid.getColumnsAndStore(caller, null, page, pageSize);
- }
- }
- } else if (k == s.HOME || k == s.END) {
- e.stopEvent();
- pageNum = k == s.HOME ? 1 : pageData.pageCount;
- field.setValue(pageNum);
- } else if (k == s.UP || k == s.PAGEUP || k == s.DOWN || k == s.PAGEDOWN) {
- e.stopEvent();
- pageNum = me.readPageFromInput(pageData);
- if (pageNum) {
- if (k == s.DOWN || k == s.PAGEDOWN) {
- increment *= -1;
- }
- pageNum += increment;
- if (pageNum >= 1 && pageNum <= pageData.pages) {
- field.setValue(pageNum);
- }
- }
- }
- me.updateInfo();
- fn(me, pageNum);
- },
- moveFirst : function(){
- var me = this;
- me.child('#inputItem').setValue(1);
- value = 1;
- page = value;
- me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
- me.updateInfo();
- fn(me,value);
- },
- movePrevious : function(){
- var me = this;
- me.child('#inputItem').setValue(me.child('#inputItem').getValue()-1);
- value = me.child('#inputItem').getValue();
- page = value;
- me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
- me.updateInfo();
- fn(me,value);
- },
- moveNext : function(){
- var me = this,
- last = me.getPageData().pageCount;
- total = last;
- me.child('#inputItem').setValue(me.child('#inputItem').getValue()+1);
- value = me.child('#inputItem').getValue();
- page = value;
- me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
- me.updateInfo();
- fn(me,value);
- },
- moveLast : function(){
- var me = this,
- last = me.getPageData().pageCount;
- total = last;
- me.child('#inputItem').setValue(last);
- value = me.child('#inputItem').getValue();
- page = value;
- me.ownerCt.getColumnsAndStore(caller, null, page, pageSize);
- me.updateInfo();
- fn(me,value);
- },
- onLoad : function() {
- var e = this, d, b, c, a;
- if (!e.rendered) {
- return
- }
- d = e.getPageData();
- b = d.currentPage;
- c = Math.ceil(dataCount / pageSize);
- a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
- e.child("#afterTextItem").setText(a);
- e.child("#inputItem").setValue(b);
- e.child("#first").setDisabled(b === 1);
- e.child("#prev").setDisabled(b === 1);
- e.child("#next").setDisabled(b === c || c===1);//
- e.child("#last").setDisabled(b === c || c===1);
- e.child("#refresh").enable();
- e.updateInfo();
- e.fireEvent("change", e, d);
- },
- onPagingBlur : function(e){
- var inputItem = this.child("#inputItem"),
- curPage;
- if (inputItem) {
- curPage = this.getPageData().currentPage;
- var e = this, d, b, c, a;
- d = e.getPageData();
- b = d.currentPage;
- c = Math.ceil(dataCount / pageSize);
- a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
- e.child("#afterTextItem").setText(a);
- e.child("#inputItem").setValue(b);
- e.child("#first").setDisabled(b === 1);
- e.child("#prev").setDisabled(b === 1);
- e.child("#next").setDisabled(b === c || c===1);
- e.child("#last").setDisabled(b === c || c===1);
- }
- },
- afterOnLoad : function(num) {
- var e = this, d, c, a, grid = e.ownerCt;
- if (!e.rendered) {
- return
- }
- d = e.getPageData();
- b = d.currentPage;
- c = Math.ceil(dataCount / pageSize);
- a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
- e.child("#afterTextItem").setText(a);
- //解决抬头筛选 页码不对
- if(num && num == 1) e.child("#inputItem").setValue(1);
- e.updateInfo();
- e.fireEvent("change", e, d);
- e.child('#last').setDisabled(c <= 1 || page == c);
- e.child('#next').setDisabled(c <= 1 || page == c);
- if(grid.noCount) {
- var m = e.down('#more');
- if(!m) {
- m = Ext.create('Ext.panel.Tool', {
- id: 'more',
- type: 'right',
- margin: '0 5 0 5',
- handler: function() {
- grid.getCount(null, null, true);
- m.hide();
- grid.noCount = false;
- }
- });
- e.add(m);
- } else {
- m.show();
- }
- }
- }
- });
- function fn(me,value){
- me.child('#last').setDisabled(value == total);
- me.child('#next').setDisabled(value == total);
- me.child('#first').setDisabled(value <= 1);
- me.child('#prev').setDisabled(value <= 1);
- }
|