very important update for widgets management..

This commit is contained in:
Harry Bomrah 2012-05-11 15:27:16 +08:00
parent 2083e0bf4f
commit 2c3637e9b4
8 changed files with 200 additions and 15 deletions

View File

@ -55,7 +55,7 @@ var orbitDesktop = function(dom){
$(document).ready(function(){o.loadWallpaper(customwallpaper);o.bindDesktopEvents();o.loadIconCache();o.initializeDesktop();});
})
}
};
}
this.changeTheme = function(theme){ // this function is used for changing theme
o.theme = theme;
$.getJSON("/"+o.themefolder+"/"+theme+"/settings/"+theme+".json",function(ts){
@ -1098,24 +1098,116 @@ var orbitDesktop = function(dom){
}
var widgets = function(){
var bindHandlers = function(){
$("#widget_list a").click(function(){
var sectionid = $(this).attr("for");
var widgetid = $(this).parent().parent().attr("for");
switch($(this).attr("href")){
case "addthis":
$this = $(this);
o.confirm({
message: "Are you sure you want to add this widget?",
buttons: ['Yes','No'],
highlighted: 1
},function(reply){
if(reply){
$.post("desktop_appstore/widgets_settings",{section:sectionid, widget:widgetid, what:"add"},function(result){
if(result[0].success){
$this.attr("href","removethis");
$targetDom = $this.parent().parent().find("div.status");
$parentDom = $this.parent();
if($targetDom.find("a").length == 0)
$targetDom.html("Status : Installed on");
$targetDom.append(" ").append($this);
if($parentDom.find("a").length == 0)
$parentDom.empty();
o.desktopData["home"]="";
o.notify("Widget added.","success",2);
}else{
o.notify(result[0].error,"imp",2);
}
})
}
})
break;
case "removethis":
$this = $(this);
o.confirm({
message: "Are you sure you want to remove this widget?",
buttons: ['Yes','No'],
highlighted: 2
},function(reply){
if(reply){
$.post("desktop_appstore/widgets_settings",{section:sectionid, widget:widgetid, what:"remove"},function(result){
if(result[0].success){
$this.attr("href","addthis");
$targetDom = $this.parent().parent().find("div.not_status");
$parentDom = $this.parent();
if($targetDom.html()=="")
$targetDom.html("Install on");
$targetDom.append(" ").append($this);
if($parentDom.find("a").length == 0)
$parentDom.html("Status : Downloaded");
o.desktopData["home"]="";
o.notify("Widget removed.","success",2);
}
})
}
})
break;
}
return false;
})
}
$("div#apps_store div#panel_r").load("/desktop_appstore/widgets",function(){
$.getJSON("/desktop_appstore/getuserwidgets",function(userwidgets){
var column = $('<div class="g_col list_t"><ul></ul></div>'),
var column = $('<div class="g_col list_t" style="width:350px;"><ul></ul></div>'),
counter = 1,
li;
$.each(userwidgets,function(i,widge){
li = $('<li class="list_t_item" for="'+widge._id+'"><div class="list_t_title">'+widge.name+'</div><div class="list_t_des">'+widge.shape+'</div></li>');
if(!widge.status)widge.status = "Downloaded";
var brick = widge.shape.split(' '),
bw = parseInt(brick[0].substr(1)),
bh = parseInt(brick[1].substr(1)),
shp = bw+" X "+bh;
li = $('<li class="list_t_item" for="'+widge._id+'"><div class="list_t_title">'+widge.name+'</div><div class="list_t_des">Author : '+widge.author+'</div><div class="list_t_des">Shape : '+shp+'</div><div class="list_t_des status">Status : '+widge.status+'</div><div class="list_t_des not_status"></div></li>');
var cur_section_names = new Array();
var section_names = new Array();
var section_links = new Array();
if(widge.section){
var s_name_list = "";
$.each(widge.section,function(x,sec){
$.each(o.sectionList,function(j,s){
if(s._id==sec){
cur_section_names.push(s.name);
s_name_list+= "<a href='removethis' for='"+s._id+"' style='text-decoration:underline;'>"+s.name +"</a> ";
}
})
})
var section_names = o.getArrayfromJson(o.sectionList,"name");
var section_links = o.getArrayfromJson(o.sectionList,"_id");
var s_name_list_not = "";
$.each(section_names,function(j,sec_name){
if($.inArray(sec_name,cur_section_names)==-1){
var sec_link = section_links[j];
s_name_list_not+= "<a href='addthis' for='"+sec_link+"' style='text-decoration:underline;'>"+sec_name+"</a> ";
}
})
li.find("div.status").html("Status : Installed on "+s_name_list);
if(s_name_list_not)
li.find("div.not_status").html("Install on "+s_name_list_not);
}else{
li.find("div.not_status").html("Install on "+o.sectionList[0].name+", "+o.sectionList[1].name+", "+o.sectionList[2].name+", "+o.sectionList[3].name);
}
//console.log(section_names);
column.find("ul").append(li);
if(counter%5==0){
$("#journal_p div#paper_list div.overview").append(column);
column = $('<div class="g_col list_t"><ul></ul></div>');
if(counter%4==0){
$("#apps_store div#widget_list").append(column);
column = $('<div class="g_col list_t" style="width:350px;"><ul></ul></div>');
}
counter++;
})
//alert(column);
$("#apps_store div#widget_list").append(column);
bindHandlers();
})
})
}

View File

@ -79,6 +79,13 @@ var orbitDesktopAPI = function(){
});
$confirm.stop(1,1).fadeIn();
};
this.getArrayfromJson = function(tjson,key){
var tempArray = new Array;
$.each(tjson,function(i,val){
tempArray.push(val[key]);
})
return tempArray;
}
};
orbitDesktopAPI.prototype.notifyImgPath = "temp";
orbitDesktopAPI.prototype.wallpaperPath = "temp";

View File

@ -9,8 +9,89 @@ class DesktopAppstoreController< ApplicationController
end
def getuserwidgets
@widgets = current_user.desktop_widgets
@widgets = current_user.desktop.desktop_widgets
@groups = Array.new
@sections = current_user.desktop.sections
@sections.each do |section|
@groups << section.groups
end
@widgets.each do |widget|
@count = 0;
@sectionids = Array.new
@groups.each do |group|
group.each do |grp|
@widge = 0
@gid = widget.id.to_s
@widge = grp.tiles.where(:data_content.all => [@gid]).count
@count = @count + @widge
if @widge > 0
@sectionids << grp.section_id
end
end
end
if @count > 0
widget.status = "Installed"
widget.section = @sectionids
else
widget.status = "Downloaded"
end
end
render :json=>@widgets.to_json
end
end
def widgets_settings
what = params["what"]
@widgetid = params["widget"]
@sectionid = params["section"]
@msg = Array.new
case what
when "remove"
@section = Section.find(@sectionid)
@groups = @section.groups
@groups.each do |group|
@tile = group.tiles.where(:data_content.all => [@widgetid])
if @tile.count > 0
@thistile = @tile
end
end
@t = Tile.find(@thistile.first.id)
@t.delete
@msg << {"success"=>true}
when "add"
@widget = current_user.desktop.desktop_widgets.find(@widgetid)
@section = Section.find(@sectionid)
@groups = @section.groups
@totalwidgets = 0
@groups.each do |group|
@tile = group.tiles.where(:data_content.all => [@widgetid]).count
if @tile > 0
@msg << {"success"=>false,"error"=>"Duplicate widget"}
else
no_of_widgets = group.tiles.where(:data_category.all => ["widget"]).count
@totalwidgets = @totalwidgets + no_of_widgets
end
end
if @totalwidgets >= 12
@msg << {"success"=>false,"error"=>"Section full"}
else
wshape = @widget.shape
wdata_content = @widgetid
wdata_category = "widget"
wname = @widget.name
if @groups.first.tiles.where(:data_category.all => ["widget"]).count >= 6
groupid = @groups.last.id
else
groupid = @groups.first.id
end
Tile.create(data_category: wdata_category,data_content: wdata_content, group_id: groupid, position: 10, title: wname, shape: wshape)
@msg << {"success"=>true}
end
end
render :json=>@msg.to_json
end
end

View File

@ -9,6 +9,7 @@ class Desktop
belongs_to :user
has_many :sections, :autosave => true, :dependent => :destroy
has_many :desktop_widgets, :autosave => true, :dependent => :destroy
before_create :initialize_section

View File

@ -5,7 +5,9 @@ class DesktopWidget
field :name
field :author
field :shape
field :user_id
field :desktop_id
field :status
field :section
belongs_to :user
belongs_to :desktop
end

View File

@ -19,7 +19,7 @@ class User
has_one :desktop, :autosave => true, :dependent => :destroy
has_many :other_accounts, :autosave => true, :dependent => :destroy
has_many :journals, :autosave => true, :dependent => :destroy
has_many :desktop_widgets, :autosave => true, :dependent => :destroy
belongs_to :role
has_and_belongs_to_many :sub_roles
accepts_nested_attributes_for :attribute_values, :allow_destroy => true

View File

@ -1,8 +1,8 @@
<div class="s_title hh3">Your Widgets</div>
<div class="tinycanvas hp">
<div class="scrollbar sb_h vp"><div class="track"><div class="thumb thmc2"><div class="end"></div></div></div></div>
<div class="viewport">
<div id="connection_setting" class="overview vp">
<div class="s_title hh3">Your Widgets</div>
<div class="overview vp">
<div class="overview" id="widget_list">
</div>

View File

@ -130,6 +130,8 @@ Orbit::Application.routes.draw do
match '/desktop_appstore/appstore'=>'desktop_appstore#appstore'
match '/desktop_appstore/widgets'=>'desktop_appstore#widgets'
match '/desktop_appstore/getuserwidgets'=>'desktop_appstore#getuserwidgets'
match '/desktop_appstore/widgets_settings'=>'desktop_appstore#widgets_settings'
match '/desktop/temp_func/'=>'desktop#temp_func'