PDA

View Full Version : when i set my record my store dont sync



mukthar
24 Jul 2013, 12:53 PM
Hello, i have a problem, all time when i update my form, my store dont sync, and i dont underistan why.

my store


Ext.require(['LMS.model.Usuario']);
Ext.define('LMS.store.ClienteUsuarios', {
extend: 'Ext.data.Store',
model: 'LMS.model.Usuario',
autoLoad: true,//Precisei tirar o autoloader por causa que preciso passar os parametros.
remoteSort:false,
proxy:{
simpleSortMode: true,
type: 'ajax',
id : "usuarioslms",
api: {
read:'php/classes/ClienteUsuarios.php?action=carregarDados',
create: 'php/classes/ClienteUsuarios.php?action=insert',
update: 'php/classes/ClienteUsuarios.php?action=update',
destroy: 'php/classes/ClienteUsuarios.php?action=destroy'
},
actionMethods:{
read:'POST',
create: 'POST',
update: 'POST',
destroy: 'POST'
},
reader:{
type:'json',
root: 'data',
successProperty:'success',
totalProperty: 'total'
},
writer:{
type:'json',
writeAllFields: true,
encode:true,
root:'data'
},
extraParams:{
start:'start',
limit:'limit',
sorte:'name',
dir:'ASC',
total:'total',
pageSize:10,
valorcnpj:''
},
listeners:{
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title:'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
})
}
}
},
listeners:{
write: function(proxy, operation ){
var obj = Ext.decode(operation.response.responseText);

if(obj.success){
Ext.MessageBox.show({
title:'Usuarios',
msg: obj.message,
icon: Ext.MessageBox.OK,
buttons: Ext.Msg.OK
})
}else{
Ext.MessageBox.show({
title:'Usuario Erros',
msg: obj.message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
})
}
}
}
});


My Controller:


"usuarioedit button[itemId=btnSalvar]": {
click: function() {
var form = this.getUsuarioedit().down("form"),
store = this.getUsuario().down("gridpanel").getStore();
var myMask = new Ext.LoadMask(form, {msg:"Atualizando dados..."});
form.down("#edtCnpj").setValue(this.getClienteedit().down("#edtCnpj").getValue());
console.log(store);
if(form.isValid()) {
if(form.down("#edtCodigo").getValue() != "") { //ALTERACAO

var record = form.getRecord();
console.log(record);
//var record = store.getById(form.down("#edtCodigo").getValue());
record.set(form.getValues());
console.log(record);
record.setDirty();

} else {
store.add(form.getValues());
}
myMask.show();
console.log(store);

store.sync({
scope: this,
success: function() {
this.getUsuarioedit().close();
this.getUsuario().down("gridpanel").getStore().reload();
myMask.hide();
},
failure: function() {
this.getUsuario().down("gridpanel").getStore().reload();
myMask.hide();
}
});
}
}
}


Any ideias ? this problem only happens when i try UPDATE , insert is OK.

Renan Cunha
24 Jul 2013, 2:30 PM
How you loaded the record in this form? You get the record from the grid store and used the form.loadRecord method?

mukthar
24 Jul 2013, 3:14 PM
yes. correct

mukthar
24 Jul 2013, 5:39 PM
I did the following, I tried putting a listener console.log in store, the first time I call to update the store works properly and it calls the listener console.log inside the store, but the second time I call the same recored and try to update again or he calls the console.log as possible and that? it is a bug on EXT ?

slemmon
30 Jul 2013, 4:09 PM
Make sure after the form is edited you're using updateRecord as well:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.Panel-method-updateRecord



Ext.define('LMS.model.Usuario', {
extend: 'Ext.data.Model',
fields: ['name', 'email']
});


Ext.require(['LMS.model.Usuario']);


Ext.define('LMS.store.ClienteUsuarios', {
extend: 'Ext.data.Store',
model: 'LMS.model.Usuario',
autoLoad: true, //Precisei tirar o autoloader por causa que preciso passar os parametros.
remoteSort: false,
proxy: {
simpleSortMode: true,
type: 'ajax',
id: "usuarioslms",
api: {
//read: 'php/classes/ClienteUsuarios.php?action=carregarDados',
read: 'data/json.json',
create: 'php/classes/ClienteUsuarios.php?action=insert',
update: 'php/classes/ClienteUsuarios.php?action=update',
destroy: 'php/classes/ClienteUsuarios.php?action=destroy'
},
actionMethods: {
read: 'POST',
create: 'POST',
update: 'POST',
destroy: 'POST'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success',
totalProperty: 'total'
},
writer: {
type: 'json',
writeAllFields: true,
encode: true,
root: 'data'
},
extraParams: {
start: 'start',
limit: 'limit',
sorte: 'name',
dir: 'ASC',
total: 'total',
pageSize: 10,
valorcnpj: ''
},
listeners: {
exception: function (proxy, response, operation) {
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
})
}
}
},
listeners: {
write: function (proxy, operation) {
var obj = Ext.decode(operation.response.responseText);


if (obj.success) {
Ext.MessageBox.show({
title: 'Usuarios',
msg: obj.message,
icon: Ext.MessageBox.OK,
buttons: Ext.Msg.OK
})
} else {
Ext.MessageBox.show({
title: 'Usuario Erros',
msg: obj.message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
})
}
}
}
});


var store = Ext.create('LMS.store.ClienteUsuarios', {});




var form = Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
tbar: [{
text: 'Load Record 0 from store',
handler: function () {
form.loadRecord(store.getAt(0));
}
}],
bbar: [{
text: 'Update from form and Sync',
handler: function () {
form.updateRecord();
store.sync();
}
}],
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
}, {
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email Address',
vtype: 'email'
}]
});