From 4875b339f81d76254ddc6bfb77ddbbff111ca035 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 11 Apr 2012 15:31:10 +0800 Subject: [PATCH] Fetching desktop from db --- app/assets/javascripts/orbitdesktop.js | 108 +++++++---- app/assets/javascripts/orbitdesktopAPI.js | 13 ++ app/controllers/desktop_controller.rb | 34 ++++ app/models/group.rb | 8 +- app/models/tile.rb | 6 + app/views/desktop/desktop.html.erb | 13 +- app/views/desktop/index.html.erb | 4 +- config/routes.rb | 3 + .../clock/{ => temp}/bg_blue.png | Bin .../clock/{ => temp}/bg_green.png | Bin .../clock/{ => temp}/bg_orange.png | Bin .../clock/{ => temp}/clock.css | 0 public/desktop_widgets/clock1/clock1.js | 171 ++++++++++++++++++ public/desktop_widgets/clock1/img/bg_blue.png | Bin 0 -> 9624 bytes .../desktop_widgets/clock1/img/bg_green.png | Bin 0 -> 6820 bytes .../desktop_widgets/clock1/img/bg_orange.png | Bin 0 -> 9761 bytes public/desktop_widgets/clock1/index.html.erb | 76 ++++++++ .../desktop_widgets/clock1/temp/bg_blue.png | Bin 0 -> 16038 bytes .../desktop_widgets/clock1/temp/bg_green.png | Bin 0 -> 15812 bytes .../desktop_widgets/clock1/temp/bg_orange.png | Bin 0 -> 16256 bytes public/desktop_widgets/clock1/temp/clock.css | 69 +++++++ .../weather1/img/clouds_180x150_bg.jpg | Bin 0 -> 3312 bytes .../desktop_widgets/weather1/index.html.erb | 6 + public/desktop_widgets/weather1/weather1.js | 0 24 files changed, 470 insertions(+), 41 deletions(-) rename public/desktop_widgets/clock/{ => temp}/bg_blue.png (100%) rename public/desktop_widgets/clock/{ => temp}/bg_green.png (100%) rename public/desktop_widgets/clock/{ => temp}/bg_orange.png (100%) rename public/desktop_widgets/clock/{ => temp}/clock.css (100%) create mode 100755 public/desktop_widgets/clock1/clock1.js create mode 100644 public/desktop_widgets/clock1/img/bg_blue.png create mode 100644 public/desktop_widgets/clock1/img/bg_green.png create mode 100644 public/desktop_widgets/clock1/img/bg_orange.png create mode 100755 public/desktop_widgets/clock1/index.html.erb create mode 100755 public/desktop_widgets/clock1/temp/bg_blue.png create mode 100755 public/desktop_widgets/clock1/temp/bg_green.png create mode 100755 public/desktop_widgets/clock1/temp/bg_orange.png create mode 100755 public/desktop_widgets/clock1/temp/clock.css create mode 100644 public/desktop_widgets/weather1/img/clouds_180x150_bg.jpg create mode 100644 public/desktop_widgets/weather1/index.html.erb create mode 100644 public/desktop_widgets/weather1/weather1.js diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 75cff229..bd31a553 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -82,34 +82,27 @@ var orbitDesktop = function(dom){ var ww = $(window).width(); $("img#thmbackground").attr({"width":ww}); }); - $(o.contentHolder).mousemove(function(event){ - /*if(($(window).width()-50)<=event.pageX){ - $("#holder").animate({scrollLeft:$("#holder").scrollLeft()+500},1000); - } - if(event.pageX<300){ - $("#holder").animate({scrollLeft:0},1000); - }*/ + var $widget_fn = $('.widget_fn'),$fn_des = $('.fn_des'); + $widget_fn.hover(function(){ + var fn_name = $(this).find('img').attr('alt'),nth = $(this).parents('.d_cate').index(),des_left = $('.dock_child').eq(nth).width(); + $(this).addClass('thmc1'); + $fn_des.text(fn_name).css({'top':nth * 60,'left': des_left + 60}).stop(true, true).fadeIn(); + },function(){ + $(this).removeClass('thmc1'); + $fn_des.stop(true, true).fadeOut(); }); - var $widget_fn = $('.widget_fn'),$fn_des = $('.fn_des'); - $widget_fn.hover(function(){ - var fn_name = $(this).find('img').attr('alt'),nth = $(this).parents('.d_cate').index(),des_left = $('.dock_child').eq(nth).width(); - $(this).addClass('thmc1'); - $fn_des.text(fn_name).css({'top':nth * 60,'left': des_left + 60}).stop(true, true).fadeIn(); - },function(){ - $(this).removeClass('thmc1'); - $fn_des.stop(true, true).fadeOut(); - }); }; this.initializeDesktop = function(target){ if(!target)target = "desktop"; o.currenthtml = target; o.currentface = "home"; - var groupWrapperWidth = 0; - var groupWrapperHeight = 0; + var extraspace = 300; var currentElement, elementParent, targetParent, tempElement, widthcheck; widthcheck = false; var bindHandlers = function(){ + var groupWrapperWidth = 0; + var groupWrapperHeight = 0; $(".element").mousedown(function(){ currentElement = $(this); elementParent = $(this).parent(); @@ -163,16 +156,65 @@ var orbitDesktop = function(dom){ $(this).removeClass('thmc2'); }); } + } + + var loadTiles = function(id){ + $("div#group_wrapper").empty(); + $.getJSON("/desktop/getgroups",{sectionid:id},function(groups){ + var tilecolors = o.themesettings.tilecolor; + var opacity = ["op05","op06","op07","op08"]; + $.each(groups,function(i,group){ + group.sort(o.sortJSON("position",true,parseInt)); + var $group = $('
'); + $.each(group,function(j,tile){ + var tilecolor = tilecolors[Math.floor(Math.random()*tilecolors.length)]; + var op = opacity[Math.floor(Math.random()*opacity.length)]; + if(tile.data_category == "app") + $li = $('
  • '+tile.title+'

  • '); + else + $li = $('
  • '+tile.title+'

    test content
  • '); + $group.find("ul").append($li); + }) + $("div#group_wrapper").append($group); + }) + bindHandlers(); + o.initializeWidgets(); + }) + } + var loadSectionList = function(){ + $.getJSON("/desktop/getsectionlist",{desktopid:o.desktopId},function(sectionlist){ + $.each(sectionlist,function(i,section){ + var tempstyle=""; + if(i==0){ + tempstyle = "style='display:none;'"; + $("span#section_heading").text(section.name); + } + $("ul#section_list").append($('
  • '+section.name+'
  • ')); + }) + bindSecondaryHandlers(); + }) + } + + var bindSecondaryHandlers = function(){ + $("ul#section_list li.section_name").click(function(){ + $("li.section_name").show(); + $(this).hide(); + $("span#section_heading").text($(this).text()); + loadTiles($(this).find("a").attr("href")); + }) + } + if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load("/desktop/"+target,function(){ - bindHandlers(); - o.initializeWidgets(); + loadTiles(o.sectionId); + loadSectionList(); }); }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); - bindHandlers(); - o.initializeWidgets(); + bindHandlers(); + o.initializeWidgets(); + bindSecondaryHandlers(); } }; this.tempFunc = function(){ @@ -206,7 +248,7 @@ var orbitDesktop = function(dom){ //for Alphabet sorting $("a#alphabet_sort_btn").click(function(){ - switch ($(this).attr("href")) { + switch ($(this).attr("href")){ case "ascending": $(this).attr("href","descending").find(".thmtxt").text("Alphabet [Z-A]"); allApps = $(".group_search .element").sort(sortAscending); @@ -225,7 +267,6 @@ var orbitDesktop = function(dom){ if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load("/desktop/"+target,function(){ bindHandlers(); - }); }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); @@ -276,9 +317,10 @@ var orbitDesktop = function(dom){ }); } }; + if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load("/desktop/"+target,function(){ - bindHandlers(); + bindHandlers(); }); }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); @@ -294,14 +336,14 @@ var orbitDesktop = function(dom){ o.changeTheme($(this).val()); }) } - if(!o.desktopData[o.currentface]){ + // if(!o.desktopData[o.currentface]){ $(o.contentHolder).empty().load("/desktop/"+target,function(){ bindHandlers(); }); - }else{ - $(o.contentHolder).html(o.desktopData[o.currentface]); - bindHandlers(); - } + // }else{ + // $(o.contentHolder).html(o.desktopData[o.currentface]); + // bindHandlers(); + // } }; this.loadWallpaper = function(wallpaper){ if(!wallpaper)wallpaper = o.themesettings.background; @@ -326,7 +368,7 @@ var orbitDesktop = function(dom){ $.each(elements,function(){ var widget = $(this); 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(){ widget.find("div.appholder").load("/desktop_widgets/"+widgename+"/index.html.erb"); }); @@ -343,4 +385,6 @@ orbitDesktop.prototype.widgetfolder = "desktop_widgets"; orbitDesktop.prototype.desktopId = "1"; orbitDesktop.prototype.notifyImgPath = "temp"; -// devin +var uselessfunction = function(){ + $.post("/desktop/temp_func",{sectionid:"4f83e7bbbd98eb041600001d"}); +} diff --git a/app/assets/javascripts/orbitdesktopAPI.js b/app/assets/javascripts/orbitdesktopAPI.js index b9594e3b..f0360b67 100644 --- a/app/assets/javascripts/orbitdesktopAPI.js +++ b/app/assets/javascripts/orbitdesktopAPI.js @@ -38,4 +38,17 @@ var orbitDesktopAPI = function(){ if(!time)time=5000; else time=time*1000; $notify.slideDown().delay(time).slideUp(); }; + this.executeFunc = function(func,callbackFn){ + func.call(this); + if(callbackFn){ + callbackFn.call(this,func); + } + }; + this.sortJSON = function(field, reverse, primer){ + var key = function (x) {return primer ? primer(x[field]) : x[field]}; + return function (a,b) { + var A = key(a), B = key(b); + return ((A < B) ? -1 : (A > B) ? +1 : 0) * [-1,1][+!!reverse]; + } + } }; \ No newline at end of file diff --git a/app/controllers/desktop_controller.rb b/app/controllers/desktop_controller.rb index 987f09ce..b1d78c0a 100644 --- a/app/controllers/desktop_controller.rb +++ b/app/controllers/desktop_controller.rb @@ -3,6 +3,7 @@ class DesktopController< ApplicationController before_filter :authenticate_user! def index @desktop = current_user.desktop + @section = @desktop.sections.first end def desktop @@ -34,4 +35,37 @@ class DesktopController< ApplicationController def settings render :layout => false end + + def getgroups + @section = Section.find(params["sectionid"]) + @groups = @section.groups + a = Array.new + @groups.each do |group| + a << group.tiles + end + render :json =>a.to_json + end + + def getsectionlist + @desktop = Desktop.find(params["desktopid"]) + @sections = @desktop.sections + render :json => @sections.to_json + end + + def temp_func + @section = Section.find(params["sectionid"]) + @groups = @section.groups + + @groups.each do |group| + a = 1; + @tiles = group.tiles + @tiles.each do |tile| + tile.update_attributes({:data_category => "widget",:data_content => "temp", :position => a}) + a = a+1; + end + end + b = Array.new + b << {"success"=>"true"} + render :json=>b.to_json + end end \ No newline at end of file diff --git a/app/models/group.rb b/app/models/group.rb index 4918514d..7346ad1e 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -7,8 +7,12 @@ class Group before_create :initialize_tile def initialize_tile - self.tiles.build - self.tiles.build + 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") end end diff --git a/app/models/tile.rb b/app/models/tile.rb index 010b9376..70066d1b 100644 --- a/app/models/tile.rb +++ b/app/models/tile.rb @@ -2,6 +2,12 @@ class Tile include Mongoid::Document include Mongoid::Timestamps + field :data_category + field :data_content + field :position, type: Integer + field :shape + field :title + belongs_to :group diff --git a/app/views/desktop/desktop.html.erb b/app/views/desktop/desktop.html.erb index aef45911..cd9d9602 100755 --- a/app/views/desktop/desktop.html.erb +++ b/app/views/desktop/desktop.html.erb @@ -1,12 +1,13 @@