Author: jmorliaguet
Date: Sun Mar 26 13:01:24 2006
New Revision: 2730

Modified:
   cpsskins/branches/jmo-perspectives/browser/tree/interfaces.py
   cpsskins/branches/jmo-perspectives/browser/tree/slot.py
   cpsskins/branches/jmo-perspectives/browser/tree/views.py
   cpsskins/branches/jmo-perspectives/ui/authoring/authoring.js
   cpsskins/branches/jmo-perspectives/ui/authoring/configure.zcml
   cpsskins/branches/jmo-perspectives/ui/authoring/views.py
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   
cpsskins/branches/jmo-perspectives/ui/screens/layoutdesigner/filters/portlet.pt
   cpsskins/branches/jmo-perspectives/ui/screens/pagedesigner/filters/portlet.pt
Log:

- elements (portlets) can be moved and reordered.

- API updates



Modified: cpsskins/branches/jmo-perspectives/browser/tree/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/tree/interfaces.py       
(original)
+++ cpsskins/branches/jmo-perspectives/browser/tree/interfaces.py       Sun Mar 
26 13:01:24 2006
@@ -43,9 +43,12 @@
 # Reordering elements in nodes
 class INodeOrdering(IView):
 
-    def reorder(order):
+    def setOrder(element, order):
         """Update the order of the element in the node"""
 
+    def getOrder(element):
+        """Get the order of the element in the node"""
+
 # Duplicating elements in nodes
 class INodeDuplicating(IView):
 

Modified: cpsskins/branches/jmo-perspectives/browser/tree/slot.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/tree/slot.py     (original)
+++ cpsskins/branches/jmo-perspectives/browser/tree/slot.py     Sun Mar 26 
13:01:24 2006
@@ -187,8 +187,8 @@
     """
     implements(INodeOrdering)
 
-    def reorder(self, content, order):
-        """Reorder the element.
+    def setOrder(self, content, order):
+        """Set the element's order in the container.
         """
         container = self.context
         request = self.request
@@ -197,11 +197,9 @@
         if not IPortlet.providedBy(content):
             raise TypeError("Only portlets can be reordered inside slots")
 
-        perspective = getMultiAdapter(
-            objects=(container, request),
-            interface=INegociation,
-            name='negociation',
-            ).getPerspective()
+        perspective = getMultiAdapter(objects=(container, request),
+                         interface=INegociation, name='negociation'
+                         ).getPerspective()
 
         display = IDisplayable(container).getEffectiveDisplay(perspective)
 
@@ -209,6 +207,20 @@
             display.remove(content)
         display.insert(order, content)
 
+    def getOrder(self, content):
+        """Get the element's order in the container.
+        """
+        container = self.context
+        request = self.request
+        if not IPortlet.providedBy(content):
+            raise TypeError("Only portlets can be contained in slots")
+
+        perspective = getMultiAdapter(objects=(container, request),
+                         interface=INegociation, name='negociation'
+                         ).getPerspective()
+
+        display = IDisplayable(container).getEffectiveDisplay(perspective)
+        return display.index(content)
 
 class SlotDuplicating(BrowserView):
     """A view for duplicating elements in nodes

Modified: cpsskins/branches/jmo-perspectives/browser/tree/views.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/tree/views.py    (original)
+++ cpsskins/branches/jmo-perspectives/browser/tree/views.py    Sun Mar 26 
13:01:24 2006
@@ -56,11 +56,11 @@
         del container[zapi.name(content)]
 
 class NodeOrdering(BrowserView):
-    """A view for reordering elements in nodes
+    """A view for managing elements' order in nodes
     """
     implements(INodeOrdering)
 
-    def reorder(self, node, order):
+    def setOrder(self, node, order):
         container = self.context
         contents = list(container.keys())
         item = zapi.name(node)
@@ -68,6 +68,11 @@
         contents.insert(order, item)
         container.updateOrder(contents)
 
+    def getOrder(self, node):
+        container = self.context
+        item = zapi.name(node)
+        return list(container.keys()).index(item)
+
 class NodeDuplicating(BrowserView):
     """A view for duplicating elements in nodes
     """
@@ -84,7 +89,7 @@
         copied_name = copier.copyTo(container)
         copied = container[copied_name]
         # move the copied element just below the original element
-        reordering = zapi.getMultiAdapter((container, request), INodeOrdering)
-        reordering.reorder(copied, int(content_order)+1)
+        ordering = zapi.getMultiAdapter((container, request), INodeOrdering)
+        ordering.setOrder(copied, int(content_order)+1)
         return copied.identifier
 

Modified: cpsskins/branches/jmo-perspectives/ui/authoring/authoring.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/authoring/authoring.js        
(original)
+++ cpsskins/branches/jmo-perspectives/ui/authoring/authoring.js        Sun Mar 
26 13:01:24 2006
@@ -1,12 +1,29 @@
 
 function insertPortlet(info) {
-
-  var url = '@@addElement'
+  var url = '@@insertElement'
   var args = {
     'id': info.target.getAttribute('targetid'),
     'type_name': info.source.getAttribute('type_name'),
     'order': 0
   }
+  alert($H(args).inspect());
+  var options = {
+    'parameters': $H(args).toQueryString(),
+    'onComplete': function(req) {
+      var controller = info.context;
+      controller.refreshViews();
+    }
+  };
+  new Ajax.Request(url, options);
+}
+
+function moveElement(info) {
+  var url = '@@moveElement'
+  var args = {
+    'src_id': info.source.getAttribute('id'),
+    'dest_id': info.target.getAttribute('id'),
+    'order': 0
+  }
   var options = {
     'parameters': $H(args).toQueryString(),
     'onComplete': function(req) {
@@ -15,7 +32,11 @@
     }
   };
   new Ajax.Request(url, options);
+  //alert($H(args).inspect());
 }
 
-CPSSkins.addActions({'insert_portlet': insertPortlet});
+CPSSkins.addActions({
+  'insert_portlet': insertPortlet,
+  'move_element': moveElement
+});
 

Modified: cpsskins/branches/jmo-perspectives/ui/authoring/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/authoring/configure.zcml      
(original)
+++ cpsskins/branches/jmo-perspectives/ui/authoring/configure.zcml      Sun Mar 
26 13:01:24 2006
@@ -87,8 +87,8 @@
       />
 
       <browser:page
-          name="addElement"
-          attribute="addElement"
+          name="insertElement"
+          attribute="insertElement"
       />
 
       <browser:page

Modified: cpsskins/branches/jmo-perspectives/ui/authoring/views.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/authoring/views.py    (original)
+++ cpsskins/branches/jmo-perspectives/ui/authoring/views.py    Sun Mar 26 
13:01:24 2006
@@ -31,8 +31,8 @@
 from cpsskins.browser.tree.interfaces import INodeMoving, INodeOrdering
 from cpsskins.browser.tree.interfaces import INodeDuplicating
 from cpsskins.browser.rendering.interfaces import IViewer
-from cpsskins.elements.interfaces import IElement, IPresentable
-from cpsskins.elements.interfaces import IDisplayable
+from cpsskins.elements.interfaces import IElement, IPresentable, IDisplayable
+from cpsskins.elements.interfaces import IInnerNode
 from cpsskins.browser.rendering.interfaces import IViewer
 from cpsskins.setup.interfaces import IResourceManager
 from cpsskins.ui.authoring.definitions import MODELS, VIEWS, CONTROLLERS
@@ -167,12 +167,17 @@
         view = Contents(container, request)
         view.pasteObjects()
 
-    def addElement(self, id, type_name, order):
-        """Add an element in a container.
-        Return the id of added element.
+    def insertElement(self, id, type_name, order):
+        """Insert an element inside a container at a given position.
+        Return the id of inserted element.
         """
         request = self.request
-        container = self._getElementById(id)
+        dest_element = self._getElementById(id)
+        if IInnerNode.providedBy(dest_element):
+            container = dest_element
+        else:
+            container = getParent(dest_element)
+            order = self.getElementOrder(id)
 
         content = createObject(type_name)
         notify(ObjectCreatedEvent(content))
@@ -181,7 +186,7 @@
 
         added = adding.add(content)
         added_id = added.identifier
-        self.reorderElement(added_id, int(order))
+        self.setElementOrder(added_id, int(order))
         return str(added_id)
 
     def moveElement(self, src_id, dest_id, order):
@@ -189,24 +194,41 @@
         return the id of the moved element.
         """
         request = self.request
-        element = self._getElementById(src_id)
-        dest_container = self._getElementById(dest_id)
+        src_element = self._getElementById(src_id)
+        src_container = getParent(src_element)
+        dest_element = self._getElementById(dest_id)
+        if IInnerNode.providedBy(dest_element):
+            dest_container = dest_element
+        else:
+            dest_container = getParent(dest_element)
+            order = self.getElementOrder(dest_id)
+            if dest_container == src_container:
+                order = order -1
+
         # move the element to the destination container
         moving = getMultiAdapter((dest_container, request), INodeMoving)
-        moved = moving.move(element)
+        moved = moving.move(src_element)
 
         # move the element to the specified order
         moved_id = moved.identifier
-        self.reorderElement(moved_id, int(order))
+        self.setElementOrder(moved_id, int(order))
         return str(moved_id)
 
-    def reorderElement(self, id, order):
+    def setElementOrder(self, id, order):
         """Move an element to a new position.
         """
         element = self._getElementById(id)
         container = getParent(element)
         ordering = getMultiAdapter((container, self.request), INodeOrdering)
-        ordering.reorder(element, int(order))
+        ordering.setOrder(element, int(order))
+
+    def getElementOrder(self, id):
+        """Get the order of an element in a container.
+        """
+        element = self._getElementById(id)
+        container = getParent(element)
+        ordering = getMultiAdapter((container, self.request), INodeOrdering)
+        return ordering.getOrder(element)
 
     def deleteElement(self, id):
         """Delete the element specified by its path.

Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar 26 
13:01:24 2006
@@ -888,6 +888,7 @@
           }
           s.parentNode.insertBefore(this.dragged, target);
           shifted = true;
+          this.droptarget = target;
           return;
         };
       }.bind(this));
@@ -929,16 +930,16 @@
     var zoomback = this.def.dragging.zoomback;
     if (inTarget) {
       zoomback = false;
-      var action_id = this.def.dropping.action;
-      if (action_id) {
-        var action_handler = CPSSkins.getAction(action_id);
-        if (action_handler) action_handler({
-          'source': this.dragged,
-          'target': this.target,
-          'context': this
-          }
-        );
-      }
+    }
+
+    var action_id = this.def.dropping.action;
+    if (action_id) {
+      var action_handler = CPSSkins.getAction(action_id);
+      if (action_handler) action_handler({
+        'source': this.dragged,
+        'target': this.droptarget || this.target,
+        'context': this
+      });
     }
 
     if (this.def.dragging.feedback) {

Modified: 
cpsskins/branches/jmo-perspectives/ui/screens/layoutdesigner/filters/portlet.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/screens/layoutdesigner/filters/portlet.pt 
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/screens/layoutdesigner/filters/portlet.pt 
    Sun Mar 26 13:01:24 2006
@@ -1,5 +1,4 @@
-<div class="editable draggable hover elementMovable elementShiftable"
-            grip="1" destination="cellcontained"
+<div class="elementMovable elementShiftable portletTarget"
   tal:define="
     info options/info;
     globals info/globals;
@@ -12,6 +11,7 @@
     editable python:1;
     formattable python: formats and 1 or 0;
     formats python: ' '.join(formats);
+    targetid id;
     id id">
   <div class="portletBox">
     <strong tal:condition="title" tal:content="title" />

Modified: 
cpsskins/branches/jmo-perspectives/ui/screens/pagedesigner/filters/portlet.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/screens/pagedesigner/filters/portlet.pt   
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/screens/pagedesigner/filters/portlet.pt   
    Sun Mar 26 13:01:24 2006
@@ -1,5 +1,4 @@
-<div class="editable draggable hover elementMovable elementShiftable"
-     grip="1" destination="cellcontained"
+<div class="elementMovable elementShiftable portletTarget"
   tal:define="
     info options/info;
     globals info/globals;
@@ -12,5 +11,6 @@
     editable python:1;
     formattable python: formats and 1 or 0;
     formats python: ' '.join(formats);
+    targetid id;
     id id"
   tal:content="structure options/markup" />
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to