Author: tyrell Date: Thu Jun 5 02:15:17 2008 New Revision: 17980 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17980
Log: Adding gadget removal code to the widgets. Modified: trunk/mashup/java/modules/dashboard/ajax_add_gadget.jsp trunk/mashup/java/modules/dashboard/index.jsp trunk/mashup/java/modules/dashboard/javascript/gadgets.js Modified: trunk/mashup/java/modules/dashboard/ajax_add_gadget.jsp URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/dashboard/ajax_add_gadget.jsp?rev=17980&r1=17979&r2=17980&view=diff ============================================================================== --- trunk/mashup/java/modules/dashboard/ajax_add_gadget.jsp (original) +++ trunk/mashup/java/modules/dashboard/ajax_add_gadget.jsp Thu Jun 5 02:15:17 2008 @@ -18,6 +18,8 @@ <%@ page import="org.wso2.registry.exceptions.RegistryException" %> <%@ page import="org.wso2.registry.ResourceImpl" %> <%@ page import="java.util.ArrayList" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="java.net.URLDecoder" %> <% String thisPage = request.getContextPath() + "/ajax_add_gadget.jsp"; @@ -32,7 +34,8 @@ String reason = ""; String gadgetPath = MashupConstants.USERS_PATH + "/" + currentUser + "/gadgets"; - String gadgetUrl = request.getParameter("gadgetUrl"); + String gadgetUrl = URLDecoder.decode(request.getParameter("gadgetUrl"), "UTF-08"); + String method = request.getParameter("_method"); Resource gadgetList = null; @@ -41,9 +44,19 @@ success = false; reason = "Unauthorized attempt to add a gadget - please log in and try again."; } else if (request.getMethod().equals("POST")) { - String method = request.getParameter("_method"); + if (method != null && method.equals("delete")) { - // todo Add deletion code + try { + gadgetList = userRegistry.get(gadgetPath); + ArrayList gadgetUrls = (ArrayList) gadgetList.getPropertyValues("GADGET_LIST"); + gadgetUrls.remove(Integer.parseInt(request.getParameter("urlIndex"))); + gadgetList.setProperty("GADGET_LIST", gadgetUrls); + + } catch (RegistryException e) { + success = false; + reason = "Gadget information is not available for the user '" + currentUser + + "' in the registry."; + } } else { try { gadgetList = userRegistry.get(gadgetPath); @@ -59,14 +72,16 @@ gadgetUrls.add(gadgetUrl); gadgetList.setProperty("GADGET_LIST", gadgetUrls); } - - try { - userRegistry.put(gadgetPath, gadgetList); - } catch (RegistryException e) { - success = false; - reason = e.getMessage(); - } } + + // Updating the registry with the new gadget list + try { + userRegistry.put(gadgetPath, gadgetList); + } catch (RegistryException e) { + success = false; + reason = e.getMessage(); + } + } } catch (RegistryException e) { success = false; @@ -77,7 +92,13 @@ Error! <%=reason%> </div> <% } else { + if (method != null && method.equals("delete")) { +%> +deleted +<% +} else { %> Done. The gadget will appear in your dashboard after a refresh <% + } }%> \ No newline at end of file Modified: trunk/mashup/java/modules/dashboard/index.jsp URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/dashboard/index.jsp?rev=17980&r1=17979&r2=17980&view=diff ============================================================================== --- trunk/mashup/java/modules/dashboard/index.jsp (original) +++ trunk/mashup/java/modules/dashboard/index.jsp Thu Jun 5 02:15:17 2008 @@ -48,6 +48,7 @@ <script type="text/javascript" src="js/rpc.js?c=1&debug=1"></script> <script type="text/javascript" src="javascript/cookies.js"></script> <script type="text/javascript" src="javascript/util.js"></script> + <script type="text/javascript" src="javascript/prototype.js"></script> <script type="text/javascript" src="javascript/gadgets.js"></script> <script type="text/javascript" src="javascript/cookiebaseduserprefstore.js"></script> <script type="text/javascript"> @@ -117,7 +118,7 @@ wso2.dashboard.renderGadgets = function() { for (var i = 0; i < wso2.dashboard.gadgetSpecUrls.length; ++i) { var gadget = gadgets.container.createGadget( - {specUrl: wso2.dashboard.gadgetSpecUrls[i]}); + {specUrl: wso2.dashboard.gadgetSpecUrls[i], urlIndex: i}); gadgets.container.addGadget(gadget); gadgets.container.renderGadget(gadget); } Modified: trunk/mashup/java/modules/dashboard/javascript/gadgets.js URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/dashboard/javascript/gadgets.js?rev=17980&r1=17979&r2=17980&view=diff ============================================================================== --- trunk/mashup/java/modules/dashboard/javascript/gadgets.js (original) +++ trunk/mashup/java/modules/dashboard/javascript/gadgets.js Thu Jun 5 02:15:17 2008 @@ -27,14 +27,14 @@ gadgets.error.TO_BE_DONE = 'to be done'; gadgets.log = function(message) { - if (window.console && console.log) { - console.log(message); - } else { - var logEntry = document.createElement('div'); - logEntry.className = 'gadgets-log-entry'; - logEntry.innerHTML = message; - document.body.appendChild(logEntry); - } + if (window.console && console.log) { + console.log(message); + } else { + var logEntry = document.createElement('div'); + logEntry.className = 'gadgets-log-entry'; + logEntry.innerHTML = message; + document.body.appendChild(logEntry); + } }; /** @@ -53,21 +53,21 @@ * function */ gadgets.callAsyncAndJoin = function(functions, continuation, opt_this) { - var pending = functions.length; - var results = []; - for (var i = 0; i < functions.length; i++) { - // we need a wrapper here because i changes and we need once index - // variable per closure - var wrapper = function(index) { - functions[index].call(opt_this, function(result) { - results[index] = result; - if (--pending == 0) { - continuation(results); - } - }); - }; - wrapper(i); - } + var pending = functions.length; + var results = []; + for (var i = 0; i < functions.length; i++) { + // we need a wrapper here because i changes and we need once index + // variable per closure + var wrapper = function(index) { + functions[index].call(opt_this, function(result) { + results[index] = result; + if (--pending == 0) { + continuation(results); + } + }); + }; + wrapper(i); + } }; @@ -83,9 +83,9 @@ * container as dependencies */ gadgets.Extensible.prototype.setDependencies = function(dependencies) { - for (var p in dependencies) { - this[p] = dependencies[p]; - } + for (var p in dependencies) { + this[p] = dependencies[p]; + } }; /** @@ -94,7 +94,7 @@ * @return {Object} Dependency with that name or undefined if not found */ gadgets.Extensible.prototype.getDependencies = function(name) { - return this[name]; + return this[name]; }; @@ -115,7 +115,7 @@ * @return {Object} All user preference of given gadget */ gadgets.UserPrefStore.prototype.getPrefs = function(gadget) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; /** @@ -124,7 +124,7 @@ * @param {Object} prefs User preferences */ gadgets.UserPrefStore.prototype.savePrefs = function(gadget) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; @@ -137,13 +137,15 @@ * @constructor */ gadgets.DefaultUserPrefStore = function() { - gadgets.UserPrefStore.call(this); + gadgets.UserPrefStore.call(this); }; gadgets.DefaultUserPrefStore.inherits(gadgets.UserPrefStore); -gadgets.DefaultUserPrefStore.prototype.getPrefs = function(gadget) { }; +gadgets.DefaultUserPrefStore.prototype.getPrefs = function(gadget) { +}; -gadgets.DefaultUserPrefStore.prototype.savePrefs = function(gadget) { }; +gadgets.DefaultUserPrefStore.prototype.savePrefs = function(gadget) { +}; // ------------- @@ -158,15 +160,15 @@ }; gadgets.GadgetService.prototype.setHeight = function(elementId, height) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; gadgets.GadgetService.prototype.setTitle = function(gadget, title) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; gadgets.GadgetService.prototype.setUserPref = function(id) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; @@ -178,31 +180,31 @@ * @constructor */ gadgets.IfrGadgetService = function() { - gadgets.GadgetService.call(this); - gadgets.rpc.register('resize_iframe', this.setHeight); - gadgets.rpc.register('set_pref', this.setUserPref); - gadgets.rpc.register('set_title', this.setTitle); - gadgets.rpc.register('requestNavigateTo', this.requestNavigateTo); + gadgets.GadgetService.call(this); + gadgets.rpc.register('resize_iframe', this.setHeight); + gadgets.rpc.register('set_pref', this.setUserPref); + gadgets.rpc.register('set_title', this.setTitle); + gadgets.rpc.register('requestNavigateTo', this.requestNavigateTo); }; gadgets.IfrGadgetService.inherits(gadgets.GadgetService); gadgets.IfrGadgetService.prototype.setHeight = function(height) { - if (height > gadgets.container.maxheight_) { - height = gadgets.container.maxheight_; - } - - var element = document.getElementById(this.f); - if (element) { - element.style.height = height + 'px'; - } + if (height > gadgets.container.maxheight_) { + height = gadgets.container.maxheight_; + } + + var element = document.getElementById(this.f); + if (element) { + element.style.height = height + 'px'; + } }; gadgets.IfrGadgetService.prototype.setTitle = function(title) { - var element = document.getElementById(this.f + '_title'); - if (element) { - element.innerHTML = title.replace(/&/g, '&').replace(/</g, '<'); - } + var element = document.getElementById(this.f + '_title'); + if (element) { + element.innerHTML = title.replace(/&/g, '&').replace(/</g, '<'); + } }; /** @@ -213,14 +215,14 @@ * More names and values may follow */ gadgets.IfrGadgetService.prototype.setUserPref = function(editToken, name, - value) { - var id = this.getGadgetIdFromModuleId(this.f); - var gadget = gadgets.container.getGadget(id); - var prefs = gadget.getUserPrefs(); - for (var i = 1, j = arguments.length; i < j; i += 2) { - prefs[arguments[i]] = arguments[i + 1]; - } - gadget.setUserPrefs(prefs); + value) { + var id = this.getGadgetIdFromModuleId(this.f); + var gadget = gadgets.container.getGadget(id); + var prefs = gadget.getUserPrefs(); + for (var i = 1, j = arguments.length; i < j; i += 2) { + prefs[arguments[i]] = arguments[i + 1]; + } + gadget.setUserPrefs(prefs); }; /** @@ -228,20 +230,20 @@ * parameters. */ gadgets.IfrGadgetService.prototype.requestNavigateTo = function(view, - opt_params) { - var id = this.getGadgetIdFromModuleId(this.f); - var url = this.getUrlForView(view); - - if (opt_params) { - var paramStr = JSON.stringify(opt_params); - if (paramStr.length > 0) { - url += '&appParams=' + encodeURIComponent(paramStr); - } - } - - if (url && document.location.href.indexOf(url) == -1) { - document.location.href = url; - } + opt_params) { + var id = this.getGadgetIdFromModuleId(this.f); + var url = this.getUrlForView(view); + + if (opt_params) { + var paramStr = JSON.stringify(opt_params); + if (paramStr.length > 0) { + url += '&appParams=' + encodeURIComponent(paramStr); + } + } + + if (url && document.location.href.indexOf(url) == -1) { + document.location.href = url; + } }; /** @@ -252,20 +254,20 @@ * @param view The view name to get the url for */ gadgets.IfrGadgetService.prototype.getUrlForView = function( - view) { - if (view === 'canvas') { - return '/canvas'; - } else if (view === 'profile') { - return '/profile'; - } else { - return null; - } + view) { + if (view === 'canvas') { + return '/canvas'; + } else if (view === 'profile') { + return '/profile'; + } else { + return null; + } } gadgets.IfrGadgetService.prototype.getGadgetIdFromModuleId = function( - moduleId) { - // Quick hack to extract the gadget id from module id - return parseInt(moduleId.match(/_([0-9]+)$/)[1], 10); + moduleId) { + // Quick hack to extract the gadget id from module id + return parseInt(moduleId.match(/_([0-9]+)$/)[1], 10); }; @@ -286,7 +288,7 @@ * @return {Object} HTML element that is the chrome for the given gadget */ gadgets.LayoutManager.prototype.getGadgetChrome = function(gadget) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; // ------------------- @@ -297,7 +299,7 @@ * @constructor */ gadgets.StaticLayoutManager = function() { - gadgets.LayoutManager.call(this); + gadgets.LayoutManager.call(this); }; gadgets.StaticLayoutManager.inherits(gadgets.LayoutManager); @@ -307,13 +309,13 @@ * @param {Array} gadgetIdToChromeIdMap Gadget id to chrome id map */ gadgets.StaticLayoutManager.prototype.setGadgetChromeIds = - function(gadgetChromeIds) { - this.gadgetChromeIds_ = gadgetChromeIds; +function(gadgetChromeIds) { + this.gadgetChromeIds_ = gadgetChromeIds; }; gadgets.StaticLayoutManager.prototype.getGadgetChrome = function(gadget) { - var chromeId = this.gadgetChromeIds_[gadget.id]; - return chromeId ? document.getElementById(chromeId) : null; + var chromeId = this.gadgetChromeIds_[gadget.id]; + return chromeId ? document.getElementById(chromeId) : null; }; @@ -327,24 +329,24 @@ * gadgets. */ gadgets.FloatLeftLayoutManager = function(layoutRootId) { - gadgets.LayoutManager.call(this); - this.layoutRootId_ = layoutRootId; + gadgets.LayoutManager.call(this); + this.layoutRootId_ = layoutRootId; }; gadgets.FloatLeftLayoutManager.inherits(gadgets.LayoutManager); gadgets.FloatLeftLayoutManager.prototype.getGadgetChrome = - function(gadget) { - var layoutRoot = document.getElementById(this.layoutRootId_); - if (layoutRoot) { - var chrome = document.createElement('div'); - chrome.className = 'gadgets-gadget-chrome'; - chrome.style.cssFloat = 'left' - layoutRoot.appendChild(chrome); - return chrome; - } else { - return null; - } +function(gadget) { + var layoutRoot = document.getElementById(this.layoutRootId_); + if (layoutRoot) { + var chrome = document.createElement('div'); + chrome.className = 'gadgets-gadget-chrome'; + chrome.style.cssFloat = 'left' + layoutRoot.appendChild(chrome); + return chrome; + } else { + return null; + } }; @@ -373,52 +375,52 @@ * javascript */ gadgets.Gadget = function(params) { - this.userPrefs_ = {}; + this.userPrefs_ = {}; - if (params) { - for (var name in params) if (params.hasOwnProperty(name)) { - this[name] = params[name]; - } - } - if (!this.secureToken) { - // Assume that the default security token implementation is - // in use on the server. - this.secureToken = 'john.doe:john.doe:appid:synd:url:0'; - } + if (params) { + for (var name in params) if (params.hasOwnProperty(name)) { + this[name] = params[name]; + } + } + if (!this.secureToken) { + // Assume that the default security token implementation is + // in use on the server. + this.secureToken = 'john.doe:john.doe:appid:synd:url:0'; + } }; gadgets.Gadget.prototype.getUserPrefs = function() { - return this.userPrefs_; + return this.userPrefs_; }; gadgets.Gadget.prototype.setUserPrefs = function(userPrefs) { - this.userPrefs_ = userPrefs; - gadgets.container.userPrefStore.savePrefs(this); + this.userPrefs_ = userPrefs; + gadgets.container.userPrefStore.savePrefs(this); }; gadgets.Gadget.prototype.getUserPref = function(name) { - return this.userPrefs_[name]; + return this.userPrefs_[name]; }; gadgets.Gadget.prototype.setUserPref = function(name, value) { - this.userPrefs_[name] = value; - gadgets.container.userPrefStore.savePrefs(this); + this.userPrefs_[name] = value; + gadgets.container.userPrefStore.savePrefs(this); }; gadgets.Gadget.prototype.render = function(chrome) { - if (chrome) { - this.getContent(function(content) { - chrome.innerHTML = content; - }); - } + if (chrome) { + this.getContent(function(content) { + chrome.innerHTML = content; + }); + } }; gadgets.Gadget.prototype.getContent = function(continuation) { - gadgets.callAsyncAndJoin([ - this.getTitleBarContent, this.getUserPrefsDialogContent, - this.getMainContent], function(results) { + gadgets.callAsyncAndJoin([ + this.getTitleBarContent, this.getUserPrefsDialogContent, + this.getMainContent], function(results) { continuation(results.join('')); - }, this); + }, this); }; /** @@ -427,7 +429,7 @@ * the one and only argument */ gadgets.Gadget.prototype.getTitleBarContent = function(continuation) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; /** @@ -436,7 +438,7 @@ * content as the one and only argument */ gadgets.Gadget.prototype.getUserPrefsDialogContent = function(continuation) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; /** @@ -445,7 +447,7 @@ * the one and only argument */ gadgets.Gadget.prototype.getMainContent = function(continuation) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; /* @@ -453,7 +455,7 @@ * Override this method if you need any custom params. */ gadgets.Gadget.prototype.getAdditionalParams = function() { - return ''; + return ''; } @@ -461,8 +463,8 @@ // IfrGadget gadgets.IfrGadget = function(opt_params) { - gadgets.Gadget.call(this, opt_params); - this.serverBase_ = '../../' // default gadget server + gadgets.Gadget.call(this, opt_params); + this.serverBase_ = '../../' // default gadget server }; gadgets.IfrGadget.inherits(gadgets.Gadget); @@ -475,177 +477,200 @@ gadgets.IfrGadget.prototype.cssClassTitleBar = 'gadgets-gadget-title-bar'; gadgets.IfrGadget.prototype.cssClassTitle = 'gadgets-gadget-title'; gadgets.IfrGadget.prototype.cssClassTitleButtonBar = - 'gadgets-gadget-title-button-bar'; +'gadgets-gadget-title-button-bar'; gadgets.IfrGadget.prototype.cssClassGadgetUserPrefsDialog = - 'gadgets-gadget-user-prefs-dialog'; +'gadgets-gadget-user-prefs-dialog'; gadgets.IfrGadget.prototype.cssClassGadgetUserPrefsDialogActionBar = - 'gadgets-gadget-user-prefs-dialog-action-bar'; +'gadgets-gadget-user-prefs-dialog-action-bar'; gadgets.IfrGadget.prototype.cssClassTitleButton = 'gadgets-gadget-title-button'; gadgets.IfrGadget.prototype.cssClassGadgetContent = 'gadgets-gadget-content'; gadgets.IfrGadget.prototype.rpcToken = (0x7FFFFFFF * Math.random()) | 0; gadgets.IfrGadget.prototype.rpcRelay = '../rpc_relay.html'; gadgets.IfrGadget.prototype.getTitleBarContent = function(continuation) { - continuation('<div id="' + this.cssClassTitleBar + '-' + this.id + - '" class="' + this.cssClassTitleBar + '"><span id="' + - this.getIframeId() + '_title" class="' + - this.cssClassTitle + '">' + (this.title ? this.title : 'Title') + '</span> | <span class="' + - this.cssClassTitleButtonBar + - '"><a href="#" onclick="gadgets.container.getGadget(' + this.id + - ').handleOpenUserPrefsDialog();return false;" class="' + this.cssClassTitleButton + - '">settings</a> <a href="#" onclick="gadgets.container.getGadget(' + - this.id + ').handleToggle();return false;" class="' + this.cssClassTitleButton + - '">toggle</a> <a href="#" onclick="gadgets.container.getGadget(' + - this.id + ').handleRemove();return false;" class="' + this.cssClassTitleButton + - '">remove</a></span></div>'); + continuation('<div id="' + this.cssClassTitleBar + '-' + this.id + + '" class="' + this.cssClassTitleBar + '"><span id="' + + this.getIframeId() + '_title" class="' + + this.cssClassTitle + '">' + (this.title ? this.title : 'Title') + + '</span> | <span class="' + + this.cssClassTitleButtonBar + + '"><a href="#" onclick="gadgets.container.getGadget(' + this.id + + ').handleOpenUserPrefsDialog();return false;" class="' + this.cssClassTitleButton + + '">settings</a> <a href="#" onclick="gadgets.container.getGadget(' + + this.id + ').handleToggle();return false;" class="' + this.cssClassTitleButton + + '">toggle</a> <a href="#" onclick="gadgets.container.getGadget(' + + this.id + ').handleRemove();return false;" class="' + this.cssClassTitleButton + + '">remove</a></span></div>'); }; gadgets.IfrGadget.prototype.getUserPrefsDialogContent = function(continuation) { - continuation('<div id="' + this.getUserPrefsDialogId() + '" class="' + - this.cssClassGadgetUserPrefsDialog + '"></div>'); + continuation('<div id="' + this.getUserPrefsDialogId() + '" class="' + + this.cssClassGadgetUserPrefsDialog + '"></div>'); }; gadgets.IfrGadget.prototype.setServerBase = function(url) { - this.serverBase_ = url; + this.serverBase_ = url; }; gadgets.IfrGadget.prototype.getServerBase = function() { - return this.serverBase_; + return this.serverBase_; }; gadgets.IfrGadget.prototype.getMainContent = function(continuation) { - var iframeId = this.getIframeId(); - gadgets.rpc.setRelayUrl(iframeId, this.serverBase_ + this.rpcRelay); - gadgets.rpc.setAuthToken(iframeId, this.rpcToken); - continuation('<div class="' + this.cssClassGadgetContent + '"><iframe id="' + - iframeId + '" name="' + iframeId + '" class="' + this.cssClassGadget + - '" src="' + this.getIframeUrl() + - '" frameborder="no" scrolling="no"' + - (this.height ? ' height="' + this.height + '"' : '') + - (this.width ? ' width="' + this.width + '"' : '') + - '></iframe></div>'); + var iframeId = this.getIframeId(); + gadgets.rpc.setRelayUrl(iframeId, this.serverBase_ + this.rpcRelay); + gadgets.rpc.setAuthToken(iframeId, this.rpcToken); + continuation('<div class="' + this.cssClassGadgetContent + '"><iframe id="' + + iframeId + '" name="' + iframeId + '" class="' + this.cssClassGadget + + '" src="' + this.getIframeUrl() + + '" frameborder="no" scrolling="no"' + + (this.height ? ' height="' + this.height + '"' : '') + + (this.width ? ' width="' + this.width + '"' : '') + + '></iframe></div>'); }; gadgets.IfrGadget.prototype.getIframeId = function() { - return this.GADGET_IFRAME_PREFIX_ + this.id; + return this.GADGET_IFRAME_PREFIX_ + this.id; }; gadgets.IfrGadget.prototype.getUserPrefsDialogId = function() { - return this.getIframeId() + '_userPrefsDialog'; + return this.getIframeId() + '_userPrefsDialog'; }; gadgets.IfrGadget.prototype.getIframeUrl = function() { - return this.serverBase_ + 'dashboard/ifr?' + - 'url=' + encodeURIComponent(this.specUrl) + - '&container=' + this.CONTAINER + - '&mid=' + this.id + - '&nocache=' + gadgets.container.nocache_ + - '&country=' + gadgets.container.country_ + - '&lang=' + gadgets.container.language_ + - '&view=' + gadgets.container.view_ + - (this.specVersion ? '&v=' + this.specVersion : '') + - (gadgets.container.parentUrl_ ? '&parent=' + encodeURIComponent(gadgets.container.parentUrl_) : '') + - (this.debug ? '&debug=1' : '') + - this.getAdditionalParams() + - this.getUserPrefsParams() + - '#rpctoken=' + this.rpcToken + - (this.secureToken ? '&st=' + this.secureToken : '') + - (this.viewParams ? - '&view-params=' + encodeURIComponent(JSON.stringify(this.viewParams)) : '') + - (this.hashData ? '&' + this.hashData : ''); + return this.serverBase_ + 'dashboard/ifr?' + + 'url=' + encodeURIComponent(this.specUrl) + + '&container=' + this.CONTAINER + + '&mid=' + this.id + + '&nocache=' + gadgets.container.nocache_ + + '&country=' + gadgets.container.country_ + + '&lang=' + gadgets.container.language_ + + '&view=' + gadgets.container.view_ + + (this.specVersion ? '&v=' + this.specVersion : '') + + (gadgets.container.parentUrl_ ? + '&parent=' + encodeURIComponent(gadgets.container.parentUrl_) : '') + + (this.debug ? '&debug=1' : '') + + this.getAdditionalParams() + + this.getUserPrefsParams() + + '#rpctoken=' + this.rpcToken + + (this.secureToken ? '&st=' + this.secureToken : '') + + (this.viewParams ? + '&view-params=' + encodeURIComponent(JSON.stringify(this.viewParams)) : '') + + (this.hashData ? '&' + this.hashData : ''); }; gadgets.IfrGadget.prototype.getUserPrefsParams = function() { - var params = ''; - if (this.getUserPrefs()) { - for(var name in this.getUserPrefs()) { - var value = this.getUserPref(name); - params += '&up_' + encodeURIComponent(name) + '=' + - encodeURIComponent(value); + var params = ''; + if (this.getUserPrefs()) { + for (var name in this.getUserPrefs()) { + var value = this.getUserPref(name); + params += '&up_' + encodeURIComponent(name) + '=' + + encodeURIComponent(value); + } } - } - return params; + return params; } gadgets.IfrGadget.prototype.handleToggle = function() { - var gadgetIframe = document.getElementById(this.getIframeId()); - if (gadgetIframe) { - var gadgetContent = gadgetIframe.parentNode; - var display = gadgetContent.style.display; - gadgetContent.style.display = display ? '' : 'none'; - } + var gadgetIframe = document.getElementById(this.getIframeId()); + if (gadgetIframe) { + var gadgetContent = gadgetIframe.parentNode; + var display = gadgetContent.style.display; + gadgetContent.style.display = display ? '' : 'none'; + } }; gadgets.IfrGadget.prototype.handleRemove = function() { - alert("Remover code here..."); + new Ajax.Request("ajax_add_gadget.jsp", { + method: "post", + parameters: { + "gadgetUrl" : this.specUrl, + "urlIndex" : this.urlIndex, + "_method" : "delete" + }, + onSuccess: function (transport) { + var resp = transport.responseText.replace(/^\s+|\s+$/g, ''); + + if (resp == 'deleted') { + // Refresh the gadget container page + location.reload(); + } else { + alert(transport.responseText.replace(/^\s+|\s+$/g, '')); + } + }, + onFailure: function (transport) { + alert(transport.responseText.replace(/^\s+|\s+$/g, '')); + } + }); }; gadgets.IfrGadget.prototype.handleOpenUserPrefsDialog = function() { - if (this.userPrefsDialogContentLoaded) { - this.showUserPrefsDialog(); - } else { - var gadget = this; - var igCallbackName = 'ig_callback_' + this.id; - window[igCallbackName] = function(userPrefsDialogContent) { - gadget.userPrefsDialogContentLoaded = true; - gadget.buildUserPrefsDialog(userPrefsDialogContent); - gadget.showUserPrefsDialog(); - }; - - var script = document.createElement('script'); - script.src = 'http://gmodules.com/ig/gadgetsettings?url=' + this.specUrl + - '&mid=' + this.id + '&output=js' + this.getUserPrefsParams(); - document.body.appendChild(script); - } + if (this.userPrefsDialogContentLoaded) { + this.showUserPrefsDialog(); + } else { + var gadget = this; + var igCallbackName = 'ig_callback_' + this.id; + window[igCallbackName] = function(userPrefsDialogContent) { + gadget.userPrefsDialogContentLoaded = true; + gadget.buildUserPrefsDialog(userPrefsDialogContent); + gadget.showUserPrefsDialog(); + }; + + var script = document.createElement('script'); + script.src = 'http://gmodules.com/ig/gadgetsettings?url=' + this.specUrl + + '&mid=' + this.id + '&output=js' + this.getUserPrefsParams(); + document.body.appendChild(script); + } }; gadgets.IfrGadget.prototype.buildUserPrefsDialog = function(content) { - var userPrefsDialog = document.getElementById(this.getUserPrefsDialogId()); - userPrefsDialog.innerHTML = content + - '<div class="' + this.cssClassGadgetUserPrefsDialogActionBar + - '"><input type="button" value="Save" onclick="gadgets.container.getGadget(' + - this.id +').handleSaveUserPrefs()"> <input type="button" value="Cancel" onclick="gadgets.container.getGadget(' + - this.id +').handleCancelUserPrefs()"></div>'; - userPrefsDialog.childNodes[0].style.display = ''; + var userPrefsDialog = document.getElementById(this.getUserPrefsDialogId()); + userPrefsDialog.innerHTML = content + + '<div class="' + this.cssClassGadgetUserPrefsDialogActionBar + + '"><input type="button" value="Save" onclick="gadgets.container.getGadget(' + + this.id + + ').handleSaveUserPrefs()"> <input type="button" value="Cancel" onclick="gadgets.container.getGadget(' + + this.id + ').handleCancelUserPrefs()"></div>'; + userPrefsDialog.childNodes[0].style.display = ''; }; gadgets.IfrGadget.prototype.showUserPrefsDialog = function(opt_show) { - var userPrefsDialog = document.getElementById(this.getUserPrefsDialogId()); - userPrefsDialog.style.display = (opt_show || opt_show == undefined) - ? '' : 'none'; + var userPrefsDialog = document.getElementById(this.getUserPrefsDialogId()); + userPrefsDialog.style.display = (opt_show || opt_show == undefined) + ? '' : 'none'; } gadgets.IfrGadget.prototype.hideUserPrefsDialog = function() { - this.showUserPrefsDialog(false); + this.showUserPrefsDialog(false); }; gadgets.IfrGadget.prototype.handleSaveUserPrefs = function() { - this.hideUserPrefsDialog(); + this.hideUserPrefsDialog(); - var prefs = {}; - var numFields = document.getElementById('m_' + this.id + - '_numfields').value; - for (var i = 0; i < numFields; i++) { - var input = document.getElementById('m_' + this.id + '_' + i); - if (input.type != 'hidden') { - var userPrefNamePrefix = 'm_' + this.id + '_up_'; - var userPrefName = input.name.substring(userPrefNamePrefix.length); - var userPrefValue = input.value; - prefs[userPrefName] = userPrefValue; + var prefs = {}; + var numFields = document.getElementById('m_' + this.id + + '_numfields').value; + for (var i = 0; i < numFields; i++) { + var input = document.getElementById('m_' + this.id + '_' + i); + if (input.type != 'hidden') { + var userPrefNamePrefix = 'm_' + this.id + '_up_'; + var userPrefName = input.name.substring(userPrefNamePrefix.length); + var userPrefValue = input.value; + prefs[userPrefName] = userPrefValue; + } } - } - this.setUserPrefs(prefs); - this.refresh(); + this.setUserPrefs(prefs); + this.refresh(); }; gadgets.IfrGadget.prototype.handleCancelUserPrefs = function() { - this.hideUserPrefsDialog(); + this.hideUserPrefsDialog(); }; gadgets.IfrGadget.prototype.refresh = function() { - var iframeId = this.getIframeId(); - document.getElementById(iframeId).src = this.getIframeUrl(); + var iframeId = this.getIframeId(); + document.getElementById(iframeId).src = this.getIframeUrl(); }; @@ -657,15 +682,15 @@ * @constructor */ gadgets.Container = function() { - this.gadgets_ = {}; - this.parentUrl_ = 'http://' + document.location.host; - this.country_ = 'ALL'; - this.language_ = 'ALL'; - this.view_ = 'default'; - this.nocache_ = 1; + this.gadgets_ = {}; + this.parentUrl_ = 'http://' + document.location.host; + this.country_ = 'ALL'; + this.language_ = 'ALL'; + this.view_ = 'default'; + this.nocache_ = 1; // signed max int - this.maxheight_ = 0x7FFFFFFF; + this.maxheight_ = 0x7FFFFFFF; }; gadgets.Container.inherits(gadgets.Extensible); @@ -685,63 +710,63 @@ gadgets.Container.prototype.gadgetService = new gadgets.GadgetService(); gadgets.Container.prototype.layoutManager = - new gadgets.StaticLayoutManager(); +new gadgets.StaticLayoutManager(); gadgets.Container.prototype.setParentUrl = function(url) { - this.parentUrl_ = url; + this.parentUrl_ = url; }; gadgets.Container.prototype.setCountry = function(country) { - this.country_ = country; + this.country_ = country; }; gadgets.Container.prototype.setNoCache = function(nocache) { - this.nocache_ = nocache; + this.nocache_ = nocache; }; gadgets.Container.prototype.setLanguage = function(language) { - this.language_ = language; + this.language_ = language; }; gadgets.Container.prototype.setView = function(view) { - this.view_ = view; + this.view_ = view; }; gadgets.Container.prototype.setMaxHeight = function(maxheight) { - this.maxheight_ = maxheight; + this.maxheight_ = maxheight; }; gadgets.Container.prototype.getGadgetKey_ = function(instanceId) { - return 'gadget_' + instanceId; + return 'gadget_' + instanceId; }; gadgets.Container.prototype.getGadget = function(instanceId) { - return this.gadgets_[this.getGadgetKey_(instanceId)]; + return this.gadgets_[this.getGadgetKey_(instanceId)]; }; gadgets.Container.prototype.createGadget = function(opt_params) { - return new this.gadgetClass(opt_params); + return new this.gadgetClass(opt_params); }; gadgets.Container.prototype.addGadget = function(gadget) { - gadget.id = this.getNextGadgetInstanceId(); - gadget.setUserPrefs(this.userPrefStore.getPrefs(gadget)); - this.gadgets_[this.getGadgetKey_(gadget.id)] = gadget; + gadget.id = this.getNextGadgetInstanceId(); + gadget.setUserPrefs(this.userPrefStore.getPrefs(gadget)); + this.gadgets_[this.getGadgetKey_(gadget.id)] = gadget; }; gadgets.Container.prototype.addGadgets = function(gadgets) { - for (var i = 0; i < gadgets.length; i++) { - this.addGadget(gadgets[i]); - } + for (var i = 0; i < gadgets.length; i++) { + this.addGadget(gadgets[i]); + } }; /** * Renders all gadgets in the container. */ gadgets.Container.prototype.renderGadgets = function() { - for (var key in this.gadgets_) { - this.renderGadget(this.gadgets_[key]); - } + for (var key in this.gadgets_) { + this.renderGadget(this.gadgets_[key]); + } }; /** @@ -749,22 +774,22 @@ * @param {Object} gadget Gadget object */ gadgets.Container.prototype.renderGadget = function(gadget) { - throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); + throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY); }; gadgets.Container.prototype.nextGadgetInstanceId_ = 0; gadgets.Container.prototype.getNextGadgetInstanceId = function() { - return this.nextGadgetInstanceId_++; + return this.nextGadgetInstanceId_++; }; /** * Refresh all the gadgets in the container. */ gadgets.Container.prototype.refreshGadgets = function() { - for (var key in this.gadgets_) { - this.gadgets_[key].refresh(); - } + for (var key in this.gadgets_) { + this.gadgets_[key].refresh(); + } }; @@ -776,7 +801,7 @@ * @constructor */ gadgets.IfrContainer = function() { - gadgets.Container.call(this); + gadgets.Container.call(this); }; gadgets.IfrContainer.inherits(gadgets.Container); @@ -786,11 +811,11 @@ gadgets.IfrContainer.prototype.gadgetService = new gadgets.IfrGadgetService(); gadgets.IfrContainer.prototype.setParentUrl = function(url) { - if (!url.match(/^http[s]?:\/\//)) { - url = document.location.href.match(/^[^?#]+\//)[0] + url; - } + if (!url.match(/^http[s]?:\/\//)) { + url = document.location.href.match(/^[^?#]+\//)[0] + url; + } - this.parentUrl_ = url; + this.parentUrl_ = url; }; /** @@ -798,8 +823,8 @@ * @param {Object} gadget Gadget object */ gadgets.IfrContainer.prototype.renderGadget = function(gadget) { - var chrome = this.layoutManager.getGadgetChrome(gadget); - gadget.render(chrome); + var chrome = this.layoutManager.getGadgetChrome(gadget); + gadget.render(chrome); }; /** _______________________________________________ Mashup-dev mailing list [email protected] http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev
