Author: sevein
Date: Fri Apr  6 15:21:44 2012
New Revision: 11418

Log:
Issue 2288, XHR request to show root objects in the treeview

Added:
   
branches/2.0/apps/qubit/modules/informationobject/templates/treeViewSuccess.php 
  (contents, props changed)
Modified:
   
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
   branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php
   branches/2.0/js/dominion.js

Modified: 
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
==============================================================================
--- 
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
  Fri Apr  6 14:01:56 2012        (r11417)
+++ 
branches/2.0/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
  Fri Apr  6 15:21:44 2012        (r11418)
@@ -21,10 +21,12 @@
 {
   public function execute($request)
   {
-    $this->response->setHttpHeader('Content-Type', 'application/json; 
charset=utf-8');
-
     $this->resource = $this->getRoute()->resource;
 
-    return 
$this->renderText(json_encode($this->resource->getChildYuiNodes($request)));
+    if ('all' == $request->show)
+    {
+      $query = new Elastica_Query_Term(array('parentId' => 
QubitInformationObject::ROOT_ID));
+      $this->resultSet = 
QubitSearch::getInstance()->index->getType('QubitInformationObject')->search($query);
+    }
   }
 }

Modified: 
branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php
==============================================================================
--- branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php   
Fri Apr  6 14:01:56 2012        (r11417)
+++ branches/2.0/apps/qubit/modules/informationobject/templates/_treeView.php   
Fri Apr  6 15:21:44 2012        (r11418)
@@ -2,7 +2,7 @@
 
   <ul class="unstyled">
 
-    <li class="back"><i></i><?php echo link_to(__('Show all'), array('module' 
=> 'informationobject', 'action' => 'browse'), array('class' => 'arrow-left')) 
?></li>
+    <li class="back" data-location="<?php echo url_for(array($resource, 
'module' => 'informationobject', 'action' => 'treeView', 'show' => 'all')) 
?>"><i></i><?php echo link_to(__('Show all'), array('module' => 
'informationobject', 'action' => 'browse')) ?></li>
 
     <?php $resultSet = $current->getResults() ?>
     <?php $doc = $resultSet[0]->getData() ?>

Added: 
branches/2.0/apps/qubit/modules/informationobject/templates/treeViewSuccess.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ 
branches/2.0/apps/qubit/modules/informationobject/templates/treeViewSuccess.php 
    Fri Apr  6 15:21:44 2012        (r11418)
@@ -0,0 +1,19 @@
+<?php $items = $resultSet->getResults() ?>
+
+<?php foreach ($items as $hit): ?>
+
+  <?php $doc = $hit->getData() ?>
+  <?php foreach ($doc['i18n'] as $i18n): ?>
+    <?php $doc[$i18n['culture']] = $i18n ?>
+  <?php endforeach; ?>
+  <?php unset($doc['i18n']); // continue; ?>
+
+  <?php $title = $doc[$sf_user->getCulture()]['title'] ?: 
$doc[$doc['sourceCulture']]['title'] ?>
+  <?php $expand = 0 < @$doc['children'] ? ' expand' : '' ?>
+  <?php if ($hit->getId() == $resource->id): ?>
+    <li class="active<?php echo $expand ?>"><?php echo $title ?></li>
+  <?php else: ?>
+    <li class="<?php echo $expand ?>"><?php echo link_to('<i></i>'.$title, 
array('module' => 'informationobject', 'slug' => $doc['slug'])) ?></li>
+  <?php endif; ?>
+
+<?php endforeach; ?>

Modified: branches/2.0/js/dominion.js
==============================================================================
--- branches/2.0/js/dominion.js Fri Apr  6 14:01:56 2012        (r11417)
+++ branches/2.0/js/dominion.js Fri Apr  6 15:21:44 2012        (r11418)
@@ -225,6 +225,7 @@
   var Treeview = function (element)
     {
       this.$element = element;
+      this.loading = false;
       this.init();
     };
 
@@ -234,13 +235,10 @@
 
     init: function()
       {
-
-        this.$element.find('li')
-          .hover(
-            $.proxy(this.mouseenter, this),
-            $.proxy(this.mouseleave, this))
-          .click(
-            $.proxy(this.click, this));
+        this.$element
+          .on('click.treeview.qubit', 'li', $.proxy(this.click, this))
+          .on('mouseenter.treeview.qubit', 'li', $.proxy(this.mouseenter, 
this))
+          .on('mouseleave.treeview.qubit', 'li', $.proxy(this.mouseleave, 
this));
 
       },
 
@@ -256,8 +254,46 @@
 
     click: function(e)
       {
+        console.log('li clicked');
         e.preventDefault();
+        e.stopPropagation();
+
+        if (this.loading)
+        {
+          console.log("Ignored");
+          return;
+        }
+
+        var $target = 'LI' == e.target.tagName ? $(e.target) : 
$(e.target).closest('li');
+
+        if ($target.hasClass('back'))
+        {
+          $.ajax({
+              url: $target.data('location'),
+              context: this,
+              dataType: 'html',
+              beforeSend: function ()
+                {
+                  this.loading = true;
+                },
+              success: function (data)
+                {
+                  $target
+                    .hide()
+                    .nextAll().remove().end()
+                    .after(data).end();
+
+                },
+              complete: function ()
+                {
+                  this.loading = false;
+                },
+              error: function ()
+                {
+                }
+            });
 
+        }
 
       }
 
@@ -277,7 +313,7 @@
 
   $(function ()
     {
-      var $treeview = $('body.sfRadPlugin.index #treeview');
+      var $treeview = $('#treeview');
       if (0 < $treeview.length)
       {
         $treeview.treeview();

-- 
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