PDA

View Full Version : Trouble with a store that won't sync



louis.maconi
10 Nov 2014, 7:34 AM
So, I'm having trouble with a store that won't sync and post data. First, here's my model:


Ext.define('SW101.model.personModel', {
extend: 'Ext.data.Model',

requires: [
'Ext.data.Field'
],

fields: [
{
name: 'id'
},
{
name: 'lastName'
},
{
name: 'firstName'
},
{
convert: function(v, rec) {
return rec.get('firstName') + ' ' + rec.get('lastName');
},
name: 'name'
},
{
name: 'middleName'
},
{
name: 'active'
},
{
name: 'gmEmail'
},
{
name: 'gmId'
},
{
name: 'gmLocationRegion'
},
{
name: 'gmPersonType'
},
{
name: 'nonGmPersonType'
},
{
name: 'phone'
},
{
name: 'modified'
},
{
name: 'modifiedBy'
}
]
});


And my store:


Ext.define('SW101.store.userStore', {
extend: 'Ext.data.Store',

requires: [
'SW101.model.personModel',
'Ext.data.proxy.Rest',
'Ext.data.reader.Json'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
autoSync: true,
model: 'SW101.model.personModel',
storeId: 'userStore',
listeners: {
write: {
fn: me.onJsonstoreWrite,
scope: me
}
},
proxy: {
type: 'rest',
url: 'api/person',
headers: {
Accept: 'application/json'
},
reader: {
type: 'json'
}
}
}, cfg)]);
},

onJsonstoreWrite: function(store, operation, eOpts) {
store.reload();
}

});


Now, in my controller, when the user clicks a button, I'm gathering the data into new record instantiated from my model, I'm suspending auto-sync because in this case I want to capture success or failure, syncing manually, and responding with the result. As you can see, I'm logging lots of stuff to the console to see what's happening. I have a good handle on the model and store, but there is never a call made to the server; I don't see any interaction in Chrome dev tools. Anyway, here's the controller code. I follow the same steps in other controllers and it works just fine. Can't figure out why it doesn't work here. Any thoughts appreciated!



var thisController = this;
var userStore = this.getStore('userStore');
//var userStore = Ext.getStore('userStore');
var gmin = Ext.ComponentQuery.query('#adminUsers #userDetails #userGmin')[0].getValue();
var fName = Ext.ComponentQuery.query('#adminUsers #userDetails #userFirstName')[0].getValue();
var lName = Ext.ComponentQuery.query('#adminUsers #userDetails #userLastName')[0].getValue();
var email = Ext.ComponentQuery.query('#adminUsers #userDetails #userEmail')[0].getValue();
var gmPType = Ext.ComponentQuery.query('#adminUsers #userDetails #userIsGm')[0].getValue() == 'Yes' || Ext.ComponentQuery.query('#adminUsers #userDetails #userIsGm')[0].getValue() == 'No' ? 'C' : 'E';
var nonGmPType = Ext.ComponentQuery.query('#adminUsers #userDetails #userIsSupplier')[0].getValue == 'Yes' ? 'SNB' : ' ';
var fon = Ext.ComponentQuery.query('#adminUsers #userDetails #userPhone')[0].getValue();

console.log(userStore);
console.log(gmin);
console.log(fName);
console.log(lName);
console.log(email);
console.log(gmPType);
console.log(nonGmPType);
console.log(fon);

var newPerson = new SW101.model.personModel({
id: gmin,
active: true,
firstName: fName,
middleName: ' ',
lastName: lName,
gmEmail: email,
gmId: ' ',
gmLocationRegion: ' ',
gmPersonType: gmPType,
nonGmPersonType: nonGmPType,
phone: fon,
modified: Date.parse(new Date()),
modifiedBy: thisController.getController('sessionController').gmin
});
console.log(newPerson);


userStore.suspendAutoSync();
//userStore.insert(0, newPerson);
userStore.add(newPerson);
userStore.sync({
//userStore.save({
success: function(){
console.log('s');
Ext.MessageBox.alert('Success!', 'This user now has access to this system.');
userStore.resumeAutoSync();
},
failure: function(batch){
console.log('f');
var errorMessages;
var ex;
for (ex in batch.exception){
errorMessages += ex + '/n';
}
Ext.MessageBox.alert('Error!', errorMessages);
userStore.resumeAutoSync();
thisController.clearUserForm();
}
});
console.log('got here');


-L

louis.maconi
10 Nov 2014, 9:54 AM
So, I never got this corrected, but I ended up using a different method to accomplish the task. Instead of using my store to sync up the record I created, I did a manual Ajax request, encoding my record, and passing it that way. It works just fine. I'm still curious why this didn't work, but in the interest of deadlines, I'm moving on.

Thanks.

-L