Improving UserBasket category selection.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 10 Dec 2012 23:23:05 +0000 (00:23 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 10 Dec 2012 23:23:05 +0000 (00:23 +0100)
apps/userfront/modules/category/templates/indexSuccess.php

index cebfd7c..bdb4d3a 100644 (file)
             hierarchyCheck($(this), checkedInput);
         });
     });
+
+    $(document).ready(function(){
+        $('[id^=node]').each(function(data){
+            if($(this).children('td').eq(1).find('input').is(':checked')) {
+                hierarchyCheck($(this), true);
+            }
+        });
+    });
 </script>
 
 
     <tr id="node-<?php echo $category->getId()?>" <?php
       // insert hierarchical info
       $node = $category->getNode();
-      if ($node->isValidNode() && $node->hasParent() && ($node->getParent()->getId() != '1'))
+      if ($node->isValidNode() && $node->hasParent() && ($node->getParent()->getLevel() != '0'))
       {
         echo 'class="child-of-node-'.$node->getParent()->getId().'"';
       }
       ?>>
       <td><a><?php echo $category ?></a></td>
-      <td><input type="checkbox" id="chosen" class="NFCheck" value="<?php echo $category->getId() ?>"
-      <?php foreach ($category->getUserBaskets() as $userBasket): ?>
-        <?php if ($userBasket->getUserId() == $userId): ?>
-            checked
-            <?php break ?>
-        <?php endif; ?>
-      <?php endforeach; ?>
-      ></td>
+      <?php if ($node->getLevel() != '0'): ?>
+        <td><input type="checkbox" id="chosen" class="NFCheck" value="<?php echo $category->getId() ?>"
+        <?php foreach ($category->getUserBaskets() as $userBasket): ?>
+            <?php if ($userBasket->getUserId() == $userId): ?>
+                checked
+                <?php break ?>
+            <?php endif; ?>
+        <?php endforeach; ?>
+        ></td>
+      <?php else: ?>
+        <td></td>
+      <?php endif; ?>
     </tr>
     <?php endforeach; ?>
   </tbody>