Author: woonsan
Date: Fri Dec 11 14:32:35 2009
New Revision: 889635

URL: http://svn.apache.org/viewvc?rev=889635&view=rev
Log:
JS2-1084: Separates api from portal ui scripts. jetui-portal.js is a YUI module 
which can be used anywhere, while portal.js is script codes using the library.
Now, other j2-admin portlets can import the library explicitly with YUI.
Also, global configuration object was renamed after the YUI convention.

Added:
    
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/
    
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
   (with props)
Modified:
    
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp
    
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js

Modified: 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp?rev=889635&r1=889634&r2=889635&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp
 (original)
+++ 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/WEB-INF/jetui/yui/jetui.jsp
 Fri Dec 11 14:32:35 2009
@@ -53,9 +53,15 @@
 <link rel="shortcut icon" href="<%=baseUrl%>images/jetspeed.jpg" 
type="image/x-icon" />
 <script type="text/javascript" 
src="<%=request.getContextPath()%>/javascript/yui/build/yui/yui-min.js"></script>
 <script language="javascript">
-var assetsDir = "assets/";
-var buildDir = "<%=request.getContextPath()%>/javascript/yui/build/" ;
-var yuiConfig = {base:"<%=request.getContextPath()%>/javascript/yui/build/", 
timeout: 10000, debug: true, useBrowserConsole: true}; // ({classNamePrefix: 
'jet'})
+var JETUI_YUI_config = {
+  base: "<%=request.getContextPath()%>/javascript/yui/build/",
+  timeout: 10000, 
+  debug: true, 
+  useBrowserConsole: true,
+  modules: {
+    'jetui-portal': { fullpath: 
"<%=request.getContextPath()%>/javascript/jetspeed/jetui/jetui-portal.js" }
+  }
+}; // ({classNamePrefix: 'jet'})
 </script>
 <link rel="stylesheet" type="text/css" 
href="<%=request.getContextPath()%>/jetui/css/portal.css"/>
 

Added: 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js?rev=889635&view=auto
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
 (added)
+++ 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
 Fri Dec 11 14:32:35 2009
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @version $Id$
+ */
+
+YUI.add('jetui-portal', function(Y) {
+    
+    Y.namespace("JetUI");
+    
+    ////////////////////////////////////////////////////
+    // the Portal Class
+    //Make this an Event Target so we can bubble to it
+    Y.JetUI.Portal = function() {
+        Y.JetUI.Portal.superclass.constructor.apply(this, arguments);
+    };
+    
+    Y.JetUI.Portal.NAME = 'portal';
+    Y.JetUI.Portal.prototype.desktopMode = false;
+    Y.JetUI.Portal.prototype.jstbLeft = null;
+    Y.JetUI.Portal.prototype.jstbRight = null;
+    Y.JetUI.Portal.prototype.isMoving = false;
+    Y.JetUI.Portal.prototype.goingUp = false;
+    Y.JetUI.Portal.prototype.goingRight = false;
+    Y.JetUI.Portal.prototype.lastY = 0;
+    Y.JetUI.Portal.prototype.lastX = 0;  
+    Y.extend(Y.JetUI.Portal, Y.Base);
+    
+    Y.JetUI.Portal.prototype.toggleToolbar = function(toolbar, toggler, 
compareStyle) {
+        toggler.toggleClass('jstbToggle1');
+        toggler.toggleClass('jstbToggle2');
+        var currentStyle = toggler.getAttribute('class');
+        var nodelist = toolbar.get('children');
+        if (currentStyle == compareStyle)
+        {
+            nodelist.setStyle('display', 'block');          
+        }
+        else
+        {
+            nodelist.setStyle('display', 'none');           
+        }           
+        toolbar.fx.set('reverse', !toolbar.fx.get('reverse')); // toggle 
reverse 
+        toolbar.fx.run();
+    };
+    
+    Y.JetUI.Portal.prototype.moveToLayout = function(e)
+    {
+        var drop = e.drop.get('node'),
+            drag = e.drag.get('node');
+        var dragParent = drag.get('parentNode');       
+        drop.appendChild(drag);
+        if (dragParent.get('children').size() == 0)
+        {
+            //node.plug(Y.Plugin.Drag);
+            var drop = new Y.DD.Drop({
+            node: dragParent,
+            groups: ['portlets']            
+            });
+        }
+        // BOZO: im manipulating internal DD structures, should find a way to 
detach the handler
+        var i = 0;
+        while (i < Y.DD.DDM.targets.length) {
+            if (Y.DD.DDM.targets[i] == e.drop) {
+                Y.DD.DDM.targets.splice(i, 1);
+                break;
+            }
+            i++;
+        }
+        // I don't think this is working
+        e.drop.unplug(Y.Plugin.Drop);
+    }
+
+    Y.JetUI.Portal.prototype.movePortlet = function(e)
+    {
+        if (!JETUI_YUI_config || !JETUI_YUI_config.portalInstance)
+            return;
+        
+        var portal = JETUI_YUI_config.portalInstance;
+        var drop = e.drop.get('node'),
+            drag = e.drag.get('node');
+        var dragParent = drag.get('parentNode');
+        var dropParent = drop.get('parentNode');
+        if (dropParent == portal.jstbLeft || dropParent == portal.jstbRight)
+        {
+          if (!dropParent.contains(drag)) {
+              dropParent.appendChild(drag);
+          }
+        }
+        else
+        {
+            if (portal.goingUp)
+            {
+                //Y.log("going UP");
+                // var next = drop.get('previousSibling');
+                var prev = drop.previous();
+                if (prev == null)
+                {
+                    //drag.remove();                    
+                    dropParent.prepend(drag);                   
+                }
+                else
+                {
+                    //drag.remove();
+                    dropParent.insertBefore(drag, drop);
+                }               
+            }
+            else
+            {
+                var next = drop.next();
+                if (next == null) 
+                {
+                    //Y.log("going down APPEND");
+                    //drag.remove();
+                    dropParent.appendChild(drag);
+                }
+                else
+                {
+                    //Y.log("going down: " + next); //next.data.get('name'));
+                    //drag.remove();
+                    dropParent.insertBefore(drag, next);
+                }
+            }
+        }
+        if (dragParent.get('children').size() == 0)
+        {
+            var drop = new Y.DD.Drop({
+            node: dragParent,
+            groups: ['portlets']            
+            });
+        }        
+    };    
+    
+    ////////////////////////////////////////////////////
+    // the Portlet Class
+    Y.JetUI.Portlet = function(config) {
+        Y.JetUI.Portlet.superclass.constructor.call(this, config);
+    };
+    Y.extend(Y.JetUI.Portlet, Y.Base, {
+        initializer : function(cfg) { 
+        },
+        destructor : function(cfg) { 
+        }               
+    });
+    Y.JetUI.Portlet.NAME = "portlet";
+    Y.JetUI.Portlet.ATTRS = {
+        "name" : { value: "undefined" }, 
+        "id" : { value: "0" },
+        "toolbar" : { value : false },
+        "detached" : { value : false },
+        "column" : { value : 0 },
+        "row" : { value : 0 }
+    };
+    Y.JetUI.Portlet.prototype.info = function() {
+        Y.log("name: " + this.get("name"));
+        Y.log("id  : " + this.get("id"));       
+        Y.log("toolbar  : " + this.get("toolbar"));     
+        Y.log("col, row  : " + this.get("column") + "," + this.get("row"));    
 
+        Y.log("---------");
+    };
+
+    ////////////////////////////////////////////////////
+    // the Layout Class
+    Y.JetUI.Layout = function(config) {
+        Y.JetUI.Layout.superclass.constructor.call(this, config);
+    };
+    Y.extend(Y.JetUI.Layout, Y.Base, {
+        initializer : function(cfg) { 
+        },
+        destructor : function(cfg) { 
+        }               
+    });
+    Y.JetUI.Layout.NAME = "layout";
+    Y.JetUI.Layout.ATTRS = {
+        "name" : { value: "undefined" }, 
+        "id" : { value: "0" },
+        "nested" : { value : false },
+        "column" : { value : 0 },
+        "locked" : { value : false },
+        "row" : { value : 0 }
+    };
+    Y.JetUI.Layout.prototype.info = function() {
+        Y.log("name: " + this.get("name"));
+        Y.log("id  : " + this.get("id"));       
+        Y.log("nested  : " + this.get("nested"));       
+        Y.log("locked  : " + this.get("locked"));       
+        Y.log("col, row  : " + this.get("column") + "," + this.get("row"));    
 
+        Y.log("---------");
+    };
+
+}, '3.0.0', {requires:['dd', 'io', 'dataschema-json', 'node-base', 
'node-menunav']});

Propchange: 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js?rev=889635&r1=889634&r2=889635&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
 (original)
+++ 
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
 Fri Dec 11 14:32:35 2009
@@ -1,6 +1,13 @@
 //Use loader to grab the modules needed
-YUI(yuiConfig).use('console', 'dd', 'anim', 'io', 'datatype-xml', 
'dataschema-xml', 'dataschema-json', 'node-base', 'node-menunav', function(Y) {
+YUI(JETUI_YUI_config).use('jetui-portal', 'console', 'dd', 'anim', 'io', 
'datatype-xml', 'dataschema-xml', 'dataschema-json', 'node-base', 
'node-menunav', function(Y) {
        
+    // initialize singleton portal instance
+    if (!JETUI_YUI_config.portalInstance) {
+        JETUI_YUI_config.portalInstance = new Y.JetUI.Portal();
+    }
+    
+    var portal = JETUI_YUI_config.portalInstance;
+
        //      Retrieve the Node instance representing the root menu
        //      (<div id="environments-menu">) and call the "plug" method
        //      passing in a reference to the MenuNav Node Plugin.
@@ -11,85 +18,15 @@
                menu.setStyle("display","inline");
        }
        //new Y.Console().render(); 
-    //Make this an Event Target so we can bubble to it
-    var Portal = function() {
-        Portal.superclass.constructor.apply(this, arguments);
-    };
-    Portal.NAME = 'portal';
-    Portal.prototype.desktopMode = false;
-    Portal.prototype.jstbLeft;
-    Portal.prototype.jstbRight;
-    Portal.prototype.isMoving;
-    Y.extend(Portal, Y.Base);
-    var portal = new Portal();
-    portal.isMoving = false;
-    var goingUp = false, goingRight = false, lastY = 0, lastX = 0;   
-    
-    ////////////////////////////////////////////////////
-    // the Portlet Class
-    function Portlet(config) {
-        Portlet.superclass.constructor.call(this, config);
-    };
-    Y.extend(Portlet, Y.Base, {
-       initializer : function(cfg) { 
-               },
-        destructor : function(cfg) { 
-               }               
-    });    
-    Portlet.NAME = "portlet";
-    Portlet.ATTRS = {
-       "name" : { value: "undefined" }, 
-        "id" : { value: "0" },
-        "toolbar" : { value : false },
-        "detached" : { value : false },
-        "column" : { value : 0 },
-        "row" : { value : 0 }
-    };
-       Portlet.prototype.info = function() {
-               Y.log("name: " + this.get("name"));
-               Y.log("id  : " + this.get("id"));               
-               Y.log("toolbar  : " + this.get("toolbar"));             
-               Y.log("col, row  : " + this.get("column") + "," + 
this.get("row"));             
-               Y.log("---------");
-    };
-
-    ////////////////////////////////////////////////////
-    // the Layout Class
-    function Layout(config) {
-        Layout.superclass.constructor.call(this, config);
-    };
-    Y.extend(Layout, Y.Base, {
-       initializer : function(cfg) { 
-               },
-        destructor : function(cfg) { 
-               }               
-    });    
-    Layout.NAME = "layout";
-    Layout.ATTRS = {
-       "name" : { value: "undefined" }, 
-        "id" : { value: "0" },
-        "nested" : { value : false },
-        "column" : { value : 0 },
-        "locked" : { value : false },
-        "row" : { value : 0 }
-    };
-       Layout.prototype.info = function() {
-               Y.log("name: " + this.get("name"));
-               Y.log("id  : " + this.get("id"));               
-               Y.log("nested  : " + this.get("nested"));               
-               Y.log("locked  : " + this.get("locked"));               
-               Y.log("col, row  : " + this.get("column") + "," + 
this.get("row"));             
-               Y.log("---------");
-    };
     
     ////////////////////////////////////////////////////    
     // Create Navigator Portlet
-    var navigator = new Portlet();
+    var navigator = new Y.JetUI.Portlet();
     navigator.set("name", "j2-admin::PageNavigator");
     navigator.set("id", "_PageNavigator");
     navigator.set("toolbar", true);
     navigator.set("detached", false);
-    var toolbox = new Portlet();
+    var toolbox = new Y.JetUI.Portlet();
     toolbox.set("name", "j2-admin::JetspeedToolbox");
     toolbox.set("id", "_JetspeedToolbox");
     toolbox.set("toolbar", true);
@@ -205,7 +142,7 @@
     }
        var draggablePortlets = Y.Node.all('.portal-layout-cell');    
     draggablePortlets.each(function(v, k) {
-        var portlet = new Portlet();
+        var portlet = new Y.JetUI.Portlet();
        Y.log("portlet = " + v.getAttribute("name") + v.getAttribute("id"));
         portlet.set("name", v.getAttribute("name"));
         portlet.set("id", v.getAttribute("id"));
@@ -232,7 +169,7 @@
     var dropLayouts = Y.Node.all('.portal-layout-column');
     dropLayouts.each(function(v, k) {
        Y.log("layout = " + v.getAttribute("name") + v.getAttribute("id"));
-        var layout = new Layout();
+        var layout = new Y.JetUI.Layout();
         layout.set("name", v.getAttribute("name"));
         layout.set("id", v.getAttribute("id"));
         layout.set("nested", false);
@@ -291,24 +228,8 @@
         v.on('click', onClickRemove);
     });
         
-    Portal.prototype.toggleToolbar = function(toolbar, toggler, compareStyle) {
-        toggler.toggleClass('jstbToggle1');
-        toggler.toggleClass('jstbToggle2');
-        var currentStyle = toggler.getAttribute('class');
-        var nodelist = toolbar.get('children');
-        if (currentStyle == compareStyle)
-        {
-            nodelist.setStyle('display', 'block');             
-        }
-        else
-        {
-            nodelist.setStyle('display', 'none');              
-        }              
-        toolbar.fx.set('reverse', !toolbar.fx.get('reverse')); // toggle 
reverse 
-        toolbar.fx.run();
-       };         
-    
        Y.DD.DDM.on('drag:drophit', function(e) {
+           var portal = JETUI_YUI_config.portalInstance;
                var drop = e.drop.get('node'),
             drag = e.drag.get('node');
         if (drag.data.get("toolbar"))
@@ -343,89 +264,6 @@
         }
     });
        
-    Portal.prototype.moveToLayout = function(e)
-    {
-        var drop = e.drop.get('node'),
-               drag = e.drag.get('node');
-        var dragParent = drag.get('parentNode');       
-       drop.appendChild(drag);
-        if (dragParent.get('children').size() == 0)
-        {
-               //node.plug(Y.Plugin.Drag);
-               var drop = new Y.DD.Drop({
-               node: dragParent,
-               groups: ['portlets']            
-               });
-        }
-        // BOZO: im manipulating internal DD structures, should find a way to 
detach the handler
-        var i = 0;
-        while (i < Y.DD.DDM.targets.length) {
-               if (Y.DD.DDM.targets[i] == e.drop) {
-                       Y.DD.DDM.targets.splice(i, 1);
-                       break;
-               }
-               i++;
-        }
-        // I don't think this is working
-        e.drop.unplug(Y.Plugin.Drop);
-    }
-
-         Portal.prototype.movePortlet = function(e)
-         {
-        var drop = e.drop.get('node'),
-            drag = e.drag.get('node');
-        var dragParent = drag.get('parentNode');
-        var dropParent = drop.get('parentNode');
-        if (dropParent == portal.jstbLeft || dropParent == portal.jstbRight)
-        {
-          if (!dropParent.contains(drag)) {
-                 dropParent.appendChild(drag);
-          }
-        }
-        else
-        {
-               if (goingUp)
-               {
-                       //Y.log("going UP");
-                       // var next = drop.get('previousSibling');
-                       var prev = drop.previous();
-                if (prev == null)
-                {
-                       //drag.remove();                        
-                       dropParent.prepend(drag);                       
-                }
-                else
-                {
-                               //drag.remove();
-                       dropParent.insertBefore(drag, drop);
-                }                      
-               }
-               else
-               {
-                       var next = drop.next();
-                if (next == null) 
-                {
-                               //Y.log("going down APPEND");
-                               //drag.remove();
-                               dropParent.appendChild(drag);
-                }
-                else
-                {
-                               //Y.log("going down: " + next); 
//next.data.get('name'));
-                               //drag.remove();
-                               dropParent.insertBefore(drag, next);
-                }
-               }
-        }
-        if (dragParent.get('children').size() == 0)
-        {
-               var drop = new Y.DD.Drop({
-               node: dragParent,
-               groups: ['portlets']            
-               });
-        }        
-    };    
-
     var onMoveComplete = function(id, o, args) { 
        var id = id; // Transaction ID. 
        var data = o.responseText; // Response data.
@@ -514,34 +352,35 @@
             srcNode.addClass('moving');                
         }
         //  drag.get('node').setStyle('border', '1px dotted #black');        
-        lastX = drag.mouseXY[0];
-        lastY = drag.mouseXY[1];
-        //Y.log("starting drag " + lastX +  " , " + lastY);
+        portal.lastX = drag.mouseXY[0];
+        portal.lastY = drag.mouseXY[1];
+        //Y.log("starting drag " + portal.lastX +  " , " + portal.lastY);
     });
 
     Y.DD.DDM.on('drag:over', function(e) {
+        var portal = JETUI_YUI_config.portalInstance;
        if (portal.isMoving)
                return;
        
        var x = e.drag.mouseXY[0],
                y = e.drag.mouseXY[1];
        
-       if (y == lastY)
+       if (y == portal.lastY)
        {               
        }
-       else if (y < lastY) {
-            goingUp = true;
+       else if (y < portal.lastY) {
+            portal.goingUp = true;
             
         } else {
-            goingUp = false;
+            portal.goingUp = false;
         }
-        lastY = y;
-        if (x < lastX) {
-            goingRight = false;
+       portal.lastY = y;
+        if (x < portal.lastX) {
+            portal.goingRight = false;
         } else {
-            goingRight = true;
+            portal.goingRight = true;
         }        
-        lastX = x;
+        portal.lastX = x;
         
         if (e.drag.get('node').data.get("toolbar"))
         {        



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to