PDA

View Full Version : MVC destroy/delete record how to send data



whisher
18 Jan 2012, 1:30 AM
Hi,
I'm stuck on how to send data from within my controller
for destroy/delete a row so my store


Ext.define('SA.store.Users', {
extend: 'Ext.data.Store',
model: 'SA.model.User',
autoLoad: true,
pageSize: 4,
proxy: {
type: 'ajax',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
},
api: {
create: 'user/insert',
read: 'user/list',
update: 'user/update',
destroy: 'user/destroy'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success',
totalProperty: 'total'
},
writer: {
type: 'json',
writeAllFields: false,
root: 'data'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});


my controller



Ext.define('SA.controller.Users', {
extend: 'Ext.app.Controller',
models: ['User'],
stores: [
'Users'
],
views: [
'user.List',
'user.Edit',
'user.Insert'
],
init: function() {
this.control({
'userlist': {
itemdblclick: this.editUser,
itemclick: this.enableDeleteButton
},
'userlist > toolbar > button#btnAdd': {
click: this.insertUser
},
'useredit button[action=save]': {
click: this.updateUser
}
});
},

insertUser: function() {
var view = Ext.widget('userinsert');
},
editUser: function(grid, record) {
var view = Ext.widget('useredit');
view.down('form').loadRecord(record);
},
enableDeleteButton: function(grid, record) {
var btnDelete = Ext.getCmp('btnDelete');
btnDelete.enable();
btnDelete.on('click', function(e, t) {
Ext.Msg.show({
title:'Delete row?',
msg: 'Do you really want to delete the row ?',
buttons: Ext.Msg.YESNOCANCEL,
fn: function(btn){
if(btn==='yes'){
var selection = grid.getSelectionModel().getSelection()[0];
if(selection){
grid.getStore().remove(selection);
// WHAT DO I HAVE TO SET HERE ?
console.log(record);
}
}
},
animEl: 'elId'
});

});



},
updateUser: function(button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
record.set(values);
win.close();
this.getUsersStore().sync();
}
});


I mean I'm looking for the build-in way I don't think I have to use

Ext.Ajax.request

mitchellsimoens
18 Jan 2012, 6:41 AM
Is getUsersStore the same store the record belongs to?

whisher
18 Jan 2012, 11:57 AM
Is getUsersStore the same store the record belongs to?
Thanks for the reply
yes, it is.