1 | (function() |
---|
2 | { |
---|
3 | var _conn = ''; |
---|
4 | var _keyTimeOut = false; |
---|
5 | var Xtools = ''; |
---|
6 | |
---|
7 | function addGroup() |
---|
8 | { |
---|
9 | if( arguments.length > 0 ) |
---|
10 | { |
---|
11 | var select_from = document.getElementById(arguments[0]); |
---|
12 | var select_to = document.getElementById(arguments[1]); |
---|
13 | |
---|
14 | for(var i = 0; i < select_to.options.length; i++) |
---|
15 | { |
---|
16 | if(select_to.options[i].value === "") |
---|
17 | { |
---|
18 | select_to.options[i].parentNode.removeChild(select_to.options[i]); |
---|
19 | i--; |
---|
20 | } |
---|
21 | } |
---|
22 | |
---|
23 | for(var i = 0; i < select_from.options.length ; i++) |
---|
24 | { |
---|
25 | if( select_from.options[i].selected ) |
---|
26 | { |
---|
27 | |
---|
28 | var flag = false; |
---|
29 | for(var j = 0; j < select_to.options.length ; j++ ) |
---|
30 | { |
---|
31 | if( select_to.options[j].value === select_from.options[i].value ) |
---|
32 | flag = true; |
---|
33 | } |
---|
34 | |
---|
35 | if ( !flag ) |
---|
36 | { |
---|
37 | var option = select_from.options[i].value.split(":"); |
---|
38 | select_to.options[select_to.length] = new Option(option[0], select_from.options[i].value, false, true); |
---|
39 | } |
---|
40 | } |
---|
41 | } |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | function createObject() |
---|
46 | { |
---|
47 | if ( typeof(_conn) != "object" ) |
---|
48 | _conn = new JITConnector(path_jabberit + 'jabberit_messenger/'); |
---|
49 | |
---|
50 | if ( typeof(Xtools) != "object" ) |
---|
51 | Xtools = new JITXtools(path_jabberit + 'jabberit_messenger/'); |
---|
52 | } |
---|
53 | |
---|
54 | function CompleteSelect(data) |
---|
55 | { |
---|
56 | var select_ldap = document.getElementById('groups_ldap_jabberit'); |
---|
57 | data = Xtools.convert(data); |
---|
58 | |
---|
59 | while( select_ldap.hasChildNodes()) |
---|
60 | select_ldap.removeChild(select_ldap.firstChild); |
---|
61 | |
---|
62 | try |
---|
63 | { |
---|
64 | if ( data && data.documentElement && data.documentElement.hasChildNodes() ) |
---|
65 | { |
---|
66 | data = data.documentElement.firstChild; |
---|
67 | var label = ""; |
---|
68 | var value = ""; |
---|
69 | |
---|
70 | while(data) |
---|
71 | { |
---|
72 | var no = data.firstChild; |
---|
73 | while(no) |
---|
74 | { |
---|
75 | if( label == "" ) |
---|
76 | var label = no.firstChild.nodeValue; |
---|
77 | else |
---|
78 | var value = no.firstChild.nodeValue; |
---|
79 | no = no.nextSibling; |
---|
80 | } |
---|
81 | select_ldap.options[select_ldap.options.length] = new Option(label,label + ":" + value, false, false); |
---|
82 | label = value = ""; |
---|
83 | data = data.nextSibling; |
---|
84 | } |
---|
85 | } |
---|
86 | }catch(e){} |
---|
87 | } |
---|
88 | |
---|
89 | function groupsLdap() |
---|
90 | { |
---|
91 | var element = null; |
---|
92 | var organization = ""; |
---|
93 | var serverLdap = null; |
---|
94 | |
---|
95 | createObject(); |
---|
96 | |
---|
97 | if( arguments.length > 0 ) |
---|
98 | { |
---|
99 | element = arguments[0]; |
---|
100 | serverLdap = element.getAttribute('serverLdap'); |
---|
101 | |
---|
102 | if( element.options.length > 0 ) |
---|
103 | { |
---|
104 | for(var i = 0; i < element.options.length ; i++ ) |
---|
105 | { |
---|
106 | if( element.options[i].selected ) |
---|
107 | { |
---|
108 | organization = 'ou=' + element.options[i].value; |
---|
109 | organization = ( serverLdap != null ) ? organization + "&serverLdap=" + serverLdap : organization ; |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | _conn.go('$this.ldap_im.getGroupsLdap', CompleteSelect, organization); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | function groupsQuickSearch() |
---|
118 | { |
---|
119 | if( arguments.length > 0 ) |
---|
120 | { |
---|
121 | var key = [8,27,37,38,39,40]; |
---|
122 | var ev = arguments[1]; |
---|
123 | var elGroups = arguments[0]; |
---|
124 | var labelGroups = "label_" + elGroups.id; |
---|
125 | var search = "search="+elGroups.value+"&serverLdap=" + document.getElementById(labelGroups).getAttribute('serverLdap'); |
---|
126 | |
---|
127 | var cleanLabel = function(Id) |
---|
128 | { |
---|
129 | document.getElementById(Id).innerHTML = ""; |
---|
130 | } |
---|
131 | |
---|
132 | var getGroups = function(search, Id) |
---|
133 | { |
---|
134 | createObject(); |
---|
135 | |
---|
136 | _conn.go('$this.ldap_im.getGroupsLdap',CompleteSelect , search); |
---|
137 | |
---|
138 | cleanLabel(Id); |
---|
139 | } |
---|
140 | |
---|
141 | for(var i in key) |
---|
142 | if( ev.keyCode == key[i]) |
---|
143 | return false; |
---|
144 | |
---|
145 | if( elGroups.value.length < 4 ) |
---|
146 | { |
---|
147 | document.getElementById(labelGroups).innerHTML = " ( Digite mais " + ( 4 - elGroups.value.length ) + " )"; |
---|
148 | setTimeout(function(){cleanLabel(labelGroups);}, 2000); |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | document.getElementById(labelGroups).innerHTML = " ( Buscando aguarde .... )"; |
---|
153 | |
---|
154 | if( _keyTimeOut ) |
---|
155 | clearTimeout(_keyTimeOut); |
---|
156 | |
---|
157 | _keyTimeOut = setTimeout(function(){ getGroups(search, labelGroups); }, 1000); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | function Selected() |
---|
163 | { |
---|
164 | if( arguments.length > 0 ) |
---|
165 | { |
---|
166 | var _select = document.getElementById(arguments[0]); |
---|
167 | |
---|
168 | for( var i = 0 ; i < _select.options.length; i++ ) |
---|
169 | _select[i].selected = true; |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | function removeGroup() |
---|
174 | { |
---|
175 | if( arguments.length > 0 ) |
---|
176 | { |
---|
177 | var _select = document.getElementById(arguments[0]); |
---|
178 | |
---|
179 | for( var i = 0 ; i < _select.options.length; i++ ) |
---|
180 | { |
---|
181 | if( _select.options[i].selected ) |
---|
182 | { |
---|
183 | _select.options[i].parentNode.removeChild( _select.options[i] ); |
---|
184 | i--; |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | function groups_ldap(){} |
---|
191 | |
---|
192 | groups_ldap.prototype.add = addGroup; |
---|
193 | groups_ldap.prototype.remove = removeGroup; |
---|
194 | groups_ldap.prototype.groups = groupsLdap; |
---|
195 | groups_ldap.prototype.quickSearch = groupsQuickSearch; |
---|
196 | groups_ldap.prototype.selectAll = Selected; |
---|
197 | window.groups_ldap = new groups_ldap; |
---|
198 | |
---|
199 | })(); |
---|