arth
10 Sep 2008, 9:28 AM
Hello,
I have a function that retrieves database rows via an AJAX call. The function then creates a new panel for each row. Each panel has a 'gear' tool that is supposed to open an edit window with the particular row fields loaded and ready for editing.
// load subjects and create a draggable panel for each
var subjectGroupPanels=[];
function loadSubjects() {
Ext.Ajax.request({
url : '../server/sl.php' ,
params : { action : 'loadSubjects', study: <? echo $study_id; ?> },
method: 'GET',
success: function ( result, request ) {
// Delete any existing panels
if (subjectGroupPanels[0] != null){
for ( var i in subjectGroupPanels ){
if (typeof subjectGroupPanels[i] == 'object'){
subjectGroupPanels[i].destroy();
}
}
}
var subject_groups = eval('(' + result.responseText + ')');
for ( var i in subject_groups ){
if (typeof subject_groups[i][2] != 'undefined'){
// Add a panel for this subject group
var x = subject_groups[i][1];
subjectGroupPanels[i] = new Ext.Panel({
header: true,
html: 'details',
renderTo: 'subject_list',
collapsible: true,
collapsed: true,
draggable: true,
collapseFirst: false,
tools: [{
id:'gear',
qtip: 'Edit or Delete this subject group',
handler: function(event, toolEl, panel){
editSubjectGroup(x); // !!! always passes the value of the LAST x
}
}],
title: subject_groups[i][3] + ' ' + subject_groups[i][2]
});
}
}
// Display raw return in history for debugging
var addTo = Ext.get('history').dom;
addTo.innerHTML = result.responseText + "<br />" + addTo.innerHTML;
},
failure: function ( result, request) {
Ext.MessageBox.alert('Unable to load subjects.', result.responseText);
}
});
}
:(( I can not get my tool handler to correctly pass the database row id to the edit function. If I write:
alert(subject_groups[i][1]); // shows correct value
handler: function(event, toolEl, panel){
editSubjectGroup(subject_groups[i][1]); // alert within called function shows passed value as undefined
If I write:
var id = subject_groups[i][1];
alert(id); // shows correct value
handler: function(event, toolEl, panel){
editSubjectGroup(id); // alert within called function shows passed value as always being the LAST database id. i.e. If there are 5 panels coresponding to ids 1,2,3,4,5 - the handlers for all 5 panels will pass '5' as the id.
I have tried defining the variables outside of this function but that didn't make a difference. Can anyone point me in the right direction? Thank you!!!
I have a function that retrieves database rows via an AJAX call. The function then creates a new panel for each row. Each panel has a 'gear' tool that is supposed to open an edit window with the particular row fields loaded and ready for editing.
// load subjects and create a draggable panel for each
var subjectGroupPanels=[];
function loadSubjects() {
Ext.Ajax.request({
url : '../server/sl.php' ,
params : { action : 'loadSubjects', study: <? echo $study_id; ?> },
method: 'GET',
success: function ( result, request ) {
// Delete any existing panels
if (subjectGroupPanels[0] != null){
for ( var i in subjectGroupPanels ){
if (typeof subjectGroupPanels[i] == 'object'){
subjectGroupPanels[i].destroy();
}
}
}
var subject_groups = eval('(' + result.responseText + ')');
for ( var i in subject_groups ){
if (typeof subject_groups[i][2] != 'undefined'){
// Add a panel for this subject group
var x = subject_groups[i][1];
subjectGroupPanels[i] = new Ext.Panel({
header: true,
html: 'details',
renderTo: 'subject_list',
collapsible: true,
collapsed: true,
draggable: true,
collapseFirst: false,
tools: [{
id:'gear',
qtip: 'Edit or Delete this subject group',
handler: function(event, toolEl, panel){
editSubjectGroup(x); // !!! always passes the value of the LAST x
}
}],
title: subject_groups[i][3] + ' ' + subject_groups[i][2]
});
}
}
// Display raw return in history for debugging
var addTo = Ext.get('history').dom;
addTo.innerHTML = result.responseText + "<br />" + addTo.innerHTML;
},
failure: function ( result, request) {
Ext.MessageBox.alert('Unable to load subjects.', result.responseText);
}
});
}
:(( I can not get my tool handler to correctly pass the database row id to the edit function. If I write:
alert(subject_groups[i][1]); // shows correct value
handler: function(event, toolEl, panel){
editSubjectGroup(subject_groups[i][1]); // alert within called function shows passed value as undefined
If I write:
var id = subject_groups[i][1];
alert(id); // shows correct value
handler: function(event, toolEl, panel){
editSubjectGroup(id); // alert within called function shows passed value as always being the LAST database id. i.e. If there are 5 panels coresponding to ids 1,2,3,4,5 - the handlers for all 5 panels will pass '5' as the id.
I have tried defining the variables outside of this function but that didn't make a difference. Can anyone point me in the right direction? Thank you!!!