jerrybrown5
12 Oct 2007, 6:30 PM
I really like programming difficult stuff. Sometimes it almost doesn't even seem like work. :) However, I hate doing boring copy and paste programming. So when I realized how tedious it was to load a complicated form purely from javascript, it motivated me to try to improve the process.
Here is my solution using the following (alpha) code:
Ext.ux.DistantChildren={
registerDistantChild: function(child){
if (!this.distantChildren) { this.distantChildren={} }
this.distantChildren[ child.mapping || child.name || child.id ]=child;
},
unRegisterDistantChild: function(child){
delete this.distantChildren[ child.mapping || child.name || child.id ];
},
findFieldDistant: function(name){
var f;
if (this.findFieldOrginal){ f= this.findFieldOrginal(name) }
if (!f){
if (!this.distantChildren) { this.identifyDistantChildren() }
f=this.distantChildren[name];
}
return f;
},
identifyDistantChildren: function(scope){ /*Lazily using slow function recursion*/
if (!this.distantChildren) { this.distantChildren={} }
var items;
if (!scope){
scope=this; items=scope.itemsPanel
}else{
items=scope.items;
}
if (items && items.length){
for (var n=0; n < items.length; n++){
var item=items.items[n];
1;
if(item.isFormField){
this.registerDistantChild(item);
1;
}else{
if (item.items && item.items.length){
this.identifyDistantChildren(item)
}
}
}
}
}
};
Ext.ux.DistantChildren_plugin={
init:function(o){
if (o.form){
Ext.apply(o.form, Ext.ux.DistantChildren);
o.form.itemsPanel=o.items;
o.form.findFieldOrginal=o.form.findField;
o.form.findField=o.form.findFieldDistant;
}
}
};
Now the following drop dead simple code below will load all child fields from the same datastore--no matter their level.
var panel = new Ext.FormPanel({
plugins: Ext.ux.DistantChildren_plugin,
... place lots of framsets, tabs, with tons of fields at each level here ...
});
panel.form.loadRecord(datastore.getAt(0));
Easy enough and fast enough... Case closed....
Best regards,
Jerry Brown
Here is my solution using the following (alpha) code:
Ext.ux.DistantChildren={
registerDistantChild: function(child){
if (!this.distantChildren) { this.distantChildren={} }
this.distantChildren[ child.mapping || child.name || child.id ]=child;
},
unRegisterDistantChild: function(child){
delete this.distantChildren[ child.mapping || child.name || child.id ];
},
findFieldDistant: function(name){
var f;
if (this.findFieldOrginal){ f= this.findFieldOrginal(name) }
if (!f){
if (!this.distantChildren) { this.identifyDistantChildren() }
f=this.distantChildren[name];
}
return f;
},
identifyDistantChildren: function(scope){ /*Lazily using slow function recursion*/
if (!this.distantChildren) { this.distantChildren={} }
var items;
if (!scope){
scope=this; items=scope.itemsPanel
}else{
items=scope.items;
}
if (items && items.length){
for (var n=0; n < items.length; n++){
var item=items.items[n];
1;
if(item.isFormField){
this.registerDistantChild(item);
1;
}else{
if (item.items && item.items.length){
this.identifyDistantChildren(item)
}
}
}
}
}
};
Ext.ux.DistantChildren_plugin={
init:function(o){
if (o.form){
Ext.apply(o.form, Ext.ux.DistantChildren);
o.form.itemsPanel=o.items;
o.form.findFieldOrginal=o.form.findField;
o.form.findField=o.form.findFieldDistant;
}
}
};
Now the following drop dead simple code below will load all child fields from the same datastore--no matter their level.
var panel = new Ext.FormPanel({
plugins: Ext.ux.DistantChildren_plugin,
... place lots of framsets, tabs, with tons of fields at each level here ...
});
panel.form.loadRecord(datastore.getAt(0));
Easy enough and fast enough... Case closed....
Best regards,
Jerry Brown