mattjones99
16 Oct 2007, 5:39 PM
Hello,
I've been working through the grid video example, and below is my current code for saving changes.
This works, in that it packages the changed rows into a json package. But, I'd rather do an XMLHttpRequest here, and pass XML to the server. At least XML will be easier to parse in RoR than the JSON data is.
So, for starters, I'd like to change the section of the code that builds jsonData to build xmlData. Any suggestions?
Thanks,
Matt
{
text: 'Save Changes',
handler: function() {
jsonData = "[";
for(i=0;i<ds.getCount();i++) {
record = ds.getAt(i);
if(record.data.newRecord || record.dirty) {
jsonData += Ext.util.JSON.encode(record.data) + ",";
}
}
jsonData = jsonData.substring(0,jsonData.length-1) + "]";
console.info(jsonData);
gridForm.submit(
{
waitMsg: 'Saving changes, please wait...',
url:'<%= url_for :action=>:save_subjects, :id=>@album %>',
params:{data:jsonData},
success:function(form, action) {
Ext.MessageBox.hide();
Ext.MessageBox.alert('Success','Subjects were saved.');
},
failure: function(form, action) {
Ext.MessageBox.hide();
Ext.MessageBox.alert('Error','An error occurred saving subjects!');
}
}
);
}
I've been working through the grid video example, and below is my current code for saving changes.
This works, in that it packages the changed rows into a json package. But, I'd rather do an XMLHttpRequest here, and pass XML to the server. At least XML will be easier to parse in RoR than the JSON data is.
So, for starters, I'd like to change the section of the code that builds jsonData to build xmlData. Any suggestions?
Thanks,
Matt
{
text: 'Save Changes',
handler: function() {
jsonData = "[";
for(i=0;i<ds.getCount();i++) {
record = ds.getAt(i);
if(record.data.newRecord || record.dirty) {
jsonData += Ext.util.JSON.encode(record.data) + ",";
}
}
jsonData = jsonData.substring(0,jsonData.length-1) + "]";
console.info(jsonData);
gridForm.submit(
{
waitMsg: 'Saving changes, please wait...',
url:'<%= url_for :action=>:save_subjects, :id=>@album %>',
params:{data:jsonData},
success:function(form, action) {
Ext.MessageBox.hide();
Ext.MessageBox.alert('Success','Subjects were saved.');
},
failure: function(form, action) {
Ext.MessageBox.hide();
Ext.MessageBox.alert('Error','An error occurred saving subjects!');
}
}
);
}