From 5b7c4224469187777961b24c3060f79f75a3fe58 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 2 May 2012 17:05:40 +0800 Subject: [PATCH 1/2] position update fixed.. --- app/assets/javascripts/orbitdesktop.js | 46 ++++++++++++-------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 623f3f6b..1cdc8339 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -1,9 +1,7 @@ + // JavaScript Document //harry //Inititialize function will initialize desktop - - - $.extend($.expr[':'], { 'containsi': function (elem, i, match, array) { return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; @@ -25,7 +23,6 @@ var orbitDesktop = function(dom){ this.contentHolder = dom; this.themesettings = ""; this.theme = "4f8d3f493b67fcd05f086359"; -// this.themefolder = "themes"; this.transitionTime = 500; this.currenthtml = "desktop.html"; this.currentface = "home"; @@ -136,11 +133,11 @@ var orbitDesktop = function(dom){ o.currentface = "home"; var bindHandlers = function(){ // this function will bind all the handlers in the desktop - var groupWrapperWidth = 0; $("div#desktop .group").each(function(){groupWrapperWidth+=$(this).outerWidth(true);}); $("div#desktop #group_wrapper").css("width",groupWrapperWidth); + var first = true; $("div#desktop .g_col").sortable({ connectWith: ".g_col", tolerance: 'pointer' , @@ -148,37 +145,37 @@ var orbitDesktop = function(dom){ containment: '#group_wrapper', helper: 'clone', stop:function(){ - var newpostitions = new Array; - var groupids = new Array; - $.each($("div#desktop .group"),function(i,grp){ - var groupone = new Array; - groupids.push($(grp).attr("id")); - $ul = $(grp).find(".g_col .element"); - $.each($ul,function(){ - groupone.push($(this).attr("id")); - }) - newpostitions.push(groupone); - }); - $.post("/desktop/newpositions",{"sectionid":o.sectionId,"newpos":newpostitions,"groupids":groupids}); + first = true; }, update:function(){ + if(first){ + first = false; + var newpostitions = new Array; + var groupids = new Array; + $.each($("div#desktop .group"),function(i,grp){ + var groupone = new Array; + groupids.push($(grp).attr("id")); + $ul = $(grp).find(".g_col .element"); + $.each($ul,function(){ + groupone.push($(this).attr("id")); + }) + newpostitions.push(groupone); + }); + $.post("/desktop/newpositions",{"sectionid":o.sectionId,"newpos":newpostitions,"groupids":groupids}); + } var s = $(this).find('.element').length; if(s!=0){ last = $(this).find('.element').eq(s-1).position(), lasth = $(this).find('.element').eq(s-1).outerHeight(true); - if ((last.top+lasth)>528){ $(this).sortable('cancel'); } }else{$(this).remove();} - }, receive: function(event, ui){ - var s = $(this).find('.element').length, last = $(this).find('.element').eq(s-1).position(), lasth = $(this).find('.element').eq(s-1).outerHeight(true); - if ((last.top+lasth)>528){ $(ui.sender).sortable('cancel'); } @@ -228,12 +225,12 @@ var orbitDesktop = function(dom){ bw = parseInt(brick[0].substr(1)), bh = parseInt(brick[1].substr(1)), bd = bw * bh; - if(bh==1 && bw==1){ small++; }else if(bh!=1 && bw!=1){ single = true; - } + } + if(small==2){ small=0; single=false; @@ -899,5 +896,4 @@ orbitDesktop.prototype.currentLanguage = "en"; orbitDesktop.prototype.currentUsername = "Harry"; var uselessfunction = function(){ $.post("/desktop/temp_func",{sectionid:"4f83e7bbbd98eb041600001d"}); -} - +} \ No newline at end of file From d6cbbff9de2b7e8bb9a993821edb3805d59330c1 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 3 May 2012 14:40:54 +0800 Subject: [PATCH 2/2] connection page working now.. --- app/assets/javascripts/orbitdesktop.js | 83 +++++++++++++++---- app/controllers/otheraccounts_controller.rb | 41 ++++++--- .../desktop/settings/connections.html.erb | 26 +++--- config/routes.rb | 1 + public/desktop_widgets/gmail/gmail.js | 45 +++++----- 5 files changed, 137 insertions(+), 59 deletions(-) diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 1e406b91..75691656 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -752,15 +752,52 @@ var orbitDesktop = function(dom){ var connection = function(){ var bindHandlers = function(){ - $("#gmail_connect_btn").click(function(){ - var usernm = $("input#gmail_username").val(), - pwd = $("input#gmail_password").val(), - type = $(this).attr("href"), - what = "edit"; - if(usernm!="" && pwd!="") - saveaccount(usernm,pwd,type,what); - - }); + $("#connection_setting ul a").click(function(){ + var what = $(this).attr("for"), + type = $(this).attr("href"), + $ul = $("#"+type+"_connection"), + 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("
"+usernm+"
") + $ul.find("input[type=password]").replaceWith("
••••••
"); + $(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); + } + break; + case "edit": + var un = $ul.find("div.usrnm").text(); + $ul.find("div.usrnm").replaceWith(''); + $ul.find("div.pwd").replaceWith(''); + $(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(''); + $ul.find("div.pwd").replaceWith(''); + $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'), conlist_w = $conlist.length * $conlist.outerWidth(true) + ($conlist.length - 1) * 25; @@ -776,14 +813,32 @@ var orbitDesktop = function(dom){ } var saveaccount = function(usernm,pwd,type,what){ $.post("/desktop/save_account_info",{email:usernm,password:pwd,account:type,dowhat:what},function(result){ - if(result[0].success=="true") - o.notify("Gmail account connected!!","success",2); - else - o.notify("Gmail account connection failed!!","imp",2); + if(what!="delete"){ + if(result[0].success=="true") + o.notify(type+" account connected!!","success",2); + else + 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(){ - bindHandlers(); + $.getJSON("desktop/getaccounts",function(accounts){ + $.each(accounts,function(i,account){ + $ul = $("#"+account.type+"_connection"); + $ul.find("input[type=text]").replaceWith("
"+account.email+"
") + $ul.find("input[type=password]").replaceWith("
••••••
"); + $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(); + }) + }) } diff --git a/app/controllers/otheraccounts_controller.rb b/app/controllers/otheraccounts_controller.rb index a9e9b858..65a9b5a4 100644 --- a/app/controllers/otheraccounts_controller.rb +++ b/app/controllers/otheraccounts_controller.rb @@ -14,8 +14,11 @@ class OtheraccountsController< ApplicationController when "new" OtherAccount.create(user_id: current_user.id, email: @email, encrypted_password: @password, type: @account) 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) + when "delete" + @otheraccount = OtherAccount.where(:type.all => [@account], :user_id.all => [current_user.id]) rescue nil + @otheraccount.destroy_all end a = Array.new a << {"success"=>"true"} @@ -23,19 +26,31 @@ class OtheraccountsController< ApplicationController end def gmail - @gmailaccount = OtherAccount.where(:type.all => ["gmail"],:user_id.all => [current_user.id]) - @decrypted_password = @gmailaccount.first.encrypted_password.decrypt - @email = @gmailaccount.first.email - url = URI.parse("https://mail.google.com/mail/feed/atom") - req = Net::HTTP::Get.new(url.path) - req.basic_auth @email, @decrypted_password - req.content_type = 'text/xml' + @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 + @email = @gmailaccount.first.email + url = URI.parse("https://mail.google.com/mail/feed/atom") + req = Net::HTTP::Get.new(url.path) + req.basic_auth @email, @decrypted_password + req.content_type = 'text/xml' - http = Net::HTTP.new(url.host, url.port) - http.use_ssl = true - response = http.start { |http| http.request(req) } + http = Net::HTTP.new(url.host, url.port) + http.use_ssl = true + response = http.start { |http| http.request(req) } - root = Document.new(response.read_body).root - render :text=>root + root = Document.new(response.read_body).root + render :text=>root + else + msg = "trueAccount setting problem." + 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 \ No newline at end of file diff --git a/app/views/desktop/settings/connections.html.erb b/app/views/desktop/settings/connections.html.erb index 3619a583..fd49915a 100644 --- a/app/views/desktop/settings/connections.html.erb +++ b/app/views/desktop/settings/connections.html.erb @@ -27,37 +27,39 @@ --> -