Desktop Widgtes updates..

This commit is contained in:
Harry Bomrah authored and chris committed 2012-11-06 10:36:34 +08:00
1 parent 3c85f3ef00
commit da5e7f670e
33 files changed
+217 -146

No files matched your search

+6 -5
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"});
}
+33 -3
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
@@ -8,6 +8,7 @@ class DesktopPublicationsController< ApplicationController
end
def journal_p_add
debugger
render "desktop/journal_pages/add", :layout => false
end
@@ -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))
+4 -2
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
+3 -3
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
+4 -2
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
+4 -2
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
+40 -67
View File
@@ -1,67 +1,40 @@
class Stylesheet < DesignFile
belongs_to :design
belongs_to :desktop_widget
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
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]
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]
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
class Stylesheet < DesignFile
# 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.css.images
content.scan(/(?<=url)(.*?)(?=\))/){
css_name = $1.gsub(' ','').gsub('(','')
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_pair do |key, value|
content.gsub!(key, value)
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
+2 -1
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
+7 -5
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
+6 -7
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
+1
View File
@@ -9,5 +9,6 @@ class Tile
field :title
belongs_to :group
has_one :desktop_widget
end
+1 -1
View File
@@ -5,7 +5,7 @@ class WidgetLayout < DesignFile
field :body
belongs_to :desktop_widget
def content
self.file.read.force_encoding("UTF-8") rescue ''
+1 -1
View File
@@ -180,7 +180,7 @@ class User
end
def initialize_desktop
self.build_desktop
self.build_desktop(desktop_widget_ids: DesktopWidget.all.collect{|widget| widget.id})
end
protected
+28 -1
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>
@@ -72,4 +84,19 @@
</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>