widget and gridster fixes

This commit is contained in:
Harry Bomrah 2013-04-01 18:00:47 +08:00 committed by Matt K. Fu
parent 0781779ac0
commit bc0477a5ed
5 changed files with 87 additions and 60 deletions

View File

@ -91,7 +91,6 @@ GEM
execjs execjs
coffee-script-source (1.4.0) coffee-script-source (1.4.0)
columnize (0.3.6) columnize (0.3.6)
curb (0.8.3)
database_cleaner (0.9.1) database_cleaner (0.9.1)
debug_inspector (0.0.2) debug_inspector (0.0.2)
debugger (1.2.4) debugger (1.2.4)
@ -128,13 +127,6 @@ GEM
multi_json (>= 1.3) multi_json (>= 1.3)
rack-oauth2 (>= 0.14.4) rack-oauth2 (>= 0.14.4)
tzinfo tzinfo
feedzirra (0.0.24)
activesupport (>= 2.3.8)
builder (>= 2.1.2)
curb (>= 0.2.3)
loofah (>= 0.3.1)
nokogiri (> 0.0.0)
sax-machine (>= 0.0.12)
ffi (1.4.0) ffi (1.4.0)
haml (3.1.8) haml (3.1.8)
highline (1.6.15) highline (1.6.15)
@ -149,8 +141,6 @@ GEM
jquery-rails jquery-rails
railties (>= 3.1.0) railties (>= 3.1.0)
json (1.7.7) json (1.7.7)
loofah (1.2.1)
nokogiri (>= 1.4.4)
mail (2.4.4) mail (2.4.4)
i18n (>= 0.4.0) i18n (>= 0.4.0)
mime-types (~> 1.16) mime-types (~> 1.16)
@ -285,10 +275,8 @@ GEM
railties (~> 3.2.0) railties (~> 3.2.0)
sass (>= 3.1.10) sass (>= 3.1.10)
tilt (~> 1.3) tilt (~> 1.3)
sax-machine (0.1.0) select2-rails (3.3.1)
nokogiri (> 0.0.0) sass-rails (>= 3.2)
select2-rails (3.3.0)
sass-rails (~> 3.2)
thor (~> 0.14) thor (~> 0.14)
selenium-webdriver (2.30.0) selenium-webdriver (2.30.0)
childprocess (>= 0.2.5) childprocess (>= 0.2.5)
@ -368,7 +356,6 @@ DEPENDENCIES
factory_girl_rails factory_girl_rails
faker faker
fb_graph fb_graph
feedzirra
impressionist! impressionist!
jquery-rails (= 2.1.4) jquery-rails (= 2.1.4)
jquery-ui-rails jquery-ui-rails
@ -400,7 +387,7 @@ DEPENDENCIES
rspec-rails (~> 2.0) rspec-rails (~> 2.0)
rubyzip rubyzip
sass-rails sass-rails
select2-rails select2-rails (= 3.3.1)
shoulda-matchers shoulda-matchers
simplecov simplecov
sinatra sinatra

View File

@ -379,7 +379,7 @@ var orbitDesktop = function(dom){
this.layout_data = function(h){ this.layout_data = function(h){
var $e; var $e;
var column_container,layout, base_width, total_width, gutter, no_of_entries = 0, pagination_link, pagination_variable; var column_container,layout, base_width , no_of_entries = 0, pagination_link , pagination_variable, gutter, total_width;
o.paging = true; o.paging = true;
gutter = (!isNaN(gutter)) ? gutter : 12; gutter = (!isNaN(gutter)) ? gutter : 12;
this.layout_data.generate_layout_html = function(l){ this.layout_data.generate_layout_html = function(l){
@ -393,6 +393,7 @@ var orbitDesktop = function(dom){
case "simple": case "simple":
total_columns++; total_columns++;
temp_div.append(column_container.html()); temp_div.append(column_container.html());
total_width = "auto";
break; break;
case "datalist": case "datalist":
no_of_entries = (typeof column_container.attr("per-column") != "undefined"? parseInt(column_container.attr("per-column")) : 4); no_of_entries = (typeof column_container.attr("per-column") != "undefined"? parseInt(column_container.attr("per-column")) : 4);
@ -411,7 +412,10 @@ var orbitDesktop = function(dom){
x = 0; x = 0;
temp_div.append(column); temp_div.append(column);
} }
}); })
if(x != 0){
temp_div.append(column);
}
} }
total_width = (!isNaN(base_width)) ? (base_width + gutter*2 +1) * total_columns : null; total_width = (!isNaN(base_width)) ? (base_width + gutter*2 +1) * total_columns : null;
break; break;
@ -419,17 +423,16 @@ var orbitDesktop = function(dom){
entries = column_container.find("div[column=true]"),x = 0,column; entries = column_container.find("div[column=true]"),x = 0,column;
if(entries.length!=0){ if(entries.length!=0){
entries.each(function(i,ul){ entries.each(function(i,ul){
column = $("<div class='column type_column' style='width:"+base_width+"px;margin-right:"+gutter+"px;padding-right:"+gutter+"px;'></div"); column = $("<div class='column type_column' style='width:"+base_width+"px;margin-right:"+gutter+"px;padding-right:"+gutter+"px;'></div");
total_columns++; total_columns++;
column.append(ul); column.append(ul);
x++; x++;
temp_div.append(column); temp_div.append(column);
}); })
total_width = (!isNaN(base_width)) ? (base_width + gutter*2 +1) * total_columns : null;
} }
total_width = (!isNaN(base_width)) ? (base_width + gutter*2 +1) * total_columns : null;
break; break;
default: default:
break; break;
} }
// total_width = (!isNaN(base_width) ? ( base_width + 12 ) * total_columns : null); // total_width = (!isNaN(base_width) ? ( base_width + 12 ) * total_columns : null);
@ -716,7 +719,8 @@ var orbitDesktop = function(dom){
.gridster({ .gridster({
widget_margins: [6, 6], widget_margins: [6, 6],
widget_base_dimensions: [120, 120], widget_base_dimensions: [120, 120],
// avoid_overlapped_widgets: true, // avoid_overlapped_widgets: true,
serialize_params: function($w, wgd) { return { col: wgd.col, row: wgd.row, id: $w.data("id") } },
draggable : { draggable : {
start : function(event, ui){ start : function(event, ui){
dragged.addClass("noClick"); dragged.addClass("noClick");
@ -769,6 +773,9 @@ var orbitDesktop = function(dom){
}) })
} }
var newpos = o.gridvar.serialize();
console.log(newpos);
$.post("/desktop/newpositions",{"newpositions":newpos});
} }
} }
}).data('gridster'); }).data('gridster');
@ -815,22 +822,44 @@ var orbitDesktop = function(dom){
var loadTiles = function(id){ //This will load tiles for a specific desktop .. id of section has to be passed here to load tiles var loadTiles = function(id){ //This will load tiles for a specific desktop .. id of section has to be passed here to load tiles
$("div#desktop div#group_wrapper").empty(); $("div#desktop div#group_wrapper").empty();
$.getJSON("/desktop/getgroups",{sectionid:id},function(tiles){ $.getJSON("/desktop/getgroups",{sectionid:id},function(tiles){
tiles.sort(o.sortJSON("position",true,parseInt)); // tiles.sort(o.sortJSON("position",true,parseInt));
var tilecolors = o.themesettings.tilecolor; var tilecolors = o.themesettings.tilecolor;
var totaltiles_in_a_row = 4; var totaltiles_in_a_row = 4;
var opacity = ["op07","op08","op09",""]; var opacity = ["op07","op08","op09",""];
var row = 1,col = 1,x = 1,y = 1; var row = 0,col = 1,x = 1,y = 1,total_x = 0,prev_y = 0;
var $group = $('<div class="grid gridster"></div>'); var $group = $('<div class="grid gridster"></div>');
var $ul = $('<ul style="margin: -6px 0 0 -6px;"></ul>'); var $ul = $('<ul style="margin: -6px 0 0 -6px;"></ul>');
$.each(tiles,function(i,tile){ $.each(tiles,function(i,tile){
if(row >= 4){
row = 1;
col++;
}
var shape = tile.shape.split(" "); var shape = tile.shape.split(" ");
x = parseInt(shape[0].substr(1,1)); // if(tile.title == "Weather")console.log("Big - row : " + tile.row + ", col : "+ tile.column);
y = parseInt(shape[1].substr(1,1)); // if(tile.title == "Google Scholar")console.log("Scholar - row : " + tile.row + ", col : "+ tile.column);
// if(total_x % 2 != 0)
// row = row - y;
// if(i == 7)tile.row = null;
if(tile.row){
row = tile.row;
col = tile.column;
x = parseInt(shape[0].substr(1,1));
y = parseInt(shape[1].substr(1,1));
}else{
console.log(row + " : " + col);
x = parseInt(shape[0].substr(1,1));
if(total_x % 2 == 0){
row = row + y;
}else if(x == 1){
col++;
}
y = parseInt(shape[1].substr(1,1));
total_x = total_x + ( x * y );
prev_y = y;
if(total_x > 8){
row = 1;
total_x = 0;
col++;
}
}
var tilecolor = tilecolors[Math.floor(Math.random()*tilecolors.length)]; var tilecolor = tilecolors[Math.floor(Math.random()*tilecolors.length)];
var op = opacity[Math.floor(Math.random()*opacity.length)]; var op = opacity[Math.floor(Math.random()*opacity.length)];
var f = (tile.fullsize?"fullsize":null); var f = (tile.fullsize?"fullsize":null);
@ -838,9 +867,9 @@ var orbitDesktop = function(dom){
if(tile.data_category == "app") if(tile.data_category == "app")
$li = $('<li data-id="'+tile.id+'" class="app" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" data-title="'+tile.title+'" 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;" data-url="'+tile.link+'"><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="app" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" data-title="'+tile.title+'" 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;" data-url="'+tile.link+'"><img src="'+o.iconPath+tile.data_content+'.png" alt="" ></a><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
else else
$li = $('<li data-id="'+tile.id+'" class="widget '+f+'" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" 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><div class="appholder"><div class="thmtxt o-loading"><i class="icon-spinning icon-spinner"></i> Loading</div></div><h1 class="appname thmtxt">'+tile.title+'</h1></li>'); $li = $('<li data-id="'+tile.id+'" class="widget '+f+'" data-row="'+row+'" data-col="'+col+'" data-sizex="'+x+'" data-sizey="'+y+'" 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><div class="appholder"><div class="thmtxt all-loading"><i class="icon-spinner icon-spin"></i> Loading </div></div><h1 class="appname thmtxt">'+tile.title+'</h1></li>');
row = row + y;
$ul.append($li); $ul.append($li);
}) })

View File

@ -141,7 +141,9 @@ class DesktopController< ApplicationController
link = "http://www.wikibooks.org" link = "http://www.wikibooks.org"
end end
end end
gr << {"id"=>tile.id,"data_category"=>tile.data_category,"data_content"=>data_content,"js"=>jsfile,"css"=>cssfile,"shape"=>shape,"position"=>tile.position,"title"=>title,"fullsize"=>fullsize,"link"=>link} gr << {"id"=>tile.id,"data_category"=>tile.data_category,"data_content"=>data_content,"js"=>jsfile,"css"=>cssfile,"shape"=>shape,"position"=>tile.position,"row"=>tile.row,"column"=>tile.column, "title"=>title,"fullsize"=>fullsize,"link"=>link}
end end
# gr << a # gr << a
end end
@ -194,29 +196,36 @@ class DesktopController< ApplicationController
end end
def newpositions def newpositions
@newpositions = params["newpos"] @newpositions = params[:newpositions]
@section = Section.find(params["sectionid"])
@groupids = params["groupids"] @newpositions.each do |t|
@groups = @section.groups @this_tile = t.last
z = 0 @tile = Tile.find(@this_tile['id'])
@newpositions.each do |grp| @tile.update_attributes({:row => @this_tile['row'],:column => @this_tile['col']})
x = 1
grp.each do |tileid|
if x != 1
y = 1
tileid.each do |id|
@tile = Tile.find(id)
@tile.update_attributes({:position => y})
if @tile.group_id != @groupids[z]
@tile.update_attributes({:group_id => @groupids[z]})
end
y = y + 1
end
z = z + 1
end
x = x + 1
end
end end
# @newpositions = params["newpos"]
# @section = Section.find(params["sectionid"])
# @groupids = params["groupids"]
# @groups = @section.groups
# z = 0
# @newpositions.each do |grp|
# x = 1
# grp.each do |tileid|
# if x != 1
# y = 1
# tileid.each do |id|
# @tile = Tile.find(id)
# @tile.update_attributes({:position => y})
# if @tile.group_id != @groupids[z]
# @tile.update_attributes({:group_id => @groupids[z]})
# end
# y = y + 1
# end
# z = z + 1
# end
# x = x + 1
# end
# end
b = Array.new b = Array.new
b << {"success"=>"true"} b << {"success"=>"true"}
render :json=>b.to_json render :json=>b.to_json

View File

@ -5,6 +5,8 @@ class Tile
field :data_category field :data_category
field :data_content field :data_content
field :position, type: Integer field :position, type: Integer
field :row, type: Integer
field :column, type: Integer
field :shape field :shape
field :fullsize, type: Boolean field :fullsize, type: Boolean
field :title field :title

View File

@ -6,13 +6,13 @@ class Panel::PersonalJournal::Desktop::JournalPagesController < ApplicationContr
page = params[:page] page = params[:page]
page ||= 1 page ||= 1
@per_column = 5
case @view_by case @view_by
when "abstract" when "abstract"
@per_column = 1 @per_column = 1
when "file" when "file"
@per_column = 2 @per_column = 2
else
@per_column = 4
end end
if @view_by.nil? if @view_by.nil?