You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by sc...@apache.org on 2012/08/03 11:54:43 UTC
svn commit: r1368858 -
/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave.js
Author: scottbw
Date: Fri Aug 3 09:54:43 2012
New Revision: 1368858
URL: http://svn.apache.org/viewvc?rev=1368858&view=rev
Log:
added a renderNewWidget() method to rave.js; when called as the successCallback from rave.api.rpc.addWidgetToPage() it adds the widget to the page immediately with no refresh required (see RAVE-743). Note that initWidgets() now filters its init actions to avoid re-initializing existing widgets, or trying to init widgets previously deleted in the same session.
Modified:
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave.js
Modified: rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave.js
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave.js?rev=1368858&r1=1368857&r2=1368858&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave.js (original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave.js Fri Aug 3 09:54:43 2012
@@ -946,6 +946,24 @@ var rave = rave || (function () {
function resetOpenAjaxHubInstance() {
openAjaxHub = null;
}
+
+ function renderNewWidget(regionWidgetId){
+ // When run as the callback argument supplied to rave.api.rpc.addWidgetToPage
+ // this method will render the widget in the current page.
+
+ // load widget into a placeholder element
+ var placeholder = document.createElement("div");
+ $(placeholder).load(rave.getContext()+"/api/rest/regionwidget/"+regionWidgetId, function(){
+ // prepend to first region
+ var region = $("#region-1-id");
+ region.prepend(placeholder);
+ // remove the placeholder around the widget-wrapper
+ region.children(":first").children(":first").unwrap();
+ // initialize
+ initializeWidgets();
+ }
+ );
+ }
function initializeWidgets() {
//We get the widget objects in a map keyed by region ID. The code below converts that map into a flat array
@@ -1003,6 +1021,18 @@ var rave = rave || (function () {
}
function initializeWidget(widget) {
+
+ // Widget has been deleted on the page but not removed from list
+ var widgetBody = $(["#widget-", widget.regionWidgetId, "-body"].join(""));
+ if(widgetBody.length === 0){
+ return;
+ } else {
+ // Widget has already been initialized
+ if(typeof widgetBody.children !== "undefined" && widgetBody.children().length !== 0){
+ return;
+ }
+ }
+
if (widget.type == "DISABLED") {
renderDisabledWidget(widget.regionWidgetId, unescape(widget.disabledMessage));
return;
@@ -1162,6 +1192,12 @@ var rave = rave || (function () {
registerWidget:registerWidget,
/**
+ * Render a newly-added widget in the page
+ * @param regionWidgetId the regionWidgetId of the widget to render
+ */
+ renderNewWidget:renderNewWidget,
+
+ /**
* Initialize all of the registered providers
*/
initProviders:initializeProviders,