PDA

View Full Version : How to use the Store.url



liqingzhu
24 Feb 2011, 8:12 PM
Dear GroupMembers:

How are you doing!

I got a small problem which is my Ext.data.json.Store is not working,when I changed the proxy url?

the code is



onTrigger2Click : function(){
/**
* I create a query function in here and it does worked and request url is “quickfindfiletopicinfo.html” but when I do the paging , the filestore request url is “findallfiletopic.html”
**/
var v = this.getRawValue();
var _url='quickfindfiletopicinfo.html';
var _obj = {start:0,limit:20,ttitle:v};
filestore.proxy.conn.url = _url;
filestore.baseParams = _obj;
filestore.load({params:_obj});
this.hasSearch = true;
this.triggers[0].show();
this.focus();
}
})
],
store:filestore,
bbar:new Ext.PagingToolbar({
store:filestore,
pageSize:20,
displayInfo: true,
displayMsg: '{0} -{1} total is {2}',
emptyMsg:'no result',
plugins: new Ext.ux.ProgressBarPager({
progBarWidth:500
})
}),

the whole code




Ext.namespace('Ysu.file');

/**
*update record
**/
window.toUpdate = function(cid){
var _winfiletopic = new Ysu.file.UpdateFileTopicWindow();
var count = filestore.getCount();
var _record;
for (var i = 0; i < count; i++) {
var _rec = filestore.getAt(i);
if (cid==_rec.get('tid')) {
_record = _rec;
break;
}
}
_winfiletopic.load(_record);
_winfiletopic.show();
_winfiletopic.on('submit',function(_win,_r){
var _form = _win.form.getForm();
_form.submit({
url:'updatefiletopic.html',
waitTitle:'',
waitMsg:'',
method:'POST',
success:function(form,action){
var data = _record.data;
for (var i in data) {
_record.set(i,_r.get(i));
}
_record.commit();
msg('','!',Ext.MessageBox.INFO);
_win.close();
},
failure:function(form,action){
msg('','!',Ext.MessageBox.ERROR);
}
});

});
}
/**
*del record
**/
window.toDelete = function(cid){
var count = filestore.getCount();
var _record;
for (var i = 0; i < count; i++) {
var _rec = filestore.getAt(i);
if (cid==_rec.get('tid')) {
_record = _rec;
break;
}
}
Ext.MessageBox.confirm('','?',function(btn){if(btn=='yes')
{
Ext.Ajax.request(
{
url:'delfiletopic.html',
params : {ttitle : cid},
success:function(response,option){
msg('','?',Ext.MessageBox.INFO);
filestore.remove(_record);
},
failure:function(response,option){
msg('','?',Ext.MessageBox.ERROR);
}
}
);
}
}
);
}
/**
*
*filestore for the gridpanel
*
***/
var filestore = new Ext.data.JsonStore({
fields:['tid','ttitle','tdescription'],
url:'findallfiletopic.html',
totalProperty: 'totalCount',
root: 'data'
});
//number sequence
var filenums = new Ext.grid.RowNumberer();

var filecb = new Ext.grid.CheckboxSelectionModel();

var fileexpander = new Ext.grid.RowExpander({
tpl : new Ext.Template(
'<p><b>content:</b> <div id="{cid}"></div></p><br>',
'<p><b></b></p>'
)
});
fileexpander.on('expand',function(obj, record, body, index){
var sno = record.get('tid');
Ext.Ajax.request({
url : 'getcollectinfo.html',
params:{cid:sno},
method : 'POST',
success : function(response,options){
var _str = response.responseText;
try{
var _obj = Ext.util.JSON.decode(_str);
}catch(err){
msg('',''+err.description,Ext.MessageBox.ERROR);
}
var _data = _obj.content;
document.getElementById(sno).innerHTML=_data;
},
failure : function(response,options){
msg('','?');
}
});
});

var filecm = new Ext.grid.ColumnModel(
[
fileexpander,
filenums,
filecb,
{header: "title",width:200,dataIndex:'ttitle',sortable: true,renderer:renderHallName},
{header: "date",width:80,dataIndex:'tid',sortable:true},
{header: "description",width:100,dataIndex:'tdescription',sortable: true},
{header: "update",width:60,dataIndex:'tid',sortable: true,
renderer:function(value, meta, rec, rowIdx, colIdx, ds){
var _str = '';
_str = '<a href="#" onclick="toUpdate('+value+')">update</a>';
return _str;
}
},
{header: "delete",width:60,dataIndex:'tid',sortable: true,
renderer:function(value){
var _str = '<a href="#" onclick="toDelete('+value+')">delete</a>';
return _str;

}
}
]
);



Ysu.file.FileTopicGridPanel = Ext.extend(Ext.grid.GridPanel,{
insertWin:new Ysu.file.InsertFileTopicWindow(),
updateWin:new Ysu.file.UpdateFileTopicWindow(),
constructor:function(){
filestore.load({params:{start:0,limit:20}});
this.insertWin.on('submit',this.onInsertWinSubmit,this);
this.updateWin.on('submit',this.onUpdateWinSubmit,this);
Ysu.file.FileTopicGridPanel.superclass.constructor.call(this,{
enableColumnMove:false,
plugins:[fileexpander],
title:'description',
viewConfig:{forceFit:true},
tbar:[
{
text:'add',
iconCls:'db-icn-add',
handler:function(){
this.insertWin.show();
},
scope:this
},'-',
{
text:'update',
iconCls:'db-icn-edit',
handler:function(){
var _sm = this.getSelectionModel();
if(_sm.getCount()!=1)
{
msg('','once only?',Ext.MessageBox.ERROR);
return;
}
var _r = _sm.getSelected();
this.updateWin.show();
this.updateWin.load(_r);
},
scope:this
},'-',
{
text:'delete',
iconCls:'db-icn-del',
handler:function(){
var _sm = this.getSelectionModel().getSelections();
if(_sm.length==0){
msg('','!',Ext.MessageBox.ERROR);
return;
}
Ext.MessageBox.confirm('','!',this.onRemoveRecord,this);
},
scope:this
},'-',
new Ext.form.TwinTriggerField({
validationEvent :false,
validateOnBlur :false,
emptyText :'quick query!',
trigger1Class :'x-form-clear-trigger',
trigger2Class :'x-form-search-trigger',
hideTrigger1 :true,
width :300,
hasSearch : false,
paramName : 'query',
listeners :{'specialkey':function(f, e){
if(e.getKey() == e.ENTER){
this.onTrigger2Click();
}
}},
onTrigger1Click : function(){
if(this.hasSearch){
this.el.dom.value = '';
this.triggers[0].hide();
this.hasSearch = false;
this.focus();
}
},
onTrigger2Click : function(){
/**
*I create a query function in here and it does worked and request url is “quickfindfiletopicinfo.html” but when I do the paging , the filestore request url is “findallfiletopic.html”
**/
var v = this.getRawValue();
var _url='quickfindfiletopicinfo.html';
var _obj = {start:0,limit:20,ttitle:v};
filestore.proxy.conn.url = _url;
filestore.baseParams = _obj;
filestore.load({params:_obj});
this.hasSearch = true;
this.triggers[0].show();
this.focus();
}
})
],
store:filestore,
bbar:new Ext.PagingToolbar({
store:filestore,
pageSize:20,
displayInfo: true,
displayMsg: '{0} -- {1} total{2}',
emptyMsg:'No result',
plugins: new Ext.ux.ProgressBarPager({
progBarWidth:500
})
}),

cm:filecm,
sm:filecb,
width:350,
height:200,

selModel:new Ext.grid.RowSelectionModel({
listeners:{'rowselect':{
fn:this.onRowSelect,
scope:this
}
}
}
)
})
},
remove:function(){
try{
var data = this.getSelectionModel().getSelections();
for(var i=0;i<data.length;i++)
{
this.getStore().remove(data[i]);
}
}catch(err){

msg('',err.description,Ext.MessageBox.ERROR);
}
},
onRemoveRecord:function(btn){
var me = this;
if(btn=='yes'){
var sel = this.getSelectionModel().getSelections();
var list = [];
for(var index=0; index<sel.length; index++) {
list.push((sel[index].get('tid')));
}
var ids = list.join(',');
var msgTip = Ext.MessageBox.show({
title:'',
width : 250,
msg:'......'
});
Ext.Ajax.request({
url : 'delfiletopic.html',
params : {ttitle : ids},
method : 'POST',
success : function(response,options){
msgTip.hide();
var result = Ext.util.JSON.decode(response.responseText);
if(result.success){

me.remove();
msg('','?',Ext.MessageBox.INFO);
}else{
msg('','?',Ext.MessageBox.ERROR);
}
},
failure : function(response,options){
msgTip.hide();
msg('','?',Ext.MessageBox.ERROR);
}
});
/*******************/
}
},
onRowSelect:function(_sel,_index,_r){
this.fireEvent('rowselect',_r);
},
insert:function(_r){
this.getStore().add(_r);
},
onInsertWinSubmit:function(_win,_r){
var me = this;
var _form = _win.form.getForm();
_form.submit({
url:'addfiletopic.html',
waitTitle:'',
waitMsg:'?...',
method:'POST',
success:function(form,action){
_r.set('tid',action.result.tid);
me.insert(_r);
_form.reset();
Ext.MessageBox.confirm('',',!',function(btn){
if(btn=='no'){
_win.hide();
}
},this);
},
failure:function(form,action){
msg('','!',Ext.MessageBox.ERROR);
}
});
},
update:function(_r){
try{
var sr = this.getSelectionModel().getSelected();
var data = sr.data;
for (var i in data) {
sr.set(i,_r.get(i));
}
sr.commit();
}catch(_err){
alert(_err.description);
}
},
onUpdateWinSubmit:function(_win,_r){
var me = this;
var _form = _win.form.getForm();
_form.submit({
url:'updatefiletopic.html',
waitTitle:'',
waitMsg:''
method:'POST',
success:function(form,action){
me.update(_r);
msg('','',Ext.MessageBox.INFO);
_win.close();
},
failure:function(form,action){
msg('','!',Ext.MessageBox.ERROR);
}
});
}
});