Desktop Widgtes updates..

This commit is contained in:
Harry Bomrah 2012-11-05 23:04:54 +08:00 committed by chris
parent 3c85f3ef00
commit da5e7f670e
33 changed files with 217 additions and 146 deletions

View File

@ -332,9 +332,9 @@ var orbitDesktop = function(dom){
if(j==0)$group.attr("id",tile.group_id); if(j==0)$group.attr("id",tile.group_id);
if(tile.data_category == "app") if(tile.data_category == "app")
$li = $('<li id="'+tile._id+'" class="element '+tile.shape+' hp vp" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'"><span class="tile '+tilecolor+' '+op+'"></span><a href="'+tile.data_content+'" class="appicon" onclick="return false;"><img src="'+o.iconPath+tile.data_content+'.png" alt="" ></a><h1 class="appname thmtxt">'+tile.title+'</h1></li>'); $li = $('<li data-id="'+tile.id+'" class="element '+tile.shape+' hp vp" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'" ><span class="tile '+tilecolor+' '+op+'"></span><a href="'+tile.data_content+'" class="appicon" onclick="return false;"><img src="'+o.iconPath+tile.data_content+'.png" alt="" ></a><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
else else
$li = $('<li id="'+tile.data_content+'" class="element '+tile.shape+' hp vp" data-category="'+tile.data_category+'" data-content="'+tile._id+'"><span class="tile '+tilecolor+' '+op+'"></span><h1 class="appname thmtxt">'+tile.title+'</h1><div class="appholder">Loading...</div></li>'); $li = $('<li data-id="'+tile.id+'" class="element '+tile.shape+' hp vp" data-category="'+tile.data_category+'" data-content="'+tile.data_content+'" js-link="'+tile.js[0].url+'" css-link="'+tile.css.url+'"><span class="tile '+tilecolor+' '+op+'"></span><h1 class="appname thmtxt">'+tile.title+'</h1><div class="appholder">Loading...</div></li>');
$group.find('.col'+colindex).append($li); $group.find('.col'+colindex).append($li);
} }
@ -1557,10 +1557,10 @@ var orbitDesktop = function(dom){
var widget = $(this); var widget = $(this);
if(widget.attr("data-category")=="widget"){ if(widget.attr("data-category")=="widget"){
var widgename = widget.attr("data-content"); var widgename = widget.attr("data-content");
$.getScript("/desktop_widgets/"+widgename+"/"+widgename+".js",function(){ $.getScript(widget.attr("js-link"),function(){
widget.find("div.appholder").load("/desktop_widgets/"+widgename+"/index.html.erb"); widget.find("div.appholder").load(widget.attr("data-content"));
}); });
// $(this).find("div.appholder").append( $('<link rel="stylesheet" id="dyn_css" type="text/css" />').attr('href', "/desktop_widgets/"+widgename+"/css/"+widgename+".css")); $(this).find("div.appholder").append( '<link rel="stylesheet" id="dyn_css" href="'+widget.attr("css-link")+'" type="text/css" />')
} }
}) })
@ -1697,3 +1697,4 @@ orbitDesktop.prototype.currentUsername = "Harry";
var uselessfunction = function(){ var uselessfunction = function(){
$.post("/desktop/temp_func",{sectionid:"4f83e7bbbd98eb041600001d"}); $.post("/desktop/temp_func",{sectionid:"4f83e7bbbd98eb041600001d"});
} }

View File

@ -103,11 +103,41 @@ class DesktopController< ApplicationController
def getgroups def getgroups
@section = Section.find(params["sectionid"]) @section = Section.find(params["sectionid"])
@groups = @section.groups @groups = @section.groups
a = Array.new
gr = Array.new
@groups.each do |group| @groups.each do |group|
a << group.tiles a = Array.new
t = group.tiles
t.each do |tile|
data_content = ""
jsfile = []
cssfile = ""
shape = "w1 h1"
if tile.data_category == "widget"
widge = DesktopWidget.find(tile.desktop_widget_id.to_s)
# data_content = widge.widget_layout.file
data_content = "desktop/widget_layout?id="+tile.desktop_widget_id.to_s
jsfile = widge.javascripts.collect{|js| js.file}
cssfile = widge.css_default.file
shape = widge.shape
title = widge.name
else
data_content = tile.data_content
title = tile.title
end end
render :json =>a.to_json a << {"id"=>tile.id,"data_category"=>tile.data_category,"data_content"=>data_content,"js"=>jsfile,"css"=>cssfile,"shape"=>shape,"position"=>tile.position,"title"=>title}
end
gr << a
end
render :json =>gr.to_json
end
def widget_layout
widget = DesktopWidget.find(params[:id])
link = '<link href="'+widget.css_default.file.to_s+'" media="screen" rel="stylesheet" type="text/css" />'
content = widget.widget_layout.body
dhtml = link + content
render :text => dhtml.html_safe
end end
def getsectionlist def getsectionlist

View File

@ -8,6 +8,7 @@ class DesktopPublicationsController< ApplicationController
end end
def journal_p_add def journal_p_add
debugger
render "desktop/journal_pages/add", :layout => false render "desktop/journal_pages/add", :layout => false
end end

View File

@ -31,7 +31,8 @@ class DesktopWidgetsController < OrbitBackendController
zip_file.entries.each do |entry| zip_file.entries.each do |entry|
case (path = entry.to_s) case (path = entry.to_s)
when /\A(#{zip_name})\/(default\.css)\z/ #for default css when /\A(#{zip_name})\/(default\.css)\z/
#for default css
dw.build_css_default(:file => get_temp_file(zip_file, dir, entry)) dw.build_css_default(:file => get_temp_file(zip_file, dir, entry))
when /\A(#{zip_name})\/(widget\.html)\z/ #for layout html when /\A(#{zip_name})\/(widget\.html)\z/ #for layout html
dw.build_widget_layout(:file => get_temp_file(zip_file, dir, entry)) dw.build_widget_layout(:file => get_temp_file(zip_file, dir, entry))

View File

@ -1,6 +1,8 @@
class CssDefault < Stylesheet class CssDefault < Stylesheet
belongs_to :design # belongs_to :design
belongs_to :desktop_widget # belongs_to :desktop_widget
belongs_to :css, polymorphic: true
end end

View File

@ -8,11 +8,11 @@ class Design
field :title, :type => String field :title, :type => String
field :version, :type => String field :version, :type => String
has_one :css_default, :autosave => true, :dependent => :destroy has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
has_one :layout, :autosave => true, :dependent => :destroy has_one :layout, :autosave => true, :dependent => :destroy
has_one :css_reset, :autosave => true, :dependent => :destroy has_one :css_reset, :autosave => true, :dependent => :destroy
has_many :images, :autosave => true, :dependent => :destroy has_many :images,as: :imgs, :autosave => true, :dependent => :destroy
has_many :javascripts, :autosave => true, :dependent => :destroy has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
has_many :pages has_many :pages
has_many :themes, :autosave => true, :dependent => :destroy has_many :themes, :autosave => true, :dependent => :destroy

View File

@ -10,8 +10,10 @@ class Image
mount_uploader :file, ImageUploader mount_uploader :file, ImageUploader
belongs_to :design # belongs_to :design
belongs_to :desktop_widget # belongs_to :desktop_widget
belongs_to :imgs, polymorphic: true
before_save :set_name before_save :set_name

View File

@ -1,4 +1,6 @@
class Javascript < DesignFile class Javascript < DesignFile
belongs_to :design # belongs_to :design
belongs_to :desktop_widget # belongs_to :desktop_widget
belongs_to :js, polymorphic: true
end end

View File

@ -1,54 +1,27 @@
class Stylesheet < DesignFile class Stylesheet < DesignFile
belongs_to :design # belongs_to :design
belongs_to :desktop_widget
mount_uploader :file_orig, AssetUploader mount_uploader :file_orig, AssetUploader
def parse_urls def parse_urls
orig_content = content = self.file.read.force_encoding("UTF-8") orig_content = content = self.file.read.force_encoding("UTF-8")
# self.remove_file! # self.remove_file!
# self.remove_file_orig! # self.remove_file_orig!
names = [] names = {}
images = self.design.images images = self.css.images
content.scan(/(?<=url)(.*?)(?=\))/){ content.scan(/(?<=url)(.*?)(?=\))/){
css_name = $1.gsub(' ','').gsub('(','') css_name = $1.gsub(' ','').gsub('(','')
unless names.has_key?(css_name)
name = File.basename(css_name).gsub(/[\\\"]/, '') name = File.basename(css_name).gsub(/[\\\"]/, '')
image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil
image.update_attribute(:in_css, true) if image if image
file_name = image.file_url rescue nil image.update_attribute(:in_css, true)
names << [css_name, file_name] file_name = image.file_url
} names.merge!({css_name => file_name})
names.each do |name|
content.gsub!(name[0], name[1]) if name[1]
end end
Dir.mktmpdir('f_path') { |dir|
orig_file_name = self.file_identifier
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
temp_file.write orig_content.force_encoding("UTF-8")
self.file_orig = temp_file
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
temp_file.write content.force_encoding("UTF-8")
self.file = temp_file
self.save
}
end end
def parse_widgets_urls
orig_content = content = self.file.read.force_encoding("UTF-8")
# self.remove_file!
# self.remove_file_orig!
names = []
images = self.desktop_widget.images
content.scan(/(?<=url)(.*?)(?=\))/){
css_name = $1.gsub(' ','').gsub('(','')
name = File.basename(css_name).gsub(/[\\\"]/, '')
image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil
image.update_attribute(:in_css, true) if image
file_name = image.file_url rescue nil
names << [css_name, file_name]
} }
names.each do |name| names.each_pair do |key, value|
content.gsub!(name[0], name[1]) if name[1] content.gsub!(key, value)
end end
Dir.mktmpdir('f_path') { |dir| Dir.mktmpdir('f_path') { |dir|
orig_file_name = self.file_identifier orig_file_name = self.file_identifier

View File

@ -2,11 +2,12 @@ class Desktop
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
field :theme, default: "4f8d3f493b67fcd05f086359" field :theme, default: "4f8d3f533b67fcd05f08635a"
field :customtheme field :customtheme
field :wallpaper field :wallpaper
belongs_to :user belongs_to :user
has_and_belongs_to_many :desktop_widgets, :autosave => true
has_many :sections, :autosave => true, :dependent => :destroy has_many :sections, :autosave => true, :dependent => :destroy
# has_many :desktop_widgets, :autosave => true, :dependent => :destroy # has_many :desktop_widgets, :autosave => true, :dependent => :destroy

View File

@ -8,10 +8,12 @@ class DesktopWidget
field :shape field :shape
field :version, :type => String field :version, :type => String
has_one :css_default, :autosave => true, :dependent => :destroy has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
has_one :widget_layout, :autosave => true, :dependent => :destroy has_one :widget_layout, :autosave => true, :dependent => :destroy
has_many :images, :autosave => true, :dependent => :destroy has_many :images, as: :imgs, :autosave => true, :dependent => :destroy
has_many :javascripts, :autosave => true, :dependent => :destroy has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
has_and_belongs_to_many :desktops, :autosave => true
belongs_to :tiles, :autosave => true
accepts_nested_attributes_for :images, :allow_destroy => true accepts_nested_attributes_for :images, :allow_destroy => true
accepts_nested_attributes_for :javascripts, :allow_destroy => true accepts_nested_attributes_for :javascripts, :allow_destroy => true
@ -24,7 +26,7 @@ class DesktopWidget
protected protected
def parse_css_for_images def parse_css_for_images
self.css_default.parse_widgets_urls self.css_default.parse_urls
parse_widget_for_images(self) parse_widget_for_images(self)
end end

View File

@ -7,13 +7,12 @@ class Group
before_create :initialize_tile before_create :initialize_tile
def initialize_tile def initialize_tile
self.tiles.build(data_category: "widget", data_content: "timetable", position: 1, shape: "w2 h2", title: "Tiime Table") self.tiles.build(data_category: "app", data_content: "quotes", position: 5, shape: "w1 h1", title: "Quotes")
self.tiles.build(data_category: "app", data_content: "quotes", position: 2, shape: "w1 h1", title: "Quotes") self.tiles.build(data_category: "app", data_content: "dailyenglish", position: 6, shape: "w1 h1", title: "Daily English Word")
self.tiles.build(data_category: "widget", data_content: "weather", position: 3, shape: "w2 h2", title: "Weather") widgets = self.section.desktop.desktop_widgets.collect{|widget| widget.id}
self.tiles.build(data_category: "widget", data_content: "clock", position: 4, shape: "w2 h1", title: "Clock") for i in 0..3
self.tiles.build(data_category: "app", data_content: "dailyenglish", position: 5, shape: "w1 h1", title: "Daily English Word") self.tiles.build(data_category: "widget", position: i+1,desktop_widget_id: widgets[i])
self.tiles.build(data_category: "widget", data_content: "school_events", position: 6, shape: "w2 h1", title: "School Events") end
end end
end end

View File

@ -9,5 +9,6 @@ class Tile
field :title field :title
belongs_to :group belongs_to :group
has_one :desktop_widget
end end

View File

@ -180,7 +180,7 @@ class User
end end
def initialize_desktop def initialize_desktop
self.build_desktop self.build_desktop(desktop_widget_ids: DesktopWidget.all.collect{|widget| widget.id})
end end
protected protected

View File

@ -61,6 +61,18 @@
</ul> </ul>
</div> </div>
</div> </div>
<div class="hh2 hp sdm">
<div class="sdm_t hh2" id='ns'>New Share</div>
<div class="admbg sdm_o">
<ul>
<li><a class="hp hh2 admtxt remote_url" href="<%= panel_personal_journal_plugin_writing_journals_path %>">Full</a></li>
<li><a class="hp hh2 admtxt" href="">Abstract</a></li>
<li><a class="hp hh2 admtxt" href="">Friends</a></li>
<li><a class="hp hh2 admtxt" href="">Private</a></li>
<li><a class="hp hh2 admtxt" href="">Group</a></li>
</ul>
</div>
</div>
<div class="hh2 hp sdm"> <div class="hh2 hp sdm">
<div class="sdm_t hh2"><span class="icon-question-sign"></span></div> <div class="sdm_t hh2"><span class="icon-question-sign"></span></div>
</div> </div>
@ -73,3 +85,18 @@
</div> </div>
</div> </div>
</div> </div>
Panel::PersonalJournal::Plugin::WritingJournals
<script type="text/javascript">
orbitDesktop.prototype.bindItems = function(){
var bindHandlers = function(){
}
$(".remote_url").click(function(){
$(".overview").load($(this).attr("href"),function(){
bindHandlers();
})
return false;
})
}
o.bindItems();
</script>

View File

@ -201,6 +201,7 @@ namespace :desktop do
match '/getapplist/'=>'desktop#getapplist' match '/getapplist/'=>'desktop#getapplist'
match '/newpositions/'=>'desktop#newpositions' match '/newpositions/'=>'desktop#newpositions'
match '/settingconnection/'=>'desktop#settingconnection' match '/settingconnection/'=>'desktop#settingconnection'
match '/widget_layout' => 'desktop#widget_layout'
match '/journal_p/'=>'desktop_publications#journal_p' match '/journal_p/'=>'desktop_publications#journal_p'
@ -221,6 +222,9 @@ namespace :desktop do
match '/research_p' => 'desktop_research#research_p' match '/research_p' => 'desktop_research#research_p'
match '/research_p_list/' => 'desktop_research#research_p_list' match '/research_p_list/' => 'desktop_research#research_p_list'
match '/research_p_add' => 'desktop_research#research_p_add' match '/research_p_add' => 'desktop_research#research_p_add'
match '/temp_func/'=>'desktop#temp_func' match '/temp_func/'=>'desktop#temp_func'
end end

View File

@ -2,13 +2,20 @@ module ParserLayoutWidget
require 'nokogiri' require 'nokogiri'
def parse_widget_for_images(widget) def parse_widget_for_images(widget)
widge = Nokogiri::HTML(widget.widget_layout.body) content = widget.widget_layout.file.read.force_encoding("UTF-8")
widge = Nokogiri::HTML(content)
a = []
b = []
widge.css('.widget_image').each do |page_image| widge.css('.widget_image').each do |page_image|
image = widget.images.where( file: File.basename(page_image['src']))[0] image = widget.images.where( file: File.basename(page_image['src']))[0]
a << page_image['src']
b << image.file
image.update_attributes(:html_id => page_image['id'], :html_class => page_image['class'], :in_html => true) if image image.update_attributes(:html_id => page_image['id'], :html_class => page_image['class'], :in_html => true) if image
end end
a.each_with_index do |img,i|
content = content.gsub(img,b[i].to_s)
end
widget.widget_layout.update_attributes(:body => content)
end end

View File

@ -0,0 +1 @@
/* No Css */

View File

@ -0,0 +1,6 @@
{
"author" : "Harry",
"name" : "Browser",
"shape" : "w2 h1",
"version" : "1.0"
}

View File

@ -1,8 +1,8 @@
.clock{ .clock{
/* The .clock div. Created dynamically by jQuery */ /* The .clock div. Created dynamically by jQuery */
/*background-color:#252525;*/ background-color:#111;
height:200px; height:75px;
width:200px; width:75px;
position:relative; position:relative;
overflow:hidden; overflow:hidden;
float:left; float:left;
@ -11,21 +11,21 @@
.clock .rotate{ .clock .rotate{
/* There are two .rotate divs - one for each half of the background */ /* There are two .rotate divs - one for each half of the background */
position:absolute; position:absolute;
width:200px; width:75px;
height:200px; height:75px;
top:0; top:0;
left:0; left:0;
} }
.rotate.right{ .rotate.right{
display:none; display:none;
z-index:11; z-index:9;
} }
.clock .bg, .clock .front{ .clock .bg, .clock .front{
width:100px; width:37.5px;
height:200px; height:75px;
/*background-color:#252525;*/ background-color:#111;
position:absolute; position:absolute;
top:0; top:0;
} }
@ -33,37 +33,42 @@
.clock .display{ .clock .display{
/* Holds the number of seconds, minutes or hours respectfully */ /* Holds the number of seconds, minutes or hours respectfully */
position:absolute; position:absolute;
width:200px; width:75px;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif; font-family: Orbitron, sans-serif;
z-index:20; z-index:17;
color:#F5F5F5; color:#F5F5F5;
font-size:60px; font-size:21px;
text-align:center; text-align:center;
top:65px; top:27.5px;
left:0; left:0px;
/* CSS3 text shadow: */
text-shadow:4px 4px 5px #333333;
} }
/* The left part of the background: */ /* The left part of the background: */
.clock .bg.left{ left:0; } .clock .bg.left{ left:0px; }
/* Individual styles for each color: */ /* Individual styles for each color: */
.orange .bg.left{ background:url(bg_orange.png) no-repeat left top; } .orange .bg.left{ background:url(desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_orange.png) no-repeat left top; }
.green .bg.left{ background:url(bg_green.png) no-repeat left top; } .green .bg.left{ background:url(desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_green.png) no-repeat left top; }
.blue .bg.left{ background:url(bg_blue.png) no-repeat left top; } .blue .bg.left{ background:url(desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_blue.png) no-repeat left top; }
/* The right part of the background: */ /* The right part of the background: */
.clock .bg.right{ left:100px; } .clock .bg.right{ left:37.5px; }
.orange .bg.right{ background:url(bg_orange.png) no-repeat right top; } .orange .bg.right{ background:url(desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_orange.png) no-repeat right top; }
.green .bg.right{ background:url(bg_green.png) no-repeat right top; } .green .bg.right{ background:url(desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_green.png) no-repeat right top; }
.blue .bg.right{ background:url(bg_blue.png) no-repeat right top; } .blue .bg.right{ background:url(desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_blue.png) no-repeat right top; }
.clock .front.left{ .clock .front.left{
left:0; left:0;
z-index:10; z-index:15;
}
#fancyClock {
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
margin: -36px 0 0 -114px;
} }

View File

@ -1,4 +1,3 @@
<style>
#search{border-radius: 5px; margin:10px;margin-top:25px;} #search{border-radius: 5px; margin:10px;margin-top:25px;}
input { input {
border:none; border:none;
@ -19,16 +18,3 @@ input {
color: #222; color: #222;
text-shadow: 0px 1px 1px #555; text-shadow: 0px 1px 1px #555;
} }
</style>
<center>
<form id="search">
<img src="desktop_widgets/4fa78140c88514014d7c59be/img/google_64.png" style='margin-right:10px;'><br />
<input id="googlesearch">
<input type="submit" style="display:none;">
<br>
<span id="eric">Powered by Eric</span>
</form>
</center>
<script>
search();
</script>

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -0,0 +1,7 @@
{
"author" : "Eric",
"name" : "Google Search",
"shape" : "w2 h1",
"version" : "1.0"
}

View File

@ -0,0 +1,13 @@
<center>
<form id="search">
<img src="desktop_widgets/4fa78140c88514014d7c59be/img/google_64.png" style='margin-right:10px;' class="widget_image"><br />
<input id="googlesearch">
<input type="submit" style="display:none;">
<br>
<span id="eric">Powered by Eric</span>
</form>
</center>
<script>
search();
</script>