Subversion Repositories wimsdev

Rev

Rev 12784 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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