1
|
function number(str, n){
|
2
|
if (n <= 0) return "";
|
3
|
else if (n > String(str).length) return str;
|
4
|
else return String(str).substring(0,n);
|
5
|
}
|
6
|
|
7
|
function parse(object){
|
8
|
var NodeList = object.getElementsByTagName('option');
|
9
|
var nodes = $A(NodeList); var array = new Array();
|
10
|
for (i=0; i<$(nodes).length; i++){
|
11
|
array[i] = $(nodes)[i].innerHTML;
|
12
|
}
|
13
|
return array;
|
14
|
}
|
15
|
|
16
|
function del(object){
|
17
|
var NodeList = object.getElementsByTagName('option');
|
18
|
var nodes = $A(NodeList);
|
19
|
nodes.each(function(node){
|
20
|
if($(node).innerHTML != '--- Выберите ---'){
|
21
|
$(node).remove();
|
22
|
};
|
23
|
});
|
24
|
}
|
25
|
|
26
|
function add(object, name, selected) {
|
27
|
object.options.add(new Option(name,name,selected,selected));
|
28
|
}
|
29
|
|
30
|
Event.observe(window, 'load', function() {
|
31
|
var block = $('issue_custom_field_values_12');
|
32
|
var block_selected = $F('issue_custom_field_values_12');
|
33
|
var service = $('issue_custom_field_values_13');
|
34
|
var service_selected = $F('issue_custom_field_values_13');
|
35
|
var array = parse(service);
|
36
|
del(service);
|
37
|
if (block_selected != '' ) {
|
38
|
for(i=0; i<array.length; i++) {
|
39
|
var block_selected = $F('issue_custom_field_values_12');
|
40
|
if(number(array[i],1) == number(block_selected,1)) {
|
41
|
if(array[i] == service_selected) {add(service,array[i],true);}
|
42
|
else {add(service,array[i],false);}
|
43
|
};
|
44
|
}; //alert(service.selectedIndex); *TODO Fix selected error in IE6
|
45
|
};
|
46
|
Event.observe(block, 'change', function() {
|
47
|
del(service);
|
48
|
for(i=0; i<array.length; i++) {
|
49
|
var block_selected = $F('issue_custom_field_values_12');
|
50
|
if(number(array[i],1) == number(block_selected,1)) {
|
51
|
add(service,array[i],false);
|
52
|
};
|
53
|
};
|
54
|
});
|
55
|
});
|