From 64be61d61b922fc8709de53715e7cd45f532c4f3 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 26 Apr 2012 14:47:49 +0800 Subject: [PATCH] with gmail widget.. --- app/controllers/desktop_controller.rb | 10 ++++- app/controllers/useless_controller.rb | 21 ++++++++++ app/views/desktop/journal_p.html.erb | 2 +- config/routes.rb | 1 + public/desktop_widgets/gmail/gmail.js | 45 +++++++++++++++++++++ public/desktop_widgets/gmail/index.html.erb | 25 ++++++++++++ 6 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 app/controllers/useless_controller.rb create mode 100644 public/desktop_widgets/gmail/gmail.js create mode 100644 public/desktop_widgets/gmail/index.html.erb diff --git a/app/controllers/desktop_controller.rb b/app/controllers/desktop_controller.rb index 664b5ba4..8a9670be 100644 --- a/app/controllers/desktop_controller.rb +++ b/app/controllers/desktop_controller.rb @@ -1,7 +1,8 @@ + class DesktopController< ApplicationController layout 'desktop' before_filter :authenticate_user! - + #to load pages... def index @@ -22,6 +23,7 @@ class DesktopController< ApplicationController def sections render :layout => false end + def settings render :layout => false end @@ -181,4 +183,10 @@ class DesktopController< ApplicationController render :json=>b.to_json end + def forgmail + + feed = Net::HTTP.get_response(URI.parse("https://mail.google.com/mail/feed/atom")).body + render :xml=>feed + end + end \ No newline at end of file diff --git a/app/controllers/useless_controller.rb b/app/controllers/useless_controller.rb new file mode 100644 index 00000000..402e5c6a --- /dev/null +++ b/app/controllers/useless_controller.rb @@ -0,0 +1,21 @@ +class UselessController< ApplicationController + require 'open-uri' + require 'rexml/document' + require 'net/http' + require 'net/https' + include REXML + + def forgmail + url = URI.parse("https://mail.google.com/mail/feed/atom") + req = Net::HTTP::Get.new(url.path) + req.basic_auth params['username'], params['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) } + + root = Document.new(response.read_body).root + render :text=>root + end +end \ No newline at end of file diff --git a/app/views/desktop/journal_p.html.erb b/app/views/desktop/journal_p.html.erb index 3fe90735..209e3cbd 100644 --- a/app/views/desktop/journal_p.html.erb +++ b/app/views/desktop/journal_p.html.erb @@ -3,7 +3,7 @@
diff --git a/config/routes.rb b/config/routes.rb index 2eb08dac..a46e58f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,6 +117,7 @@ Orbit::Application.routes.draw do match '/desktop/journal_p/'=>'desktop#journal_p' match '/desktop/journal_p_list/'=>'desktop#journal_p_list' match '/desktop/journal_p_add/'=>'desktop#journal_p_add' + match '/desktop/forgmail/'=>'useless#forgmail' match '/desktop/temp_func/'=>'desktop#temp_func' match '/panel/:app_name/front_end/:app_action/:id' => 'pages#show_from_link', :constraints => lambda { |request| diff --git a/public/desktop_widgets/gmail/gmail.js b/public/desktop_widgets/gmail/gmail.js new file mode 100644 index 00000000..14d07c8d --- /dev/null +++ b/public/desktop_widgets/gmail/gmail.js @@ -0,0 +1,45 @@ +var gmail = function(){ + var usernm = $("#gmail input[type=text]").val(); + var pwd = $("#gmail input[type=password]").val(); +// usernm = "hr@rulingcom.com"; +// pwd = "hr08973" + if(usernm!="" && pwd!=""){ + $("#gmail a#gmail_button").text("Check again"); + $("#gmail #loading").show(); + $("#gmail table#form").hide(); + $.ajax({ + url: "/desktop/forgmail", + dataType : "xml", + data : {username:usernm,password:pwd}, + success:function(data){ + if($(data).find("HEAD").find("TITLE").text()=="Unauthorized"){ + $("#gmail #forerror").text($(data).find("HEAD").find("TITLE").text()).show(); + $("#gmail table#form").show(); + }else{ + if($(data).find("fullcount").text()=="0"){ + $("#gmail #forerror").hide(); + $("#gmail #content #msgbody").text("No new mails"); + }else{ + var msg; + if($(data).find("fullcount").text()=="1") + msg = $(data).find("fullcount").text()+" new message in your inbox." + else + msg = $(data).find("fullcount").text()+" new messages in your inbox." + o.notify(msg,"alert",2); + $(data).find("entry").each(function(i,val){ + if(i==0){ + $("#gmail #forerror").hide(); + var atag = $(""+$(this).find("title").text()+""); + $("#gmail #content #subject").html($(this).find("title").text()); + $("#gmail #content #date").text($(this).find("issued").text()); + $("#gmail #content #msgbody").text($(this).find("summary").text()); + } + }) + } + } + $("#gmail #loading").hide(); + $("#gmail #content").show(); + } + }); + } +} \ No newline at end of file diff --git a/public/desktop_widgets/gmail/index.html.erb b/public/desktop_widgets/gmail/index.html.erb new file mode 100644 index 00000000..a7e58569 --- /dev/null +++ b/public/desktop_widgets/gmail/index.html.erb @@ -0,0 +1,25 @@ +
+ + + + + + + + + + + +
Check for new mail
+ + +
+ \ No newline at end of file