make api to be a rest api returning json, no redirects
support reauthorizing facebook
This commit is contained in:
mixedpuppy 2010-09-02 14:02:32 -07:00
Родитель 75742d97b6
Коммит 89ff55847e
2 изменённых файлов: 49 добавлений и 10 удалений

Просмотреть файл

@ -51,13 +51,14 @@
<!-- send form -->
<div class="section send">
<form name="messageForm" id="messageForm" action="/api/send/send" method="POST">
<form name="messageForm" id="messageForm" action="#">
<div class="row">
<div class="c1">
<input name="message">
Send via
<input type="radio" name="domain" value="twitter.com">Twitter
<input type="radio" name="domain" value="facebook.com">Facebook
<input type="radio" name="domain" value="noservice.com">No Service
<input type="hidden" name="end_point_success" value="/scratch/send/#success">
<input type="hidden" name="end_point_failure" value="/scratch/send/#failure">
@ -133,10 +134,10 @@
</div>
<!-- general failure section - an error other than auth failure...-->
<div class="section failure hidden">
<div id="resultMsg" class="section failure hidden">
<div class="row">
<div class="c1">
<p>Sorry - we failed for obscure reasons...</p>
<p id="resultReason">Sorry - we failed for obscure reasons...</p>
</div>
</div>
</div>

Просмотреть файл

@ -48,19 +48,19 @@ function (require, $, fn, rdapi, placeholder, url) {
});
}
if (value==="auth_failure") {
document.authForm.domain.value = localStorage['X-Send-Domain']
document.authForm.submit()
console.log("submitted auth form...")
reauthorize();
} else if (value==="auth_success") {
debugger;
// XXX should we automatically resend?
var domain = localStorage['X-Send-Domain'];
var message = localStorage['X-Send-Message'];
var radio = document.messageForm.domain;
for(var i = 0; i < radio.length; i++) {
if(radio[i].value==localStorage['X-Send-Domain']) {
if(radio[i].value==domain) {
radio[i].checked = true;
}
}
document.messageForm.message.value = localStorage['X-Send-Domain'];
document.messageForm.submit()
document.messageForm.message.value = message;
sendMessage();
}
//Animate!
@ -71,6 +71,43 @@ function (require, $, fn, rdapi, placeholder, url) {
//Set up hashchange listener
window.addEventListener("hashchange", onHashChange, false);
function reauthorize() {
document.authForm.domain.value = localStorage['X-Send-Domain']
document.authForm.submit()
console.log("submitted auth form...")
}
function sendMessage() {
var domain = localStorage['X-Send-Domain'];
var message = localStorage['X-Send-Message'];
rdapi('send', {
type: 'POST',
data: {
domain: domain,
message: message
},
success: function (json) {
// {'reason': u'Status is a duplicate.', 'provider': u'twitter.com'}
$("#resultMsg").removeClass("hidden")
if (json['error'] && json['error']['reason']) {
$("#resultReason").text("Error: "+json['error']['reason']);
if (json['error']['code'] == 401) {
reauthorize();
}
}
else {
$("#resultReason").text("Message Sent");
localStorage['X-Send-Domain'] = '';
localStorage['X-Send-Message'] = '';
}
},
error: function (xhr, textStatus, err) {
$("#resultMsg").removeClass("hidden")
$("#resultReason").text("XHR Error: "+err)
}
});
}
$(function () {
$("#messageForm")
@ -98,6 +135,7 @@ function (require, $, fn, rdapi, placeholder, url) {
localStorage['X-Send-Domain'] = radio[i].value;
}
}
sendMessage();
})
.each(function (i, node) {
placeholder(node);