~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/MooTools/modules/MenuSelect/scripts/select_update.js

  • 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
/**
 
2
 * © Copyright 2007, 2008 IntraHealth International, Inc.
 
3
 * 
 
4
 * This File is part of I2CE 
 
5
 * 
 
6
 * I2CE is free software; you can redistribute it and/or modify 
 
7
 * it under the terms of the GNU General Public License as published by 
 
8
 * the Free Software Foundation; either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * This program is distributed in the hope that it will be useful, 
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License 
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
/**
 
20
 * FormWorm.js -- a javascript mini-library to handle validation and submissions of forms with multiple
 
21
 * actions and options depending on the action.  
 
22
 * @package I2CE
 
23
 * @subpackage Core
 
24
 * @author Carl Leitner <litlfred@ibiblio.org>
 
25
 * @copyright Copyright &copy; 2007, 2008 IntraHealth International, Inc. 
 
26
 * This file is part of I2CE. I2CE is free software; you can redistribute it and/or modify it under 
 
27
 * the terms of the GNU General Public License as published by the Free Software Foundation; either 
 
28
 * version 3 of the License, or (at your option) any later version. I2CE is distributed in the hope 
 
29
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 
30
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 
 
31
 * received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
32
 * @version 2.1
 
33
 * @access public
 
34
 *
 
35
 * This incorporates a few ideas/code of http://forum.mootools.net/topic.php?id=3300
 
36
 */
 
37
 
 
38
 
 
39
 
 
40
var SelectUpdate = new Class( {
 
41
    select: false,
 
42
    select_id: false,
 
43
    current: new Array(),
 
44
    valNodes: new Object(),
 
45
    options: {
 
46
        show_class : false,
 
47
        hide_class : false,
 
48
        show_function : false,
 
49
        hide_function : false,
 
50
        show_function_by_val : false,
 
51
        hide_function_by_val : false,
 
52
        show_on_init : true,
 
53
        hide_on_init : true,
 
54
        prefix : 'select_update'
 
55
    },
 
56
 
 
57
    initialize: function(select_id,options ) {
 
58
        this.select_id = select_id;
 
59
        this.setOptions(options);               
 
60
        if (Browser.loaded) {
 
61
            this.setup();
 
62
        } else {
 
63
            window.addEvent('load',function(e) {
 
64
                this.setup();
 
65
            }.bind(this));
 
66
        }
 
67
    },
 
68
 
 
69
    setup: function() {
 
70
        this.select = $(this.select_id);
 
71
        if (!this.select) {
 
72
            return;
 
73
        }
 
74
        if ($type(this.options.show_function) === 'string') {
 
75
            this.options.show_function = eval(this.options.show_function);
 
76
        }
 
77
        if ($type(this.options.show_function) === 'function') {
 
78
            this.options.show_function.bind(this);
 
79
        }
 
80
        if ($type(this.options.show_function_by_val) === 'string') {
 
81
            this.options.show_function_by_val = eval(this.options.show_function_by_val);
 
82
        }
 
83
        if ($type(this.options.show_function_by_val) === 'function') {
 
84
            this.options.show_function_by_val.bind(this);
 
85
        }
 
86
        if ($type(this.options.hide_function) === 'string') {
 
87
            this.options.hide_function = eval(this.options.show_function);
 
88
        }
 
89
        if ($type(this.options.hide_function) === 'function') {
 
90
            this.options.hide_function.bind(this);
 
91
        }
 
92
        if ($type(this.options.hide_function_by_val) === 'string') {
 
93
            this.options.hide_function_by_val = eval(this.options.hide_function_by_val);
 
94
        }
 
95
        if ($type(this.options.hide_function_by_vall) === 'function') {
 
96
            this.options.hide_function_by_val.bind(this);
 
97
        }
 
98
 
 
99
        this.select.addEvent('change', function(e) {
 
100
            var new_vals = this.select.getSelected();
 
101
            this.hide(this.current, new_vals);
 
102
            this.show(this.current, new_vals);
 
103
            this.current = new_vals;
 
104
        }.bind(this));
 
105
        var new_vals = this.select.getSelected();
 
106
        if (this.options.hide_on_init) {
 
107
            this.hide(this.current, new_vals);
 
108
        }
 
109
        if (this.options.show_on_init) {
 
110
            this.show(this.current, new_vals);
 
111
        }
 
112
        this.current = new_vals;
 
113
    },
 
114
 
 
115
    show: function(old_vals, new_vals, force) {
 
116
        if (!this.select) {
 
117
            return;
 
118
        }
 
119
        if (! new_vals) {
 
120
            new_vals = this.select.getSelected();
 
121
        }
 
122
        if (! old_vals) {
 
123
            old_vals = this.current;
 
124
        }
 
125
        if (this.options.show_class || this.options.hide_class) {           
 
126
            this.select.getElements('option').each(function (option) {
 
127
                valNode = this.getValNode(option.getAttribute('value'));
 
128
                if (!valNode) {
 
129
                    return;
 
130
                }
 
131
                if (this.nodeWithin(option,new_vals)) {  
 
132
                    //th current options is among the newly selected options. we don't need to try to remove the show class
 
133
                    if (this.options.show_class) {
 
134
                        valNode.addClass(this.options.show_class);
 
135
                    } 
 
136
                    if (this.options.hide_class) {
 
137
                        valNode.removeClass(this.options.hide_class);
 
138
                    }
 
139
                } else {
 
140
                    if (this.options.show_class) {
 
141
                        valNode.removeClass(this.options.show_class);
 
142
                    } 
 
143
                    if (this.options.hide_class) {
 
144
                        valNode.addClass(this.options.hide_class);
 
145
                    }
 
146
                }
 
147
            }, this);
 
148
        }
 
149
        if ($type(this.options.show_function) === 'function') {
 
150
            this.options.show_function(this.select);
 
151
        }
 
152
        if (this.options.show_function_by_val || this.options.show_class) {
 
153
            new_vals.each (function(option) {  //run through newly selected options
 
154
                if (force !== true && this.nodeWithin(option,old_vals)) {
 
155
                    //the newly selected option was already selected   we don't need to do the showingg stuff
 
156
                    return;
 
157
                }
 
158
                valNode = this.getValNode(option.getProperty('value'));
 
159
                if (!valNode) {
 
160
                    return;
 
161
                }
 
162
                if (this.options.show_class) {
 
163
                    valNode.addClass(this.options.show_class);
 
164
                }
 
165
                if (this.options.show_function_by_val) {
 
166
                    this.options.show_function_by_val(valNode);
 
167
                }
 
168
            },this);
 
169
        }
 
170
    },
 
171
 
 
172
    nodeWithin: function (node,nodes) {
 
173
        return nodes.some(function(c_node) { return $type(c_node) === 'element' &&  c_node.isSameNode(node);});
 
174
    },
 
175
 
 
176
 
 
177
 
 
178
    hide: function(old_vals,new_vals, force) {
 
179
        if (!this.select) {
 
180
            return;
 
181
        }
 
182
        if (! new_vals) {
 
183
            new_vals = this.select.getSelected();
 
184
        }
 
185
        if (! old_vals) {
 
186
            old_vals = this.current;
 
187
        }
 
188
        if ($type(this.options.hide_function) === 'function' ) {
 
189
            this.options.hide_function(this.select);
 
190
        }
 
191
        if (this.options.hide_function_by_val || this.options.hide_class) {         
 
192
            old_vals.each (function(option) { //run through the old selected options,
 
193
                if (force !== true && this.nodeWithin(option,new_vals)) {
 
194
                    //old option remains  selected.   we don't need to do the hiding stuff
 
195
                    return;
 
196
                }
 
197
                valNode = this.getValNode(option.getProperty('value')); 
 
198
                if (!valNode) {
 
199
                    return;
 
200
                }
 
201
                if (this.options.hide_class) {              
 
202
                    valNode.addClass(this.options.hide_class);
 
203
                }
 
204
                if (this.options.hide_function_by_val) {
 
205
                    this.options.hide_function_by_val(valNode);
 
206
                }
 
207
            },this);
 
208
        }
 
209
    },
 
210
 
 
211
    getValId:function(val) {
 
212
        if (val) {
 
213
            return this.options.prefix + ':' + this.select_id + ':'+ val;
 
214
        } else {
 
215
            return this.options.prefix + ':' + this.select_id ;
 
216
        }
 
217
    },
 
218
 
 
219
    getValNode:function (val) {
 
220
        return $(this.getValId(val));
 
221
    }
 
222
 
 
223
    
 
224
 
 
225
});
 
226
 
 
227
SelectUpdate.implement(new Options);
 
 
b'\\ No newline at end of file'