<commit_before>if (typeof formdesigner === 'undefined') {
    var formdesigner = {};
}

formdesigner.widgets = (function () {
    var that = {};
    
    that.getGroupName = function (path) {
        return path.split("/")[0];
    };
    
    that.getPropertyName = function (path) {
        return path.split("/")[1];
    };
    
    that.baseWidget = function(mugType) {
        // set properties shared by all widgets
        var widget = {};
        // this shared method provides fake inheritance, assuming
        // it is called in a constructor on the object being constructed
        widget.mug = mugType;
                
        widget.getDisplayName = function () {
            // use the display text, or the property name if none found
            return this.definition.lstring ? this.definition.lstring : this.propName;
        }
        
        widget.getLabel = function () {
            var label = $("<label />").text(this.getDisplayName()).attr("for", this.getID()); 
            return label;
        };
        
        widget.getControl = function () {
            throw ("must be overridden");
        };
        
        widget.getID = function () {
            throw ("must be overridden");
        };
        
        
        widget.setValue = function (val) {
            // noop
        };
        
        widget.getValue = function () {
            // noop
        };
        
        
        widget.fireValueChanged = function () {
            var ref = this;
            return function () {
                formdesigner.controller.fire({
                    type: 'widget-value-changed',
                    widget: ref
                });
            };
        };
        
        widget.getUIElement = function () {
            // gets the whole widget (label + control)
	        var uiElem = $("<div />").addClass("widget");
	        uiElem.append(this.getLabel());
	        uiElem.append(this.getControl());
	        return uiElem;
        };
        
        return widget;
    };
    
    that.normalWidget = function(mugType, path) {
        // for "normal" = non-itext widgets.
        var widget = that.baseWidget(mugType);
        widget.path = path;
        widget.definition = mugType.getPropertyDefinition(path);
        widget.currentValue = mugType.getPropertyValue(path);
        widget.groupName = that.getGroupName(widget.path);
        widget.propName = that.getPropertyName(widget.path);
        
        widget.getID = function () {
            return this.path.split("/").join("-");
        };
        
        
        
        widget.save = function () {
            formdesigner.controller.setMugPropertyValue(this.mug.mug,
	                                                    this.groupName,
                                                        this.propName,
                                                        this.getValue(),
                                                        this.mug);
        };
        return widget;
        
    };
    
    that.textWidget = function (mugType, path) {
        // a text widget 
        var widget = that.normalWidget(mugType, path);
        
	    var input = $("<input />").attr("id", widget.getID()).attr("type", "text");
            
	    widget.getControl = function () {
            return input;
        };
        
        widget.setValue = function (value) {
            input.val(value);
        };
        
        widget.getValue = function() {
            return input.val();
        };
        
        input.keyup(widget.fireValueChanged());
        return widget;    
    };
    
    that.iTextIDWidget = function (mugType, path) {
        // a special text widget that holds itext ids
        var widget = that.textWidget(mugType, path);
        
        widget.getNodeId = function () {
            return this.mug.mug.properties.dataElement.properties.nodeID;
        }
        
        widget.autoGenerateId = function (nodeId) {
            return nodeId + "-" + widget.propName.replace("ItextID", "");<commit_msg>allow itext id rendering for select items<commit_after>if (typeof formdesigner === 'undefined') {
    var formdesigner = {};
}

formdesigner.widgets = (function () {
    var that = {};
    
    that.getGroupName = function (path) {
        return path.split("/")[0];
    };
    
    that.getPropertyName = function (path) {
        return path.split("/")[1];
    };
    
    that.baseWidget = function(mugType) {
        // set properties shared by all widgets
        var widget = {};
        // this shared method provides fake inheritance, assuming
        // it is called in a constructor on the object being constructed
        widget.mug = mugType;
                
        widget.getDisplayName = function () {
            // use the display text, or the property name if none found
            return this.definition.lstring ? this.definition.lstring : this.propName;
        }
        
        widget.getLabel = function () {
            var label = $("<label />").text(this.getDisplayName()).attr("for", this.getID()); 
            return label;
        };
        
        widget.getControl = function () {
            throw ("must be overridden");
        };
        
        widget.getID = function () {
            throw ("must be overridden");
        };
        
        
        widget.setValue = function (val) {
            // noop
        };
        
        widget.getValue = function () {
            // noop
        };
        
        
        widget.fireValueChanged = function () {
            var ref = this;
            return function () {
                formdesigner.controller.fire({
                    type: 'widget-value-changed',
                    widget: ref
                });
            };
        };
        
        widget.getUIElement = function () {
            // gets the whole widget (label + control)
	        var uiElem = $("<div />").addClass("widget");
	        uiElem.append(this.getLabel());
	        uiElem.append(this.getControl());
	        return uiElem;
        };
        
        return widget;
    };
    
    that.normalWidget = function(mugType, path) {
        // for "normal" = non-itext widgets.
        var widget = that.baseWidget(mugType);
        widget.path = path;
        widget.definition = mugType.getPropertyDefinition(path);
        widget.currentValue = mugType.getPropertyValue(path);
        widget.groupName = that.getGroupName(widget.path);
        widget.propName = that.getPropertyName(widget.path);
        
        widget.getID = function () {
            return this.path.split("/").join("-");
        };
        
        
        
        widget.save = function () {
            formdesigner.controller.setMugPropertyValue(this.mug.mug,
	                                                    this.groupName,
                                                        this.propName,
                                                        this.getValue(),
                                                        this.mug);
        };
        return widget;
        
    };
    
    that.textWidget = function (mugType, path) {
        // a text widget 
        var widget = that.normalWidget(mugType, path);
        
	    var input = $("<input />").attr("id", widget.getID()).attr("type", "text");
            
	    widget.getControl = function () {
            return input;
        };
        
        widget.setValue = function (value) {
            input.val(value);
        };
        
        widget.getValue = function() {
            return input.val();
        };
        
        input.keyup(widget.fireValueChanged());
        return widget;    
    };
    
    that.iTextIDWidget = function (mugType, path) {
        // a special text widget that holds itext ids
        var widget = that.textWidget(mugType, path);
        
        widget.getNodeId = function () {
            if (this.mug.hasDataElement()) {
                return this.mug.mug.properties.dataElement.properties.nodeID;
            } else if (formdesigner.util.isSelectItem(this.mug)) {
                return this.mug.mug.properties.controlElement.properties.defaultValue;
            } else {
                throw "can't get nodeId for " + this.mug;
            }
        }
        
        widget.autoGenerateId = function (nodeId) {
            return nodeId + "-" + widget.propName.replace("ItextID", "");
{'fraction_non_alphanumeric': 0.11411625148279952, 'fraction_numerical': 0.00047449584816132857, 'mean_word_length': 1.3622863547212105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6559855', 'n_tokens_mistral': 2136, 'n_tokens_neox': 2109, 'n_words': 452}