Permalink
Browse files

attempting to combine the two steps of installing app into one click

  • Loading branch information...
1 parent a948015 commit bce3b902df32a5dbe354ca2e5aef7dbf4f848ad6 @benadida benadida committed Mar 31, 2011
Showing with 53 additions and 47 deletions.
  1. +39 −45 index.html
  2. +1 −1 server.py
  3. +13 −1 setcredentials.html
View
@@ -8,43 +8,51 @@
<script>
function disconnect() {
- window.localStorage.setItem("user_id", null);
- window.localStorage.setItem("full_name", null);
- window.localStorage.setItem("credentials", null);
+// window.localStorage.setItem("user_id", null);
+// window.localStorage.setItem("full_name", null);
+// window.localStorage.setItem("credentials", null);
+ window.localStorage.clear();
$("#connected").hide();
$("#notconnected").show();
}
-function install() {
- navigator.apps.install({
- url:"/{{app_name}}.webapp",
- onsuccess: function() {
- $("#notinstalled").fadeOut($("#installed").fadeIn());
- },
- onerror: function() {
-
- }
- });
+function get_credentials() {
+ if (window.localStorage.getItem("user_id")) {
+ return {
+ 'user_id': window.localStorage.getItem("user_id"),
+ 'full_name': window.localStorage.getItem("full_name"),
+ 'credentials': window.localStorage.getItem("credentials"),
+ }
+ } else {
+ return null;
+ }
+}
+
+function is_connected(cb) {
+ if (!get_credentials())
+ cb(false);
+
+ // is the app installed
+ navigator.apps.amInstalled(cb);
}
+
function init() {
- if (window.localStorage.getItem("user_id")) {
- $("#notconnected").hide();
- } else {
- $("#connected").hide();
- }
- // XX check installed
- $("#installed").hide();
- $("#notinstalled").hide();
- navigator.apps.amInstalled(function(installed) {
- if (installed) $("#installed").show();
- else $("#notinstalled").show();
+ is_connected(function(connected_p) {
+ if (connected_p) {
+ $("#notinstalled").hide();
+ } else {
+ $("#installed").hide();
+ }
});
}
+
+$(document).ready(init);
+
</script>
</head>
-<body onLoad="init();">
+<body>
<div class="container">
<p>This is the {{config.PHOTO_SITE}} Connector application.</p>
@@ -61,36 +69,22 @@
<p>The {{config.PHOTO_SITE}} Connector application is <em>not installed.</em> You will
need to install it into your browser before it can do anything interesting for you.</p>
-<p style="text-align:center">
- <a class="button" href="javascript:install()">Install Application</a>
-</p>
-</div>
-
-<div id="installed">
-<p>The {{config.PHOTO_SITE}} Connector application is installed.</p>
-</div>
-
-<div id="notconnected">
-<p>By connecting to {{config.PHOTO_SITE}}, you will authorize your browser to connect
-to {{config.PHOTO_SITE}} to share your photos with other websites and web applications.
-You will still be asked to give your permission before anything is shared.
-</p>
-
<div style="text-align:center">
- <a class="button" href="/connect/start">Connect to {{config.PHOTO_SITE}}</a>
+ <a class="button" href="/connect/start">Connect to {{config.PHOTO_SITE}} and Install the App</a>
</div>
</div>
-<div id="connected">
-<p>This browser is connected to {{config.PHOTO_SITE}}. It may now share your photos with
-other websites and web applications. You will still be asked to give your
-permission before anything is shared.
+
+<div id="installed">
+<p>
+ The {{config.PHOTO_SITE}} Connector application is installed and configured.
</p>
<div style="text-align:center">
<a class="button" href="javascript:disconnect()">Disconnect</a>
</div>
</div>
+</div>
</div> <!-- end info -->
View
@@ -115,7 +115,7 @@ def get(self):
photosite.complete_authorization(self, request_token, self.on_success, self.on_error)
def on_success(self, user_id, full_name, credentials):
- self.render_platform("setcredentials", user_info={'user_id': user_id, 'full_name' : full_name, 'credentials' : simplejson.dumps(credentials)})
+ self.render_platform("setcredentials", user_info={'user_id': user_id, 'full_name' : full_name, 'credentials' : simplejson.dumps(credentials)}, app_name=APP_NAME)
def on_error(self, message):
self.write(message)
View
@@ -7,12 +7,24 @@
<script language="javascript">
+function install(cb) {
+ navigator.apps.install({
+ url:"/{{app_name}}.webapp",
+ onsuccess: cb,
+ onerror: function() {
+ alert('there was a problem installing the app');
+ }
+ });
+}
+
$(document).ready(function() {
window.localStorage.setItem("user_id", "{{ user_info['user_id'] }}");
window.localStorage.setItem("full_name", "{{ user_info['full_name'] }}");
window.localStorage.setItem("credentials", '{{ user_info["credentials"] }}');
- window.location = "/";
+ install(function() {
+ window.location = "/";
+ });
});
</script>

0 comments on commit bce3b90

Please sign in to comment.