/******************************************************************************\ |************************** CALENDAR MODULE *******************************| |********** INCLUDE PARTICIPANTS - PLUGIN USING AJAX EXPRESSOMAIL COMPONENT **| \******************************************************************************/ var contacts = ''; var expresso_offline = ''; var array_lang = new Array(); var finderTimeout = ''; // onUnload edit message if(!document.all) { var beforeunload = window.onbeforeunload; window.onbeforeunload = function() { if ( typeof beforeunload == 'function' ) beforeunload(); }; } // Verifica versão do Firefox var agt = navigator.userAgent.toLowerCase(); var is_firefox_0 = agt.indexOf('firefox/1.0') != -1 && agt.indexOf('firefox/0.') ? true : false; var handler_get_available_users = function(fill) { var groupHandler = function( toGroup ) { switch( toGroup[ 'phpgwaccounttype' ] ) { case 'u':return 'users'; break; case 'g':return 'groups'; break; case 's':return 'shared_accounts'; break } return( false ); } return fillGroupableSelect( fill, 'user_list_in', groupHandler, default_field ); } function get_available_users(module,context,type, autoSearch){ // Element('cal_input_searchUser').value = ''; // if(autoSearch != 'True'){ // return true; // } // var context = document.getElementById('combo_org').value; // cExecute (module+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users); } function optionFinderTimeout(obj, numMin, type, autoSearch, event){ if( event.keyCode === 13 ) { //limit = 0; optionFinderLdap( obj.id, numMin, type ); return( false ); } return( true ); } // Pesquisa Javascript function optionFinderLocal(id){ var sentence = Element( id ).value; finder( sentence, 'user_list_in' ); } // Pesquisa LDAP function optionFinderLdap(id,numMin, type){ var sentence = Element( id ).value; var url = 'expressoMail1_2.ldap_functions.search_users&context=' + document.getElementById('combo_org').value + '&type='+(type == '' ? 'list' : 'search')+'&filter=' + sentence; var parser = function( data ){ var result = {}; for( accountType in data ) { var target = data[ accountType ]; accountType = accountType.charAt(0); for( value in target ) { result[value] = {}; result[value][default_field] = target[value]; result[value]['phpgwaccounttype'] = accountType; } } return( result ); }; return userFinder( sentence, handler_get_available_users, url, parser, 'cal_span_searching' ); } function add_user() { var select_available_users = document.getElementById('user_list_in'); var select_users = document.getElementById('user_list'); var count_available_users = select_available_users.length; var count_users = select_users.options.length; var new_options = ''; for (i = 0 ; i < count_available_users ; i++) { if (select_available_users.options[i].selected) { if(document.all) { if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) { new_options += ''; } } else if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) { new_options += ''; } } } if (new_options != '') { if(is_firefox_0) fixBugInnerSelect(select_users,'###' + new_options + select_users.innerHTML); else select_users.innerHTML = '###' + new_options + select_users.innerHTML; select_users.outerHTML = select_users.outerHTML; } } function remove_user(){ select_users = document.getElementById('user_list'); for(var i = 0;i < select_users.options.length; i++) if(select_users.options[i].selected) select_users.options[i--] = null; } function submitValues(button){ loadScript("expressoMail1_2/js/common_functions.js"); button.disabled = true; //Desabilita Botão para evitar varios clicks var typeField = document.getElementById('cal[type]'); if (typeField && typeField.value == 'hourAppointment') { if(document.getElementsByName('categories[]')[0].value == ""){ alert(alert_msg); button.disabled = false; return false; } } var select_in = document.getElementById('user_list'); for(i = 0; i < select_in.length; i++) select_in.options[i].selected = true; var rptDay = document.getElementsByName( 'cal[rpt_day][]' ); var isChecked = false; for(var i = 0 ; i < rptDay.length; i++) if(rptDay[i].checked == true) isChecked = true; if( !isChecked && !document.getElementsByName( "cal[rpt_use_end]" )[0].checked && !(document.getElementsByName( "cal[recur_type]" )[0].value === "0")){ alert("Agendamentos recorrentes precisam de data final da repetição"); button.disabled = false; return false; } if( !isChecked && document.getElementsByName( "cal[recur_type]" )[0].value === "2" ){ //TODO: por essa mensagem no lang alert("Voce nao especificou um dia na sua repeticao semanal"); button.disabled = false; return false; } if(document.getElementsByName( "cal[rpt_use_end]" )[0].checked){ if(!validate_date_order(document.getElementById('start[str]').value, document.getElementById('recur_enddate[str]').value)){ alert("A data final não pode ser menor que a data inicial."); button.disabled = false; return false; } } //Valida data inicio nao nula if(document.getElementById('start[str]').value == ''){ alert("Necessario preencher a data de início."); document.getElementById('start[str]').focus(); button.disabled = false; return false; } //Valida data inicio if(document.getElementById('start[str]').value != ''){ if(!validate_date(document.getElementById('start[str]').value)){ document.getElementById('start[str]').value = ''; document.getElementById('start[str]').focus(); alert("A data de início não é válida."); button.disabled = false; return false; } } //Valida data termino if(document.getElementById('end[str]').value != ''){ if(!validate_date(document.getElementById('end[str]').value)){ document.getElementById('end[str]').value = ''; document.getElementById('end[str]').focus(); alert("A data de término não é válida."); button.disabled = false; return false; } } //Valida hora inicio somente numeros if(isNaN(parseInt(document.getElementById('start_hour').value))){ document.getElementById('start_hour').value = ''; document.getElementById('start_hour').focus(); alert("A hora de início deve ser números."); button.disabled = false; return false; } //Valida hora inicio somente numeros if(isNaN(parseInt(document.getElementById('start_minute').value))){ document.getElementById('start_minute').value = ''; document.getElementById('start_minute').focus(); alert("A hora de início deve ser números."); button.disabled = false; return false; } //Valida hora termino somente numeros if(isNaN(parseInt(document.getElementById('end_hour').value))){ document.getElementById('end_hour').value = ''; document.getElementById('end_hour').focus(); alert("A hora do término deve ser números."); button.disabled = false; return false; } //Valida hora termino somente numeros if(isNaN(parseInt(document.getElementById('end_minute').value))){ document.getElementById('end_minute').value = ''; document.getElementById('end_minute').focus(); alert("A hora do término deve ser números."); button.disabled = false; return false; } //Valida hora inicial maior que final if( (document.getElementById('start_hour').value != '') && (document.getElementById('end_hour').value != '') ){ if( (document.getElementById('start_hour').value) > (document.getElementById('end_hour').value) ){ //JA ESTA ERRADO document.getElementById('start_hour').value = ''; document.getElementById('end_hour').value = ''; document.getElementById('start_minute').value = ''; document.getElementById('end_minute').value = ''; document.getElementById('start_hour').focus(); alert("A hora final não pode ser menor que a hora inicial."); button.disabled = false; return false; }else if ( (document.getElementById('start_hour').value) == (document.getElementById('end_hour').value) ){ if ( (document.getElementById('start_minute').value) > (document.getElementById('end_minute').value) ){ //DEU ERRO document.getElementById('start_hour').value = ''; document.getElementById('end_hour').value = ''; document.getElementById('start_minute').value = ''; document.getElementById('end_minute').value = ''; document.getElementById('start_hour').focus(); alert("A hora final não pode ser menor que a hora inicial."); button.disabled = false; return false; } } } document.getElementById('formEvent').submit(); } function Element(id){ return document.getElementById(id); } function loadScript(scriptPath){ if(!connector) throw new Error("Error : Connector is not loaded."); if (document.getElementById('uploadscript_'+scriptPath)) { return; } if( connector.oxmlhttp === null ) connector.createXMLHTTP(); connector.oxmlhttp.open("GET", scriptPath, false); connector.oxmlhttp.setRequestHeader('Content-Type','text/plain'); connector.oxmlhttp.send(null); if(connector.oxmlhttp.status != 0 && connector.oxmlhttp.status != 200 || connector.oxmlhttp.status == 0 && connector.oxmlhttp.responseText.length == 0) throw new Error("Error " + connector.oxmlhttp.status + "("+connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'"); var head = document.getElementsByTagName("head")[0]; var script = document.createElement("SCRIPT"); script.id = 'uploadscript_'+scriptPath; script.type = 'text/javascript'; script.text = connector.oxmlhttp.responseText; head.appendChild(script); return; } function controlInputBinds(){ var div = $('#tbl_ext_participants').find('textarea'); div.bind('keydown',function(e){ //SELECIONA O CONTATO E EVITA OUTROS COMANDOS if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) { e.preventDefault(); return false; } //FECHA OS CONTATOS DINÂMICOS if( (e.keyCode == 27) && $( this ).data( "autocomplete" ).menu.active ){ e.stopPropagation(); e.preventDefault(); } //SELECIONA O CONTATO E EVITA OUTROS COMANDOS if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "autocomplete" ).menu.active){ e.preventDefault(); return false; } //BUSCA COM A TECLA F9 if((e.keyCode) == 120){ quickSearchCatalogUser(); e.preventDefault(); return false; } }); } var cache = new Array(); var dynamicPersonalContacts = new Array(); var dynamicContacts = new Array(); var topContact = 0; function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } function updateDynamicContact(userContacts){ if(!userContacts) userContacts = REST.get("/usercontacts", false); if(userContacts.collection && !userContacts.collection.error){ dynamicData = normalizeContacts(userContacts.collection.itens); }else{ dynamicData = []; } if(dynamicData){ var dynamicContactsList = []; $.each(dynamicData, function(index, dynamic){ var dataType = userContacts.collection.itens[index].dataType; dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail; dynamic['type'] = dataType dynamic['typel'] = (dataType.substring(0,7) == "/shared" ? "/"+dataType.substring(7,dataType.length)+"s" : dataType) ; dynamicContactsList.push(dynamic); }); } dynamicData = dynamicContactsList; } function updateDynamicPersonalContacts(){ dynamicPersonalContacts = new Array(); var personalContacts = REST.get("/personalContact"); if(personalContacts.collection && !personalContacts.collection.error){ var contactsData = normalizeContacts(personalContacts.collection.itens); if(contactsData){ $.each(contactsData, function(index, value){ var contact = { id : parseInt(value.id), name : value.name, email: value.email, value: value.name+ " - " + value.email, type: "P" }; dynamicPersonalContacts.push(contact); }); } } } function normalizeContacts(data){ var decoded = []; if(!$.isArray(data)){data = [data];} for(var i = 0; i < data.length; i++){ var item = {}; $.each(data[i].data, function(j, e){ item[e.name] = e.value; }); decoded.push(item); } return decoded; } function quickSearchCatalogUser(){ var begin,end; var mailList = document.getElementById('ex_participants').value; var search = ""; var ID = 1; var field = "ex_participants"; if (mailList.lastIndexOf(',') != -1){ begin = mailList.lastIndexOf(','); end = mailList.length; search = mailList.substring(begin+1,255); } else{ begin = 0; end = mailList.length; search = mailList; } var handler_Search = function(data){ if ((!data.status) && (data.error == "many results")){ return false; } if (data.length > 0){ quickSearchUser.showList(data,begin,end); } } if (search.length > 0) cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search+"&field="+field+"&ID="+ID, handler_Search); } /*Adiciona um novo contato selecionado*/ function update_mailField(name,email){ var mailList = $('#tbl_ext_participants').find('textarea'); var newList = ""; if (mailList.val().indexOf(email) != -1){ $.Zebra_Dialog('O email '+ email +' já consta na lista!'); } if (mailList.val().indexOf(',') > 0){ var ctcList = mailList.val().split(','); for(var ii=0; ii" + ","; } else{ newList += '"'+ name + '"'+ " <" + email + ">" +","; } mailList.val(newList); } function showExParticipants(el,path){ //updateDynamicPersonalContacts(); //REST.load(""); controlInputBinds(); Element('tbl_ext_participants').style.display=''; el.style.display='none'; //PREPARAÇÃO DA ARRAY DOS CONTATOS DINÂMICOS var decodeType = { '/dynamiccontacts': { css: 'recent', img: 'recent', text: 'Contato Recente' }, '/personalContact':{ css: 'personal', img: 'personal', text: 'Contato pessoal' }, '/sharedcontact':{ css: 'personal', img: 'sharedcontact', text: 'Contato compartilhado' }, '/groups':{ css: 'group', img: 'group', text: 'Grupo pessoal' }, '/sharedgroup':{ css: 'group', img: 'sharedgroup', text: 'Grupo compartilhado' } } $('#tbl_ext_participants').find('textarea').autocomplete({ source: function(request, response){ if ( request.term in cache ) { response( cache[ request.term ] ); return; } if(dynamicData === false){ updateDynamicContact(); } var data = $.ui.autocomplete.filter(dynamicData, extractLast( request.term ) ).slice(0, 50); cache[ request.term ] = data; response( data ); }, focus: function() { return false; }, //EVENTO AO SELECIONAR UM CONTATO DINÂMICO select: function( event, ui ) { event.preventDefault(); update_mailField((ui.item.name ? ui.item.name : ""),ui.item.mail); }, autoFocus: true, position : { my: "left top", at: "left bottom", collision: "fit" }, delay : 120, minLength: 0 }).bind('autocompleteopen', function(event, ui) { $(this).data('is_open',true); }).bind('autocompleteclose', function(event, ui) { canMakeBox = true; $(this).data('is_open',false); }).data( "autocomplete" )._renderItem = function( ul, item ) { if(item.typel == "/groups") return true; var autocomplete = $(this)[0].element; //cálculo dinâmico da largura da lista var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 20 ))); width = width*5 + (is_ie ? 170 : 200) + 16; width = (width < $(ul).width()) ? $(ul).width() : width; ul.css({"min-width":width,"max-width":$('#tbl_ext_participants').find('textarea').width(),"max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"}); item.raty = ((item.number_of_messages*10)/topContact) > 1 ? ((item.number_of_messages*10)/topContact) : 1; if ( item.typel != currentTypeContact) { if((item.typel == "/groups" && $(ul).find(".dynamic-recent").length) || (item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))){ currentTypeContact = item.typel; item.asDiv = true; }else{ currentTypeContact = item.typel; } } var li = ''; if(item.asDiv){ li = '
  •  
  • '; } li += '
  • '; li += ''; li += ''; li += ($.trim(item.name) != "" ? ((item.name.length > 20 ? item.name.substring(0,17)+"..." : item.name) + " - " ) : '') + item.mail; li += item.type == '/dynamiccontacts' ? '
    ' : '' li += ''; li += 'Excluir contato recente'; li += '
  • '; li = $( li ) .data( "item.autocomplete", item ) //.append( li ) .appendTo( ul ); li.find("span").button({ icons : { primary : "ui-icon-close" }, text: false }).click(function(event){ if(!event.keyCode) autocomplete.autocomplete( "close" ); canMakeBox = false; $.Zebra_Dialog('Deseja remover '+(item.name ? (item.name.length <= 30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'?', { 'type': 'question', 'custom_class': (is_ie ? 'configure-zebra-dialog' : ''), 'buttons': ['Sim','Não'], 'overlay_opacity': '0.5', 'onClose': function(caption) { if(caption == 'Sim'){ REST['delete']("/dynamiccontact/"+item.id); updateDynamicContact(); cache = new Array(); }else if(caption == 'Não'){ $(focusIn).focus(); } } }); }); li.find(".dynamic-stars").jRating({ step:true, length : 5, // nb of stars decimalLength: 2, // number of decimal in the rate rateMax: 10, isDisabled:true, bigStarsPath : 'prototype/plugins/jquery.jrating/icons/stars.png', // path of the icon stars.png smallStarsPath : 'prototype/plugins/jquery.jrating/icons/small.png' // path of the icon small.png }); if($(ul).find("li:last").hasClass("dynamic-separator")){ $(ul).find("li:last").remove(); } $(ul).scroll(function(){ canMakeBox = false; }); return li; }; } function hideExParticipants(el,path){ Element('a_ext_participants').style.display = ''; Element('tbl_ext_participants').style.display ='none'; } function save_contacts(data){ contacts = data; var input_to = Element("ex_participants"); input_to.style.width = "100%"; input_to.setAttribute("wrap","soft"); input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer));search_contacts('onfocus', this.id);}; input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);}; if (!is_ie) { input_to.rows = 2; input_to.onkeypress = function (e) { if ((e.keyCode) == 120) //F9 { emQuickSearch(input_to); } else { if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden')) { e.preventDefault(); search_contacts(e.keyCode,this.id); } } } input_to.onkeyup = function (e) { if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40)) { search_contacts(e.keyCode,this.id); } } } else { input_to.rows = 3; input_to.onkeyup = function (e) { if ((window.event.keyCode) == 120) //F9 { emQuickSearch(input_to); } else { search_contacts(window.event.keyCode,this.id); } } } } function fixBugInnerSelect(objeto,innerHTML){ /****** * select_innerHTML - altera o innerHTML de um select independente se é FF ou IE * Corrige o problema de não ser possível usar o innerHTML no IE corretamente * Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228 * Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email. * Versão: 1.0 - 06/04/2006 * Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br * Parametros: * objeto(tipo object): o select a ser alterado * innerHTML(tipo string): o novo valor do innerHTML *******/ objeto.innerHTML = "" var selTemp = document.createElement("micoxselect") var opt; selTemp.id="micoxselect1" document.body.appendChild(selTemp) selTemp = document.getElementById("micoxselect1") selTemp.style.display="none" if(innerHTML.toLowerCase().indexOf("" } innerHTML = innerHTML.replace(/