function Im()
{
this.xtools = new XTools;
this.conn = new Connector;
this.vcard = "layer";
this.nickname = null;
this.status = null;
this.statusFlag = null;
this.contacts_off_line = null;
this.timeOut_im = null;
this.nickname_contacts = [];
}
Im.prototype = {
"addemotion" : function(pEmotion,pJid)
{
function get_Element(pJid)
{
var _document = document.getElementById('iframe_' + pJid);
return _document.contentWindow.document.getElementsByTagName('body').item(0);
}
var content = get_Element(pJid);
content.innerHTML += "" + this.insertEmoticons(pEmotion);
},
"addrequest" : function(pEmail)
{
var email = pEmail;
var name = pEmail.substr(0,pEmail.indexOf('@'));
var group = 'default';
function handler_adduser(XmlData)
{
if(XmlData != "OK")
alert("Contato não adicionado !");
}
this.conn.go('$this.Ujabber.addContacts',{'request':handler_adduser},'email='+email+'&name='+name+'&group='+group);
},
"adduser" : function()
{
if(!func.trim(func.byId('im_name').value) || !func.trim(func.byId('im_group').value))
alert('Informe todos os campos !');
else
{
var jid = func.byId('im_jid').value;
var name = func.byId('im_name').value;
var group = func.byId('im_group').value;
var email = jid;
if(func.byId('im_uid') != null)
var uid = func.byId('im_uid').value;
if(uid)
email = uid + '@' + jid.substr((jid.indexOf('@')+1),jid.length);
function handler_adduser(XmlData)
{
if(XmlData != "OK")
alert("Contato não adicionado !");
else
alert("Contato Adicionado !");
}
this.conn.go('$this.Ujabber.addContacts',{'request':handler_adduser},'email='+email+'&name='+name+'&group='+group);
}
},
"button_color": function(pJid,pColor)
{
var _document = document.getElementById('iframe_' + pJid);
var _font_color = "";
function get_Element(pJid)
{
return _document.contentWindow.document.getElementsByTagName('body').item(0);
}
var content = get_Element(pJid);
if( _font_color = _document.contentWindow.document.getElementById('colors_'+pJid) )
content.innerHTML = ""+_font_color.innerHTML+"";
else
content.innerHTML = ""+content.innerHTML+"";
},
"conf_font" : function(pJid,pAction)
{
function get_Element(pJid)
{
var _document = document.getElementById('iframe_' + pJid);
return _document.contentWindow.document.getElementsByTagName('body').item(0);
}
switch(pAction)
{
case "button_bold" :
var content = get_Element(pJid);
content.innerHTML = "" + content.innerHTML + "";
break;
case "button_color" :
templates.colors(pJid);
break;
case "button_emoticons" :
templates.smiles(pJid);
break;
case "button_italic" :
var content = get_Element(pJid);
content.innerHTML = "" + content.innerHTML + "";
break;
case "button_underline" :
var content = get_Element(pJid);
content.innerHTML = "" + content.innerHTML + "";
break;
}
},
"focus_select" : function(pObj,pEv)
{
pObj.focus();
pObj.select();
},
"get_contacts" : function()
{
var contact = func.byId('im_contact_list').firstChild;
func.byId('im_remove_contact')[func.byId('im_remove_contact').length] = new Option('-- Selecione --', -1, true, true);
while ( contact )
{
if( contact.tagName == "DIV")
{
var options = new Option(contact.id.substr(0,contact.id.indexOf('@')), contact.id, false, true);
func.byId('im_remove_contact')[func.byId('im_remove_contact').length] = options;
}
contact = contact.nextSibling;
}
func.byId('im_remove_contact')[0].selected = true;
},
"get_lang" : function(_key, _arg1, _arg2, _arg3, _arg4)
{
var _value = "";
if ( !lang_im[_key.toLowerCase()] )
return _key + "*";
_value = lang_im[_key.toLowerCase()];
if ( _arg1 || _arg2 ||_arg3 || _arg4 )
{
for (j = 1; j <= 4; j++ )
if( eval("_arg"+j) )
{
var regExp = new RegExp("%" + j + "");
_value = _value.replace(regExp, eval("_arg"+j));
}
}
return _value;
},
"get_preferences" : function()
{
var preferences = "";
function func_preferences(pString)
{
var result = pString.split(';');
for(var i in result)
{
var field = result[i].substr(0,result[i].indexOf(':'));
var value = result[i].substr(result[i].indexOf(':') +1, result[i].length);
if(value === 'true' || value === 'false')
{
if(func.byId(field))
func.byId(field).checked = eval(value);
if(field === "ch_offline" )
im.contacts_off_line = eval(value);
}
else
{
if(func.byId(field))
func.byId(field).value = value;
im.timeOut_im = value;
}
}
}
if(preferences = cookies_im.checkCookie('preferences_im'))
func_preferences(preferences);
else
{
function handler_preferences(XmlData)
{
func_preferences(XmlData);
cookies_im.setCookie('preferences_im', XmlData, null);
}
this.conn.go('$this.db_im.get_preferences',{'request':handler_preferences});
}
},
"group_close" : function(pGroup)
{
var contact = func.byId('im_contact_list').firstChild;
var img_group_close = new Image();
img_group_close.src = path_im + "templates/default/images/group_close.gif";
while ( contact )
{
if(contact.getAttribute('idgroup') == pGroup)
contact.style.display = "none";
contact = contact.nextSibling;
}
func.byId('group_' + pGroup).src = img_group_close.src;
func.byId('group_' + pGroup).onclick = function(){im.group_open(pGroup)};
},
"group_open" : function(pGroup)
{
var contact = func.byId('im_contact_list').firstChild;
var img_group_open = new Image();
img_group_open.src = path_im + "templates/default/images/group_open.gif";
while ( contact )
{
if(contact.getAttribute('idgroup') == pGroup)
contact.style.display = "block";
contact = contact.nextSibling;
}
func.byId('group_' + pGroup).src = img_group_open.src;
func.byId('group_' + pGroup).onclick = function(){im.group_close(pGroup)};
},
"insertEmoticons" : function(pEmotion)
{
var emotion_regexp;
for ( i in cod_emotions )
{
try
{
emotion_regexp = new RegExp(cod_emotions[i][1], 'gi');
if ( emotion_regexp.test(pEmotion) )
{
var image = eval('smile_' + cod_emotions[i][0] + '.src.substr(smile_' +cod_emotions[i][0] + '.src.indexOf(path_im))');
emotion_regexp = new RegExp(cod_emotions[i][1], 'gi');
pEmotion = pEmotion.replace(emotion_regexp, '');
}
}catch(e){}
}
return pEmotion;
},
"ldap" : function()
{
var _this = this;
function handler_ldap(XmlData)
{
func.byId('im_ldap_ou').innerHTML = _this.xtools.parse(XmlData,'list_ldap_org.xsl');
}
this.conn.go('$this.ldap_im.list_organizations_ldap', {'request':handler_ldap});
},
"ldap_adduser" : function(pElement)
{
if(pElement.options.length > 0)
for(var i=0; i < pElement.options.length; i++)
if(pElement.options[i].selected == true)
{
document.getElementById('im_jid').value = pElement.options[i].value.substr(0,pElement.options[i].value.indexOf(';'));
document.getElementById('im_name').value = pElement.options[i].value.substr(0,pElement.options[i].value.indexOf('@'));
document.getElementById('im_group').focus();
document.getElementById('im_uid').value = pElement.options[i].value.substr((pElement.options[i].value.indexOf(';')+1), pElement.options[i].value.length);
}
},
"ldap_search_ou" : function(pElement)
{
var ldap_ou = "";
for(var i=0; i < pElement.options.length; i++)
if( pElement.options[i].selected == true )
{
ldap_ou = pElement.options[i].value;
document.getElementById('im_jid').value = "";
document.getElementById('im_name').value = "";
document.getElementById('im_ldap_user').innerHTML = "";
}
if(ldap_ou)
this.ldap_search_contacts(ldap_ou);
},
"ldap_search_contacts" : function(pOu)
{
var _this = this;
document.getElementById('_span_load_im').style.display = "block";
function handler_ldap(XmlData)
{
document.getElementById('im_ldap_user').innerHTML = _this.xtools.parse(XmlData,'list_ldap_contacts.xsl');
document.getElementById('_span_load_im').style.display = "none";
}
this.conn.go('$this.contacts_im.list_contacts',{'request':handler_ldap}, 'ou='+pOu);
},
"ldap_photo" : function(pAvatar)
{
var uid = pAvatar;
if(pAvatar != 'im_avatar')
var uid = pAvatar.substr(0,pAvatar.indexOf('@'));
function handler_ldap_photo(XmlData)
{
var data = eval(XmlData);
if(data)
if( document.getElementById(pAvatar) != null )
{
var photo_img = document.getElementById(pAvatar);
photo_img.src = ( path_im + "inc/class.ldap_im.inc.php?user="+uid ) ? path_im + "inc/class.ldap_im.inc.php?user="+uid : im_photo.src ;
}
}
this.conn.go('$this.ldap_im.photo_ldap',{'request':handler_ldap_photo},'uid='+uid);
},
"off_line" : function(pDisplay)
{
var group = func.byId('im_contact_list').firstChild;
while(group)
{
if(group.hasChildNodes())
{
if(group.id)
if( func.byId('img_' + group.id).src == im_unavailable.src )
func.confEl(group,"style","margin-left:15px;cursor:pointer;display:" + pDisplay + ";");
}
group = group.nextSibling;
}
},
"presence" : function(pType)
{
var imgStatus = null;
switch(pType)
{
case 'away' :
case 'dnd' :
case 'xa' :
this.status = 'show='+pType;
this.statusFlag = pType;
imgStatus = pType;
break;
case 'available' :
case 'unavailable' :
this.status = 'type='+pType;
this.statusFlag = pType;
imgStatus = pType;
break;
case 'custom' :
var custom = prompt('Personalize seu Status : ');
if(custom)
this.status = 'status='+custom;
else
return;
}
cookies_im.setCookie('status', this.status, null);
function handler_presence(XmlData)
{
if(imgStatus != null)
func.byId('im_status_src').src = eval('im_' + imgStatus + '.src');
}
this.conn.go('$this.Ujabber.setPresence', {'request' : handler_presence}, this.status);
},
"remove" : function(pJid)
{
if(confirm('Deseja excluir o contato ' + pJid + ' ?'))
{
function handler_remove(XmlData)
{
if(XmlData == "OK")
{
func.byId(pJid).parentNode.removeChild(func.byId(pJid));
}
}
this.conn.go('$this.Ujabber.removeContact',{'request':handler_remove},'jid='+pJid);
}
},
"remove_contact" : function(pElement)
{
var Jid = "";
if( func.byId(pElement).options.length > 0 )
for(var i=0; i < func.byId(pElement).options.length; i++)
if( func.byId(pElement).options[i].selected == true )
Jid = func.byId(pElement).options[i].value;
if(confirm('Deseja excluir o contato ' + Jid + ' ?'))
{
if( Jid && Jid != -1 )
{
function handler_remove(XmlData)
{
if(XmlData == "OK")
{
func.byId(Jid).parentNode.removeChild(func.byId(Jid));
for(var i=0 ; i < func.byId(pElement).options.length; i++)
{
func.byId(pElement).options[i] = null;
i--;
}
}
}
this.conn.go('$this.Ujabber.removeContact',{'request':handler_remove},'jid='+Jid);
}
}
},
"request_vcard" : function(pJid, pType)
{
this.vcard = pType;
function handler_getVcard(XmlData)
{
if(XmlData != "OK")
alert('Erro no Vcard !');
}
this.conn.go('$this.Ujabber.getVcard',{'request':handler_getVcard},'jid='+pJid);
},
"save_vcard" : function()
{
var xmlVcard = "" + func.byId('im_fn').value + "";
xmlVcard += "" + func.byId('im_nickname').value + "";
xmlVcard += "";
xmlVcard += "" + func.byId('im_orgname').value + "";
xmlVcard += "" + func.byId('im_orgunit').value + "";
xmlVcard += "";
xmlVcard += "" + func.byId('im_role').value + "";
xmlVcard += "" + func.byId('im_bday').value + "";
func.byId('im_layer_nickname').innerHTML = func.byId('im_nickname').value;
function handler_savevcard(XmlData)
{
if( XmlData != "OK" )
alert('Vcard não cadastrado/atualizado !');
else
alert('Vcard cadastrado/atualizado !');
}
this.conn.go('$this.Ujabber.newVcard',{'request':handler_savevcard},"vcard="+xmlVcard);
},
"set_preferences" : function()
{
var preferences = "";
var numbers = /^\d+$/;
this.timeOut_im = 1;
preferences = (func.byId('ch_offline').checked ) ? 'ch_offline:true;' : 'ch_offline:false;';
this.contacts_off_line = func.byId('ch_offline').checked;
if(numbers.test(func.byId('time_xa_im').value) && func.byId('time_xa_im').value != "0")
{
preferences += "time_xa_im:" + func.byId('time_xa_im').value + ";";
this.timeOut_im = func.byId('time_xa_im').value;
}
else
preferences += "time_xa_im:1;";
preferences += ( func.byId('rd_nm').checked ) ? 'rd_nm:true;' : 'rd_nm:false;';
preferences += ( func.byId('rd_ch').checked ) ? 'rd_ch:true' : 'rd_ch:false';
function handler_preferences(XmlData)
{
if(XmlData === "true")
{
cookies_im.setCookie('preferences_im', preferences, null);
if(im.contacts_off_line)
im.off_line('block');
else
im.off_line('none');
alert('Preferências Salvas !');
}
}
this.conn.go('$this.db_im.set_preferences',{'request':handler_preferences},'preferences='+preferences);
},
"set_timeOut" : function()
{
if( this.statusFlag === 'available')
setTimeout("im.presence(\'xa\')",parseInt(im.timeOut_im));
},
"subscription" : function(pJid, pType)
{
function handler_request(XmlData)
{
if(XmlData != 1)
alert(XmlData);
}
this.conn.go('$this.Ujabber.subscription',{'request':handler_request},"jid="+pJid+"&type="+pType);
},
"update_nickname" : function(pJid)
{
var jid = pJid;
var name = func.byId(pJid).getAttribute('idname');
var group = func.byId(pJid).getAttribute('idgroup');
cookies_im.setCookie('contacts', pJid + "=" + func.byId("img_"+ pJid).src, 1);
if( value = prompt("Digite um novo apelido para : " + jid, "" ))
{
if(func.trim(value) != "" && value != null)
{
name = value;
function handler_update_contact(XmlData)
{
if(XmlData != "OK")
alert('Contato não atualizado !');
}
this.conn.go('$this.Ujabber.updateContact',{'request':handler_update_contact},"jid="+jid+"&name="+name+"&group="+group);
}
}
},
"update_group" : function(pJid)
{
var jid = pJid;
var name = func.byId(pJid).getAttribute('idname');
var group = func.byId(pJid).getAttribute('idgroup');
cookies_im.setCookie('contacts', pJid + "=" + func.byId("img_"+ pJid).src, 1);
if( value = prompt("Digite um novo grupo para : " + jid, "" ))
{
if(func.trim(value) != "" && value != null)
{
group = value;
function handler_update_contact(XmlData)
{
if(XmlData != "OK")
alert('Contato não atualizado !');
}
this.conn.go('$this.Ujabber.updateContact',{'request':handler_update_contact},"jid="+jid+"&name="+name+"&group="+group);
}
}
}
}
var im = new Im();