// Instant Messenger // im_preferences.js function Preferences() { this.save_vcard = ""; } /* * Add */ Preferences.prototype.Add_userLoad = function() { Templates.add_user(); this.SearchOrganizationsLdap(); var select_contact = document.getElementById('ImSelAddContact'); select_contact.innerHTML = ""; } Preferences.prototype.SearchOrganizationsLdap = function() { var handler_organizations = function(data){ var select_org = document.getElementById('ImSelOrg'); if(select_org.options.length > 0) select_org.options.splice(0,select_org.options.length); var options = new Option("--Selecione -- ", -1, false, true); select_org[select_org.length] = options; for(var i in data){ var options = new Option(data[i].ou, data[i].ou, false, true); select_org[select_org.length] = options; } select_org[0].selected = true; } cIM.cExecute("$this.ldap_im.list_organizations_ldap", handler_organizations); } Preferences.prototype.SearchContacts = function() { var select_org = document.getElementById('ImSelOrg'); var select_contact = document.getElementById('ImSelAddContact'); var organization = ""; for(var i=0; i < select_org.options.length; i++){ if(select_org.options[i].selected == true){ organization = select_org.options[i].value; } } var handler_contacts = function(data){ var select_contact = document.getElementById('ImSelAddContact'); var text0 = document.getElementById('text0'); var text1 = document.getElementById('text1'); var content = ""; select_contact.innerHTML = ""; text0.value = ""; text1.value = ""; if(data){ for(var i in data){ var options = new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail, false, false); select_contact[select_contact.length] = options; } } } cIM.cExecute("$this.contacts_im.list_contacts", handler_contacts,"ou="+organization); } Preferences.prototype.preenche = function() { var select = document.getElementById('ImSelAddContact'); if(select.options.length > 0){ for(var i=0; i < select.options.length; i++){ if(select.options[i].selected == true){ document.getElementById('text0').value = select.options[i].value; document.getElementById('text1').value = select.options[i].value.substr(0,select.options[i].value.indexOf('@')); document.getElementById('text2').focus(); } } } } Preferences.prototype.Add_user = function(pFunc) { var text0 = document.getElementById('text0'); var text1 = document.getElementById('text1'); var text2 = document.getElementById('text2'); var _this = this; if(pFunc != "divUpdateUser_im"){ var jid = text0.value.substr(0,text0.value.indexOf('@')); for(var i=0; i < IM.user_not_aut.length; i++){ if(IM.user_not_aut[i].substr(0,IM.user_not_aut[i].indexOf('@')) == jid){ return; } } } if(IM.LTrim(text0.value) != "" && IM.LTrim(text1.value) != "" && IM.LTrim(text2.value) != ""){ var handler_add_contact = function(data){ if(data){ text0.value = ""; text1.value = ""; text2.value = ""; if(pFunc != 'divAddUser_im') im_win.windowClose(pFunc); IM.UpdateContacts(); } } if(pFunc == 'divAddUser_im') cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+text1.value+"&group="+text2.value+"&subscription=none"); else cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+text1.value+"&group="+text2.value+"&subscription=to"); }else{ alert("Informe todos os campos!"); } } /* * Remove */ Preferences.prototype.Remove_userLoad = function() { Templates.remove_user(); var sel_contact = document.getElementById('sel_contact'); if(sel_contact.options.length > 0) sel_contact.options.splice(0,sel_contact.options.length); var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true); sel_contact.options[sel_contact.length] = opt; for(var i=1; i < IM.vcard_contacts.length; i++){ if(IM.vcard_contacts[i].name != ""){ opt = new Option(IM.vcard_contacts[i].name,IM.vcard_contacts[i].jid, false, false); sel_contact.options[sel_contact.length] = opt; }else{ name = IM.vcard_contacts[i].jid.substr(0,IM.vcard_contacts[i].jid.indexOf('@')); opt = new Option(name,IM.vcard_contacts[i].jid, false, false); sel_contact.options[sel_contact.length] = opt; } } } Preferences.prototype.Remove_user = function() { var _this = this; var sel_contact = document.getElementById('sel_contact'); for(var i=0; i < sel_contact.options.length; i++){ if(sel_contact[i].selected && sel_contact.options[i].value != 0){ if(confirm("Excluir o contato " + sel_contact.options[i].innerHTML + "?")){ var in_el = sel_contact.options[i].innerHTML; for(var j=1 ; j < IM.vcard_contacts.length; j++){ var name = IM.vcard_contacts[j].jid.substr(0,IM.vcard_contacts[j].jid.indexOf('@')); if(IM.vcard_contacts[j].name == in_el || name == in_el){ var handler_remove_contact = function(data){ if(!data){ alert(data); return false; } setTimeout("IM.UpdateContacts()",1000); } cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+sel_contact.options[i].value); IM.vcard_contacts.splice(j,1); _this.ComboRemove(); j--; } } } } } } Preferences.prototype.ComboRemove = function() { var sel_contact = document.getElementById('sel_contact'); if(sel_contact.length > 0 ){ for(var i=0; i < sel_contact.options.length; i++){ sel_contact.options[i] = null; i--; } } var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true); sel_contact.options[sel_contact.length] = opt; for(var i=0; i < IM.vcard_contacts.length; i++){ opt = new Option(IM.vcard_contacts[i].name,IM.vcard_contacts[i].jid, false, false); sel_contact.options[sel_contact.length] = opt; } } Preferences.prototype.Remove_Contact = function(pJid) { for(var i=0; i < IM.vcard_contacts.length; i++){ if(IM.vcard_contacts[i].jid == pJid){ if(confirm("Excluir o contato " + IM.vcard_contacts[i].name + "?")){ var handler_remove_contact = function(data){ if(!data){ alert(data); return; }else{ setTimeout("IM.UpdateContacts()",1000); } } cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+pJid); } return; } } } /* * Update */ Preferences.prototype.updateLoad = function(i) { Jid = IM.vcard_contacts[i].jid; Templates.update_user(); document.getElementById('text0').value = Jid; document.getElementById('span0').innerHTML = Jid.substr(0,Jid.indexOf('@')); } Preferences.prototype.Update_ = function(pJid,pType) { var name = ""; var group = ""; var jid = pJid; for(var i=1; i < IM.vcard_contacts.length; i++){ if(IM.vcard_contacts[i].jid == pJid){ name = IM.vcard_contacts[i].name; group = IM.vcard_contacts[i].group; } } if((name != "") && (group != "")){ if(pType){ var act = prompt("Digite um apelido para :" + pJid , name); name = act; }else{ var act = prompt("Digite um novo grupo para : " + name, group); group = act; } if((act != null) && (act != "")){ var handler_update_contacts = function(data){ if(data) IM.UpdateContacts(); else alert("erro"); } cIM.cExecute("$this.Ujabber.UpdateUser",handler_update_contacts,"jid="+jid+"&name="+name+"&group="+group); } } } Preferences.prototype.Update_Group = function(pJid) { this.Update_(pJid,false); } Preferences.prototype.Update_NickName = function(pJid) { this.Update_(pJid,true); } /* * Vcard */ Preferences.prototype.vCardLoad = function() { Templates.information_user(); document.getElementById('FN').value = IM.vcard_user['VCARD_FN']; document.getElementById('NICKNAME').value = IM.vcard_user['VCARD_NICKNAME']; document.getElementById('ORGNAME').value = IM.vcard_user['VCARD_ORGNAME']; document.getElementById('ORGUNIT').value = IM.vcard_user['VCARD_ORGUNIT']; document.getElementById('ROLE').value = IM.vcard_user['VCARD_ROLE']; document.getElementById('BDAY').value = IM.vcard_user['VCARD_BDAY']; document.getElementById('DESC').value = IM.vcard_user['VCARD_DESC']; } Preferences.prototype.vCardAdd = function() { var _this = this; IM.vcard_user['VCARD_FN'] = document.getElementById('FN').value; _this.save_vcard = url_encode(encodeURI(document.getElementById('FN').value)) + ";"; IM.vcard_user['VCARD_NICKNAME'] = document.getElementById('NICKNAME').value; _this.save_vcard += url_encode(encodeURI(document.getElementById('NICKNAME').value)) + ";"; var nickname = document.getElementById('span_nickname').innerHTML; document.getElementById('span_nickname').innerHTML = (IM.vcard_user['VCARD_NICKNAME']) ? " " + IM.vcard_user['VCARD_NICKNAME'].substring(0,30) + "" : nickname; IM.vcard_user['VCARD_ORGNAME'] = document.getElementById('ORGNAME').value; _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGNAME').value)) + ";"; IM.vcard_user['VCARD_ORGUNIT'] = document.getElementById('ORGUNIT').value; _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGUNIT').value)) + ";"; IM.vcard_user['VCARD_ROLE'] = document.getElementById('ROLE').value; _this.save_vcard += url_encode(encodeURI(document.getElementById('ROLE').value)) + ";"; IM.vcard_user['VCARD_BDAY'] = document.getElementById('BDAY').value; _this.save_vcard += url_encode(encodeURI(document.getElementById('BDAY').value)) + ";"; IM.vcard_user['VCARD_DESC'] = document.getElementById('DESC').value; _this.save_vcard += url_encode(encodeURI(document.getElementById('DESC').value)); var message_desc = document.getElementById('span_message').innerHTML; document.getElementById('span_message').innerHTML = (IM.vcard_user['VCARD_DESC']) ? " " + IM.vcard_user['VCARD_DESC'].substring(0,30) + "" : message_desc ; var handler_vcardAdd = function(data){ if(!data) alert(data); else alert("Informações Cadastradas / Atualizadas !"); } cIM.cExecute("$this.Ujabber.newVcard",handler_vcardAdd,"vcard="+_this.save_vcard); } Preferences.prototype.vCardLoad_Contact = function(pJid) { Templates.information_Contact(); for(var i=0; i < IM.vcard_contacts.length; i++){ if(IM.vcard_contacts[i].jid == pJid){ document.getElementById('_lbl_FN').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_FN); document.getElementById('_lbl_Nickname').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_NICKNAME); document.getElementById('_lbl_Orgunit').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_ORGUNIT); document.getElementById('_lbl_Role').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_ROLE); document.getElementById('_lbl_Birthday').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_BDAY); return; } } } /* * Envio de arquivo */ Preferences.prototype.SendFile = function(pJid) { if(im_send_file == 'true'){ Templates.Send_file(pJid); }else{ alert('Funçao Indisponível!'); } } Preferences.prototype.SizeFile = function() { var h_SizeFile = function(data){ alert(data); } cIM.cExecute("$this.upload.size_file",h_SizeFile); } // Build Object var Preferences = new Preferences();