Author: jablko
Date: Sun Sep 20 18:01:51 2009
New Revision: 3453

Log:
Support drag and drop to reorganize nodes in tree view

Added:
   trunk/apps/qubit/modules/informationobject/actions/moveAction.class.php   
(contents, props changed)
Modified:
   trunk/apps/qubit/config/routing.yml
   
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
   trunk/web/js/treeView.js

Modified: trunk/apps/qubit/config/routing.yml
==============================================================================
--- trunk/apps/qubit/config/routing.yml Sun Sep 20 16:45:44 2009        (r3452)
+++ trunk/apps/qubit/config/routing.yml Sun Sep 20 18:01:51 2009        (r3453)
@@ -197,6 +197,12 @@
     action: list
     id: <?php echo QubitInformationObject::ROOT_ID ?>
 
+informationObjectMove:
+  url: /informationobject/move/:id
+  param:
+    module: informationobject
+    action: move
+
 informationObjectShow:
   url: /informationobject/show/:informationobject_template/:id
   param:

Added: trunk/apps/qubit/modules/informationobject/actions/moveAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/informationobject/actions/moveAction.class.php     
Sun Sep 20 18:01:51 2009        (r3453)
@@ -0,0 +1,51 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class InformationObjectMoveAction extends sfAction
+{
+  public function execute($request)
+  {
+    $this->form = new sfForm;
+
+    $this->informationObject = QubitInformationObject::getById($request->id);
+
+    // Check that object exists and that it is not the root
+    if (!isset($this->informationObject) || 
!isset($this->informationObject->parent))
+    {
+      $this->forward404();
+    }
+
+    $this->form->setValidator('parent', new sfValidatorString);
+
+    if ($request->isMethod('post'))
+    {
+      $this->form->bind($request->getPostParameters());
+
+      if ($this->form->isValid())
+      {
+        $params = 
$this->context->routing->parse(preg_replace('/.*'.preg_quote($this->request->getPathInfoPrefix(),
 '/').'/', null, $this->form->getValue('parent')));
+        $this->informationObject->parentId = $params['id'];
+
+        $this->informationObject->save();
+
+        $this->redirect(array('module' => 'informationobject', 'action' => 
'show', 'id' => $this->informationObject->id));
+      }
+    }
+  }
+}

Modified: 
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
==============================================================================
--- 
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php  
    Sun Sep 20 16:45:44 2009        (r3452)
+++ 
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php  
    Sun Sep 20 18:01:51 2009        (r3453)
@@ -33,6 +33,7 @@
     $this->getResponse()->addJavaScript('qubit');
     
$this->getResponse()->addJavaScript('/vendor/yui/yahoo-dom-event/yahoo-dom-event');
     $this->getResponse()->addJavaScript('/vendor/yui/treeview/treeview-min');
+    $this->getResponse()->addJavaScript('/vendor/yui/dragdrop/dragdrop-min');
     $this->getResponse()->addJavaScript('treeView');
     
$this->getResponse()->addStylesheet('yui/treeview/assets/skins/qubit/treeview-skin',
 'first');
 

Modified: trunk/web/js/treeView.js
==============================================================================
--- trunk/web/js/treeView.js    Sun Sep 20 16:45:44 2009        (r3452)
+++ trunk/web/js/treeView.js    Sun Sep 20 18:01:51 2009        (r3453)
@@ -12,6 +12,31 @@
           var object = objects.shift();
           var textNode = new YAHOO.widget.TextNode(object, parentNode, 
expands[object.id] !== undefined);
           textNode.isLeaf = object.isLeaf;
+
+          var dd = new YAHOO.util.DDProxy(textNode.labelElId);
+
+          dd.invalidHandleTypes = {};
+
+          dd.onDragDrop = function (event, id)
+            {
+              var newParent = parentNode.tree.getNodeByElement($('#' + id)[0]);
+
+              jQuery.ajax({
+                data: { parent: newParent.href },
+                type: 'POST',
+                url: textNode.href.replace(/\/informationobject\/\D*(\d+)/, 
'/informationobject/move/$1')});
+
+              parentNode.tree.popNode(textNode);
+              textNode.appendTo(newParent);
+
+              parentNode.refresh();
+              newParent.refresh();
+            };
+
+          dd.endDrag = function ()
+            {
+            };
+
           build(objects, expands, object.id, textNode);
         }
       }
@@ -37,6 +62,30 @@
             {
               var tmp = new YAHOO.widget.TextNode(data[i], node, false);
               tmp.isLeaf = data[i].isLeaf;
+
+              var dd = new YAHOO.util.DDProxy(tmp.labelElId);
+
+              dd.invalidHandleTypes = {};
+
+              dd.onDragDrop = function (event, id)
+                {
+                  var newParent = node.tree.getNodeByElement($('#' + id)[0]);
+
+                  jQuery.ajax({
+                    data: { parent: newParent.href },
+                    type: 'POST',
+                    url: tmp.href.replace(/\/informationobject\/\D*(\d+)/, 
'/informationobject/move/$1')});
+
+                  node.tree.popNode(tmp);
+                  tmp.appendTo(newParent);
+
+                  node.refresh();
+                  tmp.parent.refresh();
+                };
+
+              dd.endDrag = function ()
+                {
+                };
             }
 
             fnLoadComplete();

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to