Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
attempting to combine the two steps of installing app into one click
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Mar 31, 2011
1 parent a948015 commit bce3b90
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 47 deletions.
84 changes: 39 additions & 45 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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 -->
Expand Down
2 changes: 1 addition & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion setcredentials.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit bce3b90

Please sign in to comment.