connection page working now..

This commit is contained in:
Harry Bomrah 2012-05-03 14:40:54 +08:00
parent 6b8c79a9a8
commit d6cbbff9de
5 changed files with 137 additions and 59 deletions

View File

@ -752,15 +752,52 @@ var orbitDesktop = function(dom){
var connection = function(){ var connection = function(){
var bindHandlers = function(){ var bindHandlers = function(){
$("#gmail_connect_btn").click(function(){ $("#connection_setting ul a").click(function(){
var usernm = $("input#gmail_username").val(), var what = $(this).attr("for"),
pwd = $("input#gmail_password").val(),
type = $(this).attr("href"), type = $(this).attr("href"),
what = "edit"; $ul = $("#"+type+"_connection"),
if(usernm!="" && pwd!="") usernm = $ul.find("input[type=text]").val(),
pwd = $ul.find("input[type=password]").val();
switch(what){
case "save":
case "new":
if(usernm!="" && pwd!=""){
$ul.find("input[type=text]").replaceWith("<div class='c_info usrnm'>"+usernm+"</div>")
$ul.find("input[type=password]").replaceWith("<div class='c_info pwd'>&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;</div>");
$(this).text("Edit").attr("for","edit");
$(this).parent().find("a[for=delete]").show();
$ul.find("span.c_status").text("Connected").addClass("c_status_on");
if(what=="save")
what="edit";
saveaccount(usernm,pwd,type,what); saveaccount(usernm,pwd,type,what);
}
break;
case "edit":
var un = $ul.find("div.usrnm").text();
$ul.find("div.usrnm").replaceWith('<input type="text" value="'+un+'">');
$ul.find("div.pwd").replaceWith('<input type="password">');
$(this).text("Save").attr("for","save");
break;
case "delete":
var $this = $(this);
o.confirm({
message : "Are you sure that you want to remove this account?",
buttons : ["Yes","No"],
highlighted : 2
},function(reply){
if(reply){
$this.hide();
$ul.find("div.usrnm").replaceWith('<input type="text">');
$ul.find("div.pwd").replaceWith('<input type="password">');
$ul.find("span.c_status").text("No Connection").removeClass("c_status_on");
$this.parent().find("a[for=edit]").text("Connect").attr("for","new");
saveaccount("","",type,what);
}
})
break;
}
}); })
var $conlist = $('.s_form'), var $conlist = $('.s_form'),
conlist_w = $conlist.length * $conlist.outerWidth(true) + ($conlist.length - 1) * 25; conlist_w = $conlist.length * $conlist.outerWidth(true) + ($conlist.length - 1) * 25;
@ -776,16 +813,34 @@ var orbitDesktop = function(dom){
} }
var saveaccount = function(usernm,pwd,type,what){ var saveaccount = function(usernm,pwd,type,what){
$.post("/desktop/save_account_info",{email:usernm,password:pwd,account:type,dowhat:what},function(result){ $.post("/desktop/save_account_info",{email:usernm,password:pwd,account:type,dowhat:what},function(result){
if(what!="delete"){
if(result[0].success=="true") if(result[0].success=="true")
o.notify("Gmail account connected!!","success",2); o.notify(type+" account connected!!","success",2);
else else
o.notify("Gmail account connection failed!!","imp",2); o.notify(type+" account connection failed!!","imp",2);
}else{
if(result[0].success=="true")
o.notify(type+" account removed!!","success",2);
else
o.notify(type+" account removal failed!!","imp",2);
}
}) })
} }
$("div#settings div#panel_r").load("/desktop/settingconnection",function(){ $("div#settings div#panel_r").load("/desktop/settingconnection",function(){
$.getJSON("desktop/getaccounts",function(accounts){
$.each(accounts,function(i,account){
$ul = $("#"+account.type+"_connection");
$ul.find("input[type=text]").replaceWith("<div class='c_info usrnm'>"+account.email+"</div>")
$ul.find("input[type=password]").replaceWith("<div class='c_info pwd'>&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;</div>");
$ul.find("a[for=new]").text("Edit").attr("for","edit");
$ul.find("a[for=delete]").show();
$ul.find("span.c_status").text("Connected").addClass("c_status_on");
})
bindHandlers(); bindHandlers();
}) })
})
} }
$(o.contentHolder).empty().load("/desktop/"+target,function(){ $(o.contentHolder).empty().load("/desktop/"+target,function(){

View File

@ -14,8 +14,11 @@ class OtheraccountsController< ApplicationController
when "new" when "new"
OtherAccount.create(user_id: current_user.id, email: @email, encrypted_password: @password, type: @account) OtherAccount.create(user_id: current_user.id, email: @email, encrypted_password: @password, type: @account)
when "edit" when "edit"
@otheraccount = OtherAccount.where(:type.all => [@account],:user_id.all => [current_user.id]) @otheraccount = OtherAccount.where(:type.all => [@account],:user_id.all => [current_user.id]) rescue nil
@otheraccount.first.update_attributes(:email => @email, :encrypted_password => @password) @otheraccount.first.update_attributes(:email => @email, :encrypted_password => @password)
when "delete"
@otheraccount = OtherAccount.where(:type.all => [@account], :user_id.all => [current_user.id]) rescue nil
@otheraccount.destroy_all
end end
a = Array.new a = Array.new
a << {"success"=>"true"} a << {"success"=>"true"}
@ -23,7 +26,8 @@ class OtheraccountsController< ApplicationController
end end
def gmail def gmail
@gmailaccount = OtherAccount.where(:type.all => ["gmail"],:user_id.all => [current_user.id]) @gmailaccount = OtherAccount.where(:type.all => ["gmail"],:user_id.all => [current_user.id]) rescue nil
if @gmailaccount.first != nil
@decrypted_password = @gmailaccount.first.encrypted_password.decrypt @decrypted_password = @gmailaccount.first.encrypted_password.decrypt
@email = @gmailaccount.first.email @email = @gmailaccount.first.email
url = URI.parse("https://mail.google.com/mail/feed/atom") url = URI.parse("https://mail.google.com/mail/feed/atom")
@ -37,5 +41,16 @@ class OtheraccountsController< ApplicationController
root = Document.new(response.read_body).root root = Document.new(response.read_body).root
render :text=>root render :text=>root
else
msg = "<HEAD><ERROR>true</ERROR><ERRORMSG>Account setting problem.</ERRORMSG></HEAD>"
respond_to do |m|
m.xml {render :xml=>msg}
end
end
end
def getaccounts
@accounts = OtherAccount.where(:user_id.all => [current_user.id])
render :json => @accounts.to_json
end end
end end

View File

@ -27,37 +27,39 @@
<td><label for="s_name1">Password</label><input type="password" /></td> <td><label for="s_name1">Password</label><input type="password" /></td>
</tr> </tr>
</table> --> </table> -->
<ul class="s_form w2 hp"> <ul class="s_form w2 hp" id="facebook_connection">
<li><span class="c_status">No Connection</span></li> <li><span class="c_status">No Connection</span></li>
<li><img src="assets/connection/facebook.png" alt="" class="c_icon"><h1 class="c_name">Facebook</h1></li> <li><img src="assets/connection/facebook.png" alt="" class="c_icon"><h1 class="c_name">Facebook</h1></li>
<li><label for="">Account</label><input type="text"></li> <li><label for="">Account</label><input type="text"></li>
<li><label for="">Password</label><input type="password"></li> <li><label for="">Password</label><input type="password"></li>
<li> <li>
<div class="s_action"> <div class="s_action">
<a href="" class="setting_btn thmc1 thmtxt hp disable">Connecting</a> <a href="facebook" class="setting_btn thmc1 thmtxt hp" onclick="return false;" for="new">Connect</a>
<a href="facebook" class="setting_btn thmc1 thmtxt hp" onclick="return false;" for="delete" style="display:none;">Remove</a>
</div> </div>
</li> </li>
</ul> </ul>
<ul class="s_form w2 hp"> <ul class="s_form w2 hp" id="twitter_connection">
<li><spanspan class="c_status">No Connection</span></li> <li><span class="c_status">No Connection</span></li>
<li><img src="assets/connection/twitter.png" alt="" class="c_icon"><h1 class="c_name">Twitter</h1></li> <li><img src="assets/connection/twitter.png" alt="" class="c_icon"><h1 class="c_name">Twitter</h1></li>
<li><label for="">Account</label><input type="text"></li> <li><label for="">Account</label><input type="text"></li>
<li><label for="">Password</label><input type="password"></li> <li><label for="">Password</label><input type="password"></li>
<li> <li>
<div class="s_action"> <div class="s_action">
<a href="" class="setting_btn thmc1 thmtxt hp">Connect</a> <a href="twitter" class="setting_btn thmc1 thmtxt hp" onclick="return false;" for="new">Connect</a>
<a href="twitter" class="setting_btn thmc1 thmtxt hp" onclick="return false;" for="delete" style="display:none;">Remove</a>
</div> </div>
</li> </li>
</ul> </ul>
<ul class="s_form w2 hp"> <ul class="s_form w2 hp" id="gmail_connection">
<li><span class="c_status c_status_on">Connected</span></li> <li><span class="c_status">No Connection</span></li>
<li><img src="assets/connection/gmail.png" alt="" class="c_icon"><h1 class="c_name">gmail</h1></li> <li><img src="assets/connection/gmail.png" alt="" class="c_icon"><h1 class="c_name">Gmail</h1></li>
<li><label for="">Account</label><div class="c_info">Harry</div></li> <li><label for="">Account</label><input type="text"></li><!-- <div class="c_info">Harry</div></li> -->
<li><label for="">Password</label><div class="c_info">&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;</div></li> <li><label for="">Password</label><input type="password"></li><!-- <div class="c_info">&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;</div></li> -->
<li> <li>
<div class="s_action"> <div class="s_action">
<a href="" class="setting_btn thmc1 thmtxt hp">Edit</a> <a href="gmail" class="setting_btn thmc1 thmtxt hp" onclick="return false;" for="new">Connect</a>
<a href="" class="setting_btn thmc1 thmtxt hp">Remove</a> <a href="gmail" class="setting_btn thmc1 thmtxt hp" onclick="return false;" for="delete" style="display:none;">Remove</a>
</div> </div>
</li> </li>
</ul> </ul>

View File

@ -119,6 +119,7 @@ Orbit::Application.routes.draw do
match '/desktop/journal_p_add/'=>'desktop#journal_p_add' match '/desktop/journal_p_add/'=>'desktop#journal_p_add'
match '/desktop/settingconnection/'=>'desktop#settingconnection' match '/desktop/settingconnection/'=>'desktop#settingconnection'
match '/desktop/forgmail/'=>'otheraccounts#gmail' match '/desktop/forgmail/'=>'otheraccounts#gmail'
match '/desktop/getaccounts'=>'otheraccounts#getaccounts'
match '/desktop/save_account_info/'=>'otheraccounts#saveaccountinfo' match '/desktop/save_account_info/'=>'otheraccounts#saveaccountinfo'
match '/desktop/temp_func/'=>'desktop#temp_func' match '/desktop/temp_func/'=>'desktop#temp_func'

View File

@ -3,6 +3,9 @@ var gmail = function(){
url: "/desktop/forgmail", url: "/desktop/forgmail",
dataType : "xml", dataType : "xml",
success:function(data){ success:function(data){
if($(data).find("HEAD").find("ERROR").text()=="true"){
$("#gmail #content #msgbody").text($(data).find("HEAD").find("ERRORMSG").text());
}else{
if($(data).find("HEAD").find("TITLE").text()=="Unauthorized"){ if($(data).find("HEAD").find("TITLE").text()=="Unauthorized"){
$("#gmail #forerror").text($(data).find("HEAD").find("TITLE").text()).show(); $("#gmail #forerror").text($(data).find("HEAD").find("TITLE").text()).show();
}else{ }else{
@ -27,8 +30,10 @@ var gmail = function(){
}) })
} }
} }
}
$("#gmail #loading").hide(); $("#gmail #loading").hide();
$("#gmail #content").show(); $("#gmail #content").show();
} }
}); });
} }