summaryrefslogtreecommitdiff
path: root/js/codeq/settings.js
blob: 9eb436660f4dee6c9ee3bbbb34bd3dd5770dd8b0 (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
/**
 * Created by robert on 9/29/15.
 */
(function(){

    var guiLangSelect = $("#gui_lang_select");
    var previousLang = guiLangSelect.val();
    var closedWithSave = false;

    guiLangSelect.on("change",function() {
        var lang = $("#gui_lang_select").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;
        previousLang = codeq.getLang();
    }).on("hidden.bs.dropdown", function() {
        if(closedWithSave){
            var lang = $("#gui_lang_select").val();
            if (lang in codeq.supportedLangs) {
                codeq.comms.updateSettings({'lang': lang})
                    .then(function (data) {
                        if (data.code !== 0) throw new Error('Change language failed, code: ' + data.code + ', message: ' + data.message);//error msg if something went wring while saving to db
                    })
                    .done();
            }
        }else{
            $("#gui_lang_select").val(previousLang);
            if (previousLang in codeq.supportedLangs) codeq.setLang(previousLang);
        }
    });
})();