{"size": 1808, "ext": "js", "max_stars_repo_path": "dist/uncompressed/skylark-grapejs/trait_manager/view/TraitCheckboxView.js", "max_stars_repo_name": "skylark-integration/skylark-grapejs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dist/uncompressed/skylark-grapejs/trait_manager/view/TraitCheckboxView.js", "max_issues_repo_name": "skylark-integration/skylark-grapejs", "max_issues_repo_issues_event_min_datetime": "2021-10-17T03:42:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-17T03:42:16.000Z", "max_forks_repo_path": "src/trait_manager/view/TraitCheckboxView.js", "max_forks_repo_name": "skylark-integration/skylark-grapejs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 34.7692307692, "max_line_length": 79, "alphanum_fraction": 0.4657079646}
define([
    'skylark-underscore',
    './TraitView'
], function (a, TraitView) {
    'use strict';
    return TraitView.extend({
        appendInput: 0,
        templateInput() {
            const {ppfx, clsField} = this;
            return `<label class="${ clsField }" data-input>
    <i class="${ ppfx }chk-icon"></i>
  </label>`;
        },
        onChange() {
            const value = this.getInputElem().checked;
            this.model.set('value', this.getCheckedValue(value));
        },
        getCheckedValue(checked) {
            let result = checked;
            const {valueTrue, valueFalse} = this.model.attributes;
            if (result && !a.isUndefined(valueTrue)) {
                result = valueTrue;
            }
            if (!result && !a.isUndefined(valueFalse)) {
                result = valueFalse;
            }
            return result;
        },
        getInputEl(...args) {
            const toInit = !this.$input;
            const el = TraitView.prototype.getInputEl.apply(this, args);
            if (toInit) {
                let checked, targetValue;
                const {model, target} = this;
                const {valueTrue, valueFalse} = model.attributes;
                const name = model.get('name');
                if (model.get('changeProp')) {
                    checked = target.get(name);
                    targetValue = checked;
                } else {
                    targetValue = target.get('attributes')[name];
                    checked = targetValue || targetValue === '' ? !0 : !1;
                }
                if (!a.isUndefined(valueFalse) && targetValue === valueFalse) {
                    checked = !1;
                }
                el.checked = checked;
            }
            return el;
        }
    });
});