~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/MooTools/modules/TreeSelect/I2CE_Module_TreeSelect.php

  • Committer: litlfred at ibiblio
  • Date: 2009-10-26 13:55:16 UTC
  • Revision ID: litlfred@ibiblio.org-20091026135516-7er0260tad01febt
ihris suite updated to 4.0.1 pre-release...
follows that did not get added on the last attempt did this time... the problem is that bzr does not like to include branches in a sub-directory even if you add them in which 
  is how ihris-suite/lib/* was structed.  so i had to move ihris-suite/lib/*/.bzr to ihris-suite/lib/*/.bzr_dir to trick it
the site will now succesfully install.  have not attempted change the root drive letter yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
* © Copyright 2009 IntraHealth International, Inc.
 
4
 
5
* This File is part of I2CE 
 
6
 
7
* I2CE is free software; you can redistribute it and/or modify 
 
8
* it under the terms of the GNU General Public License as published by 
 
9
* the Free Software Foundation; either version 3 of the License, or
 
10
* (at your option) any later version.
 
11
 
12
* This program is distributed in the hope that it will be useful, 
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
15
* GNU General Public License for more details.
 
16
 
17
* You should have received a copy of the GNU General Public License 
 
18
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
* @package i2ce
 
20
* @subpackage core
 
21
* @author Carl Leitner <litlfred@ibiblio.org>
 
22
* @version v3.2.0
 
23
* @since v3.2.0
 
24
* @filesource 
 
25
*/ 
 
26
/** 
 
27
* Class I2CE_Module_TreeSelect
 
28
 
29
* @access public
 
30
*/
 
31
 
 
32
 
 
33
class I2CE_Module_TreeSelect extends I2CE_Module{
 
34
 
 
35
    
 
36
    public static function getMethods() {
 
37
        return array(
 
38
            'I2CE_Page->addAutoCompleteInputTreeById'=>'addAutoCompleteInputTreeById',
 
39
            'I2CE_Template->addAutoCompleteInputTreeById'=>'addAutoCompleteInputTreeById',
 
40
            'I2CE_Page->addAutoCompleteInputTree'=>'addAutoCompleteInputTree',
 
41
            'I2CE_Template->addAutoCompleteInputTree'=>'addAutoCompleteInputTree'
 
42
            );
 
43
    }
 
44
 
 
45
    public static function getHooks() {
 
46
        return array(
 
47
            'post_page_prepare_display_I2CE_Template'=> 'writeOutJS'
 
48
            );
 
49
    }
 
50
 
 
51
    protected $trees;
 
52
 
 
53
    public function  __construct() {
 
54
        $this->trees = array();
 
55
    }
 
56
 
 
57
    /**
 
58
     * Adds a auto complete input tree
 
59
     * @param string $tree_id The id of the tree
 
60
     * @param array $tree_options.  Defaults to empty array.  Passed to the javascript formwork constructor.
 
61
     * @param array $autocomplete_options.  Defaults to empty array.  Passed to the javascript formwork constructor.
 
62
     */
 
63
    public function addAutoCompleteInputTreeById($obj,$tree_id,$tree_options=array(),$autocomplete_options = array()) {
 
64
        if (!array_key_exists('auto_input',$this->trees) || !is_array($this->trees['auto_input'])) {
 
65
            $this->trees['auto_input'] = array();
 
66
        }
 
67
        if (is_array($tree_options) ) {
 
68
            $tree_options = json_encode($tree_options);
 
69
        }
 
70
        if (!is_string($tree_options)) {
 
71
            $tree_options = '{}';
 
72
        }
 
73
        if (is_array($autocomplete_options)) {
 
74
            $autocomplete_options = json_encode($autocomplete_options);
 
75
        }
 
76
        if (!is_string($autocomplete_options)) {
 
77
            $autocomplete_options = '{}';
 
78
        }
 
79
        $this->trees['auto_input'][] = "new I2CE_TreeSelectAutoCompleter(new I2CE_TreeInputSelect('{$tree_id}',{$tree_options}),{$autocomplete_options});\n";
 
80
    }
 
81
 
 
82
 
 
83
 
 
84
    
 
85
    public function addAutoCompleteInputTree($template,$node,$hidden_name,$hidden_id,$selected=null,$data, 
 
86
                                             $tree_options=array(),$autocomplete_options=array()) {
 
87
        if ($template instanceof I2CE_Page) {
 
88
            $template = $template->getTemplate();
 
89
        }
 
90
        if (!$template instanceof I2CE_Template) {
 
91
            return;
 
92
        }
 
93
        if (!is_array($data)) {
 
94
            return;
 
95
        }
 
96
        if (!$node instanceof DOMElement) {
 
97
            return;
 
98
        }
 
99
        $display_id = $hidden_id . '_inputtree_display';
 
100
        $tree_id = $hidden_id . '_inputtree_tree';
 
101
        $toggle_class = $tree_id . '_toggle';
 
102
        $hiddenNode = $template->createElement(
 
103
            'input', 
 
104
            array(
 
105
                'id'=>$hidden_id,
 
106
                'name'=>$hidden_name,
 
107
                'type'=>'hidden'
 
108
                ));
 
109
        if (is_array($selected) && array_key_exists('value', $selected)) {
 
110
            $hiddenNode->setAttribute('value',$selected['value']);
 
111
        }
 
112
 
 
113
        $node->appendChild($hiddenNode);
 
114
        $displayNode = $template->createElement(
 
115
            'input', 
 
116
            array(
 
117
                'id'=>$display_id,
 
118
                'type'=>'text'
 
119
                ));
 
120
        if (is_array($selected) && array_key_exists('display', $selected)) {
 
121
            $displayNode->setAttribute('value',$selected['display']);
 
122
        }
 
123
        $node->appendChild($displayNode);
 
124
        $toggleNode = $template->createElement(
 
125
            'span', 
 
126
            array(
 
127
                'class'=>"tree_main_toggle $toggle_class"
 
128
                ),
 
129
            'Select Value');        
 
130
        $node->appendChild($toggleNode);        
 
131
        $treeNode = $template->createElement(
 
132
            'span', 
 
133
            array(
 
134
                'id'=>$tree_id,
 
135
                'class'=>'tree_closed treeselect'
 
136
                ));
 
137
        $template->setClassValues(
 
138
            $treeNode,
 
139
            array(
 
140
                'inputSelectHidden'=>$hidden_id,
 
141
                'inputSelectVisible'=>$display_id
 
142
                ));
 
143
        $node->appendChild($treeNode);        
 
144
        $this->createTreeData($template,$treeNode, $data);
 
145
        $this->addAutoCompleteInputTreeById($template,$tree_id, $tree_options,$autocomplete_options);
 
146
    }
 
147
 
 
148
 
 
149
    protected function createTreeData($template,$treeNode,$data) {
 
150
        $has_selectable = false;
 
151
        foreach ($data as $d) {
 
152
            if (!is_array($d)) {
 
153
                continue;
 
154
            }
 
155
            if (!array_key_exists('display',$d)) {
 
156
                continue;
 
157
            }            
 
158
            if (array_key_exists('children',$d) && is_array($d['children'])) {
 
159
                $childNode = $template->createElement('span',array('class'=>'tree_children tree_closed'));
 
160
                $has_selectable_children = $this->createTreeData($template,$childNode,$d['children']);
 
161
                //we have children, so this is an expander
 
162
                $expanderNode = $template->createElement('span',array('class'=>'tree_expandable'));
 
163
                $treeNode->appendChild($expanderNode);
 
164
                if (array_key_exists('value',$d)) {
 
165
                    //it is selectable
 
166
                    $has_selectable = true;
 
167
                    $expanderNode->appendChild( //the toggler
 
168
                        $template->createElement('span',array('class'=>'tree_toggle'),' '));
 
169
                    $selectorNode = 
 
170
                        $template->createElement(
 
171
                            'span',
 
172
                            array('class'=>'treeselect_selectable'),
 
173
                            $d['display']);
 
174
                    if (array_key_exists('title',$d)) {
 
175
                        $selectorNode->setAttribute('title',$d['title']);
 
176
                    }
 
177
                    $template->setClassValue($selectorNode, 'treeselect_value',$d['value']);
 
178
                    $expanderNode->appendChild( $selectorNode);
 
179
                } else {
 
180
                    //it is not selectable
 
181
                    $class = 'tree_toggle';
 
182
                    if ($has_selectable_children){
 
183
                        $has_selectable = true;
 
184
                    } else {
 
185
                        $class .= ' treeselect_notselectable';
 
186
                        continue;
 
187
                    }
 
188
                    $togglerNode = $template->createElement('span',array('class'=>$class),$d['display']);
 
189
                    if (array_key_exists('title',$d)) {
 
190
                        $togglerNode->setAttribute('title',$d['title']);
 
191
                    }
 
192
                    $expanderNode->appendChild( $togglerNode);
 
193
                }
 
194
                $expanderNode->appendChild($childNode);
 
195
            } else {
 
196
                //we have no children, so this is not an expander
 
197
                $childNode = $template->createElement('span', array(),$d['display']);                
 
198
                if (array_key_exists('value',$d)) {
 
199
                    $has_selectable = true;
 
200
                    $childNode->setAttribute('class','treeselect_selectable');
 
201
                    $template->setClassValue($childNode,'treeselect_value', $d['value']);
 
202
                } else {
 
203
                    $childNode->setAttribute('class','treeselect_notselectable');
 
204
                    continue;
 
205
                }
 
206
                if (array_key_exists('title',$d)) {
 
207
                    $childNode->setAttribute('title',$d['title']);
 
208
                }
 
209
                $treeNode->appendChild($childNode);
 
210
            }
 
211
        }
 
212
        return $has_selectable;
 
213
    }
 
214
 
 
215
 
 
216
 
 
217
 
 
218
 
 
219
    public function writeOutJS($page) {
 
220
        if (count($this->trees) == 0) {
 
221
            return;
 
222
        }
 
223
        if (!$page instanceof I2CE_Page) {
 
224
            return;
 
225
        }
 
226
        $template= $page->getTemplate();
 
227
        if (!$template instanceof I2CE_Template) {
 
228
            return;
 
229
        }
 
230
        $template->addHeaderLink("mootools-core.js");
 
231
        $template->addHeaderLink("mootools-more.js");
 
232
        $template->addHeaderLink("getElementsByClassName-1.0.1.js");
 
233
        $template->addHeaderLink("I2CE_ClassValues.js");       
 
234
        $template->addHeaderLink("I2CE_Window.js");       
 
235
        $template->addHeaderLink("I2CE_ToggableWindow.js");       
 
236
        $template->addHeaderLink("I2CE_TreeSelect.js");       
 
237
        $template->addHeaderLink("Tree.css");       
 
238
        if (array_key_exists('auto_input',$this->trees) && is_array($this->trees['auto_input']) && count($this->trees['auto_input'])> 0) {
 
239
            $template->addHeaderLink('Observer.js');
 
240
            $template->addHeaderLink('Autocompleter.js');
 
241
            $template->addHeaderLink('Autocompleter.css');
 
242
            $template->addHeaderLink('I2CE_TreeSelectAutoCompleter.js');
 
243
        }
 
244
        $js = '';
 
245
        foreach ($this->trees as $type=>$trees) {
 
246
            foreach ($trees as $tree_js) {
 
247
                $js .= $tree_js;
 
248
            }            
 
249
        }        
 
250
        $js = "window.addEvent('domready',function() {\n" . $js . "\n});\n";        
 
251
        $template->addHeaderText($js,'script','treeselect');
 
252
    }
 
253
 
 
254
 
 
255
 
 
256
}
 
257
# Local Variables:
 
258
# mode: php
 
259
# c-default-style: "bsd"
 
260
# indent-tabs-mode: nil
 
261
# c-basic-offset: 4
 
262
# End: