Created
August 5, 2011 16:15
-
-
Save adomado/1127890 to your computer and use it in GitHub Desktop.
Myshaadi.in app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(config) { | |
var MyShaadi = { | |
auth : function(username, password, successCb, errorCb) { | |
var endpoint = "http://myshaadi.in/api/users/index.php?action=authenticateUser&resp_type=jsonp&username=" + | |
username + "&password=" + password; | |
$j.ajax({ | |
url : endpoint, | |
dataType : "jsonp", | |
callback : "callback", | |
success : function(response) { | |
if(response) | |
response.error == false ? successCb(response) : errorCb(response); | |
else | |
errorCb({}); | |
} | |
}); // ajax | |
} | |
}; // MyShaadi | |
var MyWedSite = { | |
wedsiteAdmin : "http://myshaadi.in/admin/__UID__", | |
init : function() { | |
}, | |
options : function() { | |
config.api.loadResources(["http://localhost/content_scripts/public/myshaadi_my_wedsite/style.css"], function() { | |
if(MyWedSite.needAuth() == true) | |
MyWedSite.showLogin(); | |
else | |
MyWedSite.gotoAdmin(config.api.getData("uid")); | |
}); | |
}, | |
showLogin : function() { | |
if($j("#mws-container")) | |
$j("#mws-container").remove(); | |
jQuery("<div/>", { | |
id : "mws-container", | |
html : '<table>\ | |
<tr>\ | |
<td id="mws-td-username">\ | |
<ul>\ | |
<li>\ | |
<h3>Username</h3>\ | |
<input id="mws-input-username" type="text" />\ | |
</li>\ | |
</ul>\ | |
</td>\ | |
<td id="mws-td-password">\ | |
<ul class="formdecorator">\ | |
<li>\ | |
<h3>Password</h3>\ | |
<input id="mws-input-password" type="password" />\ | |
</li>\ | |
</ul>\ | |
</td>\ | |
</tr>\ | |
<tr>\ | |
<td id="mws-td-button" colspan="2">\ | |
<div id="mws-auth-message"></div>\ | |
<img src="http://localhost/content_scripts/public/myshaadi_my_wedsite/spinner.gif" id="mws-spinner">\ | |
<input type="button" value="Login">\ | |
</td>\ | |
</tr>\ | |
</table>' | |
}) | |
.appendTo($j("body")) | |
.wijdialog({ | |
title : "Login to MyShaadi.in", | |
width: 375, | |
height: 150, | |
captionButtons: {pin: {visible: false}, refresh: {visible: false}, toggle: {visible: false}, minimize: {visible: false}, maximize: {visible: false}}, | |
close : function() {$j("#mws-container").remove();} | |
}); | |
$j("#mws-td-button input") | |
.button() | |
.click(function() { | |
$j("#mws-auth-message").html(""); | |
$j("#mws-spinner").show(); | |
MyShaadi.auth($j("#mws-input-username").val(), $j("#mws-input-password").val(), MyWedSite.successAuth, MyWedSite.errorAuth); | |
}); | |
}, | |
successAuth : function(response) { | |
$j("#mws-spinner").hide(); | |
$j("#mws-auth-message").html("Successfully logged in. Redirecting to your Wedsite.").css({color: "green"}); | |
MyWedSite.saveAuth(response); | |
setTimeout(function() { | |
MyWedSite.gotoAdmin(response.uid); | |
}, 1000); | |
}, | |
errorAuth : function(response) { | |
$j("#mws-spinner").hide(); | |
$j("#mws-auth-message").html("Error in logging in...").css({color: "red"}); | |
}, | |
saveAuth : function(response) { | |
if(response && response.uid) | |
config.api.setData("uid", response.uid); | |
}, | |
needAuth : function() { | |
var uid = config.api.getData("uid"); | |
if(uid && uid.length > 1) | |
return false; | |
else | |
{ | |
config.api.setData("uid", "0"); | |
return true; | |
} | |
}, | |
// Does redirection to admin URL for wedsite | |
gotoAdmin : function(uid) { | |
document.location.href = MyWedSite.wedsiteAdmin.replace("__UID__", uid); | |
} | |
}; // MyWedSite | |
config.api.callbacks({ | |
init : MyWedSite.init, | |
options : MyWedSite.options | |
}); | |
})({ | |
api : new IJAppApi.v1({appId : "__APP_ID__"}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment