<commit_before>/*
 * Base prototype for selectable models
 */

function SelectableModel(elem) {
    this.element = $(elem);
    this.isSelected = false;
    this.toggleSelection = this.select;
    this.id = this.element.attr("id");
}
SelectableModel.prototype = {
    constructor: SelectableModel,
    select: function() {
        this.isSelected = true;
        this.element.addClass("focused");
        this.toggleSelection = this.unselect;
        this.element.triggerHandler("select", this);
    },
    unselect: function() {
        this.isSelected = false;
        this.element.removeClass("focused");
        this.toggleSelection = this.select;
        this.element.triggerHandler("unselect", this);
    },
    enable: function() {
        this.element.removeAttr('disabled');
        this.element.removeClass("disabled");
        this.element.triggerHandler("enable", this);
    },
    disable: function() {
        this.element.attr('disabled', 'true');
        this.element.addClass("disabled");
        this.element.triggerHandler("disable", this);
    },
    show: function() {
        this.enable();
        if (this.isSelected) {
            this.select();
        }
        this.element.triggerHandler("show", this);
    },
    hide: function() {
        this.disable();
        // TODO do we want to unselect here if selected? probably...
        this.element.triggerHandler("hide", this);
    },
    onExit: function() {
        // override this to provide onExit functionality
        this.element.triggerHandler("exit", this);
        return true;
    },
    isDisabled: function() {
        return this.element.is(":disabled") || this.element.hasClass("disabled");
    }
}

// TODO so it looks like exit handlers can only be applied to fields, but validators can be applied to fields and questions--is this correct?

/*
 * Prototype for fields
 */
function FieldModel(elem, container, parentQuestion, messagesContainer) {
    SelectableModel.apply(this, [elem]);
    this.container = container;
    this.parentQuestion = parentQuestion;
    this.messagesContainer = messagesContainer;
    this.validators = [];this.exitHandlers = [];
    this.label = $('label[for="' + this.element.attr('id') + ', "], label[for="' + this.element.parent().attr('id') + '"]').text().trim();

    // you can specify validators directly on the element, or the parent p or fieldset
    var classes = this.element.attr("class") + " "
                    + this.element.closest("p").attr("class") + " "
                    + this.element.closest("field").attr("class") + " "
                    + this.element.closest("fieldset").attr("class");

    if(classes) {
        _.each(classes.split(' '), function(klass) {
            Validators[klass] && this.validators.push(Validators[klass]);<commit_msg>UICM-70: [Simple Form UI] Bug in FieldModel object when setting label property<commit_after>/*
 * Base prototype for selectable models
 */

function SelectableModel(elem) {
    this.element = $(elem);
    this.isSelected = false;
    this.toggleSelection = this.select;
    this.id = this.element.attr("id");
}
SelectableModel.prototype = {
    constructor: SelectableModel,
    select: function() {
        this.isSelected = true;
        this.element.addClass("focused");
        this.toggleSelection = this.unselect;
        this.element.triggerHandler("select", this);
    },
    unselect: function() {
        this.isSelected = false;
        this.element.removeClass("focused");
        this.toggleSelection = this.select;
        this.element.triggerHandler("unselect", this);
    },
    enable: function() {
        this.element.removeAttr('disabled');
        this.element.removeClass("disabled");
        this.element.triggerHandler("enable", this);
    },
    disable: function() {
        this.element.attr('disabled', 'true');
        this.element.addClass("disabled");
        this.element.triggerHandler("disable", this);
    },
    show: function() {
        this.enable();
        if (this.isSelected) {
            this.select();
        }
        this.element.triggerHandler("show", this);
    },
    hide: function() {
        this.disable();
        // TODO do we want to unselect here if selected? probably...
        this.element.triggerHandler("hide", this);
    },
    onExit: function() {
        // override this to provide onExit functionality
        this.element.triggerHandler("exit", this);
        return true;
    },
    isDisabled: function() {
        return this.element.is(":disabled") || this.element.hasClass("disabled");
    }
}

// TODO so it looks like exit handlers can only be applied to fields, but validators can be applied to fields and questions--is this correct?

/*
 * Prototype for fields
 */
function FieldModel(elem, container, parentQuestion, messagesContainer) {
    SelectableModel.apply(this, [elem]);
    this.container = container;
    this.parentQuestion = parentQuestion;
    this.messagesContainer = messagesContainer;
    this.validators = [];this.exitHandlers = [];
    this.label = $('label[for="' + this.element.attr('id') + ' "], label[for="' + this.element.parent().attr('id') + '"]').text().trim();

    // you can specify validators directly on the element, or the parent p or fieldset
    var classes = this.element.attr("class") + " "
                    + this.element.closest("p").attr("class") + " "
                    + this.element.closest("field").attr("class") + " "
                    + this.element.closest("fieldset").attr("class");

    if(classes) {
        _.each(classes.split(' '), function(klass) {
            Validators[klass] && this.validators.push(Validators[klass]);
{'fraction_non_alphanumeric': 0.14782762274814554, 'fraction_numerical': 0.00035323207347227127, 'mean_word_length': 2.747849106551952, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '2276886', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1532, 'n_words': 336}