+++++++++++++++++++++++++++++Ext.data.DWRProxy+++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++Ext.data.DWRProxy+++++++++++++++++++++++++++++++++++++
Ext.data.DWRProxy = function(config) {
Ext.data.DWRProxy.superclass.constructor.call(this);
this.fn = config.fn;
};
Ext.extend(Ext.data.DWRProxy, Ext.data.DataProxy, {
toJSON : function(text) {
alert(text);
text = text.replace(/\n/g, ' ');
text = text.replace(/\r/g, ' ');
if (text.match(/^\s*\{.*\}\s*$/)) {
text = '[' + text + '][0]';
}
return eval(text);
},
load : function(params, reader, callback, scope, arg) {
//alert(dwr.util.toDescriptiveString(params, 3));
params = params || {};
if (this.fireEvent("beforeload", this, params) !== false) {
var proxy = this;
// dwr回调函数
dwrcallback = function(ret) {
//alert(dwr.util.toDescriptiveString(ret.pageResults[0],3));
var result;
try {
result = reader.readRecords(ret);
} catch (e) {
this.fireEvent("loadexception", this, arg, null, e);
callback.call(scope, null, arg, false);
return;
}
//alert(dwr.util.toDescriptiveString(result,4))
callback.call(scope, result, arg, true);
}
//alert(dwr.util.toDescriptiveString(params,2))
// 需要将参数加入到调用参数
var callParams = new Array();
for (var i = 0; i < params.length; ++i) {
callParams.push(params[i]);
}
// 将回调函数加入的参数数组
callParams.push(dwrcallback);
//alert(dwr.util.toDescriptiveString(callParams, 3));
this.fn.apply(this, callParams);
}
}
});
+++++++++++++++++++++++++++++Ext.PagingToolbarExt+++++++++++++++++++++++++++++++++++++
/*
* Ext JS Library 2.1
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.PagingToolbar
* @extends Ext.Toolbar
* A specialized toolbar that is bound to a {@link Ext.data.Store} and provides automatic paging controls.
* @constructor
* Create a new PagingToolbar
* @param {Object} config The config object
*/
Ext.PagingToolbarExt = Ext.extend(Ext.Toolbar, {
/**
* @cfg {Ext.data.Store} store The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
*/
/**
* @cfg {Boolean} displayInfo
* True to display the displayMsg (defaults to false)
*/
/**
* @cfg {Number} pageSize
* The number of records to display per page (defaults to 20)
*/
pageSize: 20,
/**
* @cfg {String} displayMsg
* The paging status message to display (defaults to "Displaying {0} - {1} of {2}"). Note that this string is
* formatted using the braced numbers 0-2 as tokens that are replaced by the values for start, end and total
* respectively. These tokens should be preserved when overriding this string if showing those values is desired.
*/
displayMsg : paginglang.displayMsg + '{2}',
/**
* @cfg {String} emptyMsg
* The message to display when no records are found (defaults to "No data to display")
*/
emptyMsg : paginglang.emptyMsg,
/**
* Customizable piece of the default paging text (defaults to "Page")
* @type String
*/
beforePageText : paginglang.beforePageText,
/**
* Customizable piece of the default paging text (defaults to "of {0}"). Note that this string is
* formatted using {0} as a token that is replaced by the number of total pages. This token should be
* preserved when overriding this string if showing the total page count is desired.
* @type String
*/
afterPageText : paginglang.afterPageText + '{0}',
/**
* Customizable piece of the default paging text (defaults to "First Page")
* @type String
*/
firstText : paginglang.firstText,
/**
* Customizable piece of the default paging text (defaults to "Previous Page")
* @type String
*/
prevText : paginglang.prevText,
/**
* Customizable piece of the default paging text (defaults to "Next Page")
* @type String
*/
nextText : paginglang.nextText,
/**
* Customizable piece of the default paging text (defaults to "Last Page")
* @type String
*/
lastText : paginglang.lastText,
/**
* Customizable piece of the default paging text (defaults to "Refresh")
* @type String
*/
refreshText : paginglang.refreshText,
/**
* Object mapping of parameter names for load calls (defaults to {start: 'start', limit: 'limit'})
*/
paramNames : {start: 'start', limit: 'limit'},
initComponent : function(){
Ext.PagingToolbarExt.superclass.initComponent.call(this);
this.cursor = 0;
this.bind(this.store);
},
// private
onRender : function(ct, position){
Ext.PagingToolbarExt.superclass.onRender.call(this, ct, position);
this.first = this.addButton({
tooltip: this.firstText,
iconCls: "x-tbar-page-first",
disabled: true,
handler: this.onClick.createDelegate(this, ["first"])
});
this.prev = this.addButton({
tooltip: this.prevText,
iconCls: "x-tbar-page-prev",
disabled: true,
handler: this.onClick.createDelegate(this, ["prev"])
});
this.addSeparator();
this.add(this.beforePageText);
this.field = Ext.get(this.addDom({
tag: "input",
type: "text",
size: "3",
value: "1",
cls: "x-tbar-page-number"
}).el);
this.field.on("keydown", this.onPagingKeydown, this);
this.field.on("focus", function(){this.dom.select();});
this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
this.field.setHeight(18);
this.addSeparator();
this.next = this.addButton({
tooltip: this.nextText,
iconCls: "x-tbar-page-next",
disabled: true,
handler: this.onClick.createDelegate(this, ["next"])
});
this.last = this.addButton({
tooltip: this.lastText,
iconCls: "x-tbar-page-last",
disabled: true,
handler: this.onClick.createDelegate(this, ["last"])
});
this.addSeparator();
this.loading = this.addButton({
tooltip: this.refreshText,
iconCls: "x-tbar-loading",
handler: this.onClick.createDelegate(this, ["refresh"])
});
if(this.displayInfo){
this.displayEl = Ext.fly(this.el.dom).createChild({cls:'x-paging-info'});
}
if(this.dsLoaded){
this.onLoad.apply(this, this.dsLoaded);
}
},
// private
updateInfo : function(){
if(this.displayEl){
var count = this.store.getCount();
var msg = count == 0 ?
this.emptyMsg :
String.format(
this.displayMsg,
this.cursor+1, this.cursor+count, this.store.getTotalCount()
);
this.displayEl.update(msg);
}
},
// private
onLoad : function(store, r, o){
//alert(dwr.util.toDescriptiveString(store, 3));
//alert(dwr.util.toDescriptiveString(r, 3));
//alert(dwr.util.toDescriptiveString(o, 3));
if(!this.rendered){
this.dsLoaded = [store, r, o];
return;
}
if(o.params){
this.params = o.params;
}
this.cursor = o.params ? o.params[0][this.paramNames.start] : 0;
var d = this.getPageData(), ap = this.cursor, ps = d.pages;
this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
this.field.dom.value = ap;