PDA

View Full Version : the .sync() doesn't seem to properly call the specified url



nfuids
12 Dec 2011, 5:50 AM
Hi,

I have created a small demo app following the MVC tutorial.

Pretty much everything works as expected, except one thing: myStore.sync() method.

When I doubleclick a row on the grid, the form (in a window) appears, I can change the text and click the save button. In the console, I see the handler function for the click event is called, and there is a small red icon that appears in the row that was changed (dirty.gif), but the url that should be called is never called.

I'm wondering what could cause this?

Here is the code of the click handler of the save button:


updateProcessGroup: function(button) {
console.log('Save Button clicked');

var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();


record.set(values);
win.close();

this.getProcessGroupStore().sync();
},

mitchellsimoens
12 Dec 2011, 12:32 PM
Is the store returned by this.getProcessGroupStore() the same store instance that is used on the grid?

nfuids
12 Dec 2011, 1:21 PM
Well,,.. I doubt it is.

In the Grid.js file, I specifically create a new instance of the store by doing this:

this.store = new ElementsPMI.store.ProcessGroup({ storeId: 'gridProcessGroupStore' });


and in the controller, I use the auto-generated method getProcessGroupStore() to get the store.

Since the controller is for the window poping up to make the edit, and the correct store is in the grid (that is not in the window), how can I get a reference to the grid (which would allow me to access the underlying store)?

Or how do you suggest I get a reference to the correct store?

and finally, what's the best practice for this kind of situation?

Regards,
Martin

mitchellsimoens
12 Dec 2011, 1:34 PM
Yeah, so that is two different instances. Where is the button in relation to the grid? Is it in a docked toolbar? If so, you can do button.up('gridpanel') to get the grid and then grid.getStore() to get the store.

nfuids
12 Dec 2011, 1:39 PM
I have a grid panel, and when I double click an item, it opens up a window that has a form and a save button.

So I guess Button.up would only get me to the window...

mitchellsimoens
12 Dec 2011, 1:46 PM
I usually put a reference to the grid on the form then

nfuids
12 Dec 2011, 2:13 PM
What I find confusing, is the data is updated in the grid, so I kinda thought the store was the correct one.

I guess I was wrong and only the model is updated and the model could be attached to 2 different instance of the same store?


I'm trying to add a reference to the store in the form.. it's not successful so far.

My window's definition:

initComponent: function() {
this.items = [
{
xtype: 'form',
border: 0,
bodyPadding: 5,
items: [
{
xtype: 'textfield',
name : 'name',
fieldLabel: 'Name'
},
{
xtype: 'textfield',
name : 'description',
fieldLabel: 'Description'
}
]
}
];


this.buttons = [
{
text: 'Save',
action: 'save'
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
];


this.callParent(arguments);
}


and my controller handling the double click event on a grid item:

onItemDblClick: function(grid, record) { console.log('Item was double clicked (' + record.get('name') + ')');

var view = Ext.widget('processgroupedit');

var form = view.down('form');

form.loadRecord(record);
form.store = grid.store;
},


and finally, the form's save button code

updateProcessGroup: function(button) { console.log('Save Button clicked');

var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();


record.set(values);
win.close();

form.store.sync();
},

this works, but I don't feel like it's an elegant solution.. what do you think?