summaryrefslogtreecommitdiff
path: root/js/codeq/settings.js
blob: dd844a58e600398cf0f1dbcfd9198112979f70e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
 * Created by robert on 9/29/15.
 */
(function(){

    var guiLangSelect = $('#gui_lang_select'),
        robotAddressInput = $('#robot_address_input'),
        previousGuiLang = guiLangSelect.val(),
        closedWithSave = false;

    guiLangSelect.on("change",function() {
        var lang = guiLangSelect.val();
        if (lang in codeq.supportedLangs) {
            codeq.setLang(lang);
        }
    });

    $("#settings_save_btn").on("click", function() {
        closedWithSave = true;
    });

    $("#settings_dropdown_menu").on("shown.bs.dropdown", function() {
        closedWithSave = false;
        previousGuiLang = codeq.settings['gui_lang'];
    }).on("hidden.bs.dropdown", function() {
        if(closedWithSave){
            codeq.settings['robot_address'] = robotAddressInput.val();
            codeq.comms.updateSettings(codeq.settings)
                .then(function (data) {
                    if (data.code !== 0) {
                        throw new Error('Updating settings failed, code: ' + data.code + ', message: ' + data.message);
                    }
                })
                .done();
        }else{
            guiLangSelect.val(previousGuiLang);
            if (previousGuiLang in codeq.supportedLangs) codeq.setLang(previousGuiLang);
            robotAddressInput.val(codeq.settings['robot_address']);
        }
    });
})();