Desktop Widgtes updates..

This commit is contained in:
Harry Bomrah 2012-11-05 23:04:54 +08:00
parent 28337c6b5b
commit f68fe22cba
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(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
$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);
}
@ -1557,10 +1557,10 @@ var orbitDesktop = function(dom){
var widget = $(this);
if(widget.attr("data-category")=="widget"){
var widgename = widget.attr("data-content");
$.getScript("/desktop_widgets/"+widgename+"/"+widgename+".js",function(){
widget.find("div.appholder").load("/desktop_widgets/"+widgename+"/index.html.erb");
$.getScript(widget.attr("js-link"),function(){
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(){
$.post("/desktop/temp_func",{sectionid:"4f83e7bbbd98eb041600001d"});
}

View File

@ -103,11 +103,41 @@ class DesktopController< ApplicationController
def getgroups
@section = Section.find(params["sectionid"])
@groups = @section.groups
a = Array.new
gr = Array.new
@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
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 =>a.to_json
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
def getsectionlist

View File

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

View File

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

View File

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

View File

@ -8,11 +8,11 @@ class Design
field :title, :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 :css_reset, :autosave => true, :dependent => :destroy
has_many :images, :autosave => true, :dependent => :destroy
has_many :javascripts, :autosave => true, :dependent => :destroy
has_many :images,as: :imgs, :autosave => true, :dependent => :destroy
has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
has_many :pages
has_many :themes, :autosave => true, :dependent => :destroy

View File

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

View File

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

View File

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

View File

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

View File

@ -8,13 +8,15 @@ class DesktopWidget
field :shape
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_many :images, :autosave => true, :dependent => :destroy
has_many :javascripts, :autosave => true, :dependent => :destroy
has_many :images, as: :imgs, :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 :javascripts, :allow_destroy => true
accepts_nested_attributes_for :javascripts, :allow_destroy => true
after_save :parse_css_for_images
@ -24,7 +26,7 @@ class DesktopWidget
protected
def parse_css_for_images
self.css_default.parse_widgets_urls
self.css_default.parse_urls
parse_widget_for_images(self)
end

View File

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

View File

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

View File

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

View File

@ -61,6 +61,18 @@
</ul>
</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="sdm_t hh2"><span class="icon-question-sign"></span></div>
</div>
@ -73,3 +85,18 @@
</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 '/newpositions/'=>'desktop#newpositions'
match '/settingconnection/'=>'desktop#settingconnection'
match '/widget_layout' => 'desktop#widget_layout'
match '/journal_p/'=>'desktop_publications#journal_p'
@ -221,6 +222,9 @@ namespace :desktop do
match '/research_p' => 'desktop_research#research_p'
match '/research_p_list/' => 'desktop_research#research_p_list'
match '/research_p_add' => 'desktop_research#research_p_add'
match '/temp_func/'=>'desktop#temp_func'
end

View File

@ -2,13 +2,20 @@ module ParserLayoutWidget
require 'nokogiri'
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|
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
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

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