Author: sevein
Date: Tue Jun 26 16:49:50 2012
New Revision: 11810

Log:
Check sorting permissions, highlight nodes when moved

Modified:
   trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
   
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
   trunk/apps/qubit/modules/informationobject/templates/_treeView.php
   trunk/css/graphic.css
   trunk/js/treeView.js

Modified: 
trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php 
Tue Jun 26 16:29:19 2012        (r11809)
+++ trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php 
Tue Jun 26 16:49:50 2012        (r11810)
@@ -23,13 +23,19 @@
 
   public function execute($request)
   {
-    if (isset($this->getRoute()->resource))
+    if ('all' == $request->show)
     {
-      $this->resource = $this->getRoute()->resource;
+      $this->resource = QubitInformationObject::getRoot();
     }
     else
     {
-      $this->resource = QubitInformationObject::getRoot();
+      $this->resource = $this->getRoute()->resource;
+    }
+
+    // Check authorization
+    if (!QubitAcl::check($this->resource, 'update'))
+    {
+      QubitAcl::forwardUnauthorized();
     }
 
     $sql = 'SELECT
@@ -97,13 +103,14 @@
       case 'moveAfter':
       case 'moveBefore':
         $params = 
$this->context->routing->parse(Qubit::pathInfo($request->target));
-        $target = $params['_sf_route']->resource;
 
-        if (QubitInformationObject::ROOT_ID == $this->resource->id)
+        if (!isset($params['_sf_route']))
         {
-          break;
+          $this->forward404();
         }
 
+        $target = $params['_sf_route']->resource;
+
         if ('moveAfter' == $request->show)
         {
           $this->resource->moveToNextSiblingOf($target);
@@ -113,7 +120,8 @@
           $this->resource->moveToPrevSiblingOf($target);
         }
 
-        break;
+
+        return sfView::NONE;
     }
   }
 }

Modified: 
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
==============================================================================
--- 
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php  
    Tue Jun 26 16:29:19 2012        (r11809)
+++ 
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php  
    Tue Jun 26 16:49:50 2012        (r11810)
@@ -168,5 +168,7 @@
 
     array_cut('shift', $this->treeview['prevSiblings'], $prevSiblingsSlice);
     array_cut('pop', $this->treeview['nextSiblings'], $nextSiblingsSlice);
+
+    $this->sortable = QubitAcl::check($this->resource, 'update') ? 'true' : 
'false';
   }
 }

Modified: trunk/apps/qubit/modules/informationobject/templates/_treeView.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/_treeView.php  Tue Jun 
26 16:29:19 2012        (r11809)
+++ trunk/apps/qubit/modules/informationobject/templates/_treeView.php  Tue Jun 
26 16:49:50 2012        (r11810)
@@ -1,4 +1,4 @@
-<div id="treeview" data-current-id="<?php echo $resource->id ?>">
+<div id="treeview" data-current-id="<?php echo $resource->id ?>" 
data-sortable="<?php echo $sortable ?>">
 
   <ul class="unstyled">
     <li class="back" style="<?php echo QubitInformationObject::ROOT_ID == 
$resource->parentId ? 'display: none;' : '' ?>" data-xhr-location="<?php echo 
url_for(array('module' => 'informationobject', 'action' => 'treeView')) ?>">

Modified: trunk/css/graphic.css
==============================================================================
--- trunk/css/graphic.css       Tue Jun 26 16:29:19 2012        (r11809)
+++ trunk/css/graphic.css       Tue Jun 26 16:49:50 2012        (r11810)
@@ -359,6 +359,11 @@
   border: 1px solid #ccc;
 }
 
+#treeview.loading li
+{
+  cursor: wait !important;
+}
+
 #treeview li .loading
 {
   display: inline-block;
@@ -370,7 +375,3 @@
   position: absolute;
   left: -7px;
 }
-
-
-
-

Modified: trunk/js/treeView.js
==============================================================================
--- trunk/js/treeView.js        Tue Jun 26 16:29:19 2012        (r11809)
+++ trunk/js/treeView.js        Tue Jun 26 16:49:50 2012        (r11810)
@@ -159,12 +159,20 @@
     {
       this.$element = element;
       this.$showAllButton = this.$element.find('li:first');
-      this.loading = false;
+
+      // Used to control loading status and block interface if needed
+      this.setLoading(false);
+
+      // Regular nodes selector
+      this.nodesSelector = 'li:not(.back, .ancestor, .more)';
 
       // Store the current resource id to highlight it
       // during the treeview browsing
       this.resourceId = this.$element.data('current-id');
 
+      // Check if the treeview is sortable
+      this.sortable = !!this.$element.data('sortable');
+
       this.init();
     };
 
@@ -178,6 +186,8 @@
           .on('click.treeview.qubit', 'li', $.proxy(this.click, this))
           .on('mousedown.treeview.qubit', 'li', $.proxy(this.mousedownup, 
this))
           .on('mouseup.treeview.qubit', 'li', $.proxy(this.mousedownup, this))
+          .on('mouseenter.treeview.qubit', 'li', $.proxy(this.mouseenter, 
this))
+          .on('mouseleave.treeview.qubit', 'li', $.proxy(this.mouseleave, 
this))
           .bind('scroll', $.proxy(this.scroll, this))
           .bind('scroll-debounced', $.proxy(this.debouncedScroll, this));
 
@@ -193,17 +203,62 @@
             self.$element.trigger('scroll-debounced', e);
           });
 
+        this.installSortableBehavior();
+
+        this.highlightLastAncestor();
+      },
+
+    setLoading: function (status)
+      {
+        this.loading = status;
+
+        this.$element.toggleClass('loading', status);
+      },
+
+    installSortableBehavior: function ()
+      {
+        // Create jquery-ui sortable object
+        if (!this.sortable)
+        {
+          return this;
+        }
+
         this.$element.sortable(
           {
-            items: 'li:not(.back, .ancestor, .more)',
+            items: this.nodesSelector,
             placeholder: 'placeholder',
             forcePlaceholderSize: true,
             start: $.proxy(this.drag, this),
-            stop: $.proxy(this.drop, this)
+            stop: $.proxy(this.drop, this),
+            axis: 'y'
           });
         this.$element.disableSelection();
+      },
 
-        this.highlightLastAncestor();
+    refreshSortableBehavior: function ()
+      {
+        var nodes = this.$element.find(this.nodesSelector);
+
+        if (1 < nodes)
+        {
+          nodes.sortable('refresh');
+        }
+
+        return this;
+      },
+
+    mouseenter: function (e)
+      {
+        // var $li = 'LI' === e.target.tagName ? $(e.target) : 
$(e.target).closest('li');
+
+        return this;
+      },
+
+    mouseleave: function (e)
+      {
+        // var $li = 'LI' === e.target.tagName ? $(e.target) : 
$(e.target).closest('li');
+
+       return this;
       },
 
     mousedownup: function (e)
@@ -247,30 +302,37 @@
           data: data,
           beforeSend: function ()
             {
-              this.loading = true;
+              this.setLoading(true);
 
+              // Add loading icon
               ui.item.prepend('<div class="loading" />');
               ui.item.children('i').css('visibility', 'hidden');
             },
-          // success: function (data) { },
+          success: function ()
+            {
+              // Green highlight effect
+              ui.item.effect("highlight", { color: '#dff0d8' }, 500);
+            },
           complete: function ()
             {
-              this.loading = false;
+              this.setLoading(false);
 
+              // Remove loading icon
               ui.item
-                .children('.loading').hide('fast', function()
-                  {
-                    $(this).remove()
-                  }).end()
+                .children('.loading').remove().end()
                 .children('i').css('visibility', 'visible');
             },
           error: function (jqXHR, textStatus, thrownError)
             {
               // Cancel event if HTTP error
+              // Item will be moved back to its original position
               if (thrownError.length)
               {
                 this.$element.sortable('cancel');
               }
+
+              // Red highlight effect
+              ui.item.effect("highlight", { color: '#f2dede' }, 500);
             }
           });
 
@@ -371,7 +433,7 @@
           data: { show: 'all', resourceId: this.resourceId },
           beforeSend: function ()
             {
-              this.loading = true;
+              this.setLoading(true);
             },
           success: function (data)
             {
@@ -380,11 +442,13 @@
                 .nextAll().remove().end()
                 .after(data);
 
+              this.refreshSortableBehavior();
+
               this.highlightLastAncestor();
             },
           complete: function ()
             {
-              this.loading = false;
+              this.setLoading(false);
             },
           error: function ()
             {
@@ -403,7 +467,7 @@
           data: { show: 'item', resourceId: this.resourceId },
           beforeSend: function ()
             {
-              this.loading = true;
+              this.setLoading(true);
             },
           success: function (data)
             {
@@ -425,11 +489,13 @@
                 .after($element).next()
                 .removeClass('expand').addClass('ancestor');
 
+              this.refreshSortableBehavior();
+
               this.highlightLastAncestor();
             },
           complete: function ()
             {
-              this.loading = false;
+              this.setLoading(false);
             },
           error: function ()
             {
@@ -448,7 +514,7 @@
           data: { show: 'item', resourceId: this.resourceId },
           beforeSend: function ()
             {
-              this.loading = true;
+              this.setLoading(true);
             },
           success: function (data)
             {
@@ -460,11 +526,13 @@
                 // Add new nodes
                 .after(data);
 
+              this.refreshSortableBehavior();
+
               this.highlightLastAncestor();
             },
           complete: function ()
             {
-              this.loading = false;
+              this.setLoading(false);
             },
           error: function ()
             {
@@ -489,17 +557,19 @@
           data: { show: !$element.next().length ? 'nextSiblings' : 
'prevSiblings', resourceId: this.resourceId },
           beforeSend: function()
             {
-              this.loading = true;
+              this.setLoading(true);
             },
           success: function (data)
             {
               $element.replaceWith(data);
 
+              this.refreshSortableBehavior();
+
               this.highlightLastAncestor();
             },
           complete: function ()
             {
-              this.loading = false;
+              this.setLoading(false);
 
               window.clearTimeout(loadingId);
             },

-- 
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.com/group/qubit-commits?hl=en.

Reply via email to