
$(document).ready(function () {
    getMapInfo(getSelectedMap());
    $(".save").click(function () {
        let info = {};
        info['title'] = $('#titleInput').val();
        info['description'] = $('#descriptionInput').val();
        let object = {
            "function": 'save_map_info',
            'selector': getSelectedMap(),
            'info': info,
        };
        $.get(
            "ajax.php",
            object,
            function (data) {
                alert(data);
            }
        );
    });
    $('#mapSelect').on('change', function () {
        getMapInfo(getSelectedMap());
    });
});

function getSelectedMap() {
    return $('#mapSelect').val();
}

function getMapInfo(selector) {
    let object = {
        "function": 'get_map_info',
        'selector': selector,
    };
    $.get(
        "../../ajax/read",
        object,
        function (data) {
            console.log(data);
            $('#titleInput').val(data[0]['title']);
            $('#descriptionInput').val(data[0]['description']);
        }
    );
}
