From 4bad25e682f575f4b69ea298a62a5b4ff2b08c0d Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 18 Apr 2012 22:01:12 +0800 Subject: [PATCH] Msg box added and background image saving complete --- app/assets/javascripts/orbitdesktop.js | 92 ++++++++++++++++------ app/assets/javascripts/orbitdesktopAPI.js | 46 +++++++---- app/controllers/desktop_controller.rb | 3 + app/models/desktop.rb | 1 + app/views/desktop/index.html.erb | 4 +- app/views/desktop/settings/themes.html.erb | 26 +++--- 6 files changed, 117 insertions(+), 55 deletions(-) diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index f6f09d76..605cae43 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -1,5 +1,20 @@ // JavaScript Document -//harry +//harry +$.extend($.expr[':'], { + 'containsi': function (elem, i, match, array) { + return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; + } +}); +$.fn.sort = function(c) { + return this.pushStack([].sort.apply(this, arguments), []); + }; +var sortAscending = function(a, b) { + return $(a).find("h1").text() > $(b).find("h1").text() ? 1 : -1; +}; +var sortDescending = function(a, b) { + return $(a).find("h1").text() < $(b).find("h1").text() ? 1 : -1; +}; + var orbitDesktop = function(dom){ orbitDesktopAPI.apply(this); o = this; @@ -25,18 +40,18 @@ var orbitDesktop = function(dom){ custom = true; } o.theme = theme; - loadTheme(desktopSettings.customtheme); + loadTheme(desktopSettings.customtheme,desktopSettings.wallpaper); }else{loadTheme();} }) - var loadTheme = function(dhtml){ + var loadTheme = function(customtheme,customwallpaper){ $.getJSON("/"+o.themefolder+"/"+theme+"/settings/"+theme+".json",function(ts){ o.themesettings = eval(ts); $('head').append( $('').attr('href', "/"+o.themefolder+"/"+theme+"/css/"+ts.css)); if(custom){ $("head").find("#dyn_css").remove(); - $("head").append(dhtml); + $("head").append(customtheme); } - $(document).ready(function(){o.loadWallpaper();o.bindDesktopEvents();o.loadIconCache();o.initializeDesktop();}); + $(document).ready(function(){o.loadWallpaper(customwallpaper);o.bindDesktopEvents();o.loadIconCache();o.initializeDesktop();}); }) } }; @@ -263,7 +278,9 @@ var orbitDesktop = function(dom){ } }; this.tempFunc = function(th){ - + o.confirm("What","","",function(reply){ + alert(reply); + }) } this.initializeAppSearch = function(target){ o.currenthtml = target; @@ -602,25 +619,33 @@ var orbitDesktop = function(dom){ }); $("a#theme_submit").click(function(){ - var colors = new Array; - $("tr#color_inputs input").each(function(){ - colors[$(this).attr("for")] = $(this).val(); - }) - var dhtml =""; - $("head").find("#dyn_css").remove(); - $("head").append(dhtml); - $.post("/desktop/save_desktop_settings",{"save":"customtheme","desktopid":o.desktopId,"theme":dhtml},function(result,status){ - if(status=="success"){ - if(result[0].success=="true") - o.notify("Custom theme saved!!","success",2); - else - o.notify("Custom theme saving failed!!","imp",2); - }else{ - o.notify("Connection problem!!","alert",2); + o.confirm("Are you sure that you want to set this custom theme?",["Yes","No"],3,function(reply){ + if(reply){ + var colors = new Array; + $("#color_input input").each(function(){ + colors[$(this).attr("for")] = $(this).val(); + }) + var dhtml =""; + $("head").find("#dyn_css").remove(); + $("head").append(dhtml); + $.post("/desktop/save_desktop_settings",{"save":"customtheme","desktopid":o.desktopId,"theme":dhtml},function(result,status){ + if(status=="success"){ + if(result[0].success=="true") + o.notify("Custom theme saved!!","success",2); + else + o.notify("Custom theme saving failed!!","imp",2); + }else{ + o.notify("Connection problem!!","alert",2); + } + }) } }) + }); + + $(".stock_wallpaper .ssl_item").click(function(){ + var wallpapername = $(this).find("img").attr("alt"); + o.changeWallpaper(wallpapername); }) - } var loadthmc = function(){ $('.color-picker').each(function(){ @@ -658,17 +683,19 @@ var orbitDesktop = function(dom){ themes(); }); }; + this.loadWallpaper = function(wallpaper){ - if(!wallpaper)wallpaper = o.themesettings.background; + if(!wallpaper)wallpapernm = o.themesettings.background;else wallpapernm = wallpaper var ww = $(window).width(); var wh = $(window).height(); - if(o.themesettings.background) - $("img#thmbackground").attr({"src":"/"+o.themefolder+"/"+o.theme+"/images/"+wallpaper,"width":ww}).css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","height":"auto"}); + if(!wallpaper) + $("img#thmbackground").attr({"src":"/"+o.themefolder+"/"+o.theme+"/images/"+wallpapernm,"width":ww}).css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","height":"auto"}); else - $("img#thmbackground").attr({"src":"/"+"images/"+wallpaper,"width":ww}).css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","height":"auto"}); + $("img#thmbackground").attr({"src":o.wallpaperPath+wallpaper,"width":ww}).css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","height":"auto"}); $("div#bgover").css({"position":"fixed","top":"0px","left":"0px","z-index":"-1","width":ww,"height":wh}); }; + this.loadIconCache = function(){ var imgs = $("ul.docklist img"); $.each(imgs,function(){ @@ -690,6 +717,18 @@ var orbitDesktop = function(dom){ }) }; + this.saveWallpaper = function(wallpaper){ + $.post("desktop/save_desktop_settings",{"save":"wallpaper","wallpapernm":wallpaper,"desktopid":o.desktopId},function(result,status){ + if(status=="success"){ + if(result[0].success=="true") + o.notify("Wallpaper saved!!","success",2); + else + o.notify("Wallpaper saving failed!!","imp",2); + }else{ + o.notify("Connection problem!!","alert",2); + } + }) + } o.initialize(); } @@ -697,6 +736,7 @@ orbitDesktop.prototype.themefolder = "themes"; orbitDesktop.prototype.widgetfolder = "desktop_widgets"; orbitDesktop.prototype.desktopId = "1"; orbitDesktop.prototype.notifyImgPath = "temp"; +orbitDesktop.prototype.wallpaperPath = "/assets/stockBackground/"; orbitDesktop.prototype.iconPath = "/assets/icons/"; orbitDesktop.prototype.currentLanguage = "en"; var uselessfunction = function(){ diff --git a/app/assets/javascripts/orbitdesktopAPI.js b/app/assets/javascripts/orbitdesktopAPI.js index 83e0af39..95447c19 100644 --- a/app/assets/javascripts/orbitdesktopAPI.js +++ b/app/assets/javascripts/orbitdesktopAPI.js @@ -1,18 +1,5 @@ // JavaScript Document -$.extend($.expr[':'], { - 'containsi': function (elem, i, match, array) { - return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; - } -}); -$.fn.sort = function(c) { - return this.pushStack([].sort.apply(this, arguments), []); - }; -var sortAscending = function(a, b) { - return $(a).find("h1").text() > $(b).find("h1").text() ? 1 : -1; -}; -var sortDescending = function(a, b) { - return $(a).find("h1").text() < $(b).find("h1").text() ? 1 : -1; -}; +//Harry Bomrah var orbitDesktopAPI = function(){ o = this; this.notify = function(msg,type,time){ @@ -63,4 +50,35 @@ var orbitDesktopAPI = function(){ } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); }; + this.changeWallpaper = function(wallpaper){ + $("img#thmbackground").attr("src",o.wallpaperPath+wallpaper); + o.saveWallpaper(wallpaper); + }; + this.confirm = function(msg,btnvalues,highlighted,callbackfn){ + if(!btnvalues)btnvalues=["Ok","Cancel"]; + if(highlighted!=1 || highlighted!=2)highlighted=2; + if(!msg)msg = "Are you sure?" + var $confirm = $("#orbitdiag"); + $confirm.find(".diag_action a").addClass("admbg admtxt"); + $confirm.find(".diag_message").text(msg); + if(highlighted == 1) + $confirm.find("#diag_confirm").removeClass("admbg admtxt").addClass("thmc1 thmtxt"); + if(highlighted == 2) + $confirm.find("#diag_cancel").removeClass("admbg admtxt").addClass("thmc1 thmtxt"); + $confirm.find("#diag_confirm").text(btnvalues[0]).one("click",function(){ + $confirm.hide(); + $confirm.find(".diag_action a").unbind(); + if(typeof callbackfn=="function") + callbackfn.call(this,true); + }); + $confirm.find("#diag_cancel").text(btnvalues[1]).one("click",function(){ + $confirm.hide(); + $confirm.find(".diag_action a").unbind(); + if(typeof callbackfn=="function") + callbackfn.call(this,false); + }); + $confirm.show(); + } }; +orbitDesktopAPI.prototype.notifyImgPath = "temp"; +orbitDesktopAPI.prototype.wallpaperPath = "temp"; diff --git a/app/controllers/desktop_controller.rb b/app/controllers/desktop_controller.rb index c94f8328..997267be 100644 --- a/app/controllers/desktop_controller.rb +++ b/app/controllers/desktop_controller.rb @@ -42,6 +42,7 @@ class DesktopController< ApplicationController case @savewhat when "theme" @desktop.update_attributes(:theme => params["theme"]) + @desktop.update_attributes(:wallpaper => nil) when "desktopnames" @sections = @desktop.sections x = 0; @@ -64,6 +65,8 @@ class DesktopController< ApplicationController when "customtheme" @desktop.update_attributes(:theme => "custom") @desktop.update_attributes(:customtheme => params['theme']) + when "wallpaper" + @desktop.update_attributes(:wallpaper => params["wallpapernm"]) end a = Array.new a << {"success"=>"true"} diff --git a/app/models/desktop.rb b/app/models/desktop.rb index cb804684..2b3aa402 100644 --- a/app/models/desktop.rb +++ b/app/models/desktop.rb @@ -4,6 +4,7 @@ class Desktop field :theme, default: "default" field :customtheme + field :wallpaper belongs_to :user diff --git a/app/views/desktop/index.html.erb b/app/views/desktop/index.html.erb index d4474f68..ebe4048c 100755 --- a/app/views/desktop/index.html.erb +++ b/app/views/desktop/index.html.erb @@ -81,8 +81,8 @@
Continue anyway?
- Yes - Cancel + Yes + Cancel
diff --git a/app/views/desktop/settings/themes.html.erb b/app/views/desktop/settings/themes.html.erb index 9be87d27..c43feb4b 100644 --- a/app/views/desktop/settings/themes.html.erb +++ b/app/views/desktop/settings/themes.html.erb @@ -64,21 +64,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
1.jpg
+
2.jpg
+
3.jpg
+
4.jpg
+
5.jpg
+
6.jpg
+
7.jpg
+
8.jpg
+
9.jpg
+
10.jpg
+
11.jpg
+
12.jpg
- Confirm +