1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| addRelation = function(_caller) {
var parentFieldset = Ext.getCmp($('#'+_caller.id).prev('fieldset').attr('id'));
var prevFieldset = $('#'+_caller.id).prev('fieldset').find('fieldset:last');
prevFieldset = Ext.getCmp(prevFieldset.attr('id'));
nextFieldset = prevFieldset.cloneConfig();
nextFieldset.cascade(prepareFields);
parentFieldset.add(nextFieldset);
parentFieldset.doLayout();
}
/**
* Function preparing fields dupplication
*/
function prepareFields(_target) {
// prepare increment
var nameRE = new RegExp('\\[(\\d+)\\]');
var matches = '';
var tmpName = '';
// Copy store for combo boxes
if(_target.store !== undefined) {
var oldField = $("input[name='"+_target.name+"']:first").next("input");
oldField = Ext.getCmp(oldField.attr('id'));
var records = [];
oldField.store.each(function(r){
records.push(r.copy());
});
var newStore = new Ext.data.Store({
recordType: oldField.store.recordType
});
newStore.add(records);
_target.store = newStore;
tmpName = _target.hiddenName;
matches = nameRE.exec(tmpName);
_target.name = _target.hiddenName = tmpName.replace(nameRE, '['+(parseInt(matches[1],10)+1)+']');
}
// Change id for auto created fields
if(_target.autoCreate !== undefined) {
_target.autoCreate.id = Ext.id();
tmpName = _target.autoCreate.name;
matches = nameRE.exec(_target.autoCreate.name);
_target.autoCreate.name = tmpName.replace(nameRE, '['+(parseInt(matches[1],10)+1)+']');
}
} |
Partager