// 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], data[i], 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 = ""; var span_load = document.getElementById('_span_load_im'); span_load.style.visibility = "visible"; 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.length > 0 ){ for(var i in data){ if(data[i].cn != ""){ var options = new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail, false, false); select_contact[select_contact.length] = options; } } } span_load.style.visibility = "hidden"; } 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; var jid = text0.value; var subscription = ""; if(func.trim(text0.value) != "" && func.trim(text1.value) != "" && func.trim(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(); _this.Refresh_Screen(jid); } } var name = url_encode(encodeURI(text1.value)); var group = url_encode(encodeURI(text2.value)); if(pFunc == 'divAddUser_im') subscription = "none"; else subscription = "to"; cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+name+"&group="+group+"&subscription="+subscription); }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.array_users.length; i++){ if(decodeURI(IM.array_users[i].name) != ""){ opt = new Option(decodeURI(IM.array_users[i].name),IM.array_users[i].jid, false, false); sel_contact.options[sel_contact.length] = opt; }else{ name = IM.array_users[i].jid.substr(0,IM.array_users[i].jid.indexOf('@')); opt = new Option(name,IM.array_users[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.array_users.length; j++){ var name = IM.array_users[j].jid.substr(0,IM.array_users[j].jid.indexOf('@')); if(decodeURI(IM.array_users[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.array_users.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=1; i < IM.array_users.length; i++){ opt = new Option(decodeURI(IM.array_users[i].name),IM.array_users[i].jid, false, false); sel_contact.options[sel_contact.length] = opt; } } Preferences.prototype.Remove_Contact = function(pJid) { var _this = this; for(var i=0; i < IM.array_users.length; i++){ if(IM.array_users[i].jid == pJid){ if(confirm("Excluir o contato " + decodeURI(IM.array_users[i].name) + "?")){ var handler_remove_contact = function(data){ if(!data){ alert(data); return; }else{ _this.Refresh_Screen(pJid); IM.UpdateContacts(); } } cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+pJid); } return; } } } /* * Update */ Preferences.prototype.updateLoad = function(pJid) { Jid = pJid; 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.array_users.length; i++){ if(IM.array_users[i].jid == pJid){ name = decodeURI(IM.array_users[i].name); group = decodeURI(IM.array_users[i].group); } } if((name != "") && (group != "")){ if(pType){ var act = prompt("Digite um apelido para :" + pJid , name); name = url_encode(encodeURI(act)); group = url_encode(encodeURI(group)); }else{ var act = prompt("Digite um novo grupo para : " + name, group); group = url_encode(encodeURI(act)); name = url_encode(encodeURI(name)); } 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.array_users.length; i++){ if(IM.array_users[i].jid == pJid){ document.getElementById('_lbl_FN').innerHTML = decodeURI(IM.array_users[i].VCARD_FN); document.getElementById('_lbl_Nickname').innerHTML = decodeURI(IM.array_users[i].VCARD_NICKNAME); document.getElementById('_lbl_Orgunit').innerHTML = decodeURI(IM.array_users[i].VCARD_ORGUNIT); document.getElementById('_lbl_Role').innerHTML = decodeURI(IM.array_users[i].VCARD_ROLE); document.getElementById('_lbl_Birthday').innerHTML = decodeURI(IM.array_users[i].VCARD_BDAY); return; } } } /* * Detalhes do Contato para Autorização */ Preferences.prototype.Info_Contact = function(pJid) { var element = "_span_not_" + pJid; var pElement = "teste"; var uid = pJid.substr(0,pJid.indexOf('@')); var handler_ldap = function(data){ var form_details = '' + '' + ''+ '
' + '
' + '
'+ data[0].cn + '


' + '
'+ data[0].mail + '

' + '
' + '
'; im_menu_action.menu(element, form_details); // Foto Ldap; im_win.get_photo_ldap(pJid); } cIM.cExecute("$this.ldap_im.info_user",handler_ldap,"uid="+uid); } /* * Envio de arquivo */ Preferences.prototype.SendFile = function(pJid) { if(im_send_file == 'true'){ Templates.Send_file(pJid); }else{ alert('Função Indisponível!'); } } Preferences.prototype.SizeFile = function() { var h_SizeFile = function(data){ alert(data); } cIM.cExecute("$this.upload.size_file",h_SizeFile); } /* * Preferências do Usuário */ Preferences.prototype.yourPreferences = function() { //Templates.yourPreferences(); } /* * Tela de permissão para novos contatos */ Preferences.prototype.Refresh_Screen = function(pJid) { var el_tbl = document.getElementById("_cell_" + pJid); if(el_tbl != null) el_tbl.parentNode.removeChild(el_tbl); } // Build Object var Preferences = new Preferences();