Example #1
0
 public function collapsibleTree($tree, $options = array())
 {
     if (!empty($options['images'])) {
         $this->_collapse_images['open'] = $options['images']['open'];
         $this->_collapse_images['close'] = $options['images']['close'];
     }
     if (!empty($options['li_template'])) {
         $this->_li_template = $options['li_template'];
     }
     parent::tree($tree, $options);
     return "<ul id='{$this->_ul_id}' class='{$this->_class}'>" . $this->generateList($tree) . "</ul>";
 }
Example #2
0
 /**
  * Set default values and the first level container (ul)
  *
  * @param Mixed $menu    If String: Fecth menu data according its name.<br/>
  *                       If Array: It must contain the menu tree.
  *
  * @param array $options Options to manage menu behaviour<br />
  *                       Ex: disable_nesting => true, parentAltId => (string)
  *
  * @return string html code to display the menu and is children
  */
 public function menu($menu, $options = array())
 {
     $this->_addSeparator = "";
     $menuItem = array();
     $_menu = "";
     if (isset($options['addEnclosure'])) {
         $this->_addEnclosure = $options['addEnclosure'];
     }
     if (isset($options['class']) && $options['class'] == 'sitemap') {
         $this->_isSiteMap = true;
     } else {
         $this->_isSiteMap = false;
     }
     if ($this->view->selectedPage) {
         $this->_selectedPage = $this->view->selectedPage;
     } elseif (Zend_Registry::isRegistered('selectedPage')) {
         $this->_selectedPage = Zend_Registry::get('selectedPage');
     } else {
         $params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
         $this->_selectedPage = $params['controller'];
         if ($params['controller'] == 'index') {
             $this->_selectedPage = Cible_FunctionsPages::getPageNameByID(1);
         }
     }
     if (isset($options['addSeparator'])) {
         $this->_addSeparator = $options['addSeparator'];
     }
     $oPages = new PagesObject();
     $pageData = $oPages->pageIdByController($this->_selectedPage);
     $this->_selectedPageId = $pageData['P_ID'];
     if (!is_array($menu)) {
         $_menu = new MenuObject($menu);
         $parentId = isset($options['parentId']) ? $options['parentId'] : 0;
         $tree = $_menu->populate($parentId);
     } elseif (count($menu) > 1 && empty($menu['MID_MenuID'])) {
         $tree = $menu;
     } else {
         $_menu = new MenuObject($menu['MID_MenuID']);
         unset($menu['MID_MenuID'], $menu['MID_ParentId']);
         $tree = $menu;
         if (Zend_Registry::isRegistered('selectedCatalogPage')) {
             $currentUrl = preg_replace('#\\/page\\/[0-9]*#', '', substr($this->view->request->getPathInfo(), 1));
             if (strrpos($currentUrl, '/') == 1) {
                 $currentUrl = substr($currentUrl, -1);
             }
             $nbParts = substr_count($currentUrl, '/');
             if ($nbParts >= 3) {
                 $lastPos = strrpos($currentUrl, '/');
                 $currentUrl = substr($this->view->request->getPathInfo(), 1, $lastPos);
             } elseif ($nbParts == 0) {
                 $currentUrl = $tree[0]['Link'];
             }
             $this->_selectedPage = $currentUrl;
         }
     }
     if (is_object($_menu) && $_menu->getId()) {
         $menuItem = $_menu->getMenuItemByPageId($this->_selectedPageId);
     }
     if ($menuItem) {
         $this->_getParentsMenuId($menuItem, $_menu);
         $this->view->assign('menuId', $menuItem['MID_MenuID']);
     }
     if (is_array($options)) {
         $parentId = isset($options['parentId']) ? $options['parentId'] : 0;
         $this->_parent_alt_id = isset($options['parentIdAlt']) ? $options['parentIdAlt'] : "parentid-";
     }
     if (!empty($options['startLevel'])) {
         $this->_startLevel = $options['startLevel'];
     }
     $this->_disable_nesting = isset($options['disable_nesting']) && $options['disable_nesting'] == true ? true : false;
     parent::tree($tree, $options);
     // var_dump($tree);
     if ($tree) {
         return "<ul id='{$this->_ul_id}' class='{$this->_class}' {$this->_attribs}>" . $this->generateList($tree, true) . "</ul>";
     }
 }
Example #3
0
    public function sortableTree($tree, $options = array())
    {
        $this->_li_template = "<li id='%OBJECT_ID%' class='%LI_CLASS%'><img class='handle' src='" . $this->view->baseUrl() . "/icons/file.png' />";
        $menu = parent::tree($tree, $options);
        if (empty($options['acceptClass'])) {
            throw new Exception('SortableTree must define the acceptClass options to work');
        }
        $attr['acceptClass'] = $options['acceptClass'];
        $attr['onChange'] = !empty($options['onChange']) ? $options['onChange'] . '(serialized)' : 'alert(\'Implementing the onchange method would let you save the state.\');';
        $attr['receive'] = !empty($options['receive']) ? $options['receive'] . '(event, ui)' : '';
        $attr['stop'] = !empty($options['stop']) ? $options['stop'] . '(event, ui)' : '';
        // Removed from var $script
        /**/
        $script = <<<EOS

            function format{$this->_id}SortableTree(){

                \$('ul#ul_{$this->_id}').find('ul').each(function(){
                    if( \$(this).children('li').size() == 0 ){
                        \$(this).remove();
                    }
                });

                \$('ul#ul_{$this->_id}').find('li').each(function(){

                    var child_list = \$(this).find('ul:first');

                    if( child_list.size() > 0){
                        \$(this).addClass('hasChildren');
                    } else {
                        \$(this).removeClass('hasChildren');
                    }
                });
            }

            function build{$this->_id}Sortable(){

                \$('ul#ul_{$this->_id}').SortableDestroy();
                \$('ul#ul_{$this->_id}').NestedSortable({
                    accept: '{$attr['acceptClass']}',
                    helperclass: 'helper',
                    handle: '.handle',
                    noNestingClass: 'no-nesting',
                    onChange: function(serialized){
                        {$attr['onChange']}
                        build{$this->_id}Sortable();
                        format{$this->_id}SortableTree();

                    },
                    receive: function(event, ui){
                        {$attr['receive']}
                    },
                    stop: function(event, ui){
                        {$attr['stop']}
                    }
                });
            }

            \$(function(){

                \$('ul#ul_{$this->_id}').NestedSortable({
                    accept: '{$attr['acceptClass']}',
                    helperclass: 'helper',
                    handle: '.handle',
                    noNestingClass: 'no-nesting',
                    onChange: function(serialized){
                        {$attr['onChange']}
                        build{$this->_id}Sortable();
                        format{$this->_id}SortableTree();

                    },
                    receive: function(event, ui){
                        {$attr['receive']}
                    },
                    stop: function(event, ui){
                        {$attr['stop']}
                    }
                });
                format{$this->_id}SortableTree();
            });

EOS;
        $this->view->headScript()->appendFile("{$this->view->baseUrl()}/js/jquery/jquery.livequery.js");
        $this->view->headScript()->appendFile("{$this->view->baseUrl()}/js/jquery/jquery.rightClick.js");
        $this->view->headScript()->appendFile("{$this->view->baseUrl()}/js/interface.js");
        $this->view->headScript()->appendFile("{$this->view->baseUrl()}/js/inestedsortable.js");
        $this->view->headScript()->appendFile("{$this->view->baseUrl()}/js/csa/overlay.js");
        $this->view->headScript()->appendScript($script);
        //$this->view->headScript()->offsetSetScript(100,$script);
        return $menu;
    }