<commit_before>Vps.Form.MultiFields = Ext.extend(Ext.Panel, {
    minEntries: 1,
    position: true,
    initComponent : function() {
        Vps.Form.MultiFields.superclass.initComponent.call(this);

        this.hiddenCountValue = new Vps.Form.MultiFieldsHidden({
            name: this.name,
            multiFieldsPanel: this
        });
        this.add(this.hiddenCountValue);

        this.groups = [];
    },

    enableRecursive: function() {
        Vps.Form.MultiFields.superclass.enableRecursive.call(this);
        this.groups.each(function(g) {
            g.item.enableRecursive();
        });
    },

    disableRecursive: function() {
        Vps.Form.MultiFields.superclass.disableRecursive.call(this);
        this.groups.each(function(g) {
            g.item.disableRecursive();
        });
    },

    // private
    onRender : function(ct, position){
        Vps.Form.MultiFields.superclass.onRender.call(this, ct, position);

    	if (!this.maxEntries || !this.minEntries || this.maxEntries != this.minEntries) {
	        this.addGroupButton = new Vps.Form.MultiFieldsAddButton({
	            multiFieldsPanel: this,
	            renderTo: this.body
	        }, position);
    	}

        for (var i = 0; i < this.minEntries; i++) {
            this.addGroup();
        }
    },

    // private
    addGroup : function()
    {
    	var items = [];
    	if (!this.maxEntries || !this.minEntries || this.maxEntries != this.minEntries) {
            var deleteButton = new Vps.Form.MultiFieldsDeleteButton({
                multiFieldsPanel: this
            });
            items.push(deleteButton);
            if (this.position) {
                var upButton = new Vps.Form.MultiFieldsUpButton({
                    multiFieldsPanel: this
                });
                items.push(upButton);
                var downButton = new Vps.Form.MultiFieldsDownButton({
                    multiFieldsPanel: this
                });
                items.push(downButton);
            }
    	}

        this.multiItems.each(function(i) {
            items.push(i);
        });

        var item = this.add({
            layout: 'form',
            border: false,
            items: items
        });
        if (deleteButton) deleteButton.groupItem = item;
        if (upButton) upButton.groupItem = item;
        if (downButton) downButton.groupItem = item;
        this.doLayout();

        item.cascade(function(i) {
            if (i.title && i.title.match(/\{(\w+)\}/)) {
                i.replaceTitle = i.title;
                if (RegExp.$1 != 0) i.replaceTitleField = RegExp.$1;
            }
        }, this);

        this.hiddenCountValue._findFormFields(item, function(i) {
            i.setDefaultValue();
            i.clearInvalid();
        });

        if (this.multiItems[this.multiItems.length-1].xtype == 'fieldset') {
            if (upButton && upButton.el) {
                upButton.el.applyStyles('clear: right; left: 0;');
            } else if (upButton) {
                upButton.style += ' clear: right; left: 0;';
            }
            if (downButton && downButton.el) {
                downButton.el.applyStyles('clear: right; left: 0;');
            } else if (downButton) {
                downButton.style += ' clear: right; left: 0;';
            }
        }

        //firefox schiebt den button ned nach unten
        if(this.addGroupButton) this.addGroupButton.hide();
        if(this.addGroupButton) this.addGroupButton.show.defer(100, this.addGroupButton);

        if (this.disabled) {
            item.disableRecursive();
        } else {
            item.enableRecursive();
        }

        this.groups.push({
            item: item,
            deleteButton: deleteButton,
            upButton: upButton,
            downButton: downButton
        });

        this.updateButtonsState();

        return item;
    },

    updateButtonsState: function(values) {
        if (this.addGroupButton) {
            if (this.maxEntries && this.groups.length >= this.maxEntries) {
                this.addGroupButton.disable();
            } else {
                this.addGroupButton.enable();
            }
            if (this.multiItems[this.multiItems.length-1].xtype == 'fieldset') {
                if (this.groups.length) {
                    this.addGroupButton.el.setStyle('top', '-19px');
                } else {
                    this.addGroupButton.el.setStyle('top', '0');
                }
            }
        }
        for (var i = 0; i < this.groups.length; i++) {
            var g = this.groups[i];
            if (g.upButton && i == 0) {
                g.upButton.disable();
            } else if (g.upButton) {
                g.upButton.enable();
            }
            if (g.downButton && i == this.groups.length-1) {
                g.downButton.disable();
            } else if (g.downButton) {
                g.downButton.enable();
            }
            if (g.deleteButton && this.minEntries >= this.groups.length) {
                g.deleteButton.disable();
            } else if (g.deleteButton) {
                g.deleteButton.enable();
            }
            g.item.cascade(function(item) {
                if (item.replaceTitle) {
                	var title = item.replaceTitle;
                	title = title.replace(/\{0\}/, i+1);
                	if (item.replaceTitleField) {
                		var exp = /\{\w+\}/;
                		if (values && values[i]) {
                			title = title.replace(exp, values[i][item.replaceTitleField]);
                		} else {
                			title = item.title;
                			if (exp.test(title)) title = trlVps('New Entry');
                		}
                	}
                    item.setTitle(title);
                }
            }, this);
        }
    }
});
Ext.reg('multifields', Vps.Form.MultiFields);

Vps.Form.MultiFieldsDeleteButton = Ext.extend(Ext.BoxComponent,  {
    // private
    onRender : function(ct, position){
        this.el = ct.createChild({
            tag: 'a',
            html: '<img src="/assets/silkicons/delete.png" />',
            href: '#',
            style: 'float: right; position: relative; z-index: 10; left: -20px; top: 1px;'
        }, position);
        this.el.on('click', function(e) {
            e.stopEvent();
            if (this.disabled) return;
            var p = this.multiFieldsPanel;
            for(var i=0; i < p.groups.length; i++) {
                var g = p.groups[i];
                if (g.item == this.groupItem) {
                    p.remove(g.item);<commit_msg>tabs -> spaces<commit_after>Vps.Form.MultiFields = Ext.extend(Ext.Panel, {
    minEntries: 1,
    position: true,
    initComponent : function() {
        Vps.Form.MultiFields.superclass.initComponent.call(this);

        this.hiddenCountValue = new Vps.Form.MultiFieldsHidden({
            name: this.name,
            multiFieldsPanel: this
        });
        this.add(this.hiddenCountValue);

        this.groups = [];
    },

    enableRecursive: function() {
        Vps.Form.MultiFields.superclass.enableRecursive.call(this);
        this.groups.each(function(g) {
            g.item.enableRecursive();
        });
    },

    disableRecursive: function() {
        Vps.Form.MultiFields.superclass.disableRecursive.call(this);
        this.groups.each(function(g) {
            g.item.disableRecursive();
        });
    },

    // private
    onRender : function(ct, position){
        Vps.Form.MultiFields.superclass.onRender.call(this, ct, position);

        if (!this.maxEntries || !this.minEntries || this.maxEntries != this.minEntries) {
            this.addGroupButton = new Vps.Form.MultiFieldsAddButton({
                multiFieldsPanel: this,
                renderTo: this.body
            }, position);
        }

        for (var i = 0; i < this.minEntries; i++) {
            this.addGroup();
        }
    },

    // private
    addGroup : function()
    {
        var items = [];
        if (!this.maxEntries || !this.minEntries || this.maxEntries != this.minEntries) {
            var deleteButton = new Vps.Form.MultiFieldsDeleteButton({
                multiFieldsPanel: this
            });
            items.push(deleteButton);
            if (this.position) {
                var upButton = new Vps.Form.MultiFieldsUpButton({
                    multiFieldsPanel: this
                });
                items.push(upButton);
                var downButton = new Vps.Form.MultiFieldsDownButton({
                    multiFieldsPanel: this
                });
                items.push(downButton);
            }
        }

        this.multiItems.each(function(i) {
            items.push(i);
        });

        var item = this.add({
            layout: 'form',
            border: false,
            items: items
        });
        if (deleteButton) deleteButton.groupItem = item;
        if (upButton) upButton.groupItem = item;
        if (downButton) downButton.groupItem = item;
        this.doLayout();

        item.cascade(function(i) {
            if (i.title && i.title.match(/\{(\w+)\}/)) {
                i.replaceTitle = i.title;
                if (RegExp.$1 != 0) i.replaceTitleField = RegExp.$1;
            }
        }, this);

        this.hiddenCountValue._findFormFields(item, function(i) {
            i.setDefaultValue();
            i.clearInvalid();
        });

        if (this.multiItems[this.multiItems.length-1].xtype == 'fieldset') {
            if (upButton && upButton.el) {
                upButton.el.applyStyles('clear: right; left: 0;');
            } else if (upButton) {
                upButton.style += ' clear: right; left: 0;';
            }
            if (downButton && downButton.el) {
                downButton.el.applyStyles('clear: right; left: 0;');
            } else if (downButton) {
                downButton.style += ' clear: right; left: 0;';
            }
        }

        //firefox schiebt den button ned nach unten
        if(this.addGroupButton) this.addGroupButton.hide();
        if(this.addGroupButton) this.addGroupButton.show.defer(100, this.addGroupButton);

        if (this.disabled) {
            item.disableRecursive();
        } else {
            item.enableRecursive();
        }

        this.groups.push({
            item: item,
            deleteButton: deleteButton,
            upButton: upButton,
            downButton: downButton
        });

        this.updateButtonsState();

        return item;
    },

    updateButtonsState: function(values) {
        if (this.addGroupButton) {
            if (this.maxEntries && this.groups.length >= this.maxEntries) {
                this.addGroupButton.disable();
            } else {
                this.addGroupButton.enable();
            }
            if (this.multiItems[this.multiItems.length-1].xtype == 'fieldset') {
                if (this.groups.length) {
                    this.addGroupButton.el.setStyle('top', '-19px');
                } else {
                    this.addGroupButton.el.setStyle('top', '0');
                }
            }
        }
        for (var i = 0; i < this.groups.length; i++) {
            var g = this.groups[i];
            if (g.upButton && i == 0) {
                g.upButton.disable();
            } else if (g.upButton) {
                g.upButton.enable();
            }
            if (g.downButton && i == this.groups.length-1) {
                g.downButton.disable();
            } else if (g.downButton) {
                g.downButton.enable();
            }
            if (g.deleteButton && this.minEntries >= this.groups.length) {
                g.deleteButton.disable();
            } else if (g.deleteButton) {
                g.deleteButton.enable();
            }
            g.item.cascade(function(item) {
                if (item.replaceTitle) {
                    var title = item.replaceTitle;
                    title = title.replace(/\{0\}/, i+1);
                    if (item.replaceTitleField) {
                        var exp = /\{\w+\}/;
                        if (values && values[i]) {
                            title = title.replace(exp, values[i][item.replaceTitleField]);
                        } else {
                            title = item.title;
                            if (exp.test(title)) title = trlVps('New Entry');
                        }
                    }
                    item.setTitle(title);
                }
            }, this);
        }
    }
});
Ext.reg('multifields', Vps.Form.MultiFields);

Vps.Form.MultiFieldsDeleteButton = Ext.extend(Ext.BoxComponent,  {
    // private
    onRender : function(ct, position){
        this.el = ct.createChild({
            tag: 'a',
            html: '<img src="/assets/silkicons/delete.png" />',
            href: '#',
            style: 'float: right; position: relative; z-index: 10; left: -20px; top: 1px;'
        }, position);
        this.el.on('click', function(e) {
            e.stopEvent();
            if (this.disabled) return;
            var p = this.multiFieldsPanel;
            for(var i=0; i < p.groups.length; i++) {
                var g = p.groups[i];
                if (g.item == this.groupItem) {
                    p.remove(g.item);
{'fraction_non_alphanumeric': 0.1309353600722402, 'fraction_numerical': 0.004214011588531868, 'mean_word_length': 1.4529346622369879, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6406690', 'n_tokens_mistral': 3846, 'n_tokens_neox': 3690, 'n_words': 656}