small modifications so that at least something can work
authorRobert Kaiser <kairo@kairo.at>
Thu, 18 Apr 2013 01:06:57 +0000 (03:06 +0200)
committerRobert Kaiser <kairo@kairo.at>
Thu, 18 Apr 2013 01:06:57 +0000 (03:06 +0200)
index.html
js/ui.js

index 24de1eeed64458a4a910ff02e01bd840b435fb6e..ef087e9aded7ae578fb9e77c80516312e1aa8090 100644 (file)
@@ -27,7 +27,7 @@
 <input type="button" id="dumpTrackButton" value="Dump"
        onclick="saveTrackDump();" class="debugHide">
 <input type="button" id="uploadTrackButton" value="Upload" disabled="true"
-       onclick="uploadTrack();">
+       onclick="uploadTrack();" class="debugHide">
 <input type="button" id="clearTrackButton" value="Clear"
        onclick="clearTrack();"><br/>
 <input type="checkbox" id="trackCheckbox"
@@ -47,6 +47,7 @@ Map style:
 <br/>
 <input type="button" id="clearCacheButton" value="Clear Cached Maps"
        onclick="gTileService.clearDB();">
+<div id="uploadSettingsArea" class="debugHide">
 <p class="settingsSubTitle">OpenStreetMap Track Upload:</p>
 <label for="uploadUser">User name:</label>
 <input type="text" id="uploadUser" maxlength="255"
@@ -54,6 +55,7 @@ Map style:
 <label for="uploadPwd">Password:</label>
 <input type="password" id="uploadPwd" maxlength="255"
        onchange="setUploadField(this);">
+</div>
 </fieldset>
 </div>
 
index f8a45b1d6278ce230a6fb58b261951d6726bb09e..7dc5d331cb0281db9ed4c660b30cb499d8baf98d 100644 (file)
--- a/js/ui.js
+++ b/js/ui.js
@@ -9,7 +9,7 @@ var mainDB;
 var gUIHideCountdown = 0;
 var gWaitCounter = 0;
 var gAction, gActionLabel;
-var gOSMAPIURL = "http://api06.dev.openstreetmap.org/"; // "http://api.openstreetmap.org/";
+var gOSMAPIURL = "http://api.openstreetmap.org/";
 
 window.onload = function() {
   gAction = document.getElementById("action");
@@ -43,6 +43,14 @@ window.onload = function() {
     // For Firefox OS, don't display the "save" button.
     // Do this by setting the debugHide class for testing in debug mode.
     document.getElementById("saveTrackButton").classList.add("debugHide");
+    // For now, only show the upload UI on Firefox OS.
+    document.getElementById("uploadTrackButton").classList.remove("debugHide");
+    // Without OAuth, the login data is useless
+    //document.getElementById("uploadSettingsArea").classList.remove("debugHide");
+  }
+
+  if (gDebug) {
+    gOSMAPIURL = "http://api06.dev.openstreetmap.org/";
   }
 
   initDB();
@@ -61,13 +69,13 @@ window.onload = function() {
       gActionLabel.textContent = "";
       gAction.style.display = "none";
       setTracking(document.getElementById("trackCheckbox"));
-      gPrefs.get("osm_user", function(aValue) {
+      gPrefs.get(gDebug ? "osm_dev_user" : "osm_user", function(aValue) {
         if (aValue) {
           document.getElementById("uploadUser").value = aValue;
           document.getElementById("uploadTrackButton").disabled = false;
         }
       });
-      gPrefs.get("osm_pwd", function(aValue) {
+      gPrefs.get(gDebug ? "osm_dev_pwd" : "osm_pwd", function(aValue) {
         var upwd = document.getElementById("uploadPwd");
         if (aValue)
           document.getElementById("uploadPwd").value = aValue;
@@ -212,11 +220,11 @@ var uiEvHandler = {
 function setUploadField(aField) {
   switch (aField.id) {
     case "uploadUser":
-      gPrefs.set("osm_user", aField.value);
+      gPrefs.set(gDebug ? "osm_dev_user" : "osm_user", aField.value);
       document.getElementById("uploadTrackButton").disabled = !aField.value.length;
       break;
     case "uploadPwd":
-      gPrefs.set("osm_pwd", aField.value);
+      gPrefs.set(gDebug ? "osm_dev_pwd" : "osm_pwd", aField.value);
       break;
   }
 }
@@ -294,11 +302,6 @@ function uploadTrack() {
   formData.append("visibility", "private");
   var XHR = new XMLHttpRequest();
   XHR.onreadystatechange = function() {
-    if (XHR.readyState == 4) {/*
-      gLog.appendChild(document.createElement("li"))
-          .appendChild(document.createTextNode(aURL + " - " + XHR.status +
-                                               " " + XHR.statusText));*/
-    }
     if (XHR.readyState == 4 && XHR.status == 200) {
       // so far so good
       reportUploadStatus(true);
@@ -307,9 +310,10 @@ function uploadTrack() {
       reportUploadStatus(false);
     }
   };
-  XHR.open("POST", gOSMAPIURL + "api/0.6/gpx/create", true,
-           document.getElementById("uploadUser").value,
-           document.getElementById("uploadPwd").value);
+  XHR.open("POST", gOSMAPIURL + "api/0.6/gpx/create", true);
+  // Cross-Origin XHR doesn't allow username/password (HTTP Auth), so need to look into OAuth.
+  // But for now, we'll ask the user for entering credentials with this.
+  XHR.withCredentials = true;
   try {
     XHR.send(formData);
   }