1 | /******************************************************************************\ |
---|
2 | |************************** CALENDAR MODULE *******************************| |
---|
3 | |********** INCLUDE PARTICIPANTS - PLUGIN USING AJAX EXPRESSOMAIL COMPONENT **| |
---|
4 | \******************************************************************************/ |
---|
5 | var contacts = ''; |
---|
6 | var expresso_offline = ''; |
---|
7 | var array_lang = new Array(); |
---|
8 | var finderTimeout = ''; |
---|
9 | // onUnload edit message |
---|
10 | if(!document.all) |
---|
11 | { |
---|
12 | var beforeunload = window.onbeforeunload; |
---|
13 | window.onbeforeunload = function() |
---|
14 | { |
---|
15 | if ( typeof beforeunload == 'function' ) |
---|
16 | beforeunload(); |
---|
17 | }; |
---|
18 | } |
---|
19 | |
---|
20 | // Verifica versão do Firefox |
---|
21 | var agt = navigator.userAgent.toLowerCase(); |
---|
22 | var is_firefox_0 = agt.indexOf('firefox/1.0') != -1 && agt.indexOf('firefox/0.') ? true : false; |
---|
23 | |
---|
24 | function get_available_users(filter,autoSearch) |
---|
25 | //function get_available_users(path,context,type) |
---|
26 | { |
---|
27 | text= document.getElementById("cal_input_searchUser"); |
---|
28 | |
---|
29 | var handler_get_available_users = function(data) |
---|
30 | { |
---|
31 | select_available_users = document.getElementById('user_list_in'); |
---|
32 | |
---|
33 | for(var i=0; i<select_available_users.options.length; i++){ |
---|
34 | select_available_users.options[i] = null; |
---|
35 | i--; |
---|
36 | } |
---|
37 | var options = '###'; |
---|
38 | if (data) { |
---|
39 | if(data.groups && data.groups.length > 0) { |
---|
40 | data.groups = '<option value="-1" disabled>------------------- '+document.getElementById("txt_groups").value+' ------------------ </option>' + data.groups; |
---|
41 | } |
---|
42 | |
---|
43 | if(data.users && data.users.length > 0) { |
---|
44 | data.users = '<option value="-1" disabled>------------------- '+document.getElementById("txt_users").value+' ------------------ </option>' + data.users; |
---|
45 | } |
---|
46 | options += data.groups && data.groups.length > 0 ? data.groups : ''; |
---|
47 | options += data.users && data.users.length > 0 ? data.users : ''; |
---|
48 | |
---|
49 | if(is_firefox_0) |
---|
50 | fixBugInnerSelect(select_available_users,options); |
---|
51 | else |
---|
52 | select_available_users.innerHTML = options; |
---|
53 | |
---|
54 | select_available_users.outerHTML = select_available_users.outerHTML; |
---|
55 | select_available_users.disabled = false; |
---|
56 | select_available_users_clone = document.getElementById('user_list_in').cloneNode(true); |
---|
57 | //document.getElementById('cal_input_searchUser').value = ''; |
---|
58 | } |
---|
59 | } |
---|
60 | context = document.getElementById('combo_org').value; |
---|
61 | cExecute ('expressoMail1_2'+'.ldap_functions.search_users&filter='+filter+'&context='+context+'&type=search', handler_get_available_users); |
---|
62 | |
---|
63 | if((autoSearch == 'True') && (!text.value)){ |
---|
64 | var search = " "; |
---|
65 | get_available_users(search); |
---|
66 | } |
---|
67 | //cExecute (path+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users); |
---|
68 | } |
---|
69 | |
---|
70 | function optionFinderTimeout(obj,numMin){ |
---|
71 | var oWait = document.getElementById("cal_span_searching"); |
---|
72 | clearTimeout(finderTimeout); |
---|
73 | if (obj.value.length >= numMin){ |
---|
74 | oWait.innerHTML = 'Buscando...'; |
---|
75 | finderTimeout = setTimeout("optionFinder('"+obj.id+"','"+numMin+"')",500); |
---|
76 | }else { |
---|
77 | oWait.innerHTML = 'Mínimo de '+numMin+' letras para pesquisa'; |
---|
78 | var select_available_users_tmp = document.getElementById('user_list_in'); |
---|
79 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
80 | select_available_users_tmp.options[i--] = null; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | function optionFinder(id,numMin){ |
---|
85 | |
---|
86 | var oWait = document.getElementById("cal_span_searching"); |
---|
87 | var oText = document.getElementById(id); |
---|
88 | |
---|
89 | if (oText.value.length < numMin) { |
---|
90 | oWait.innerHTML = ''; |
---|
91 | var select_available_users_tmp = document.getElementById('user_list_in'); |
---|
92 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
93 | select_available_users_tmp.options[i--] = null; |
---|
94 | } |
---|
95 | |
---|
96 | if (oText.value.length >= numMin) { |
---|
97 | get_available_users(oText.value); |
---|
98 | |
---|
99 | var select_available_users_tmp = document.getElementById('user_list_in'); |
---|
100 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
101 | select_available_users_tmp.options[i--] = null; |
---|
102 | var RegExp_name = new RegExp("\\b"+oText.value, "i"); |
---|
103 | |
---|
104 | oWait.innerHTML = ' '; |
---|
105 | } |
---|
106 | } |
---|
107 | function autoOptionFinder(){ |
---|
108 | var oWait = document.getElementById("cal_span_searching"); |
---|
109 | var oText = document.getElementById(id); |
---|
110 | var select_available_users_tmp = document.getElementById('user_list_in'); |
---|
111 | for(var i = 0;i < select_available_users_tmp.options.length; i++) |
---|
112 | select_available_users_tmp.options[i--] = null; |
---|
113 | var RegExp_name = new RegExp("\\b ", "i"); |
---|
114 | oWait.innerHTML = ' '; |
---|
115 | } |
---|
116 | |
---|
117 | function add_user() |
---|
118 | { |
---|
119 | var select_available_users = document.getElementById('user_list_in'); |
---|
120 | var select_users = document.getElementById('user_list'); |
---|
121 | var count_available_users = select_available_users.length; |
---|
122 | var count_users = select_users.options.length; |
---|
123 | var new_options = ''; |
---|
124 | |
---|
125 | for (i = 0 ; i < count_available_users ; i++) { |
---|
126 | if (select_available_users.options[i].selected) { |
---|
127 | if(document.all) { |
---|
128 | if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) { |
---|
129 | new_options += '<option value=' |
---|
130 | + select_available_users.options[i].value |
---|
131 | + '>' |
---|
132 | + select_available_users.options[i].text |
---|
133 | + '</option>'; |
---|
134 | } |
---|
135 | } |
---|
136 | else if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) { |
---|
137 | new_options += '<option value=' |
---|
138 | + select_available_users.options[i].value |
---|
139 | + '>' |
---|
140 | + select_available_users.options[i].text |
---|
141 | + '</option>'; |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | if (new_options != '') { |
---|
147 | |
---|
148 | if(is_firefox_0) |
---|
149 | fixBugInnerSelect(select_users,'###' + new_options + select_users.innerHTML); |
---|
150 | else |
---|
151 | select_users.innerHTML = '###' + new_options + select_users.innerHTML; |
---|
152 | |
---|
153 | select_users.outerHTML = select_users.outerHTML; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | function remove_user(){ |
---|
158 | select_users = document.getElementById('user_list'); |
---|
159 | |
---|
160 | for(var i = 0;i < select_users.options.length; i++) |
---|
161 | if(select_users.options[i].selected) |
---|
162 | select_users.options[i--] = null; |
---|
163 | } |
---|
164 | |
---|
165 | function submitValues(){ |
---|
166 | var typeField = document.getElementById('cal[type]'); |
---|
167 | if (typeField && typeField.value == 'hourAppointment') { |
---|
168 | if(document.getElementsByName('categories[]')[0].value == ""){ |
---|
169 | alert(alert_msg); |
---|
170 | return false; |
---|
171 | } |
---|
172 | } |
---|
173 | var select_in = document.getElementById('user_list'); |
---|
174 | for(i = 0; i < select_in.length; i++) |
---|
175 | select_in.options[i].selected = true; |
---|
176 | } |
---|
177 | |
---|
178 | function Element(id){ |
---|
179 | return document.getElementById(id); |
---|
180 | } |
---|
181 | |
---|
182 | function loadScript(scriptPath){ |
---|
183 | |
---|
184 | if(!connector) |
---|
185 | throw new Error("Error : Connector is not loaded."); |
---|
186 | |
---|
187 | if (document.getElementById('uploadscript_'+scriptPath)) { |
---|
188 | return; |
---|
189 | } |
---|
190 | |
---|
191 | connector.oxmlhttp.open("GET", scriptPath, false); |
---|
192 | connector.oxmlhttp.setRequestHeader('Content-Type','text/plain'); |
---|
193 | connector.oxmlhttp.send(null); |
---|
194 | if(connector.oxmlhttp.status != 0 && connector.oxmlhttp.status != 200 || connector.oxmlhttp.status == 0 && connector.oxmlhttp.responseText.length == 0) |
---|
195 | throw new Error("Error " + connector.oxmlhttp.status + "("+connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'"); |
---|
196 | |
---|
197 | var head = document.getElementsByTagName("head")[0]; |
---|
198 | var script = document.createElement("SCRIPT"); |
---|
199 | script.id = 'uploadscript_'+scriptPath; |
---|
200 | script.type = 'text/javascript'; |
---|
201 | script.text = connector.oxmlhttp.responseText; |
---|
202 | head.appendChild(script); |
---|
203 | return; |
---|
204 | } |
---|
205 | |
---|
206 | function showExParticipants(el,path){ |
---|
207 | Element('tbl_ext_participants').style.display=''; |
---|
208 | el.style.display='none'; |
---|
209 | loadScript(path+"/js/DropDownContacts.js"); |
---|
210 | loadScript(path+"/js/common_functions.js"); |
---|
211 | loadScript(path+"/js/QuickCatalogSearch.js"); |
---|
212 | loadScript("calendar/templates/default/js/over_fn_exmail.js"); |
---|
213 | if(!contacts) |
---|
214 | cExecute (path+'.db_functions.get_dropdown_contacts', save_contacts); |
---|
215 | } |
---|
216 | |
---|
217 | function hideExParticipants(el,path){ |
---|
218 | Element('a_ext_participants').style.display = ''; |
---|
219 | Element('tbl_ext_participants').style.display ='none'; |
---|
220 | } |
---|
221 | |
---|
222 | function save_contacts(data){ |
---|
223 | contacts = data; |
---|
224 | var input_to = Element("ex_participants"); |
---|
225 | input_to.style.width = "100%"; |
---|
226 | input_to.setAttribute("wrap","soft"); |
---|
227 | input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);}; |
---|
228 | input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);}; |
---|
229 | if (!is_ie) |
---|
230 | { |
---|
231 | input_to.rows = 2; |
---|
232 | input_to.onkeypress = function (e) |
---|
233 | { |
---|
234 | if ((e.keyCode) == 120) //F9 |
---|
235 | { |
---|
236 | emQuickSearch(input_to); |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden')) |
---|
241 | { |
---|
242 | e.preventDefault(); |
---|
243 | search_contacts(e.keyCode,this.id); |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | input_to.onkeyup = function (e) |
---|
248 | { |
---|
249 | if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40)) |
---|
250 | { |
---|
251 | search_contacts(e.keyCode,this.id); |
---|
252 | } |
---|
253 | } |
---|
254 | } |
---|
255 | else |
---|
256 | { |
---|
257 | input_to.rows = 3; |
---|
258 | input_to.onkeyup = function (e) |
---|
259 | { |
---|
260 | if ((window.event.keyCode) == 120) //F9 |
---|
261 | { |
---|
262 | emQuickSearch(input_to); |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | search_contacts(window.event.keyCode,this.id); |
---|
267 | } |
---|
268 | } |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | function fixBugInnerSelect(objeto,innerHTML){ |
---|
273 | /****** |
---|
274 | * select_innerHTML - altera o innerHTML de um select independente se é FF ou IE |
---|
275 | * Corrige o problema de não ser possível usar o innerHTML no IE corretamente |
---|
276 | * Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228 |
---|
277 | * Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email. |
---|
278 | * Versão: 1.0 - 06/04/2006 |
---|
279 | * Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br |
---|
280 | * Parametros: |
---|
281 | * objeto(tipo object): o select a ser alterado |
---|
282 | * innerHTML(tipo string): o novo valor do innerHTML |
---|
283 | *******/ |
---|
284 | objeto.innerHTML = "" |
---|
285 | var selTemp = document.createElement("micoxselect") |
---|
286 | var opt; |
---|
287 | selTemp.id="micoxselect1" |
---|
288 | document.body.appendChild(selTemp) |
---|
289 | selTemp = document.getElementById("micoxselect1") |
---|
290 | selTemp.style.display="none" |
---|
291 | if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto |
---|
292 | innerHTML = "<option>" + innerHTML + "</option>" |
---|
293 | } |
---|
294 | innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span") |
---|
295 | selTemp.innerHTML = innerHTML |
---|
296 | for(var i=0;i<selTemp.childNodes.length;i++){ |
---|
297 | if(selTemp.childNodes[i].tagName){ |
---|
298 | opt = document.createElement("OPTION") |
---|
299 | for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){ |
---|
300 | opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true)) |
---|
301 | } |
---|
302 | opt.value = selTemp.childNodes[i].getAttribute("value") |
---|
303 | opt.text = selTemp.childNodes[i].innerHTML |
---|
304 | if(document.all){ //IEca |
---|
305 | objeto.add(opt) |
---|
306 | }else{ |
---|
307 | objeto.appendChild(opt) |
---|
308 | } |
---|
309 | } |
---|
310 | } |
---|
311 | document.body.removeChild(selTemp) |
---|
312 | selTemp = null |
---|
313 | } |
---|
314 | |
---|
315 | function changeViewMode(eltype){ |
---|
316 | var chValue = eltype; |
---|
317 | switch (chValue){ |
---|
318 | case 'hourAppointment': |
---|
319 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
320 | for (var i=0; i < names.length; i++) |
---|
321 | { |
---|
322 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
323 | if (Field[0]) |
---|
324 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
325 | } |
---|
326 | |
---|
327 | Field = document.getElementsByName('participants[]'); |
---|
328 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
329 | Field[1].parentNode.parentNode.style.display = "none"; |
---|
330 | Field = document.getElementById('txt_loading'); |
---|
331 | Field.parentNode.parentNode.style.display = "none"; |
---|
332 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
333 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
334 | break; |
---|
335 | case 'privateHiddenFields': |
---|
336 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
337 | for (var i=0; i < names.length; i++) |
---|
338 | { |
---|
339 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
340 | if (Field[0]) |
---|
341 | Field[0].parentNode.parentNode.style.display = ""; |
---|
342 | } |
---|
343 | Field = document.getElementsByName('participants[]'); |
---|
344 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
345 | Field[1].parentNode.parentNode.style.display = "none"; |
---|
346 | Field = document.getElementById('txt_loading'); |
---|
347 | Field.parentNode.parentNode.style.display = "none"; |
---|
348 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
349 | Field[0].parentNode.parentNode.style.display = ""; |
---|
350 | break; |
---|
351 | default: |
---|
352 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
353 | for (var i=0; i < names.length; i++) |
---|
354 | { |
---|
355 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
356 | if (Field[0]) |
---|
357 | Field[0].parentNode.parentNode.style.display = ""; |
---|
358 | } |
---|
359 | Field = document.getElementsByName('participants[]'); |
---|
360 | Field[0].parentNode.parentNode.style.display = ""; |
---|
361 | Field[1].parentNode.parentNode.style.display = ""; |
---|
362 | Field = document.getElementById('txt_loading'); |
---|
363 | Field.parentNode.parentNode.style.display = ""; |
---|
364 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
365 | Field[0].parentNode.parentNode.style.display = ""; |
---|
366 | break; |
---|
367 | } |
---|
368 | |
---|
369 | } |
---|
370 | function updateTitleField(select){ |
---|
371 | var typeField = document.getElementsByName('cal[type]'); |
---|
372 | if (typeField[0].value != 'hourAppointment') |
---|
373 | return; |
---|
374 | var titleField = document.getElementsByName('cal[title]'); |
---|
375 | var optionsArray = select.childNodes; |
---|
376 | titleField[0].value = ''; |
---|
377 | for(option in optionsArray) |
---|
378 | if (optionsArray[option].selected) |
---|
379 | titleField[0].value += optionsArray[option].text + ' '; |
---|
380 | } |
---|
381 | |
---|
382 | var __onLoad = window.onload; |
---|
383 | window.onload = function(){ |
---|
384 | __onLoad(); |
---|
385 | var cal_type = document.getElementById('cal[type]').value; |
---|
386 | changeViewMode(cal_type); |
---|
387 | if(cal_type == 'hourAppointment'){ |
---|
388 | clearTimeout(timeout_get_available_users); |
---|
389 | } |
---|
390 | }; |
---|