rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zh...@apache.org
Subject svn commit: r1130207 - in /incubator/rave/trunk/rave-portal/src/main/webapp: WEB-INF/views/home.jsp script/rave.js script/rave_api.js
Date Wed, 01 Jun 2011 16:19:04 GMT
Author: zhguo
Date: Wed Jun  1 16:19:04 2011
New Revision: 1130207

URL: http://svn.apache.org/viewvc?rev=1130207&view=rev
Log:
RAVE-41: Need to be able to delete widgets from a page
https://issues.apache.org/jira/browse/RAVE-41

Hopefully fixed the gadget/widget deletion bug discovered by Marlon.  Added a datastructure
to map widget id to id of the region it belongs to. When a widget is added/moved/deleted,
the map is updated accordingly.

Modified:
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp?rev=1130207&r1=1130206&r2=1130207&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp Wed Jun  1 16:19:04
2011
@@ -60,7 +60,7 @@
          If so, region.id must be included. When a gadget is moved, region id must be updated.

          Otherwise, it is not needed.
     -->
-    <div class="widget-wrapper" id="widget-wrapper-${region.id}-${regionWidget.id}">
+    <div class="widget-wrapper" id="widget-wrapper-${regionWidget.id}">
         <div class="widget-title-bar" >
             <span id="widget-${regionWidget.id}-title">${regionWidget.widget.title}</span>
             
@@ -81,18 +81,20 @@
 					      icons: {
 					        primary: "ui-icon-close"
 					      }
-					    }).click(function() {
+					    }).unbind("click").click(function() {
+					        alert("remove gadget");
 					      rave.api.rpc.removeWidget({
 					    	  regionWidgetId: "${regionWidget.id}", 
 					    	  pageId: "${defaultPage.id}",
 					    	  region: {
-					    		  id: "region-${region.id}-id"
+					    	      id : rave.getGadgetRegion("${regionWidget.id}")
 					    	  },
 					    	  succCB: function() {
-					    		  $("#widget-wrapper-${region.id}-${regionWidget.id}").remove();
+					    		  $("#widget-wrapper-${regionWidget.id}").remove();
 					    	  }
 					    	});
 					    });
+						  rave.mapGadgetToRegion("${regionWidget.id}", "${region.id}");
 						  </script>
 						</span>
             

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js?rev=1130207&r1=1130206&r2=1130207&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js Wed Jun  1 16:19:04 2011
@@ -19,6 +19,9 @@
 var rave = rave || (function() {
     var providerList = [];
     var context = "";
+    
+    // map widget id to region id
+    var widgetRegionMap = {};
 
 
     /**
@@ -97,7 +100,7 @@ var rave = rave || (function() {
         }
 
         return {
-            init : init,
+            init : init
         }
 
     })();
@@ -164,6 +167,26 @@ var rave = rave || (function() {
 	 function deleteWidgetFromPage() {
 		  return null;
 	 }
+	 
+	 /**
+	  * Map a widget to the region where it is located.
+	  * 
+	  * @param widgetId: id of the widget (not DOM id)
+	  * @param regionId: if it is non null, it is mapped. It it is null or not present, delete
the map entry.
+	  */
+	 function mapGadgetToRegion(widgetId, regionId) {
+	     delete widgetRegionMap[widgetId];
+	     if (arguments.length > 1 && regionId != null)
+	         widgetRegionMap[widgetId] = regionId;
+	 }
+	 
+	 /**
+      * Get the region where a widget/gadget belongs to.
+      * @param widgetId: id of the widget. (not DOM id)
+      */
+	 function getGadgetRegion(widgetId) {
+         return widgetRegionMap[widgetId];
+     }
 
     /**
      * Public API
@@ -225,11 +248,19 @@ var rave = rave || (function() {
          */
         getContext: getContext,
 
-		  /**
-			* Remove a selected gadget from the page
-			*/
-		  deleteGadget : deleteWidgetFromPage
-
-
+    	/**
+    	* Remove a selected gadget from the page
+    	*/
+    	deleteGadget : deleteWidgetFromPage,
+
+    	/**
+    	 * Change or delete gadget to region map entry.
+    	 */
+    	mapGadgetToRegion : mapGadgetToRegion,
+    	
+    	/**
+    	 * Get the region where a widget/gadget belongs to.
+    	 */
+    	getGadgetRegion : getGadgetRegion
     }
 })();
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js?rev=1130207&r1=1130206&r2=1130207&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js Wed Jun  1 16:19:04
2011
@@ -28,16 +28,21 @@ rave.api = rave.api || (function() {
 
       //This method is implemented by PageApi.java.  
         function moveWidgetOnPage(args) {
+            var widgetObjectId = rave.getObjectIdFromDomId(args.widget.id);
+            var toRegionObjectId = rave.getObjectIdFromDomId(args.targetRegion.id);
+            var fromRegionObjectId = rave.getObjectIdFromDomId(args.currentRegion.id);
             //Note context must be set outside this library.  See home.jsp for example.
-            $.post(rave.getContext() + path + "page/regionWidget/" + rave.getObjectIdFromDomId(args.widget.id)
+ "/move",
+            $.post(rave.getContext() + path + "page/regionWidget/" + widgetObjectId + "/move",
                     {
                         newPosition: args.targetIndex,
-                        toRegion: rave.getObjectIdFromDomId(args.targetRegion.id),
-                        fromRegion: rave.getObjectIdFromDomId(args.currentRegion.id)
+                        toRegion: toRegionObjectId,
+                        fromRegion: fromRegionObjectId
                     },
                     function(result) {
                         if (result.error) {
                             handleRpcError(result);
+                        } else {
+                            rave.mapGadgetToRegion(widgetObjectId, toRegionObjectId);
                         }
                     }
             ).error(handleError);
@@ -59,12 +64,13 @@ rave.api = rave.api || (function() {
         $.post(rave.getContext() + path + "page/" +args.pageId + "/widget/delete",
              {
                 widgetId: args.regionWidgetId,
-                regionId: rave.getObjectIdFromDomId(args.region.id)            
+                regionId: args.region.id            
              },
              function(result) {
                 if(result.error && result.error == true) {
                   handleRpcError(result);
                 } else {
+                    rave.mapGadgetToRegion(args.regionWidgetId, null);
                 	if (args.succCB != null && typeof args.succCB == 'function')
                 		args.succCB();
                 }
@@ -95,7 +101,7 @@ rave.api = rave.api || (function() {
         return {
             moveWidget : moveWidgetOnPage,
             addWidgetToPage : addWidgetToPage,
-      removeWidget : deleteWidgetOnPage
+            removeWidget : deleteWidgetOnPage
         };
 
     })();



Mime
View raw message