Misiu
3 Jul 2012, 10:47 PM
I've declared store like so:
Ext.define('Urlopy.Store.Plan', {
extend : "Sch.data.EventStore",
autoLoad : true,
autoSync : true,
batch : false,
proxy : {
type : 'ajax',
sortParam : undefined,
startParam : undefined,
pageParam : undefined,
limitParam : undefined,
noCache : false,
extraParams : {view: 'all'},
//actionMethods: {create: "POST", read: "POST", update: "POST", destroy: "POST"},//also tried this
headers : {
"Content-Type" : "application/json; charset=utf-8"
},
api : {
read : 'services/Terminy.asmx/Get',
create : 'services/Terminy.asmx/Create',
destroy : 'services/Terminy.asmx/Delete',
update : 'services/Terminy.asmx/Update'
},
reader : {
type : 'json',
root : 'd.data'
},
writer : {
type : 'json',
encode : false,
writeAllFields : true,
root : 'data'
}
},
listeners : {
update : function() {
//console.log('data changed');
}
},
model : 'Urlopy.Model.Plan'
});
I have problem with adding extra parameters to my store, somehow extJS sends them as string not like JSON.
What I need is to change event store GET behaviour, when I pass 'all' I want to load all events when I pass 'user' I would like to load events for current user only, just need to load different sets of data based on my param.
I've created button in tbar:
{
text : 'All',
icon : 'resources/images/calendar.png',
enableToggle : true,
//scope : this,
listeners: {
scope: this,
toggle: function(btn, pressed) {
if(pressed){
btn.setText('User');
this.eventStore.proxy.extraParams.view = 'all';
} else {
btn.setText('All');
this.eventStore.proxy.extraParams.view = 'user';
}
this.eventStore.load();
}
}
}
Searching trough sencha api I found extraParams section, but when I try to use it as so I get error on server-side:
{"Message":"Nieprawidłowy element pierwotny JSON: plan.","StackTrace":" w System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n w System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n w System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n w System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n w System.Web.Script.Services.RestHandler.GetRawParamsFromGetRequest(HttpContext context, JavaScriptSerializer serializer, WebServiceMethodData methodData)\r\n w System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n w System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
It looks like somehow ext JS is encoding extra params so that they aren't pass correct.
I sure that my webservice works because I've checked it with jquery:
$("#test").click(function() {
jQuery.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: "{view:'all'}",
url: 'http://localhost:3253/services/Terminy.asmx/Get',
success: function(result) {
alert(result);
}
});
});
What I need to do is to add default param for GET operation (if it is possible only for this one) and sometimes be able to change it so that using it I will be able to change events that come from server.
Removing extraParams and changing api section of proxy to:
api : {
read : 'services/Terminy.asmx/Get?view="all"',
create : 'services/Terminy.asmx/Create',
destroy : 'services/Terminy.asmx/Delete',
update : 'services/Terminy.asmx/Update'
}
helped, but this is just different url for operation. Can this be changed at runtime? This is second option: to remove extraParams and change url for read operation at runtime.
Ext.define('Urlopy.Store.Plan', {
extend : "Sch.data.EventStore",
autoLoad : true,
autoSync : true,
batch : false,
proxy : {
type : 'ajax',
sortParam : undefined,
startParam : undefined,
pageParam : undefined,
limitParam : undefined,
noCache : false,
extraParams : {view: 'all'},
//actionMethods: {create: "POST", read: "POST", update: "POST", destroy: "POST"},//also tried this
headers : {
"Content-Type" : "application/json; charset=utf-8"
},
api : {
read : 'services/Terminy.asmx/Get',
create : 'services/Terminy.asmx/Create',
destroy : 'services/Terminy.asmx/Delete',
update : 'services/Terminy.asmx/Update'
},
reader : {
type : 'json',
root : 'd.data'
},
writer : {
type : 'json',
encode : false,
writeAllFields : true,
root : 'data'
}
},
listeners : {
update : function() {
//console.log('data changed');
}
},
model : 'Urlopy.Model.Plan'
});
I have problem with adding extra parameters to my store, somehow extJS sends them as string not like JSON.
What I need is to change event store GET behaviour, when I pass 'all' I want to load all events when I pass 'user' I would like to load events for current user only, just need to load different sets of data based on my param.
I've created button in tbar:
{
text : 'All',
icon : 'resources/images/calendar.png',
enableToggle : true,
//scope : this,
listeners: {
scope: this,
toggle: function(btn, pressed) {
if(pressed){
btn.setText('User');
this.eventStore.proxy.extraParams.view = 'all';
} else {
btn.setText('All');
this.eventStore.proxy.extraParams.view = 'user';
}
this.eventStore.load();
}
}
}
Searching trough sencha api I found extraParams section, but when I try to use it as so I get error on server-side:
{"Message":"Nieprawidłowy element pierwotny JSON: plan.","StackTrace":" w System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n w System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n w System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n w System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n w System.Web.Script.Services.RestHandler.GetRawParamsFromGetRequest(HttpContext context, JavaScriptSerializer serializer, WebServiceMethodData methodData)\r\n w System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n w System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
It looks like somehow ext JS is encoding extra params so that they aren't pass correct.
I sure that my webservice works because I've checked it with jquery:
$("#test").click(function() {
jQuery.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: "{view:'all'}",
url: 'http://localhost:3253/services/Terminy.asmx/Get',
success: function(result) {
alert(result);
}
});
});
What I need to do is to add default param for GET operation (if it is possible only for this one) and sometimes be able to change it so that using it I will be able to change events that come from server.
Removing extraParams and changing api section of proxy to:
api : {
read : 'services/Terminy.asmx/Get?view="all"',
create : 'services/Terminy.asmx/Create',
destroy : 'services/Terminy.asmx/Delete',
update : 'services/Terminy.asmx/Update'
}
helped, but this is just different url for operation. Can this be changed at runtime? This is second option: to remove extraParams and change url for read operation at runtime.