Development

Changeset 33225

You must first sign up to be able to contribute.

Changeset 33225

Show
Ignore:
Timestamp:
11/23/11 13:22:58 (2 years ago)
Author:
pmacadden
Message:

Se agrega parametro initially_open, si se pone como falso no se inicia abierto

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/dcReloadedFormExtraPlugin/trunk/lib/widget/crWidgetFormJsTreeAjax.class.php

    r33190 r33225  
    11<?php 
    2  /**   
     2 /** 
    33  * crWidgetFormJsTreeAjax is a tree select widget extending crWidgetFormJsTree to provide 
    44  * nodes load asynchornously using ajax 
     
    2020   * 
    2121   *    Nodes returned by this url action must be in json format, as described in the following exmaple: 
    22    *    [  
     22   *    [ 
    2323   *      { data: 'Folder Node name', 
    2424   *        attr: { id: 1 , rel: 'folder'}, 
     
    3333   *    See also, the rel attribute that will be used to change node properties for folder type nodes 
    3434   * 
    35    *  * get_path_to_node_callback: function to retrieve path up to node as array. Use in forms that set default  
     35   *  * get_path_to_node_callback: function to retrieve path up to node as array. Use in forms that set default 
    3636   *    value and should be displayed open up to selected node 
    37    *      
     37   * 
    3838   * Available options: 
    39    *  Same as parent class. @see crWidgetFormJsTree.  
     39   *  Same as parent class. @see crWidgetFormJsTree. 
    4040   * 
    4141   * @param array $options     An array of options 
     
    4646  protected function configure($options = array(), $attributes = array()) { 
    4747    $this->addOption('tree',array()); 
     48    $this->addOption('initially_open', true); 
    4849    parent::configure($options, $attributes); 
    4950    $this->addRequiredOption('url'); 
    5051    $this->addRequiredOption('get_path_to_node_callback'); 
    5152  } 
    52    
     53 
    5354 /** 
    5455  * Returns needed javascript in order to replace json static tree of crWidgetFormJsTree by 
     
    6869    ); 
    6970  } 
    70    
     71 
    7172 /** 
    7273  * Core options must be overwritten so we can tell jstree to open nodes in path to selected node 
     
    7778  protected function getCoreOptions($value) { 
    7879    $options = $this->getOption('tree_options'); 
    79     $options->initially_open = array_map (array($this, 'generateNodeId'),  $this->getPathUpTo($value)); 
     80    if ($this->getOption('initially_open')) 
     81    { 
     82      $options->initially_open = array_map (array($this, 'generateNodeId'),  $this->getPathUpTo($value)); 
     83    } 
     84    else 
     85    { 
     86      $options->initially_open = array(); 
     87    } 
    8088    return $options; 
    8189  } 
     
    97105  */ 
    98106  protected function getJstreeAjaxCallback() { 
    99     return 'function (n) {  
    100             return {  
     107    return 'function (n) { 
     108            return { 
    101109                operation: n == -1? "get_root":"get_children", 
    102                 node_id: n == -1? -1 : n.data("id")   
     110                node_id: n == -1? -1 : n.data("id") 
    103111                   }; 
    104112                }'; 
     
    113121  protected function getJstreeAjaxSuccessCallback() { 
    114122    return sprintf('function (data) { jQuery(data).each(function (i,o){ o.metadata={id: o.attr.id}; o.attr.id="%s_%s_"+ o.attr.id;}); }', 
    115             $this->getPrefix(),  
    116             $this->getOption('prefix_tree_node_id'));  
     123            $this->getPrefix(), 
     124            $this->getOption('prefix_tree_node_id')); 
    117125  } 
    118126 
    119127 /** 
    120   * Overwite parent function to add these two callbacks in a valid format. The problem is that json_encode  
     128  * Overwite parent function to add these two callbacks in a valid format. The problem is that json_encode 
    121129  * breaks javascript function format, because it adds quotes to returned values 
    122130  * 
     
    124132  */ 
    125133  protected function toJson($data) { 
    126     return strtr(parent::toJson($data), array(  
     134    return strtr(parent::toJson($data), array( 
    127135      '"#JSTREE_AJAX_CALLBACK#"'  =>  $this->getJstreeAjaxCallback(), 
    128136      '"#JSTREE_AJAX_SUCCESS#"'   =>  $this->getJstreeAjaxSuccessCallback()));