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 | var handler_get_available_users = function(fill) |
---|
25 | { |
---|
26 | var groupHandler = function( toGroup ) |
---|
27 | { |
---|
28 | switch( toGroup[ 'phpgwaccounttype' ] ) |
---|
29 | { |
---|
30 | case 'u':return 'users'; |
---|
31 | break; |
---|
32 | case 'g':return 'groups'; |
---|
33 | break; |
---|
34 | case 's':return 'shared_accounts'; |
---|
35 | break |
---|
36 | } |
---|
37 | |
---|
38 | return( false ); |
---|
39 | } |
---|
40 | |
---|
41 | return fillGroupableSelect( fill, 'user_list_in', groupHandler, default_field ); |
---|
42 | } |
---|
43 | |
---|
44 | function get_available_users(module,context,type, autoSearch){ |
---|
45 | // Element('cal_input_searchUser').value = ''; |
---|
46 | // if(autoSearch != 'True'){ |
---|
47 | // return true; |
---|
48 | // } |
---|
49 | // var context = document.getElementById('combo_org').value; |
---|
50 | // cExecute (module+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users); |
---|
51 | } |
---|
52 | |
---|
53 | function optionFinderTimeout(obj, numMin, type, autoSearch, event){ |
---|
54 | |
---|
55 | if( event.keyCode === 13 ) |
---|
56 | { |
---|
57 | //limit = 0; |
---|
58 | |
---|
59 | optionFinderLdap( obj.id, numMin, type ); |
---|
60 | |
---|
61 | return( false ); |
---|
62 | } |
---|
63 | |
---|
64 | return( true ); |
---|
65 | } |
---|
66 | // Pesquisa Javascript |
---|
67 | function optionFinderLocal(id){ |
---|
68 | |
---|
69 | var sentence = Element( id ).value; |
---|
70 | |
---|
71 | finder( sentence, 'user_list_in' ); |
---|
72 | } |
---|
73 | |
---|
74 | // Pesquisa LDAP |
---|
75 | function optionFinderLdap(id,numMin, type){ |
---|
76 | |
---|
77 | var sentence = Element( id ).value; |
---|
78 | |
---|
79 | var url = 'expressoMail1_2.ldap_functions.search_users&context=' + document.getElementById('combo_org').value + '&type='+(type == '' ? 'list' : 'search')+'&filter=' + sentence; |
---|
80 | |
---|
81 | var parser = function( data ){ |
---|
82 | |
---|
83 | var result = {}; |
---|
84 | |
---|
85 | for( accountType in data ) |
---|
86 | { |
---|
87 | var target = data[ accountType ]; |
---|
88 | |
---|
89 | accountType = accountType.charAt(0); |
---|
90 | |
---|
91 | for( value in target ) |
---|
92 | { |
---|
93 | result[value] = {}; |
---|
94 | result[value][default_field] = target[value]; |
---|
95 | result[value]['phpgwaccounttype'] = accountType; |
---|
96 | } |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | return( result ); |
---|
101 | }; |
---|
102 | |
---|
103 | return userFinder( sentence, handler_get_available_users, url, parser, 'cal_span_searching' ); |
---|
104 | } |
---|
105 | |
---|
106 | function add_user() |
---|
107 | { |
---|
108 | var select_available_users = document.getElementById('user_list_in'); |
---|
109 | var select_users = document.getElementById('user_list'); |
---|
110 | var count_available_users = select_available_users.length; |
---|
111 | var count_users = select_users.options.length; |
---|
112 | var new_options = ''; |
---|
113 | |
---|
114 | for (i = 0 ; i < count_available_users ; i++) { |
---|
115 | if (select_available_users.options[i].selected) { |
---|
116 | if(document.all) { |
---|
117 | if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) { |
---|
118 | new_options += '<option value=' |
---|
119 | + select_available_users.options[i].value |
---|
120 | + '>' |
---|
121 | + select_available_users.options[i].text |
---|
122 | + '</option>'; |
---|
123 | } |
---|
124 | } |
---|
125 | else if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) { |
---|
126 | new_options += '<option value=' |
---|
127 | + select_available_users.options[i].value |
---|
128 | + '>' |
---|
129 | + select_available_users.options[i].text |
---|
130 | + '</option>'; |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | if (new_options != '') { |
---|
136 | |
---|
137 | if(is_firefox_0) |
---|
138 | fixBugInnerSelect(select_users,'###' + new_options + select_users.innerHTML); |
---|
139 | else |
---|
140 | select_users.innerHTML = '###' + new_options + select_users.innerHTML; |
---|
141 | |
---|
142 | select_users.outerHTML = select_users.outerHTML; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | function remove_user(){ |
---|
147 | select_users = document.getElementById('user_list'); |
---|
148 | |
---|
149 | for(var i = 0;i < select_users.options.length; i++) |
---|
150 | if(select_users.options[i].selected) |
---|
151 | select_users.options[i--] = null; |
---|
152 | } |
---|
153 | |
---|
154 | function submitValues(button){ |
---|
155 | loadScript("expressoMail1_2/js/common_functions.js"); |
---|
156 | button.disabled = true; //Desabilita Botão para evitar varios clicks |
---|
157 | |
---|
158 | var typeField = document.getElementById('cal[type]'); |
---|
159 | if (typeField && typeField.value == 'hourAppointment') { |
---|
160 | if(document.getElementsByName('categories[]')[0].value == ""){ |
---|
161 | alert(alert_msg); |
---|
162 | button.disabled = false; |
---|
163 | return false; |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | var select_in = document.getElementById('user_list'); |
---|
168 | for(i = 0; i < select_in.length; i++) |
---|
169 | select_in.options[i].selected = true; |
---|
170 | |
---|
171 | var rptDay = document.getElementsByName( 'cal[rpt_day][]' ); |
---|
172 | var isChecked = false; |
---|
173 | |
---|
174 | for(var i = 0 ; i < rptDay.length; i++) |
---|
175 | if(rptDay[i].checked == true) |
---|
176 | isChecked = true; |
---|
177 | |
---|
178 | if( !isChecked && !document.getElementsByName( "cal[rpt_use_end]" )[0].checked && !(document.getElementsByName( "cal[recur_type]" )[0].value === "0")){ |
---|
179 | alert("Agendamentos recorrentes precisam de data final da repetição"); |
---|
180 | button.disabled = false; |
---|
181 | return false; |
---|
182 | } |
---|
183 | |
---|
184 | if( !isChecked && document.getElementsByName( "cal[recur_type]" )[0].value === "2" ){ |
---|
185 | //TODO: por essa mensagem no lang |
---|
186 | alert("Voce nao especificou um dia na sua repeticao semanal"); |
---|
187 | button.disabled = false; |
---|
188 | return false; |
---|
189 | } |
---|
190 | if(document.getElementsByName( "cal[rpt_use_end]" )[0].checked){ |
---|
191 | if(!validate_date_order(document.getElementById('start[str]').value, document.getElementById('recur_enddate[str]').value)){ |
---|
192 | alert("A data final não pode ser menor que a data inicial."); |
---|
193 | button.disabled = false; |
---|
194 | return false; |
---|
195 | } |
---|
196 | } |
---|
197 | //Valida data inicio nao nula |
---|
198 | if(document.getElementById('start[str]').value == ''){ |
---|
199 | alert("Necessario preencher a data de início."); |
---|
200 | document.getElementById('start[str]').focus(); |
---|
201 | button.disabled = false; |
---|
202 | return false; |
---|
203 | } |
---|
204 | //Valida data inicio |
---|
205 | if(document.getElementById('start[str]').value != ''){ |
---|
206 | if(!validate_date(document.getElementById('start[str]').value)){ |
---|
207 | document.getElementById('start[str]').value = ''; |
---|
208 | document.getElementById('start[str]').focus(); |
---|
209 | alert("A data de início não é válida."); |
---|
210 | button.disabled = false; |
---|
211 | return false; |
---|
212 | } |
---|
213 | } |
---|
214 | //Valida data termino |
---|
215 | if(document.getElementById('end[str]').value != ''){ |
---|
216 | if(!validate_date(document.getElementById('end[str]').value)){ |
---|
217 | document.getElementById('end[str]').value = ''; |
---|
218 | document.getElementById('end[str]').focus(); |
---|
219 | alert("A data de término não é válida."); |
---|
220 | button.disabled = false; |
---|
221 | return false; |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | //Valida hora inicio somente numeros |
---|
226 | if(isNaN(parseInt(document.getElementById('start_hour').value))){ |
---|
227 | document.getElementById('start_hour').value = ''; |
---|
228 | document.getElementById('start_hour').focus(); |
---|
229 | alert("A hora de início deve ser números."); |
---|
230 | button.disabled = false; |
---|
231 | return false; |
---|
232 | } |
---|
233 | //Valida hora inicio somente numeros |
---|
234 | if(isNaN(parseInt(document.getElementById('start_minute').value))){ |
---|
235 | document.getElementById('start_minute').value = ''; |
---|
236 | document.getElementById('start_minute').focus(); |
---|
237 | alert("A hora de início deve ser números."); |
---|
238 | button.disabled = false; |
---|
239 | return false; |
---|
240 | } |
---|
241 | //Valida hora termino somente numeros |
---|
242 | if(isNaN(parseInt(document.getElementById('end_hour').value))){ |
---|
243 | document.getElementById('end_hour').value = ''; |
---|
244 | document.getElementById('end_hour').focus(); |
---|
245 | alert("A hora do término deve ser números."); |
---|
246 | button.disabled = false; |
---|
247 | return false; |
---|
248 | } |
---|
249 | //Valida hora termino somente numeros |
---|
250 | if(isNaN(parseInt(document.getElementById('end_minute').value))){ |
---|
251 | document.getElementById('end_minute').value = ''; |
---|
252 | document.getElementById('end_minute').focus(); |
---|
253 | alert("A hora do término deve ser números."); |
---|
254 | button.disabled = false; |
---|
255 | return false; |
---|
256 | } |
---|
257 | |
---|
258 | //Valida hora inicial maior que final |
---|
259 | if( (document.getElementById('start_hour').value != '') && (document.getElementById('end_hour').value != '') ){ |
---|
260 | if( (document.getElementById('start_hour').value) > (document.getElementById('end_hour').value) ){ |
---|
261 | //JA ESTA ERRADO |
---|
262 | document.getElementById('start_hour').value = ''; |
---|
263 | document.getElementById('end_hour').value = ''; |
---|
264 | document.getElementById('start_minute').value = ''; |
---|
265 | document.getElementById('end_minute').value = ''; |
---|
266 | document.getElementById('start_hour').focus(); |
---|
267 | alert("A hora final não pode ser menor que a hora inicial."); |
---|
268 | button.disabled = false; |
---|
269 | return false; |
---|
270 | }else if ( (document.getElementById('start_hour').value) == (document.getElementById('end_hour').value) ){ |
---|
271 | if ( (document.getElementById('start_minute').value) > (document.getElementById('end_minute').value) ){ |
---|
272 | //DEU ERRO |
---|
273 | document.getElementById('start_hour').value = ''; |
---|
274 | document.getElementById('end_hour').value = ''; |
---|
275 | document.getElementById('start_minute').value = ''; |
---|
276 | document.getElementById('end_minute').value = ''; |
---|
277 | document.getElementById('start_hour').focus(); |
---|
278 | alert("A hora final não pode ser menor que a hora inicial."); |
---|
279 | button.disabled = false; |
---|
280 | return false; |
---|
281 | } |
---|
282 | } |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | document.getElementById('formEvent').submit(); |
---|
287 | } |
---|
288 | |
---|
289 | function Element(id){ |
---|
290 | return document.getElementById(id); |
---|
291 | } |
---|
292 | |
---|
293 | function loadScript(scriptPath){ |
---|
294 | |
---|
295 | if(!connector) |
---|
296 | throw new Error("Error : Connector is not loaded."); |
---|
297 | |
---|
298 | if (document.getElementById('uploadscript_'+scriptPath)) { |
---|
299 | return; |
---|
300 | } |
---|
301 | |
---|
302 | if( connector.oxmlhttp === null ) |
---|
303 | connector.createXMLHTTP(); |
---|
304 | |
---|
305 | connector.oxmlhttp.open("GET", scriptPath, false); |
---|
306 | connector.oxmlhttp.setRequestHeader('Content-Type','text/plain'); |
---|
307 | connector.oxmlhttp.send(null); |
---|
308 | if(connector.oxmlhttp.status != 0 && connector.oxmlhttp.status != 200 || connector.oxmlhttp.status == 0 && connector.oxmlhttp.responseText.length == 0) |
---|
309 | throw new Error("Error " + connector.oxmlhttp.status + "("+connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'"); |
---|
310 | |
---|
311 | var head = document.getElementsByTagName("head")[0]; |
---|
312 | var script = document.createElement("SCRIPT"); |
---|
313 | script.id = 'uploadscript_'+scriptPath; |
---|
314 | script.type = 'text/javascript'; |
---|
315 | script.text = connector.oxmlhttp.responseText; |
---|
316 | head.appendChild(script); |
---|
317 | return; |
---|
318 | } |
---|
319 | |
---|
320 | function controlInputBinds(){ |
---|
321 | var div = $('#tbl_ext_participants').find('textarea'); |
---|
322 | div.bind('keydown',function(e){ |
---|
323 | //SELECIONA O CONTATO E EVITA OUTROS COMANDOS |
---|
324 | if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "catcomplete" ).menu.active ) { |
---|
325 | e.preventDefault(); |
---|
326 | return false; |
---|
327 | } |
---|
328 | |
---|
329 | //FECHA OS CONTATOS DINÂMICOS |
---|
330 | if( (e.keyCode == 27) && $( this ).data( "catcomplete" ).menu.active ){ |
---|
331 | e.stopPropagation(); |
---|
332 | e.preventDefault(); |
---|
333 | } |
---|
334 | |
---|
335 | //SELECIONA O CONTATO E EVITA OUTROS COMANDOS |
---|
336 | if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "catcomplete" ).menu.active){ |
---|
337 | e.preventDefault(); |
---|
338 | return false; |
---|
339 | } |
---|
340 | //BUSCA COM A TECLA F9 |
---|
341 | if((e.keyCode) == 120){ |
---|
342 | |
---|
343 | quickSearchCatalogUser(); |
---|
344 | e.preventDefault(); |
---|
345 | return false; |
---|
346 | } |
---|
347 | }); |
---|
348 | } |
---|
349 | |
---|
350 | var cache = new Array(); |
---|
351 | var dynamicPersonalContacts = new Array(); |
---|
352 | var dynamicContacts = new Array(); |
---|
353 | var topContact = 0; |
---|
354 | |
---|
355 | function split( val ) { |
---|
356 | return val.split( /,\s*/ ); |
---|
357 | } |
---|
358 | |
---|
359 | function extractLast( term ) { |
---|
360 | return split( term ).pop(); |
---|
361 | } |
---|
362 | |
---|
363 | function updateDynamicContact(){ |
---|
364 | dynamicContacts = new Array(); |
---|
365 | var dynamicData = REST.get("/dynamiccontacts").collection.itens; |
---|
366 | if(dynamicData){ |
---|
367 | $.each(dynamicData, function(index, value){ |
---|
368 | if(index ==0){ |
---|
369 | topContact = parseInt(value.data[2].value); |
---|
370 | } |
---|
371 | var dynamic = { |
---|
372 | name : value.data[0].value, |
---|
373 | mail : value.data[1].value, |
---|
374 | value: value.data[0].value + " - " + value.data[1].value, |
---|
375 | type: "", |
---|
376 | id: parseInt(value.data[3].value), |
---|
377 | qtd : parseInt(value.data[2].value) |
---|
378 | }; |
---|
379 | dynamicContacts.push(dynamic); |
---|
380 | }); |
---|
381 | } |
---|
382 | } |
---|
383 | |
---|
384 | |
---|
385 | function updateDynamicPersonalContacts(){ |
---|
386 | dynamicPersonalContacts = new Array(); |
---|
387 | var contactsData = REST.get("/contacts").collection.itens; |
---|
388 | if(contactsData){ |
---|
389 | $.each(contactsData, function(index, value){ |
---|
390 | var contact = { |
---|
391 | id : parseInt(value.data[0].value), |
---|
392 | name : value.data[1].value, |
---|
393 | email : value.data[2].value, |
---|
394 | value: value.data[1].value + " - " + value.data[2].value, |
---|
395 | type: "P" |
---|
396 | }; |
---|
397 | dynamicPersonalContacts.push(contact); |
---|
398 | }); |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | function quickSearchCatalogUser(){ |
---|
403 | var begin,end; |
---|
404 | var mailList = document.getElementById('ex_participants').value; |
---|
405 | var search = ""; |
---|
406 | var ID = 1; |
---|
407 | var field = "ex_participants"; |
---|
408 | if (mailList.lastIndexOf(',') != -1){ |
---|
409 | begin = mailList.lastIndexOf(','); |
---|
410 | end = mailList.length; |
---|
411 | search = mailList.substring(begin+1,255); |
---|
412 | } |
---|
413 | else{ |
---|
414 | begin = 0; |
---|
415 | end = mailList.length; |
---|
416 | search = mailList; |
---|
417 | } |
---|
418 | var handler_Search = function(data){ |
---|
419 | if ((!data.status) && (data.error == "many results")){ |
---|
420 | return false; |
---|
421 | } |
---|
422 | if (data.length > 0){ |
---|
423 | quickSearchUser.showList(data,begin,end); |
---|
424 | } |
---|
425 | } |
---|
426 | if (search.length > 0) |
---|
427 | cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search+"&field="+field+"&ID="+ID, handler_Search); |
---|
428 | } |
---|
429 | |
---|
430 | /*Adiciona um novo contato selecionado*/ |
---|
431 | function update_mailField(name,email){ |
---|
432 | var mailList = $('#tbl_ext_participants').find('textarea'); |
---|
433 | var newList = ""; |
---|
434 | if (mailList.val().indexOf(email) != -1){ |
---|
435 | $.Zebra_Dialog('O email <b>'+ email +'</b> já consta na lista!'); |
---|
436 | } |
---|
437 | if (mailList.val().indexOf(',') > 0){ |
---|
438 | var ctcList = mailList.val().split(','); |
---|
439 | for(var ii=0; ii<ctcList.length - 1;ii++){ |
---|
440 | newList += ctcList[ii] + ","; |
---|
441 | } |
---|
442 | newList += '"'+ name + '"'+ " <" + email + ">" + ","; |
---|
443 | } |
---|
444 | else{ |
---|
445 | newList += '"'+ name + '"'+ " <" + email + ">" +","; |
---|
446 | } |
---|
447 | mailList.val(newList); |
---|
448 | } |
---|
449 | |
---|
450 | function showExParticipants(el,path){ |
---|
451 | updateDynamicContact(); |
---|
452 | updateDynamicPersonalContacts(); |
---|
453 | REST.load(""); |
---|
454 | controlInputBinds(); |
---|
455 | Element('tbl_ext_participants').style.display=''; |
---|
456 | el.style.display='none'; |
---|
457 | $.widget( "custom.catcomplete", $.ui.autocomplete, { |
---|
458 | _renderMenu: function( ul, items ) { |
---|
459 | var self = this, |
---|
460 | currentType = ""; |
---|
461 | $.each( items, function( index, item ) { |
---|
462 | if ( item.typel != currentType) { |
---|
463 | if(item.typel == "/groups" && $(ul).find(".dynamic-recent").length) |
---|
464 | self._renderItem( ul, {name:"", value:"", type:"linha"} ); |
---|
465 | if(item.typel == "/contacts" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length)) |
---|
466 | self._renderItem( ul, {name:"", value:"", type:"linha"} ); |
---|
467 | currentType = item.typel; |
---|
468 | } |
---|
469 | self._renderItem( ul, item ); |
---|
470 | $(ul).find("li:last").find(".dynamic-stars").raty({ |
---|
471 | readOnly : true, |
---|
472 | half : true, |
---|
473 | hints : ['','','','',''], |
---|
474 | score : ((item.number_of_messages*5)/topContact) > 0.5 ? ((item.number_of_messages*5)/topContact) : 0.5, |
---|
475 | starOn : '../prototype/plugins/jq-raty/img/star-on.png', |
---|
476 | starOff : '../prototype/plugins/jq-raty/img/star-off.png', |
---|
477 | starHalf : '../prototype/plugins/jq-raty/img/star-half.png' |
---|
478 | }); |
---|
479 | }); |
---|
480 | |
---|
481 | if($(ul).find("li:last").hasClass("dynamic-separator")){ |
---|
482 | $(ul).find("li:last").remove(); |
---|
483 | } |
---|
484 | $(ul).scroll(function(){ |
---|
485 | canMakeBox = false; |
---|
486 | }); |
---|
487 | } |
---|
488 | }); |
---|
489 | $('#tbl_ext_participants').find('textarea').catcomplete({ |
---|
490 | minLength: 1, |
---|
491 | source: function(request, response){ |
---|
492 | request.term = extractLast( request.term ); |
---|
493 | if ( request.term in cache ) { |
---|
494 | response( cache[ request.term ] ); |
---|
495 | return; |
---|
496 | } |
---|
497 | dynamicContactsList = new Array(); |
---|
498 | REST.get("/usercontacts", false, function(data){ |
---|
499 | dynamicData = data.collection.itens; |
---|
500 | if(dynamicData){ |
---|
501 | $.each(dynamicData, function(index, value){ |
---|
502 | dynamic = {}; |
---|
503 | $.each(value.data, function(index, value){ |
---|
504 | dynamic[value.name] = value.value; |
---|
505 | }); |
---|
506 | dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail; |
---|
507 | dynamic['type'] = value.dataType; |
---|
508 | dynamic['typel'] = (value.dataType.substring(0,7) == "/shared" ? "/"+value.dataType.substring(7,value.dataType.length)+"s" : value.dataType) ; |
---|
509 | dynamicContactsList.push(dynamic); |
---|
510 | }); |
---|
511 | } |
---|
512 | var data = $.ui.autocomplete.filter(dynamicContactsList, request.term ); |
---|
513 | cache[ request.term ] = data; |
---|
514 | response( data ); |
---|
515 | }); |
---|
516 | }, |
---|
517 | focus: function() { |
---|
518 | return false; |
---|
519 | }, |
---|
520 | |
---|
521 | //EVENTO AO SELECIONAR UM CONTATO DINÂMICO |
---|
522 | select: function( event, ui ) { |
---|
523 | event.preventDefault(); |
---|
524 | update_mailField((ui.item.name ? ui.item.name : ""),ui.item.mail); |
---|
525 | }, |
---|
526 | position : { my: "left top", at: "left bottom", collision: "fit" } |
---|
527 | }).bind('catcompleteopen', function(event, ui) { |
---|
528 | $(this).data('is_open',true); |
---|
529 | }).bind('catcompleteclose', function(event, ui) { |
---|
530 | $(this).data('is_open',false); |
---|
531 | }) |
---|
532 | |
---|
533 | //MONTAGEM DA LISTA DE CONTATOS DINÂMICOS DO AUTO COMPLETE |
---|
534 | .data( "catcomplete" )._renderItem = function( ul, item ) { |
---|
535 | if($(ul).find("li").length < 50){ |
---|
536 | var autocomplete = $(this)[0].element; |
---|
537 | //cálculo dinâmico da largura da lista |
---|
538 | var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.email ? item.email.length : 20 ))); |
---|
539 | width = width*5 + (is_ie ? 170 : 200) + 16; |
---|
540 | if (width < $(ul).width()) |
---|
541 | width = $(ul).width(); |
---|
542 | ul.css({"min-width":width,"max-width":$('#tbl_ext_participants').find('textarea').width(),"max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"}); |
---|
543 | var listContacts = DataLayer.render("calendar/templates/default/listContacts.ejs", item); |
---|
544 | return $(listContacts).data( "item.autocomplete", item ).appendTo( ul ).find("span:last").button({ |
---|
545 | icons : { |
---|
546 | primary : "ui-icon-close" |
---|
547 | }, |
---|
548 | text: false |
---|
549 | }).click(function(event){ |
---|
550 | var removeLi = $(this).parents("li:first"); |
---|
551 | if(!event.keyCode) |
---|
552 | autocomplete.catcomplete( "close" ); |
---|
553 | canMakeBox = false; |
---|
554 | $.Zebra_Dialog('Deseja remover <b>'+(item.name ? item.name+" - " : "")+ item.mail+'</b>?', { |
---|
555 | 'type': 'question', |
---|
556 | 'custom_class': (is_ie ? 'configure-zebra-dialog' : ''), |
---|
557 | 'title': 'Atenção', |
---|
558 | 'buttons': ['Sim','Não'], |
---|
559 | 'overlay_opacity': '0.5', |
---|
560 | 'onClose': function(caption) { |
---|
561 | if(caption == 'Sim'){ |
---|
562 | $(removeLi).remove(); |
---|
563 | REST['delete']("/dynamiccontact/"+item.id); |
---|
564 | updateDynamicContact(); |
---|
565 | cache = new Array(); |
---|
566 | }else if(caption == 'Não'){ |
---|
567 | $(focusIn).focus(); |
---|
568 | } |
---|
569 | } |
---|
570 | }); |
---|
571 | }); |
---|
572 | } |
---|
573 | return; |
---|
574 | }; |
---|
575 | } |
---|
576 | |
---|
577 | function hideExParticipants(el,path){ |
---|
578 | Element('a_ext_participants').style.display = ''; |
---|
579 | Element('tbl_ext_participants').style.display ='none'; |
---|
580 | } |
---|
581 | |
---|
582 | function save_contacts(data){ |
---|
583 | contacts = data; |
---|
584 | var input_to = Element("ex_participants"); |
---|
585 | input_to.style.width = "100%"; |
---|
586 | input_to.setAttribute("wrap","soft"); |
---|
587 | input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer));search_contacts('onfocus', this.id);}; |
---|
588 | input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);}; |
---|
589 | if (!is_ie) |
---|
590 | { |
---|
591 | input_to.rows = 2; |
---|
592 | input_to.onkeypress = function (e) |
---|
593 | { |
---|
594 | if ((e.keyCode) == 120) //F9 |
---|
595 | { |
---|
596 | emQuickSearch(input_to); |
---|
597 | } |
---|
598 | else |
---|
599 | { |
---|
600 | if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden')) |
---|
601 | { |
---|
602 | e.preventDefault(); |
---|
603 | search_contacts(e.keyCode,this.id); |
---|
604 | } |
---|
605 | } |
---|
606 | } |
---|
607 | input_to.onkeyup = function (e) |
---|
608 | { |
---|
609 | if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40)) |
---|
610 | { |
---|
611 | search_contacts(e.keyCode,this.id); |
---|
612 | } |
---|
613 | } |
---|
614 | } |
---|
615 | else |
---|
616 | { |
---|
617 | input_to.rows = 3; |
---|
618 | input_to.onkeyup = function (e) |
---|
619 | { |
---|
620 | if ((window.event.keyCode) == 120) //F9 |
---|
621 | { |
---|
622 | emQuickSearch(input_to); |
---|
623 | } |
---|
624 | else |
---|
625 | { |
---|
626 | search_contacts(window.event.keyCode,this.id); |
---|
627 | } |
---|
628 | } |
---|
629 | } |
---|
630 | } |
---|
631 | |
---|
632 | function fixBugInnerSelect(objeto,innerHTML){ |
---|
633 | /****** |
---|
634 | * select_innerHTML - altera o innerHTML de um select independente se é FF ou IE |
---|
635 | * Corrige o problema de não ser possível usar o innerHTML no IE corretamente |
---|
636 | * Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228 |
---|
637 | * Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email. |
---|
638 | * Versão: 1.0 - 06/04/2006 |
---|
639 | * Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br |
---|
640 | * Parametros: |
---|
641 | * objeto(tipo object): o select a ser alterado |
---|
642 | * innerHTML(tipo string): o novo valor do innerHTML |
---|
643 | *******/ |
---|
644 | objeto.innerHTML = "" |
---|
645 | var selTemp = document.createElement("micoxselect") |
---|
646 | var opt; |
---|
647 | selTemp.id="micoxselect1" |
---|
648 | document.body.appendChild(selTemp) |
---|
649 | selTemp = document.getElementById("micoxselect1") |
---|
650 | selTemp.style.display="none" |
---|
651 | if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto |
---|
652 | innerHTML = "<option>" + innerHTML + "</option>" |
---|
653 | } |
---|
654 | innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span") |
---|
655 | selTemp.innerHTML = innerHTML |
---|
656 | for(var i=0;i<selTemp.childNodes.length;i++){ |
---|
657 | if(selTemp.childNodes[i].tagName){ |
---|
658 | opt = document.createElement("OPTION") |
---|
659 | for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){ |
---|
660 | opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true)) |
---|
661 | } |
---|
662 | opt.value = selTemp.childNodes[i].getAttribute("value") |
---|
663 | opt.text = selTemp.childNodes[i].innerHTML |
---|
664 | if(document.all){ //IEca |
---|
665 | objeto.add(opt) |
---|
666 | }else{ |
---|
667 | objeto.appendChild(opt) |
---|
668 | } |
---|
669 | } |
---|
670 | } |
---|
671 | document.body.removeChild(selTemp) |
---|
672 | selTemp = null |
---|
673 | } |
---|
674 | |
---|
675 | function changeViewMode(eltype){ |
---|
676 | var chValue = eltype; |
---|
677 | switch (chValue){ |
---|
678 | case 'hourAppointment': |
---|
679 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
680 | for (var i=0; i < names.length; i++) |
---|
681 | { |
---|
682 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
683 | if (Field[0]) |
---|
684 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
685 | } |
---|
686 | |
---|
687 | Field = document.getElementsByName('participants[]'); |
---|
688 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
689 | Field[1].parentNode.parentNode.style.display = "none"; |
---|
690 | Field = document.getElementById('txt_loading'); |
---|
691 | Field.parentNode.parentNode.style.display = "none"; |
---|
692 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
693 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
694 | break; |
---|
695 | case 'privateHiddenFields': |
---|
696 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
697 | for (var i=0; i < names.length; i++) |
---|
698 | { |
---|
699 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
700 | if (Field[0]) |
---|
701 | Field[0].parentNode.parentNode.style.display = ""; |
---|
702 | } |
---|
703 | Field = document.getElementsByName('participants[]'); |
---|
704 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
705 | Field[1].parentNode.parentNode.style.display = "none"; |
---|
706 | Field = document.getElementById('txt_loading'); |
---|
707 | Field.parentNode.parentNode.style.display = "none"; |
---|
708 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
709 | Field[0].parentNode.parentNode.style.display = ""; |
---|
710 | break; |
---|
711 | default: |
---|
712 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
713 | for (var i=0; i < names.length; i++) |
---|
714 | { |
---|
715 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
716 | if (Field[0]) |
---|
717 | Field[0].parentNode.parentNode.style.display = ""; |
---|
718 | } |
---|
719 | Field = document.getElementsByName('participants[]'); |
---|
720 | Field[0].parentNode.parentNode.style.display = ""; |
---|
721 | Field[1].parentNode.parentNode.style.display = ""; |
---|
722 | Field = document.getElementById('txt_loading'); |
---|
723 | Field.parentNode.parentNode.style.display = ""; |
---|
724 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
725 | Field[0].parentNode.parentNode.style.display = ""; |
---|
726 | break; |
---|
727 | } |
---|
728 | |
---|
729 | } |
---|
730 | function updateTitleField(select){ |
---|
731 | var typeField = document.getElementsByName('cal[type]'); |
---|
732 | if (typeField[0].value != 'hourAppointment') |
---|
733 | return; |
---|
734 | var titleField = document.getElementsByName('cal[title]'); |
---|
735 | var optionsArray = select.childNodes; |
---|
736 | titleField[0].value = ''; |
---|
737 | for(option in optionsArray) |
---|
738 | if (optionsArray[option].selected) |
---|
739 | titleField[0].value += optionsArray[option].text + ' '; |
---|
740 | } |
---|
741 | |
---|
742 | var __onLoad = window.onload; |
---|
743 | window.onload = function(){ |
---|
744 | __onLoad(); |
---|
745 | var cal_type = document.getElementById('cal[type]').value; |
---|
746 | changeViewMode(cal_type); |
---|
747 | if(cal_type == 'hourAppointment'){ |
---|
748 | clearTimeout(timeout_get_available_users); |
---|
749 | } |
---|
750 | }; |
---|