Grey out username text field for bugs when logged in.
authorKai Krueger <kakrueger@gmail.com>
Thu, 21 Apr 2011 15:05:44 +0000 (09:05 -0600)
committerKai Krueger <kakrueger@gmail.com>
Thu, 21 Apr 2011 15:05:44 +0000 (09:05 -0600)
app/views/site/index.html.erb
public/javascripts/openstreetbugs.js

index 633a7ba3b0c9ee1edbdf7e2408c58af6ef03ea6e..08bada0b998cab34a4a2dce3030da3fa48600adb 100644 (file)
@@ -25,7 +25,7 @@
 <div id="permalink">
   <a href="/" id="permalinkanchor"><%= t 'site.index.permalink' %></a><br/>
   <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a><br/>
-  <a href="javascript:void()" id="ReportBug">Report a problem</a>      
+  <a href="javascript:void();" id="ReportBug">Report a problem</a>     
 </div>
 
 <div id="attribution">
@@ -129,6 +129,10 @@ end
 
   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
 
+  <% if @user %>
+    var loginName = "<%= @user.display_name %>"
+  <% end %>
+
   function createBugCallBack() {
        map.osbControl.deactivate();
        document.getElementById("OpenLayers.Map_18_OpenLayers_Container").style.cursor = "default";
index 888477e7f3094824c3e05a8aedbe49c481d1af0d..fa3586ba39b375776333ceb274a9142eb459023f 100644 (file)
@@ -396,11 +396,22 @@ OpenLayers.Layer.OpenStreetBugs = new OpenLayers.Class(OpenLayers.Layer.Markers,
                        el1.appendChild(el2);
                        el2 = document.createElement("dd");
                        var inputUsername = document.createElement("input");
-                       inputUsername.value = this.username;
+                       var inputUsername = document.createElement("input");;
+                       if (typeof loginName === 'undefined') {
+                               inputUsername.value = this.username;
+                       } else {
+                               inputUsername.value = loginName;
+                               inputUsername.setAttribute('disabled','true');
+                       }
                        inputUsername.className = "osbUsername";
                        inputUsername.onkeyup = function(){ layer.setUserName(inputUsername.value); };
                        el2.appendChild(inputUsername);
-                       el1.appendChild(el2);
+                       el3 = document.createElement("a");
+                       el3.setAttribute("href","login");
+                       el3.className = "hide_if_logged_in";
+                       el3.appendChild(document.createTextNode(OpenLayers.i18n("Login")));
+                       el2.appendChild(el3)
+                       el1.appendChild(el2);                   
 
                        el2 = document.createElement("dt");
                        el2.appendChild(document.createTextNode(OpenLayers.i18n("Comment")));
@@ -410,6 +421,7 @@ OpenLayers.Layer.OpenStreetBugs = new OpenLayers.Class(OpenLayers.Layer.Markers,
                        inputComment.setAttribute("cols",40);                   
                        el2.appendChild(inputComment);
                        el1.appendChild(el2);
+                       
                        el_form.appendChild(el1);
 
                        el1 = document.createElement("ul");
@@ -646,11 +658,22 @@ OpenLayers.Control.OpenStreetBugs = new OpenLayers.Class(OpenLayers.Control, {
                el2.appendChild(document.createTextNode(OpenLayers.i18n("Nickname")));
                el1.appendChild(el2);
                el2 = document.createElement("dd");
-               var inputUsername = document.createElement("input");
-               inputUsername.value = this.osbLayer.username;
+               var inputUsername = document.createElement("input");;
+               if (typeof loginName === 'undefined') {
+                   inputUsername.value = this.osbLayer.username;
+               } else {
+                       inputUsername.value = loginName;
+                       inputUsername.setAttribute('disabled','true');
+               }               
                inputUsername.className = "osbUsername";
+               
                inputUsername.onkeyup = function(){ control.osbLayer.setUserName(inputUsername.value); };
                el2.appendChild(inputUsername);
+               el3 = document.createElement("a");
+               el3.setAttribute("href","login");
+               el3.className = "hide_if_logged_in";
+               el3.appendChild(document.createTextNode(OpenLayers.i18n("Login")));
+               el2.appendChild(el3);
                el1.appendChild(el2);
 
                el2 = document.createElement("dt");