PDA

View Full Version : The Proxy is calling the create api rather than update



Trok1
7 Sep 2010, 10:44 AM
Hi,

I am having a very frustrating problem that I can't seem to figure out. I am updating a record in a JsonStore with the code below based on a change made in a textfield by the customer. So they type the new file name and click on a save button which fires the code below. following the update into the store I call the jsonstore's save function. For some reason it is using the create api rather than update when it calls out to the server.

I stepped through the code execution with firebug and indeed it is updating the record in the store as planned, I also inspected the proxy's api upon creation of the web page and immediately before executing the save() function and it is properly mapped with the update url but the output back to the server is the create url and not the update url. This has been working with all my pages and now just seems to stop working.

Code:

ImageManager.Functions.ChangeName = function(){

var id = Ext.getCmp('site_image_id').getValue();
var name = Ext.getCmp('image_name').getValue().trim();

if(id && name){
var RecordIndex = ImageManager.Data.ImageStore.find('site_image_id', id );
var Record = ImageManager.Data.ImageStore.getAt(RecordIndex);
Record.set('image_name', name);
ImageManager.Data.ImageStore.save();

}else{
if(!name){
Ext.Msg.show({
title: 'Name Cannot be empty',
msg: 'Please type a new name in the field before saving',
minWidth: 200,
modal: true,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
}else{
Ext.Msg.show({
title: 'No Image Selected',
msg: 'Please select an image first and edit before clicking the save button',
minWidth: 200,
modal: true,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
}

}
}

Here is the api:

ImageManager.Data.ImageProxy = new Ext.data.HttpProxy({
api : {
read : 'index.php?Action=RetrieveImages',
create : 'index.php?Action=CreateImage',
update : 'index.php?Action=UpdateImage',
destroy : 'index.php?Action=DeleteImage',
}
});

I have been using this model for many files without a problem but now it just stopped working. I do know that i could/should use the params to pass the action but when I began I did not realize this. Even though I am passing the action in the url, it has worked without fail for many files now.

Please advise if anything seems to stand out.

Thank you sooo much ahead of time.

Todd

Trok1
7 Sep 2010, 10:46 AM
FYI, here is the datastore:

ImageManager.Data.ImageStore = new Ext.data.JsonStore({
storeId : 'ImageStore',
proxy : ImageManager.Data.ImageProxy,
baseParams : { xPage: 'ImageManager', ImageType: 'ALL'},
root : 'images',
totalProperty : 'totalCount',
idProperty : 'image_id',
fields : ImageManager.Data.ImageRecordFields ,
successProperty : 'success' ,
autoLoad : true,
remoteSort : false,
autoSave : false,
writer : ImageManager.Data.ImageWriter,
reader : ImageManager.Data.ImageReader
});

Trok1
7 Sep 2010, 4:44 PM
Hi All,

I found the problem. It had to do with the record being considered a phantom record (no id) so it was creating a new record. The issue was with my idProperty in my datastore not matching up with the id from the Record Field. The one thing I did not put in my message above :(

So basically I screwed up because I changed the name of my record id in one place and didn't remember to change it in the data store.

Thanks for reading and I hope this helps someone else in the future with a similar problem.