1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// JavaScript Document
/*
** ZABBIX
** Copyright (C) 2000-2008 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
*/
// Title: automatic checkbox range selection class
// Author: Aly
var chkbx_range_ext = {
startbox: null, // start checkbox obj
startbox_name: null, // start checkbox name
chkboxes: new Array(), // ckbx list
init: function(){
var chk_bx = document.getElementsByTagName('input');
for(var i=0; i < chk_bx.length; i++){
if((typeof(chk_bx[i]) != 'undefined') && (chk_bx[i].type.toLowerCase() == 'checkbox')){
this.implement(chk_bx[i]);
}
}
},
implement: function(obj){
var obj_name = obj.name.split('[')[0];
if(typeof(this.chkboxes[obj_name]) == 'undefined') this.chkboxes[obj_name] = new Array();
this.chkboxes[obj_name].push(obj);
addListener(obj, 'click', this.check.bindAsEventListener(this), false);
},
check: function(e){
var e = e || window.event;
if(!e.ctrlKey) return true;
var obj = eventTarget(e);
if((typeof(obj) != 'undefined') && (obj.type.toLowerCase() == 'checkbox')){
var obj_name = obj.name.split('[')[0];
if(!is_null(this.startbox) && (this.startbox_name == obj_name) && (obj.name != this.startbox.name)){
var chkbx_list = this.chkboxes[obj_name];
var flag = false;
for(var i=0; i < chkbx_list.length; i++){
if(typeof(chkbx_list[i]) !='undefined'){
//alert(obj.name+' == '+chkbx_list[i].name);
if(flag){
chkbx_list[i].checked = this.startbox.checked;
}
if(obj.name == chkbx_list[i].name) break;
if(this.startbox.name == chkbx_list[i].name) flag = true;
}
}
if(flag){
this.startbox = null;
this.startbox_name = null;
return true;
}
else{
for(var i=chkbx_list.length-1; i >= 0; i--){
if(typeof(chkbx_list[i]) !='undefined'){
//alert(obj.name+' == '+chkbx_list[i].name);
if(flag){
chkbx_list[i].checked = this.startbox.checked;
}
if(obj.name == chkbx_list[i].name){
this.startbox = null;
this.startbox_name = null;
return true;
}
if(this.startbox.name == chkbx_list[i].name) flag = true;
}
}
}
}
else{
if(!is_null(this.startbox)) this.startbox.checked = !this.startbox.checked;
this.startbox = obj;
this.startbox_name = obj_name;
}
}
}
}
|