<commit_before>'use strict';

class FieldController extends ModelController {

    static create(model, parent) {
        // console.log('FieldController.create', model.getFullName());
        let obj;
        if (model.data.js) {
            const CustomClass = eval(model.data.js);
            if (!CustomClass) throw new Error(`custom class of "${model.getName()}" field does not return type`);
            obj = new CustomClass(model, parent);
        } else {
            obj = eval(`new ${model.data.class}Controller(model, parent);`);
        }
        return obj;
    }

    constructor(model, parent) {
        super(model);
        this.parent = parent;
        this.views  = new Map();    // list of all views that controlled by this field
        this.html   = null;
    }

    init() {
    }

    deinit() {
        //console.log('FieldController.deinit: ' + this.model.getName());
        this.views = null;
    }

    renderView() {
        if (this.html === null) {
            this.html = QForms.render(this.model.data.view, {model: this.model});
        }
        return $(this.html).get(0);
    }

    fill(row, view) {
        // console.log('FieldController.fill', this.model.getFullName());
        this.views.set(row, view);
        view.dbRow = row;
        const value = this.model.getValue(row);
        this.setValue(value, view);
        this.setViewStyle(view, row);
    }

    refill(row, view) {
        // console.log('FieldController.refill', this.model.getFullName());
        const value = this.model.getValue(row);
        this.setValue(value, view);
        this.setViewStyle(view, row);
        this.updateChangedClass(row, view);
        view.firstElementChild.classList.remove('error');
    }

    updateChangedClass(row, view) {
        // console.log('FieldController.updateChangedClass', this.model.getFullName(), this.isChanged(row, view));
        if (this.isChanged(row, view)) {
            $(view).addClass('changed');
        } else {
            $(view).removeClass('changed');
        }
    }

    getValue(view) {
        // console.log('FieldController.getValue', this.model.getFullName());
        const getStringValue = this.getStringValue(view);
        if (this.model.getColumnType() === 'object') return this.parseValue(getStringValue);
        return getStringValue;
    }

    getStringValue(view) {
        switch (this.model.getForm().getClassName()) {
            case 'RowForm': return view.firstElementChild.value;
            case 'TableForm': return view.firstElementChild.innerHTML;
            default: throw new Error(`unknown form class: ${this.model.getForm().getClassName()}`);
        }
    }

    setStringValue(stringValue, view) {
        switch (this.model.getForm().getClassName()) {
            case 'RowForm':view.firstElementChild.value = stringValue;break;
            case 'TableForm':view.firstElementChild.innerHTML = stringValue;break;
            default: throw new Error(`unknown form class: ${this.model.getForm().getClassName()}`);
        }
    }

    parseValue(value) {
        // console.log('FieldController.parseValue', this.model.getFullName());
        if (value.trim() === '') return null;
        return JSON.parse(value);
    }

    setPlaceHolder(value, view) {
        // console.log('FieldController.setPlaceHolder', this.model.getFullName(), value);
        if (this.model.getForm().getClassName() === 'RowForm') {
            if (value === undefined) {
                view.firstElementChild.placeholder = 'undefined';
            } else if (value === null) {
                view.firstElementChild.placeholder = 'null';
            } else if (value === '') {
                view.firstElementChild.placeholder = 'empty string';
            } else {
                view.firstElementChild.placeholder = this.valueToString(value);
            }
        }
    }
<commit_msg>do not set placeholder for visible value<commit_after>'use strict';

class FieldController extends ModelController {

    static create(model, parent) {
        // console.log('FieldController.create', model.getFullName());
        let obj;
        if (model.data.js) {
            const CustomClass = eval(model.data.js);
            if (!CustomClass) throw new Error(`custom class of "${model.getName()}" field does not return type`);
            obj = new CustomClass(model, parent);
        } else {
            obj = eval(`new ${model.data.class}Controller(model, parent);`);
        }
        return obj;
    }

    constructor(model, parent) {
        super(model);
        this.parent = parent;
        this.views  = new Map();    // list of all views that controlled by this field
        this.html   = null;
    }

    init() {
    }

    deinit() {
        //console.log('FieldController.deinit: ' + this.model.getName());
        this.views = null;
    }

    renderView() {
        if (this.html === null) {
            this.html = QForms.render(this.model.data.view, {model: this.model});
        }
        return $(this.html).get(0);
    }

    fill(row, view) {
        // console.log('FieldController.fill', this.model.getFullName());
        this.views.set(row, view);
        view.dbRow = row;
        const value = this.model.getValue(row);
        this.setValue(value, view);
        this.setViewStyle(view, row);
    }

    refill(row, view) {
        // console.log('FieldController.refill', this.model.getFullName());
        const value = this.model.getValue(row);
        this.setValue(value, view);
        this.setViewStyle(view, row);
        this.updateChangedClass(row, view);
        view.firstElementChild.classList.remove('error');
    }

    updateChangedClass(row, view) {
        // console.log('FieldController.updateChangedClass', this.model.getFullName(), this.isChanged(row, view));
        if (this.isChanged(row, view)) {
            $(view).addClass('changed');
        } else {
            $(view).removeClass('changed');
        }
    }

    getValue(view) {
        // console.log('FieldController.getValue', this.model.getFullName());
        const getStringValue = this.getStringValue(view);
        if (this.model.getColumnType() === 'object') return this.parseValue(getStringValue);
        return getStringValue;
    }

    getStringValue(view) {
        switch (this.model.getForm().getClassName()) {
            case 'RowForm': return view.firstElementChild.value;
            case 'TableForm': return view.firstElementChild.innerHTML;
            default: throw new Error(`unknown form class: ${this.model.getForm().getClassName()}`);
        }
    }

    setStringValue(stringValue, view) {
        switch (this.model.getForm().getClassName()) {
            case 'RowForm':view.firstElementChild.value = stringValue;break;
            case 'TableForm':view.firstElementChild.innerHTML = stringValue;break;
            default: throw new Error(`unknown form class: ${this.model.getForm().getClassName()}`);
        }
    }

    parseValue(value) {
        // console.log('FieldController.parseValue', this.model.getFullName());
        if (value.trim() === '') return null;
        return JSON.parse(value);
    }

    setPlaceHolder(value, view) {
        // console.log('FieldController.setPlaceHolder', this.model.getFullName(), value);
        if (this.model.getForm().getClassName() === 'RowForm') {
            if (value === undefined) {
                view.firstElementChild.placeholder = 'undefined';
            } else if (value === null) {
                view.firstElementChild.placeholder = 'null';
            } else if (value === '') {
                view.firstElementChild.placeholder = 'empty string';
            }
        }
    }

{'fraction_non_alphanumeric': 0.14276418532014576, 'fraction_numerical': 0.0002602811035918792, 'mean_word_length': 2.2954545454545454, 'pattern_counts': {'":': 0, '<': 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': '3440952', 'n_tokens_mistral': 2132, 'n_tokens_neox': 2110, 'n_words': 409}