Nuvolar_Scanner_Android.Login = function (params, viewInfo) {
    $.each(Nuvolar_Scanner_Android.app.navigation, function (_, command) {
        command.option("root", false);
    })
    var viewModel = {
        commands: Nuvolar_Scanner_Android.app.navigation,
        getlogin: function (e) {
            IsLoggedOn = false;
            SimpleQuery.UserName = username();
            SimpleQuery.Password = password();
            SimpleQuery.Database = database();
            SimpleQuery.Query = 'DX_Login';
            JSON_Text = JSON.stringify(SimpleQuery, null);
            if (URL_DIR() != "" && URL_DIR() != null) {
                URL("http://" + URL_IP() + "/" + URL_DIR() + "/Service.svc/GetInfo?callback=?");
            }
            else {
                URL("http://" + URL_IP() + "/Service.svc/GetInfo?callback=?");
            }
            //Most kell bejelentkeztetni
            $.getJSON(URL(), 'id=' + JSON_Text, function (results) {
                if (JSON.parse(results).ResultStatus == 1) {
                    IsLoggedOn = true;
                    //Ideiglenesen !!!
                    database("pcs_324");
                    
                    Nuvolar_Scanner_Android.app.createNavigation(navigation);
                    Nuvolar_Scanner_Android.app.renderNavigation();
                    Nuvolar_Scanner_Android.app.navigate(currentnavigate(), { root: true });

                    window.localStorage.setItem("username", username());
                    window.localStorage.setItem("database", database());
                    window.localStorage.setItem("URL_IP", URL_IP());
                    window.localStorage.setItem("URL_DIR", URL_DIR());

                };
            }
            ).done(function () {
                loadPanelVisible(false);
            }).fail(function (jqXHR, textStatus, errorThrown) {
                loadPanelVisible(false);
                alert(textStatus);
                alert(jqXHR.responseText);

                DevExpress.ui.notify("Kapcsolati hiba, próbálja meg újra!", "error", 2000);
            });
        },
        viewShown: function (e) {
            loadPanelVisible(true);
            IsLoggedOn = false;
            //Nuvolar_Scanner_Android.app.navigate("Login", { root: true,target:"current",clearHistory: true });
            if (window.localStorage.getItem("database") != null)
            {
                database(window.localStorage.getItem("database"));
                username(window.localStorage.getItem("username"));
                URL_IP(window.localStorage.getItem("URL_IP"));
                URL_DIR(window.localStorage.getItem("URL_DIR"));
                if (URL_DIR() != "" && URL_DIR() != null) {
                    URL("http://" + URL_IP() + "/" + URL_DIR() + "/Service.svc/GetInfo?callback=?");
                }
                else
                {
                    URL("http://" + URL_IP() + "/Service.svc/GetInfo?callback=?");
                }
            }
            loadPanelVisible(false);
        }
    };
    
    return viewModel;
};

