[20] | 1 | // Instant Messenger |
---|
| 2 | // im_preferences.js |
---|
| 3 | |
---|
| 4 | function Preferences() |
---|
| 5 | { |
---|
| 6 | this.save_vcard = ""; |
---|
| 7 | } |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | * Add |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | Preferences.prototype.Add_userLoad = function() |
---|
| 14 | { |
---|
| 15 | Templates.add_user(); |
---|
| 16 | this.SearchOrganizationsLdap(); |
---|
| 17 | var select_contact = document.getElementById('ImSelAddContact'); |
---|
| 18 | select_contact.innerHTML = ""; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | Preferences.prototype.SearchOrganizationsLdap = function() |
---|
| 22 | { |
---|
| 23 | var handler_organizations = function(data){ |
---|
| 24 | var select_org = document.getElementById('ImSelOrg'); |
---|
| 25 | if(select_org.options.length > 0) |
---|
| 26 | select_org.options.splice(0,select_org.options.length); |
---|
| 27 | var options = new Option("--Selecione -- ", -1, false, true); |
---|
| 28 | select_org[select_org.length] = options; |
---|
| 29 | |
---|
| 30 | for(var i in data){ |
---|
| 31 | var options = new Option(data[i].ou, data[i].ou, false, true); |
---|
| 32 | select_org[select_org.length] = options; |
---|
| 33 | } |
---|
| 34 | select_org[0].selected = true; |
---|
| 35 | } |
---|
| 36 | cIM.cExecute("$this.ldap_im.list_organizations_ldap", handler_organizations); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | Preferences.prototype.SearchContacts = function() |
---|
| 40 | { |
---|
| 41 | var select_org = document.getElementById('ImSelOrg'); |
---|
[23] | 42 | var select_contact = document.getElementById('ImSelAddContact'); |
---|
[20] | 43 | var organization = ""; |
---|
[23] | 44 | |
---|
[20] | 45 | for(var i=0; i < select_org.options.length; i++){ |
---|
| 46 | if(select_org.options[i].selected == true){ |
---|
| 47 | organization = select_org.options[i].value; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | var handler_contacts = function(data){ |
---|
| 51 | var select_contact = document.getElementById('ImSelAddContact'); |
---|
| 52 | var text0 = document.getElementById('text0'); |
---|
| 53 | var text1 = document.getElementById('text1'); |
---|
| 54 | var content = ""; |
---|
| 55 | select_contact.innerHTML = ""; |
---|
| 56 | text0.value = ""; |
---|
| 57 | text1.value = ""; |
---|
| 58 | if(data){ |
---|
| 59 | for(var i in data){ |
---|
| 60 | var options = new Option(data[i].cn + " ( "+ data[i].mail + " )", data[i].mail, false, false); |
---|
| 61 | select_contact[select_contact.length] = options; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | cIM.cExecute("$this.contacts_im.list_contacts", handler_contacts,"ou="+organization); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | Preferences.prototype.preenche = function() |
---|
| 69 | { |
---|
| 70 | var select = document.getElementById('ImSelAddContact'); |
---|
| 71 | if(select.options.length > 0){ |
---|
| 72 | for(var i=0; i < select.options.length; i++){ |
---|
| 73 | if(select.options[i].selected == true){ |
---|
| 74 | document.getElementById('text0').value = select.options[i].value; |
---|
| 75 | document.getElementById('text1').value = select.options[i].value.substr(0,select.options[i].value.indexOf('@')); |
---|
| 76 | document.getElementById('text2').focus(); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | Preferences.prototype.Add_user = function(pFunc) |
---|
| 83 | { |
---|
| 84 | var text0 = document.getElementById('text0'); |
---|
| 85 | var text1 = document.getElementById('text1'); |
---|
| 86 | var text2 = document.getElementById('text2'); |
---|
| 87 | var _this = this; |
---|
| 88 | |
---|
| 89 | if(pFunc != "divUpdateUser_im"){ |
---|
| 90 | var jid = text0.value.substr(0,text0.value.indexOf('@')); |
---|
| 91 | for(var i=0; i < IM.user_not_aut.length; i++){ |
---|
| 92 | if(IM.user_not_aut[i].substr(0,IM.user_not_aut[i].indexOf('@')) == jid){ |
---|
| 93 | return; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if(IM.LTrim(text0.value) != "" && IM.LTrim(text1.value) != "" && IM.LTrim(text2.value) != ""){ |
---|
| 99 | var handler_add_contact = function(data){ |
---|
| 100 | if(data){ |
---|
| 101 | text0.value = ""; |
---|
| 102 | text1.value = ""; |
---|
| 103 | text2.value = ""; |
---|
| 104 | if(pFunc != 'divAddUser_im') |
---|
| 105 | im_win.windowClose(pFunc); |
---|
| 106 | IM.UpdateContacts(); |
---|
| 107 | |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | if(pFunc == 'divAddUser_im') |
---|
| 111 | cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+text1.value+"&group="+text2.value+"&subscription=none"); |
---|
| 112 | else |
---|
| 113 | cIM.cExecute("$this.Ujabber.AddNewContacts",handler_add_contact,"email="+text0.value+"&name="+text1.value+"&group="+text2.value+"&subscription=to"); |
---|
| 114 | }else{ |
---|
| 115 | alert("Informe todos os campos!"); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /* |
---|
| 120 | * Remove |
---|
| 121 | */ |
---|
| 122 | |
---|
| 123 | Preferences.prototype.Remove_userLoad = function() |
---|
| 124 | { |
---|
| 125 | Templates.remove_user(); |
---|
| 126 | var sel_contact = document.getElementById('sel_contact'); |
---|
| 127 | if(sel_contact.options.length > 0) |
---|
| 128 | sel_contact.options.splice(0,sel_contact.options.length); |
---|
| 129 | var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true); |
---|
| 130 | sel_contact.options[sel_contact.length] = opt; |
---|
| 131 | |
---|
| 132 | for(var i=1; i < IM.vcard_contacts.length; i++){ |
---|
| 133 | if(IM.vcard_contacts[i].name != ""){ |
---|
| 134 | opt = new Option(IM.vcard_contacts[i].name,IM.vcard_contacts[i].jid, false, false); |
---|
| 135 | sel_contact.options[sel_contact.length] = opt; |
---|
| 136 | }else{ |
---|
| 137 | name = IM.vcard_contacts[i].jid.substr(0,IM.vcard_contacts[i].jid.indexOf('@')); |
---|
| 138 | opt = new Option(name,IM.vcard_contacts[i].jid, false, false); |
---|
| 139 | sel_contact.options[sel_contact.length] = opt; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | Preferences.prototype.Remove_user = function() |
---|
| 145 | { |
---|
| 146 | var _this = this; |
---|
| 147 | var sel_contact = document.getElementById('sel_contact'); |
---|
| 148 | for(var i=0; i < sel_contact.options.length; i++){ |
---|
| 149 | if(sel_contact[i].selected && sel_contact.options[i].value != 0){ |
---|
| 150 | if(confirm("Excluir o contato " + sel_contact.options[i].innerHTML + "?")){ |
---|
| 151 | var in_el = sel_contact.options[i].innerHTML; |
---|
| 152 | for(var j=1 ; j < IM.vcard_contacts.length; j++){ |
---|
| 153 | var name = IM.vcard_contacts[j].jid.substr(0,IM.vcard_contacts[j].jid.indexOf('@')); |
---|
| 154 | if(IM.vcard_contacts[j].name == in_el || name == in_el){ |
---|
| 155 | var handler_remove_contact = function(data){ |
---|
| 156 | if(!data){ |
---|
| 157 | alert(data); |
---|
| 158 | return false; |
---|
| 159 | } |
---|
| 160 | setTimeout("IM.UpdateContacts()",1000); |
---|
| 161 | } |
---|
| 162 | cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+sel_contact.options[i].value); |
---|
| 163 | IM.vcard_contacts.splice(j,1); |
---|
| 164 | _this.ComboRemove(); |
---|
| 165 | j--; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | Preferences.prototype.ComboRemove = function() |
---|
| 174 | { |
---|
| 175 | var sel_contact = document.getElementById('sel_contact'); |
---|
| 176 | if(sel_contact.length > 0 ){ |
---|
| 177 | for(var i=0; i < sel_contact.options.length; i++){ |
---|
| 178 | sel_contact.options[i] = null; |
---|
| 179 | i--; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | var opt = new Option("-- "+IM.get_lang('Choice Contact')+" -- ","0",true,true); |
---|
| 184 | sel_contact.options[sel_contact.length] = opt; |
---|
| 185 | for(var i=0; i < IM.vcard_contacts.length; i++){ |
---|
| 186 | opt = new Option(IM.vcard_contacts[i].name,IM.vcard_contacts[i].jid, false, false); |
---|
| 187 | sel_contact.options[sel_contact.length] = opt; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | Preferences.prototype.Remove_Contact = function(pJid) |
---|
| 192 | { |
---|
| 193 | for(var i=0; i < IM.vcard_contacts.length; i++){ |
---|
| 194 | if(IM.vcard_contacts[i].jid == pJid){ |
---|
| 195 | if(confirm("Excluir o contato " + IM.vcard_contacts[i].name + "?")){ |
---|
| 196 | var handler_remove_contact = function(data){ |
---|
| 197 | if(!data){ |
---|
| 198 | alert(data); |
---|
| 199 | return; |
---|
| 200 | }else{ |
---|
| 201 | setTimeout("IM.UpdateContacts()",1000); |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | cIM.cExecute("$this.Ujabber.RosterRemoveUser",handler_remove_contact,"jid="+pJid); |
---|
| 205 | } |
---|
| 206 | return; |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | /* |
---|
| 212 | * Update |
---|
| 213 | */ |
---|
| 214 | |
---|
| 215 | Preferences.prototype.updateLoad = function(i) |
---|
| 216 | { |
---|
| 217 | Jid = IM.vcard_contacts[i].jid; |
---|
| 218 | Templates.update_user(); |
---|
| 219 | document.getElementById('text0').value = Jid; |
---|
| 220 | document.getElementById('span0').innerHTML = Jid.substr(0,Jid.indexOf('@')); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | Preferences.prototype.Update_ = function(pJid,pType) |
---|
| 224 | { |
---|
| 225 | var name = ""; |
---|
| 226 | var group = ""; |
---|
| 227 | var jid = pJid; |
---|
| 228 | |
---|
| 229 | for(var i=1; i < IM.vcard_contacts.length; i++){ |
---|
| 230 | if(IM.vcard_contacts[i].jid == pJid){ |
---|
| 231 | name = IM.vcard_contacts[i].name; |
---|
| 232 | group = IM.vcard_contacts[i].group; |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | if((name != "") && (group != "")){ |
---|
| 237 | if(pType){ |
---|
| 238 | var act = prompt("Digite um apelido para :" + pJid , name); |
---|
| 239 | name = act; |
---|
| 240 | }else{ |
---|
| 241 | var act = prompt("Digite um novo grupo para : " + name, group); |
---|
| 242 | group = act; |
---|
| 243 | } |
---|
| 244 | if((act != null) && (act != "")){ |
---|
| 245 | var handler_update_contacts = function(data){ |
---|
| 246 | if(data) |
---|
| 247 | IM.UpdateContacts(); |
---|
| 248 | else |
---|
| 249 | alert("erro"); |
---|
| 250 | } |
---|
| 251 | cIM.cExecute("$this.Ujabber.UpdateUser",handler_update_contacts,"jid="+jid+"&name="+name+"&group="+group); |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | Preferences.prototype.Update_Group = function(pJid) |
---|
| 257 | { |
---|
| 258 | this.Update_(pJid,false); |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | Preferences.prototype.Update_NickName = function(pJid) |
---|
| 262 | { |
---|
| 263 | this.Update_(pJid,true); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | /* |
---|
| 267 | * Vcard |
---|
| 268 | */ |
---|
| 269 | |
---|
| 270 | Preferences.prototype.vCardLoad = function() |
---|
| 271 | { |
---|
| 272 | Templates.information_user(); |
---|
| 273 | document.getElementById('FN').value = IM.vcard_user['VCARD_FN']; |
---|
| 274 | document.getElementById('NICKNAME').value = IM.vcard_user['VCARD_NICKNAME']; |
---|
| 275 | document.getElementById('ORGNAME').value = IM.vcard_user['VCARD_ORGNAME']; |
---|
| 276 | document.getElementById('ORGUNIT').value = IM.vcard_user['VCARD_ORGUNIT']; |
---|
| 277 | document.getElementById('ROLE').value = IM.vcard_user['VCARD_ROLE']; |
---|
| 278 | document.getElementById('BDAY').value = IM.vcard_user['VCARD_BDAY']; |
---|
| 279 | document.getElementById('DESC').value = IM.vcard_user['VCARD_DESC']; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | Preferences.prototype.vCardAdd = function() |
---|
| 283 | { |
---|
| 284 | var _this = this; |
---|
| 285 | IM.vcard_user['VCARD_FN'] = document.getElementById('FN').value; |
---|
[21] | 286 | _this.save_vcard = url_encode(encodeURI(document.getElementById('FN').value)) + ";"; |
---|
[20] | 287 | IM.vcard_user['VCARD_NICKNAME'] = document.getElementById('NICKNAME').value; |
---|
[21] | 288 | _this.save_vcard += url_encode(encodeURI(document.getElementById('NICKNAME').value)) + ";"; |
---|
[20] | 289 | var nickname = document.getElementById('span_nickname').innerHTML; |
---|
| 290 | document.getElementById('span_nickname').innerHTML = (IM.vcard_user['VCARD_NICKNAME']) ? "<b> " + IM.vcard_user['VCARD_NICKNAME'].substring(0,30) + "</b>" : nickname; |
---|
| 291 | IM.vcard_user['VCARD_ORGNAME'] = document.getElementById('ORGNAME').value; |
---|
[21] | 292 | _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGNAME').value)) + ";"; |
---|
[20] | 293 | IM.vcard_user['VCARD_ORGUNIT'] = document.getElementById('ORGUNIT').value; |
---|
[21] | 294 | _this.save_vcard += url_encode(encodeURI(document.getElementById('ORGUNIT').value)) + ";"; |
---|
[20] | 295 | IM.vcard_user['VCARD_ROLE'] = document.getElementById('ROLE').value; |
---|
[21] | 296 | _this.save_vcard += url_encode(encodeURI(document.getElementById('ROLE').value)) + ";"; |
---|
[20] | 297 | IM.vcard_user['VCARD_BDAY'] = document.getElementById('BDAY').value; |
---|
[21] | 298 | _this.save_vcard += url_encode(encodeURI(document.getElementById('BDAY').value)) + ";"; |
---|
[20] | 299 | IM.vcard_user['VCARD_DESC'] = document.getElementById('DESC').value; |
---|
[21] | 300 | _this.save_vcard += url_encode(encodeURI(document.getElementById('DESC').value)); |
---|
[20] | 301 | var message_desc = document.getElementById('span_message').innerHTML; |
---|
| 302 | document.getElementById('span_message').innerHTML = (IM.vcard_user['VCARD_DESC']) ? "<b> " + IM.vcard_user['VCARD_DESC'].substring(0,30) + "</b>" : message_desc ; |
---|
| 303 | |
---|
| 304 | var handler_vcardAdd = function(data){ |
---|
| 305 | if(!data) |
---|
| 306 | alert(data); |
---|
| 307 | else |
---|
| 308 | alert("Informações Cadastradas / Atualizadas !"); |
---|
| 309 | } |
---|
| 310 | cIM.cExecute("$this.Ujabber.newVcard",handler_vcardAdd,"vcard="+_this.save_vcard); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | Preferences.prototype.vCardLoad_Contact = function(pJid) |
---|
| 314 | { |
---|
| 315 | Templates.information_Contact(); |
---|
| 316 | for(var i=0; i < IM.vcard_contacts.length; i++){ |
---|
| 317 | if(IM.vcard_contacts[i].jid == pJid){ |
---|
[21] | 318 | document.getElementById('_lbl_FN').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_FN); |
---|
| 319 | document.getElementById('_lbl_Nickname').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_NICKNAME); |
---|
| 320 | document.getElementById('_lbl_Orgunit').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_ORGUNIT); |
---|
| 321 | document.getElementById('_lbl_Role').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_ROLE); |
---|
| 322 | document.getElementById('_lbl_Birthday').innerHTML = decodeURI(IM.vcard_contacts[i].VCARD_BDAY); |
---|
[20] | 323 | return; |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | /* |
---|
| 329 | * Envio de arquivo |
---|
| 330 | */ |
---|
| 331 | |
---|
| 332 | Preferences.prototype.SendFile = function(pJid) |
---|
| 333 | { |
---|
| 334 | if(im_send_file == 'true'){ |
---|
| 335 | Templates.Send_file(pJid); |
---|
| 336 | }else{ |
---|
| 337 | alert('Funçao Indisponível!'); |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | Preferences.prototype.SizeFile = function() |
---|
| 342 | { |
---|
| 343 | var h_SizeFile = function(data){ |
---|
| 344 | alert(data); |
---|
| 345 | } |
---|
| 346 | cIM.cExecute("$this.upload.size_file",h_SizeFile); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | // Build Object |
---|
| 350 | var Preferences = new Preferences(); |
---|