ZBase.registerView((function() {

  var submitForm = function(e) {
    e.preventDefault();

    var postdata = ZBase.util.buildQueryString({
      userid: this.querySelector("input[name='userid']").value,
      password: this.querySelector("input[name='password']").value
    });

    console.log(postdata);
    ZBase.util.httpPost("/analytics/api/v1/auth/login", postdata, function(http) {
      if (http.status == 200) {
        ZBase.navigateTo("/a/");
        return;
      }

      if (http.status == 401) {
        showErrorMessage("Invalid Credentials");
        return;
      }

      showErrorMessage("Server Error; please try again and contact support if the problem persists.");
    });

    return false;
  };

  var hideErrorMessage = function() {
    var viewport = document.getElementById("zbase_viewport");
    var elem = viewport.querySelector(".zbase_login .error_message");
    elem.classList.add("hidden");
  };

  var showErrorMessage = function(msg) {
    var viewport = document.getElementById("zbase_viewport");
    var elem = viewport.querySelector(".zbase_login .error_message");
    elem.innerHTML = msg;
    elem.classList.remove("hidden");
  };

  var render = function(path) {
    var viewport = document.getElementById("zbase_viewport");
    var page = ZBase.getTemplate("login", "zbase_login_form_tpl");

    var form = page.querySelector("form");
    form.addEventListener("submit", submitForm);

    viewport.innerHTML = "";
    viewport.appendChild(page);
  };

  return {
    name: "login",
    loadView: function(params) { render(params.path); },
    unloadView: function() {},
    handleNavigationChange: render
  };
})());

@@ -27,16 +27,405 @@
 on() %7B%0A%0A
+  var kServerErrorMsg = %22Server Error; please try again and contact support if the problem persists.%22;%0A%0A  var finishLogin = function() %7B%0A    ZBase.util.httpGet(%22/a/_/c%22, function(http) %7B%0A      if (http.status != 200) %7B%0A        showErrorMessage(kServerErrorMsg);%0A        return;%0A      %7D%0A%0A      ZBase.updateConfig(JSON.parse(http.responseText));%0A      ZBase.navigateTo(%22/a/%22);%0A    %7D);%0A  %7D;%0A%0A
   var su
@@ -445,24 +445,24 @@
 nction(e) %7B%0A
-
     e.preven
@@ -813,38 +813,28 @@
         
-ZBase.navigateTo(%22/a/%22
+finishLogin(
 );%0A     
@@ -986,85 +986,23 @@
 age(
-%22
+k
 Server
- 
 Error
-; please try again and contact support if the problem persists.%22
+Msg
 );%0A 

update config on login