(function()
{
var _conn;
var _xtools;
var _window;
function _add_user()
{
var _win_add = _window.load('add_user_im');
_win_add.title('.:: Adicionar Novos Contatos ::.');
_win_add.size(600);
_win_add.position(30, 30);
_win_add.wc.style.padding = "3px";
var _params = {
'lang1':imGetLang('organization unit'),
'lang2':imGetLang('member of organization'),
'lang3':imGetLang('nickname'),
'lang4':imGetLang('group'),
'lang5':imGetLang('add'),
'lang6':imGetLang('close')
};
_win_add.content(_xtools.parse(_xtools.xml('adduser'), 'add_user.xsl', _params));
function _handler(_data)
{
var _target = top.document.getElementById('im_ldap_ou');
_target.innerHTML = _xtools.parse(_data, 'list_ldap_org.xsl');
var _organization_unit = _target.firstChild;
while ( _organization_unit )
{
_config(_organization_unit, 'onclick', _members);
_config(_organization_unit, 'onmouseover', _highlight);
_config(_organization_unit, 'onmouseout', _highlight);
_organization_unit = _organization_unit.nextSibling;
}
_config(_win_add.wc.childNodes[2].childNodes[0],
'onclick',
function()
{
var _name = top.document.getElementById('im_name');
var _group = top.document.getElementById('im_group');
var _jid = top.document.getElementById('im_jid').value;
var _status = top.document.getElementById('im_status_add');
_status.innerHTML = '';
_name.previousSibling.style.color = "#000";
_group.previousSibling.style.color = "#000";
if ( !_jid )
{
_status.innerHTML = 'Selecione uma organização no campo da esquerda e em
'
+ ' seguida, no campo da direita, um membro da organização
'
+ ' para adicionar como contato';
}
else
{
_name.value = _name.value.replace(/^( )*|( )*$/g, '');
_group.value = _group.value.replace(/^( )*|( )*$/g, '');
if ( !(_name.value) || !(_group.value) )
{
_status.innerHTML = '
O campo destacado em vermelho é obrigatório!
';
if ( !(_name.value) )
{
_name.previousSibling.style.color = "#f00";
_status.innerHTML += '
** Informe um "NOME" para o contato.';
}
if ( !(_group.value) )
{
_group.previousSibling.style.color = "#f00";
_status.innerHTML += '
** Informe um "GRUPO" para o contato.';
}
}
else
{
var _uid;
if ( (_uid = top.document.getElementById('im_uid')) )
_uid = _uid.value;
else
_uid = _jid.substr(0, (_jid.indexOf('@') - 1));
_name.parentNode.style.display = 'none';
_name.parentNode.nextSibling.style.display = 'none';
_status.innerHTML = '
Adicionado contanto, aguarde.
';
_conn.go(
'$this.Ujabber.addContact',
function()
{
_status.innerHTML = '
Contato adicionado com "SUCESSO"!
';
},
'uid='+_uid+'&name='+_name.value+'&group='+_group.value
);
_name.value = '';
_group.value = '';
}
}
}
);
_config(_win_add.wc.childNodes[2].childNodes[1],
'onclick',
function()
{
_win_add.button(_win_add.bc);
}
);
}
_organizations(_handler);
}
function _config(pObj, pEvent, pHandler)
{
if ( typeof pObj == 'object' )
{
if ( pEvent.substring(0, 2) == 'on' )
pEvent = pEvent.substring(2, pEvent.length);
if ( pObj.addEventListener )
pObj.addEventListener(pEvent, pHandler, false);
else if ( pObj.attachEvent )
pObj.attachEvent('on' + pEvent, pHandler);
}
}
function _highlight(e)
{
var el = ( e.target ) ? e.target : e.srcElement;
var color = "#fff";
if ( e.type.indexOf('mouseover') != -1 )
color = "#b4cfe5";
el.style.backgroundColor = color;
}
function _organizations(_handler)
{
_conn.go('$this.ldap_im.list_organizations_ldap', _handler);
}
function _photo(_pId, _target)
{
if ( _pId.indexOf('/') > -1 )
_pId = _pId.substr(0, _pId.indexOf('/'));
function _handler(_thereIsUserPhoto)
{
if ( _thereIsUserPhoto == "true" )
_target.style.backgroundImage = 'url(' + path_im + 'inc/class.ldap_im.inc.php?user=' + _pId + ')';
}
_conn.go('$this.ldap_im.photo_ldap', _handler,'uid='+_pId);
}
function _members(e)
{
var el = ( e.target ) ? e.target : e.srcElement;
var _organization = false;
var _target = false;
var _action = false;
var _over = false;
var _out = false;
switch ( el.nodeName.toLowerCase() )
{
case 'span' :
_organization = el.firstChild.nodeValue;
_target = top.document.getElementById('im_ldap_user');
function _show(m)
{
m = ( m.target ) ? m.target : m.srcElement;
m = m.getAttribute('value');
top.document.getElementById('im_jid').value = m.substr(0, m.indexOf(';'));
top.document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1));
var _name = top.document.getElementById('im_name');
_name.value = m.substr(0, m.indexOf('@'));
_name.previousSibling.style.color = "#000";
_name.parentNode.style.display = 'block';
_name.parentNode.nextSibling.style.display = 'block';
_name.parentNode.nextSibling.nextSibling.innerHTML = '';
var _group = top.document.getElementById('im_group');
_group.value = '';
_group.focus();
}
_action = _show;
_over = _out = _highlight;
break;
}
if ( _organization )
{
var _loading = top.document.getElementById('__span_load_im');
_loading.style.display = "block";
_conn.go(
'$this.contacts_im.list_contacts',
function(_data)
{
_target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl');
var _member = _target.firstChild;
while ( _member )
{
if ( _action )
_config(_member, 'onclick', _action);
if ( _over )
_config(_member, 'onmouseover', _over);
if ( _out )
_config(_member, 'onmouseout', _out);
_member = _member.nextSibling;
}
_loading.style.display = "none";
},
'ou='+_organization
);
}
}
function LDAP()
{
_conn = arguments[0];
_xtools = arguments[1];
_window = arguments[2];
}
LDAP.prototype.photo = _photo;
LDAP.prototype.add = _add_user;
window.InstantMessengerLDAP = LDAP;
}
)();