/******************************************************************************\
|************************** 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( "catcomplete" ).menu.active ) {
e.preventDefault();
return false;
}
//FECHA OS CONTATOS DINÂMICOS
if( (e.keyCode == 27) && $( this ).data( "catcomplete" ).menu.active ){
e.stopPropagation();
e.preventDefault();
}
//SELECIONA O CONTATO E EVITA OUTROS COMANDOS
if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "catcomplete" ).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(){
dynamicContacts = new Array();
var dynamicData = REST.get("/dynamiccontacts").collection.itens;
if(dynamicData){
$.each(dynamicData, function(index, value){
if(index ==0){
topContact = parseInt(value.data[2].value);
}
var dynamic = {
name : value.data[0].value,
mail : value.data[1].value,
value: value.data[0].value + " - " + value.data[1].value,
type: "",
id: parseInt(value.data[3].value),
qtd : parseInt(value.data[2].value)
};
dynamicContacts.push(dynamic);
});
}
}
function updateDynamicPersonalContacts(){
dynamicPersonalContacts = new Array();
var contactsData = REST.get("/contacts").collection.itens;
if(contactsData){
$.each(contactsData, function(index, value){
var contact = {
id : parseInt(value.data[0].value),
name : value.data[1].value,
email : value.data[2].value,
value: value.data[1].value + " - " + value.data[2].value,
type: "P"
};
dynamicPersonalContacts.push(contact);
});
}
}
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){
updateDynamicContact();
updateDynamicPersonalContacts();
REST.load("");
controlInputBinds();
Element('tbl_ext_participants').style.display='';
el.style.display='none';
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentType = "";
$.each( items, function( index, item ) {
if ( item.typel != currentType) {
if(item.typel == "/groups" && $(ul).find(".dynamic-recent").length)
self._renderItem( ul, {name:"", value:"", type:"linha"} );
if(item.typel == "/contacts" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))
self._renderItem( ul, {name:"", value:"", type:"linha"} );
currentType = item.typel;
}
self._renderItem( ul, item );
$(ul).find("li:last").find(".dynamic-stars").raty({
readOnly : true,
half : true,
hints : ['','','','',''],
score : ((item.number_of_messages*5)/topContact) > 0.5 ? ((item.number_of_messages*5)/topContact) : 0.5,
starOn : '../prototype/plugins/jq-raty/img/star-on.png',
starOff : '../prototype/plugins/jq-raty/img/star-off.png',
starHalf : '../prototype/plugins/jq-raty/img/star-half.png'
});
});
if($(ul).find("li:last").hasClass("dynamic-separator")){
$(ul).find("li:last").remove();
}
$(ul).scroll(function(){
canMakeBox = false;
});
}
});
$('#tbl_ext_participants').find('textarea').catcomplete({
minLength: 1,
source: function(request, response){
request.term = extractLast( request.term );
if ( request.term in cache ) {
response( cache[ request.term ] );
return;
}
dynamicContactsList = new Array();
REST.get("/usercontacts", false, function(data){
dynamicData = data.collection.itens;
if(dynamicData){
$.each(dynamicData, function(index, value){
dynamic = {};
$.each(value.data, function(index, value){
dynamic[value.name] = value.value;
});
dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail;
dynamic['type'] = value.dataType;
dynamic['typel'] = (value.dataType.substring(0,7) == "/shared" ? "/"+value.dataType.substring(7,value.dataType.length)+"s" : value.dataType) ;
dynamicContactsList.push(dynamic);
});
}
var data = $.ui.autocomplete.filter(dynamicContactsList, request.term );
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);
},
position : { my: "left top", at: "left bottom", collision: "fit" }
}).bind('catcompleteopen', function(event, ui) {
$(this).data('is_open',true);
}).bind('catcompleteclose', function(event, ui) {
$(this).data('is_open',false);
})
//MONTAGEM DA LISTA DE CONTATOS DINÂMICOS DO AUTO COMPLETE
.data( "catcomplete" )._renderItem = function( ul, item ) {
if($(ul).find("li").length < 50){
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.email ? item.email.length : 20 )));
width = width*5 + (is_ie ? 170 : 200) + 16;
if (width < $(ul).width())
width = $(ul).width();
ul.css({"min-width":width,"max-width":$('#tbl_ext_participants').find('textarea').width(),"max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"});
var listContacts = DataLayer.render("calendar/templates/default/listContacts.ejs", item);
return $(listContacts).data( "item.autocomplete", item ).appendTo( ul ).find("span:last").button({
icons : {
primary : "ui-icon-close"
},
text: false
}).click(function(event){
var removeLi = $(this).parents("li:first");
if(!event.keyCode)
autocomplete.catcomplete( "close" );
canMakeBox = false;
$.Zebra_Dialog('Deseja remover '+(item.name ? item.name+" - " : "")+ item.mail+'?', {
'type': 'question',
'custom_class': (is_ie ? 'configure-zebra-dialog' : ''),
'title': 'Atenção',
'buttons': ['Sim','Não'],
'overlay_opacity': '0.5',
'onClose': function(caption) {
if(caption == 'Sim'){
$(removeLi).remove();
REST['delete']("/dynamiccontact/"+item.id);
updateDynamicContact();
cache = new Array();
}else if(caption == 'Não'){
$(focusIn).focus();
}
}
});
});
}
return;
};
}
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("