with gmail widget..

This commit is contained in:
Harry Bomrah 2012-04-26 14:47:49 +08:00
parent a298cbd5f6
commit 64be61d61b
6 changed files with 102 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -3,7 +3,7 @@
<div id="content">
<div id="header" class="hh3">
<div class="dtitle w2 hh3 hp">
<span class="thmtxth">Journal Pages</span>
<span class="thmtxth">Journal Papers</span>
</div>
</div>
<div id="holder">

View File

@ -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|

View File

@ -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 = $("<a href='"+$(this).find("link").attr("href")+"'>"+$(this).find("title").text()+"</a>");
$("#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();
}
});
}
}

View File

@ -0,0 +1,25 @@
<div id="gmail">
<div id="forerror" style="color:red;display:none;"></div>
<table id="form">
<tr>
<td><label class="thmtxt" style="width:75px;">Username:</label></td><td><input type="text" style="width:150px;" /></td>
</tr>
<tr>
<td><label class="thmtxt" style="width:75px;">Password:</label></td><td><input type="password" style="width:150px;" /></td>
</tr>
<tr>
<td colspan="2" align='center'><a href="" onclick="gmail();return false;" class='thmtxt' id="gmail_button">Check for new mail</button></td>
</tr>
</table>
<div id="loading" style="display:none" class="thmtxt">Retrieving new emails...</div>
<div id="content" style="display:none;"background-color:#000;height:200px;"" >
<div id="subject" ></div>
<div id="date" class='thmtxt'></div>
<div id="msgbody" class='thmtxt'></div>
</div>
</div>
<script>
$(document).ready(function(){
// gmail();
})
</script>