Set autocorrect and autocapitalize off for username/password.
[guacamole.git] / src / main / webapp / index.xhtml
index e86778c..9e4ed55 100644 (file)
@@ -23,7 +23,9 @@
 
     <head>
         <link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
+        <link rel="apple-touch-icon" type="image/png" href="images/guacamole-logo-64.png"/>
         <link rel="stylesheet" type="text/css" href="styles/login.css"/>
+        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>
         <title>Guacamole ${project.version}</title>
     </head>
 
@@ -66,8 +68,8 @@
         <!-- Connection list UI -->
         <div id="connection-list-ui" style="display: none">
 
-            <div id="logout">
-                <a href="logout">Logout</a>
+            <div id="logout-panel">
+                <button id="logout">Logout</button>
             </div>
             
             <h1>
@@ -78,7 +80,7 @@
             <table class="connections">
                 <thead>
                     <tr>
-                        <th class="protocol">Protocol</th>
+                        <th class="protocol"> </th>
                         <th class="name">Name</th>
                     </tr>
                 </thead>
             Guacamole ${project.version}
         </div>
 
+        <script type="text/javascript" src="scripts/connections.js"></script>
+
         <!-- Init -->
         <script type="text/javascript"> /* <![CDATA[ */
 
-            function Config(protocol, id) {
-                this.protocol = protocol;
-                this.id = id;
-            }
-
-            function getConfigList() {
-
-                // Get config list
-                var xhr = new XMLHttpRequest();
-                xhr.open("GET", "configs", false);
-                xhr.send(null);
-
-                // If fail, throw error
-                if (xhr.status != 200)
-                    throw new Error(xhr.statusText);
-
-                // Otherwise, get list
-                var configs = new Array();
-
-                var configElements = xhr.responseXML.getElementsByTagName("config");
-                for (var i=0; i<configElements.length; i++) {
-                    configs.push(new Config(
-                        configElements[i].getAttribute("protocol"),
-                        configElements[i].getAttribute("id")
-                    ));
-                }
-
-                return configs;
+            // Constructs the URL for a client which connects to the connection
+            // with the given id.
+            function getClientURL(id) {
+                
+                // Construct URL for client with given id
+                return "client.xhtml?id=" + encodeURIComponent(id);
                 
             }
 
+            // Resets the interface such that the login UI is displayed if
+            // the user is not authenticated (or authentication fails) and
+            // the connection list UI (or the client for the only available
+            // connection, if there is only one) is displayed if the user is
+            // authenticated.
             function resetUI() {
 
+                // Get parameters from query string
+                var parameters = window.location.search.substring(1);
+
                 var configs;
                 try {
-                    configs = getConfigList();
+                    configs = getConfigList(parameters);
                 }
                 catch (e) {
 
-                    console.log(e);
-
                     // Show login UI if unable to get configs
                     loginUI.style.display = "";
                     connectionListUI.style.display = "none";
 
                 // If only one connection, redirect to that.
                 if (configs.length == 1) {
-                    window.location.href = "client.xhtml?" + encodeURIComponent(configs[0].id);
+                    window.location.href = getClientURL(configs[0].id);
                     return;
                 }
 
                     var protocol = document.createElement("td");
                     var id = document.createElement("td");
 
+                    var protocolIcon = document.createElement("div");
+                    protocolIcon.className = "protocol icon " + configs[i].protocol;
+
                     // Set CSS
                     protocol.className = "protocol";
                     id.className = "name";
 
                     // Create link to client
                     var clientLink = document.createElement("a");
-                    clientLink.setAttribute("href",
-                        "client.xhtml?" + encodeURIComponent(configs[i].id));
+                    clientLink.setAttribute("href", getClientURL(configs[i].id));
 
                     // Set cell contents
-                    protocol.textContent   = configs[i].protocol;
+                    protocol.appendChild(protocolIcon);
+                    //protocol.textContent   = configs[i].protocol;
                     clientLink.textContent = configs[i].id;
                     id.appendChild(clientLink);
 
             var loginForm = document.getElementById("login-form");
             var loginUI = document.getElementById("login-ui");
             var connectionListUI = document.getElementById("connection-list-ui");
+            var logout = document.getElementById("logout");
+            var username = document.getElementById("username");
+            var password = document.getElementById("password");
 
-            // TODO: Get connection list
-            // On no-auth fail, show login UI 
+            logout.onclick = function() {
+                window.location.href = "logout";
+            };
 
             loginForm.onsubmit = function() {
 
-                var username = document.getElementById("username");
-                var password = document.getElementById("password");
+                // Get parameters from query string
+                var parameters = window.location.search.substring(1);
 
+                // Get username and password from form
                 var data =
                        "username=" + encodeURIComponent(username.value)
                     + "&password=" + encodeURIComponent(password.value)
 
+                // Include query parameters in submission data
+                if (parameters) data += "&" + parameters;
+
                 try {
 
                     // Log in
 
             }
 
+            // Turn off autocorrect and autocapitalization on usename 
+            username.setAttribute("autocorrect", "off");
+            username.setAttribute("autocapitalize", "off");
+
             resetUI();
 
             /* ]]> */ </script>