PDA

View Full Version : Check tree - how to save changes



ezriel
20 Sep 2012, 8:33 AM
Hi,
i'm using check tree example. When i check several nodes i want to save changes but store.sync() doesn't do anything. How to do it??
Here is my code


window.newSolveExamWindowOpened = false;

Ext.define('AnswerToSolve', {
extend: 'Ext.data.Model',
fields: [
{name: 'answerId', type: 'int', convert: null},
{name: 'text', type: 'string'},
{name: 'leaf', type: 'boolean'},
{name: 'checked', type: 'boolean'}
],
belongsTo:'QuestionToSolve',
idProperty: 'questionId'
});

Ext.define('QuestionToSolve', {
extend: 'Ext.data.Model',
fields: [
{name: 'questionId', type: 'int', convert: null},
{name: 'text', type: 'string'},
{name: 'cls', type: 'string'},
{name: 'expanded', type: 'boolean'}
],
hasMany : {model: 'AnswerToSolve', name: 'children'},
idProperty: 'questionId'
});

SolveExam = function() {

this.createNewWindow = function(desktop, exam) {

var store = Ext.create('Ext.data.TreeStore', {
autoLoad: false,
model: 'QuestionToSolve',
proxy: {
type: 'ajax',
api: {
read : 'exam/loadExamToSolve.action',
update: 'exam/checkExamToSolve.action',
},
reader: {
type: 'json',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true,
encode: false
// root: 'data'
},
listeners: {
exception: function(proxy, response, operation){
var msg;
if (response.responseText != undefined){
var responseObj = Ext.decode(response.responseText,true);
if (responseObj != null && responseObj.message != undefined){
msg = responseObj.message;
}else{
msg = 'Nieznany błąd: Serwer nie wysłał żadnych informacji o błędzie';
}
}else{
msg = 'Nieznany błąd: Nieznana odpowiedz serwera';
}
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: msg,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
},
listeners: {
datachanged: function(store){
Ext.Msg.alert("Changes","Changes");
}
}
});

store.load({params:{examId: exam.get("examId")}})

var win = desktop.createWindow({
title:'Egzamin ' + exam.get('name'),
constrainHeader: true,
width: 1004,
height: 600,
border: false,
autoScroll: true,
resizable: true,
iconCls: 'icon-grid',
layout: 'fit',
listeners: {
show: function() {
window.newSolveExamWindowOpened = true;
},
beforeclose: function() {
window.newSolveExamWindowOpened = false;
}
},
items: [
{
xtype: 'treepanel',
store: store,
rootVisible: false,
useArrows: true,
dockedItems: [{
xtype: 'toolbar',
items: {
text: 'Get checked nodes',
handler: function(){
var records = this.up('treepanel').getView().getChecked(),
names = [];

Ext.Array.each(records, function(rec){
names.push(rec.get('text'));
});

Ext.MessageBox.show({
title: 'Selected Nodes',
msg: names.join('<br />'),
icon: Ext.MessageBox.INFO
});
}
}
},
{
xtype: 'toolbar',
dock: 'bottom',
ui: 'footer',
layout: {
pack: 'center'
},
items: [{
minWidth: 80,
iconCls:'save',
text: 'Save',
handler: function(){
Ext.Msg.confirm('END', 'Do you really want to end?', function(btn){
if (btn == 'yes'){
store.sync();
Ext.Msg.alert("xxx",store.getUpdatedRecords().length);

}
});
}
}]
}]
}
]
});
win.show();
}
}


Example JSON



[{"questionId":3601,"text":"Ile to jest 12:4?","cls":"folder","expanded":true,
"children":[
{"answerId":704,"text":"4","leaf":true,"checked":false},
{"answerId":1154,"text":"8","leaf":true,"checked":false},
{"answerId":1155,"text":"6","leaf":true,"checked":false},
{"answerId":1156,"text":"3","leaf":true,"checked":false}]},
{"questionId":4100,"text":"12:4?","cls":"folder","expanded":true,
"children":[
{"answerId":1051,"text":"11","leaf":true,"checked":false},
{"answerId":1052,"text":"12","leaf":true,"checked":false},
{"answerId":1053,"text":"3","leaf":true,"checked":false},
{"answerId":1054,"text":"4","leaf":true,"checked":false}]},
{"questionId":3802,"text":"Ile to jest 20:20?","cls":"folder","expanded":true,
"children":[
{"answerId":752,"text":"5","leaf":true,"checked":false},
{"answerId":753,"text":"20","leaf":true,"checked":false},
{"answerId":1157,"text":"10:10","leaf":true,"checked":false},
{"answerId":755,"text":"1","leaf":true,"checked":false}]},
{"questionId":600,"text":"200:10","cls":"folder","expanded":true,
"children":[
{"answerId":1158,"text":"4","leaf":true,"checked":false},
{"answerId":1159,"text":"3","leaf":true,"checked":false},
{"answerId":1160,"text":"2","leaf":true,"checked":false},
{"answerId":1161,"text":"1","leaf":true,"checked":false}]},
{"questionId":200,"text":"Ile to jest 2 + 2?","cls":"folder","expanded":true,
"children":[
{"answerId":1150,"text":"2","leaf":true,"checked":false},
{"answerId":1151,"text":"6","leaf":true,"checked":false},
{"answerId":1152,"text":"5","leaf":true,"checked":false},
{"answerId":1153,"text":"4","leaf":true,"checked":false}]
}]

Thanks!

mitchellsimoens
24 Sep 2012, 6:39 AM
Did you set a breakpoint on the store.sync() to see where the breakdown is?