PDA

View Full Version : Problem with Serverside "EDIT"



ExitusBlack
12 Dec 2011, 7:26 AM
Hi there,

I have a litte problem :)

Here my Controller


Ext.define("FeeTrack.controller.User", {extend: "Ext.app.Controller",
models: [
"User"
],
stores: [
"User"
],
views: [
"user.Show",
"user.Edit",
"user.Create"
],
init: function () {
if (typeof console !== "undefined") {
console.log('Initialized Users!');
console.log('This happens before the Application launch function is called');
}


this.control({
"viewport > panel": {
render: this.onPanelRendered
},
"usershow": {
itemdblclick: this.editUser
},
"useredit button[action=save]": {
click: this.updateUser
}
// "usershow button[action=add]": {
// click: this.createUser
// },
// "usercreate button[action=save]": {
// click: this.generateUser
// }
});
},
onPanelRendered: function () {
if (typeof console !== "undefined") {
console.log('The panel was rendered');
}
},
editUser: function(grid, record) {
if (typeof console !== "undefined") {
console.log('Double clicked on ' + record.get('username'));
}
var viewEdit = Ext.widget("useredit");
viewEdit.down("form").loadRecord(record);
},
updateUser: function(button) {
var win = button.up("window"),
form = win.down("form"),
record = form.getRecord(),
values = form.getValues();
if (typeof console !== "undefined") {
console.log('clicked the Save button');
}
record.set(values);
win.close();
this.getUserStore().sync();
},
// createUser: function(grid, record) {
// var viewCreate = Ext.widget("usercreate");
// },
//
// generateUser: function(button) {
// var win = button.up("window"),
// form = win.down("form"),
// //user = Ext.create(""),
// values = form.getValues();
//
// win.close();
// //this.getUserStore().sync();
// }
});

Here my Modell


Ext.define("FeeTrack.model.User", {extend: "Ext.data.Model",
fields: [
{name:"id", type: "int"},
{name:"chamber_id", type: "int"},
{name:"username", type: "string"},
{name:"email", type: "string"},
{name:"password", type: "string"},
{name:"role", type: "string"},
{name:"active", type: "int"},
{name:"deleted", type: "int"}
]
});

Here my Store


Ext.define("FeeTrack.store.User", {extend: "Ext.data.Store",
model: "FeeTrack.model.User",
autoLoad: true,
//autoSync: true,
//restful: true,
proxy: {
type: "rest",
api: {
create: "http://localhost/feetrack/feetrackNew/backend/public/user/create/",
read: "http://localhost/feetrack/feetrackNew/backend/public/user/",
update: "http://localhost/feetrack/feetrackNew/backend/public/user/edit/id/",
destroy: "http://localhost/feetrack/feetrackNew/backend/public/user/delete/id/"
},
reader: {
type: 'json'
},
writer: {
type: 'json',
successProperty : 'success'
}
}
});

Here my Views UserShow


Ext.define("FeeTrack.view.user.Show" ,{extend: "Ext.grid.Panel",
alias: "widget.usershow",
title: "Alle Benutzer",


initComponent: function() {
this.store = "User",
this.iconCls = "icon-user";
this.columns = [
{header: "Name", dataIndex: "username", flex: 1},
{header: "E-Mail", dataIndex: "email", flex: 1},
{header: "Aktiv", dataIndex: "active", flex: 1},
];
this.dockedItems = [{
xtype: "toolbar",
items: [{
text: "Add",
iconCls: "icon-add",
action: "add",
}, {
text: "Delete",
iconCls: "icon-delete",
action: "delete",
}],
}, {
xtype: "pagingtoolbar",
store: "User",
dock: "bottom",
displayInfo: true,
}];
this.callParent(arguments);
}
});

AND UserEdit


Ext.define("FeeTrack.view.user.Edit", {extend: "Ext.window.Window",
alias: "widget.useredit",
title: "Benutzer editieren",
layout: "fit",
autoShow: true,
initComponent: function() {
this.items = [{
xtype: "form",
items: [{
xtype: "textfield",
name: "username",
fieldLabel: "Name",
allowBlank: false,
}, {
xtype: "textfield",
name: "email",
fieldLabel: "E-Mail",
allowBlank: false,
}, {
xtype: "textfield",
name: "password",
fieldLabel: "Neues Passwort",
inputType: 'password',
allowBlank: false,
},{
xtype: "fieldcontainer",
fieldLabel : "Rolle",
defaultType: "radiofield",
items: [
{
boxLabel : "Admin",
name : "role",
inputValue: "admin",
id : "admin"
}, {
boxLabel : "Benutzer",
name : "role",
inputValue: "account",
id : "account"
}, {
boxLabel : "Sekretärin",
name : "role",
inputValue: "office",
id : "office"
}
]
}, {
xtype: "fieldcontainer",
fieldLabel : "Zustand",
defaultType: "checkboxfield",
items: [{
boxLabel : "Aktiv",
name : "active",
inputValue: "1",
id : "active"
}, {
boxLabel : "Entfernt",
name : "deleted",
inputValue: "1",
id : "deleted"
}]
}]
}];
this.buttons = [{
text: "Speichern",
action: "save"
}, {
text: "Abbrechen",
scope: this,
handler: this.close
}];
this.callParent(arguments);
}
});

And a little screenshot
befor edit
29935
29936
and under it after edit
when I press "Speichern" (Save) then
my app deleted my edit object and created two new empty records and i have no idea why.
Has anyone an idea ? :)
Thanks byby :)

Mathias.Deshayes
12 Dec 2011, 9:24 AM
Hi,

What is the server response when you save a record ?

ExitusBlack
12 Dec 2011, 11:05 PM
HI,

i get an Json Array as Request Payload like this

{"id":196,"chamber_id":1,"username":"testaaa","email":"test@cnd2.com","password":"a12289167aaa862aab1ca97464e307ed","role":"office","active":1,"deleted":0}

:)