{"size": 1562, "ext": "js", "max_stars_repo_path": "src/static/js/settings/sourceSettings.js", "max_stars_repo_name": "intersystems-ru/iknow-entity-browser", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/static/js/settings/sourceSettings.js", "max_issues_repo_name": "intersystems-ru/iknow-entity-browser", "max_issues_repo_issues_event_min_datetime": "2017-04-19T01:31:29.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-29T18:44:58.000Z", "max_forks_repo_path": "src/static/js/settings/sourceSettings.js", "max_forks_repo_name": "intersystems-ru/iknow-entity-browser", "max_forks_repo_forks_event_min_datetime": "2017-11-18T10:55:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-26T02:47:34.000Z"}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": 4, "avg_line_length": 29.4716981132, "max_line_length": 84, "alphanum_fraction": 0.5781049936}
import { setInputValue, getOption, getChanges, applyChanges } from "./values.js";
import * as model from "../model"
import * as graph from "../graph";

function bind (elements) {
    for (let e of elements) {
        let el = document.getElementById(e);
        setInputValue(el);
        if (el.getAttribute("type") === "text")
            el.addEventListener(`input`, setInputValue);
        else
            el.addEventListener(`change`, setInputValue);
    }
}

export function init () {

    bind([
        "settings.host",
        "settings.port",
        "settings.domain",
        "settings.queryType",
        "settings.seed",
        "settings.webAppName",
        "settings.keepQueryTypeInView",
        "settings.keepSeedInView",
        "settings.tabularShowHiddenNodes"
    ]);

    function apply () {
        if (getChanges().length !== 0) {
            applyChanges();
            model.update(() => graph.update(true));
        }
    }

    document.getElementById("settings.queryType").addEventListener(`change`, () => {
        if (!getOption("keepQueryTypeInView") || model.uiState.settingsToggled)
            return;
        apply();
    });

    document.getElementById("settings.seed").addEventListener(`blur`, () => {
        if (!getOption("keepSeedInView") || model.uiState.settingsToggled)
            return;
        apply();
    });
    document.getElementById("settings.seed").addEventListener(`keydown`, (e) => {
        if (e.keyCode !== 13)
            return;
        document.getElementById("settings.seed").blur();
    });
}