Changeset 33225
- Timestamp:
- 11/23/11 13:22:58 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/dcReloadedFormExtraPlugin/trunk/lib/widget/crWidgetFormJsTreeAjax.class.php
r33190 r33225 1 1 <?php 2 /** 2 /** 3 3 * crWidgetFormJsTreeAjax is a tree select widget extending crWidgetFormJsTree to provide 4 4 * nodes load asynchornously using ajax … … 20 20 * 21 21 * Nodes returned by this url action must be in json format, as described in the following exmaple: 22 * [ 22 * [ 23 23 * { data: 'Folder Node name', 24 24 * attr: { id: 1 , rel: 'folder'}, … … 33 33 * See also, the rel attribute that will be used to change node properties for folder type nodes 34 34 * 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 36 36 * value and should be displayed open up to selected node 37 * 37 * 38 38 * Available options: 39 * Same as parent class. @see crWidgetFormJsTree. 39 * Same as parent class. @see crWidgetFormJsTree. 40 40 * 41 41 * @param array $options An array of options … … 46 46 protected function configure($options = array(), $attributes = array()) { 47 47 $this->addOption('tree',array()); 48 $this->addOption('initially_open', true); 48 49 parent::configure($options, $attributes); 49 50 $this->addRequiredOption('url'); 50 51 $this->addRequiredOption('get_path_to_node_callback'); 51 52 } 52 53 53 54 /** 54 55 * Returns needed javascript in order to replace json static tree of crWidgetFormJsTree by … … 68 69 ); 69 70 } 70 71 71 72 /** 72 73 * Core options must be overwritten so we can tell jstree to open nodes in path to selected node … … 77 78 protected function getCoreOptions($value) { 78 79 $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 } 80 88 return $options; 81 89 } … … 97 105 */ 98 106 protected function getJstreeAjaxCallback() { 99 return 'function (n) { 100 return { 107 return 'function (n) { 108 return { 101 109 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") 103 111 }; 104 112 }'; … … 113 121 protected function getJstreeAjaxSuccessCallback() { 114 122 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')); 117 125 } 118 126 119 127 /** 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 121 129 * breaks javascript function format, because it adds quotes to returned values 122 130 * … … 124 132 */ 125 133 protected function toJson($data) { 126 return strtr(parent::toJson($data), array( 134 return strtr(parent::toJson($data), array( 127 135 '"#JSTREE_AJAX_CALLBACK#"' => $this->getJstreeAjaxCallback(), 128 136 '"#JSTREE_AJAX_SUCCESS#"' => $this->getJstreeAjaxSuccessCallback()));