PDA

View Full Version : Store using POST to update data



Paulo Brito
16 Jan 2012, 9:40 AM
I've googled a lot and I can't figure out why my form always use POST to update records. This leads to 409 error from my django server. There's a "id" fields, so what's wrong?



Ext.define('Material', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'nome', type: 'string'},
{name: 'descricao', type: 'string'},
{name: 'preco_kg', type: 'number'}
]
});


var proxy = Ext.create("Ext.data.HttpProxy", {
type: 'rest',
url: '/api/material',
reader: {
type: 'json',
root: 'data'
}
});


var materialStore = Ext.create('Ext.data.Store', {
storeId:'materialStore',
model: "Material",
proxy: proxy,
autoLoad: true,
autoSync: true,
idProperty: 'id',
api: {
create: '/api/material',
read: '/api/material',
update: '/api/material',
destroy: '/api/material'
}


});




var toolbar = Ext.create('Ext.toolbar.Toolbar', {
region: 'north',
items: [
{
// xtype: 'button', // default for Toolbars
text: 'Novo'
},
{
text : 'Editar'
},
{
text: 'Excluir'
},
// begin using the right-justified button container
'->', // same as { xtype: 'tbfill' }
{
xtype : 'textfield',
name : 'busca',
emptyText: 'Pesquisar'
}
]
})




var grid = Ext.create('Ext.grid.Panel', {
//title: 'Materiais', Não criar barra de título
region: 'center',
store: materialStore,
columns: [
{ header: 'Nome', dataIndex: 'nome', editor: 'textfield' },
{ header: 'Descricao', dataIndex: 'descricao', flex: true, editor: 'textfield'},
{ header: 'Preço (Kg)', dataIndex: 'preco_kg', xtype: 'numbercolumn', format: ',0.00',
editor: {
type: 'numberfield',
renderer: Ext.util.Format.number
}
}
],
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
]
})


Ext.create('Ext.window.Window', {
title: 'Materiais',
height: 400,
width: 600,
layout: 'border',
items: [
Ext.create('Ext.tab.Panel', {
region: 'center',
items: [
Ext.create('Ext.panel.Panel', {
layout: 'border',
items: [
toolbar,
grid
]
}),


Ext.create('Ext.panel.Panel', {


})
]
})
]
}).show();

mitchellsimoens
16 Jan 2012, 11:04 AM
You are using api on the store but a url on the proxy (an old proxy name also). Those I'm sure are conflicting, you should just use api on the proxy.

Paulo Brito
18 Jan 2012, 4:19 AM
What I needed was just put the proxy definition on the model. It works now. I could even delete the api definition.

Thanks mitchellsimoens.