Subversion Repositories wimsdev

Rev

Rev 7479 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7479 Rev 12784
Line 1... Line 1...
1
<script type="text/javascript">
1
<script type="text/javascript">
2
/*<![CDATA[*/
2
/*<![CDATA[*/
-
 
3
 
-
 
4
/**
-
 
5
 * chooselist, inspired by qfamsHAndler HTML_QuickForm_advmultiselect
-
 
6
 
-
 
7
 * JavaScript functions to handle a multiselect element (Move elements between 2 select boxes)
-
 
8
 * @author     Laurent Laville <pear@laurent-laville.org>
-
 
9
 * @copyright  2007-2009 Laurent Laville
-
 
10
 * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
-
 
11
 * @website    https://github.com/pear/HTML_QuickForm_advmultiselect
-
 
12
 */
-
 
13
 
-
 
14
 
-
 
15
/**
-
 
16
 * QFAMS.moveSelection
-
 
17
 * in double select box mode, to move current selection and update live counter
-
 
18
 *
-
 
19
 * @param      dom element   selectLeft     Data source list
-
 
20
 * @param      dom element   selectRight    Target data list
-
 
21
 * @param      dom element   selectHidden   Full data source (selected, unselected)
-
 
22
 *                                          private usage
-
 
23
 * @param      string        action         Action name (add, remove, all, none, toggle)
-
 
24
 */
3
function moveSelections(selectLeft, selectRight, selectHidden, action) {
25
function moveSelections(selectLeft, selectRight, selectHidden, action) {
-
 
26
    var isIE = /*@cc_on!@*/false; //IE detector
-
 
27
    var source = null;
-
 
28
    var target = null;
-
 
29
    var option;
4
  var menuFrom; var menuTo;  var i ;
30
    var c      = null;
-
 
31
    var s      = null;
-
 
32
    var i;
5
    if (action == 'add') {
33
    var maxFrom, maxTo;
-
 
34
 
-
 
35
    if (action === 'add' || action === 'all' || action === 'toggle') {
6
        menuFrom = selectLeft;
36
        source = selectLeft;
7
        menuTo = selectRight;
37
        target = selectRight;
8
    }
-
 
9
    else {
38
    } else {
10
        menuFrom = selectRight;
39
        source = selectRight;
11
        menuTo = selectLeft;
40
        target = selectLeft;
12
    }
41
    }
13
    // Don't do anything if nothing selected. Otherwise we throw javascript errors.
42
    // Don't do anything if nothing selected. Otherwise we throw javascript errors.
14
    if (menuFrom.selectedIndex == -1) {
43
    if (source.selectedIndex === -1 && (action === 'add' || action === 'remove')) {
15
        return;
44
        return;
16
    }
45
    }
-
 
46
    maxFrom = source.options.length;
-
 
47
    maxTo   = target.options.length;
17
 
48
 
18
    // Add items to the 'TO' list.
49
    // check if target list is empty and remove fake empty option (tip to be XHTML compliant)
19
    for (i=0; i < menuFrom.length; i++) {
50
    if (maxTo > 0 && target.options[0].value === "") {
20
        if (menuFrom.options[i].selected == true ) {
51
        target.removeAttribute("disabled");
21
            menuTo.options[menuTo.length]= new Option(menuFrom.options[i].text, menuFrom.options[i].value);
-
 
22
        }
52
        target.options[0] = null;
23
    }
53
    }
24
 
54
 
-
 
55
    // Add items to the 'TO' list.
-
 
56
    for (i = (maxFrom - 1); i >= 0; i--) {
-
 
57
        if (action === 'all' || action === 'none' || action === 'toggle' || source.options[i].selected === true) {
-
 
58
            if (source.options[i].disabled === false) {
-
 
59
                if (isIE) {
-
 
60
                    option = source.options[i].removeNode(true);
-
 
61
                    //option.selected = env.persistantSelection;
-
 
62
                    target.appendChild(option);
-
 
63
                } else {
-
 
64
                    option = source.options[i].cloneNode(true);
-
 
65
                    //option.selected = env.persistantSelection;
-
 
66
                    target.options[target.options.length] = option;
-
 
67
                }
-
 
68
            }
-
 
69
        }
-
 
70
    }
-
 
71
 
25
    // Remove items from the 'FROM' list.
72
    // Remove items from the 'FROM' list.
-
 
73
    if (!isIE) {
26
    for (i=(menuFrom.length - 1); i>=0; i--){
74
        for (i = (maxFrom - 1); i >= 0; i--) {
-
 
75
            if (action === 'all' || action === 'none' || action === 'toggle' || source.options[i].selected === true) {
-
 
76
                if (source.options[i].disabled === false) {
-
 
77
                    source.options[i] = null;
-
 
78
                }
-
 
79
            }
-
 
80
        }
-
 
81
    }
-
 
82
 
-
 
83
    // Add items to the 'FROM' list for toggle function
-
 
84
    if (action === 'toggle') {
-
 
85
        for (i = (maxTo - 1); i >= 0; i--) {
27
        if (menuFrom.options[i].selected == true ) {
86
            if (target.options[i].disabled === false) {
-
 
87
                if (isIE) {
-
 
88
                    option = target.options[i].removeNode(true);
-
 
89
                    //option.selected = env.persistantSelection;
-
 
90
                    source.appendChild(option);
-
 
91
                } else {
-
 
92
                    option = target.options[i].cloneNode(true);
-
 
93
                    //option.selected = env.persistantSelection;
-
 
94
                    source.options[source.options.length] = option;
-
 
95
                }
-
 
96
            }
-
 
97
        }
-
 
98
        if (!isIE) {
-
 
99
            for (i = (maxTo - 1); i >= 0; i--) {
-
 
100
                if (target.options[i].disabled === false) {
28
            menuFrom.options[i] = null;
101
                    target.options[i] = null;
-
 
102
                }
-
 
103
            }
29
        }
104
        }
30
    }
105
    }
31
 
106
 
32
    // Set the appropriate items as 'selected in the hidden select.
107
    // Set the appropriate items as 'selected in the hidden select.
33
    // These are the values that will actually be posted with the form.
108
    // These are the values that will actually be posted with the form.
34
    updateHidden(selectHidden, selectRight);
109
    updateHidden(selectHidden, selectRight);
35
}
110
}
36
 
111
 
-
 
112
/*
-
 
113
 * QFAMS.updateHidden
-
 
114
 * updates the private list that handle selection of all elements (selected and unselected)
-
 
115
 * @param      dom element   h              hidden list (contains all elements)
-
 
116
 * @param      dom element   r              selection list (contains only elements selected)
-
 
117
 */
37
function updateHidden(h,r) {
118
function updateHidden(h, r) {
-
 
119
    var i;
-
 
120
 
38
    for (var i=0; i < h.length; i++) {
121
    for(i = h.options.length - 1 ; i >= 0 ; i--)
-
 
122
    {
39
        h.options[i].selected = false;
123
        //h.options[i].selected = false;
-
 
124
        h.remove(i);
40
    }
125
    }
41
 
126
 
42
    for (i=0; i < r.length; i++) {
127
    for (i = 0; i < r.length; i++) {
43
        h.options[h.length] = new Option(r.options[i].text, r.options[i].value);
128
        h.options[h.length] = new Option(r.options[i].text, r.options[i].value);
44
        h.options[h.length-1].selected = true;
129
        h.options[h.length - 1].selected = true;
45
    }
130
    }
46
}
131
}
47
 
132
 
-
 
133
/**
-
 
134
 * QFAMS.moveUp
-
 
135
 * end-user may arrange and element up to the selection list
-
 
136
 *
-
 
137
 * @param      dom element   l              selection list (contains only elements selected)
-
 
138
 * @param      dom element   h              hidden list (contains all elements)
-
 
139
 *
-
 
140
 */
48
function moveUp(l,h) {
141
function moveUp(l, h) {
49
    var indice = l.selectedIndex;
142
    var indice = l.selectedIndex;
50
    if (indice < 0) {
143
    if (indice < 0) {
51
        return;
144
        return;
52
    }
145
    }
53
    if (indice > 0) {
146
    if (indice > 0) {
54
        moveSwap(l, indice, indice-1);
147
        moveSwap(l, indice, indice - 1);
55
        updateHidden(h, l);
148
        updateHidden(h, l);
56
    }
149
    }
57
}
150
}
58
 
151
 
-
 
152
/**
-
 
153
 * QFAMS.moveDown
-
 
154
 * end-user may arrange and element down to the selection list
-
 
155
 *
-
 
156
 * @param      dom element   l              selection list (contains only elements selected)
-
 
157
 * @param      dom element   h              hidden list (contains all elements)
-
 
158
 *
-
 
159
 */
59
function moveDown(l,h) {
160
function moveDown(l, h) {
60
    var indice = l.selectedIndex;
161
    var indice = l.selectedIndex;
61
    if (indice < 0) {
162
    if (indice < 0) {
62
        return;
163
        return;
63
    }
164
    }
64
    if (indice < l.options.length-1) {
165
    if (indice < l.options.length - 1) {
65
        moveSwap(l, indice, indice+1);
166
        moveSwap(l, indice, indice + 1);
66
        updateHidden(h, l);
167
        updateHidden(h, l);
67
    }
168
    }
68
}
169
}
69
 
170
 
-
 
171
/**
-
 
172
 * QFAMS.moveSwap
-
 
173
 * end-user may invert two elements position in the selection list
-
 
174
 *
-
 
175
 * @param      dom element   l              selection list (contains only elements selected)
-
 
176
 * @param      integer       i              element source indice
-
 
177
 * @param      integer       j              element target indice
-
 
178
 *
-
 
179
 */
70
function moveSwap(l,i,j) {
180
function moveSwap(l,i,j) {
71
    var valeur = l.options[i].value;
181
    var valeur = l.options[i].value;
72
    var texte = l.options[i].text;
182
    var texte = l.options[i].text;
73
    l.options[i].value = l.options[j].value;
183
    l.options[i].value = l.options[j].value;
74
    l.options[i].text = l.options[j].text;
184
    l.options[i].text = l.options[j].text;
75
    l.options[j].value = valeur;
185
    l.options[j].value = valeur;
76
    l.options[j].text = texte;
186
    l.options[j].text = texte;
77
    l.selectedIndex = j
187
    l.selectedIndex = j
-
 
188
}
-
 
189
 
-
 
190
 
-
 
191
/**
-
 
192
 * filterSelectExoSheet
-
 
193
 * Display only exo corresponding to specific sheet Id in a select box
-
 
194
 * The Sheet Id is the value selected by selectFilter (it can be a list like 1,2,3)
-
 
195
 *
-
 
196
 * @param      dom element   selectbox            selection list
-
 
197
 * @param      dom element   selectFilter         WIMS Sheet Id
-
 
198
 *
-
 
199
 */
-
 
200
function filterSelectExoSheet(selectTarget, selectFilter) {
-
 
201
    var i,current;
-
 
202
    // Converts selectFilter to an array
-
 
203
    var sheetIds = selectFilter.value.split(',');
-
 
204
 
-
 
205
    for(i = selectTarget.options.length - 1 ; i >= 0 ; i--){
-
 
206
        current = selectTarget.options[i]
-
 
207
        if (sheetIds.indexOf(current.dataset.sheetid) >= 0){
-
 
208
            selectTarget.options[i].style.display = "block";
-
 
209
        }
-
 
210
        else{
-
 
211
            selectTarget.options[i].style.display = "none";
-
 
212
            selectTarget.options[i].selected = false;
-
 
213
        }
-
 
214
    }
78
}
215
}
79
 
216
 
80
/* end javascript for HTML_QuickForm_advmultiselect */
217
/* end javascript for HTML_QuickForm_advmultiselect */
81
/*]]>*/
218
/*]]>*/
82
</script>
219
</script>