From 868d1c2201197ac65e7aaf8186f8370787b93628 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 22 Nov 2012 16:31:37 +0800 Subject: [PATCH] fix for json and some other bugs --- .../javascripts/desktop/journal_pages.js.erb | 1 + app/assets/javascripts/orbitdesktop.js | 57 +++++++++++-------- config/mongoid.yml | 2 +- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/desktop/journal_pages.js.erb b/app/assets/javascripts/desktop/journal_pages.js.erb index 139f94fc..2c6821da 100644 --- a/app/assets/javascripts/desktop/journal_pages.js.erb +++ b/app/assets/javascripts/desktop/journal_pages.js.erb @@ -1,5 +1,6 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // this init journal papers this.initializeJournalPapers.formCallback = function(data){ + if(data.success){ o.notify(data.msg,"success"); o.sub_menu_item($("div[content-type=menu] a").eq(0)); }else{ diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index bf5e35fe..dc183d3d 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -2,8 +2,10 @@ //harry //Inititialize function will initialize desktop -//callback-method will be called after desktop controlled ajax call; +//callback-method will be called after desktop controlled ajax call //container=true is the area where the view will be loaded +//load = true is used to load the list element by default +//response-type = "json"|"script"|"xml|html" default is json $.extend($.expr[':'], { @@ -88,30 +90,30 @@ var orbitDesktop = function(dom){ o.data_method = $(this).attr("callback-method"); if(o.currenthtml!=target){ if(o.desktopData[o.currentface] == "undefined") - o.desktopData[o.currentface] = ""; - o.desktopData[o.currentface] = $(o.contentHolder).html(); - $("#content").hide("drop",o.transitionTime,function(){ - o.currenthtml = target; - o.currentface = target; - var cache = false; - if(!o.desktopData[o.currentface]){ - $(o.contentHolder).empty().load(url,function(){ - if(typeof o.data_method != "undefined"){ - if(o.data_method != "") - window.o[o.data_method](target,url,cache); + o.desktopData[o.currentface] = ""; + o.desktopData[o.currentface] = $(o.contentHolder).html(); + $("#content").hide("drop",o.transitionTime,function(){ + o.currenthtml = target; + o.currentface = target; + var cache = false; + if(!o.desktopData[o.currentface]){ + $(o.contentHolder).empty().load(url,function(){ + if(typeof o.data_method != "undefined"){ + if(o.data_method != "") + window.o[o.data_method](target,url,cache); + } + o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]")); + }) + }else{ + $(o.contentHolder).html(o.desktopData[o.currentface]); + o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]")); + cache = true; + if(typeof o.data_method != "undefined"){ + if(o.data_method != "") + window.o[o.data_method](target,url,cache); + } } - o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]")); }); - }else{ - $(o.contentHolder).html(o.desktopData[o.currentface]); - o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]").trigger("click")); - cache = true; - if(typeof o.data_method != "undefined"){ - if(o.data_method != "") - window.o[o.data_method](target,url,cache); - } - } - }); } return false; }) @@ -135,13 +137,22 @@ var orbitDesktop = function(dom){ $("body").on("submit","form[form-type=ajax_form]",function(){ var callback_method = $(this).attr("callback-method"); + var dt = null; + dt = $(this).attr("response-type"); + if(dt == null){ + dt = "json"; + } var options = { + dataType : dt, success:function(responseText, statusText, xhr, $form){ if(typeof callback_method != "undefined"){ if(callback_method != ""){ window.o[o.data_method][callback_method](responseText,statusText,xhr,$form); } } + }, + error:function(){ + o.notify("Please try again later!","imp"); } } $(this).ajaxSubmit(options); diff --git a/config/mongoid.yml b/config/mongoid.yml index 75c5ef80..a809bc06 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -2,7 +2,7 @@ defaults: &defaults host: localhost # slaves: # - host: slave1.local - port: 37017 + port: 27017 # - host: slave2.local # port: 27019