[305] | 1 | (function() |
---|
| 2 | { |
---|
| 3 | var _conn; |
---|
| 4 | var _xtools; |
---|
| 5 | var _window; |
---|
| 6 | |
---|
| 7 | function _add_user() |
---|
| 8 | { |
---|
| 9 | var _win_add = _window.load('add_user_im'); |
---|
| 10 | _win_add.title('.:: Adicionar Novos Contatos ::.'); |
---|
| 11 | _win_add.size(600); |
---|
| 12 | _win_add.position(30, 30); |
---|
| 13 | _win_add.wc.style.padding = "3px"; |
---|
| 14 | var _params = { |
---|
| 15 | 'lang1':imGetLang('organization unit'), |
---|
| 16 | 'lang2':imGetLang('member of organization'), |
---|
| 17 | 'lang3':imGetLang('nickname'), |
---|
| 18 | 'lang4':imGetLang('group'), |
---|
| 19 | 'lang5':imGetLang('add'), |
---|
| 20 | 'lang6':imGetLang('close') |
---|
| 21 | }; |
---|
| 22 | |
---|
| 23 | _win_add.content(_xtools.parse(_xtools.xml('adduser'), 'add_user.xsl', _params)); |
---|
| 24 | |
---|
| 25 | function _handler(_data) |
---|
| 26 | { |
---|
| 27 | var _target = top.document.getElementById('im_ldap_ou'); |
---|
| 28 | _target.innerHTML = _xtools.parse(_data, 'list_ldap_org.xsl'); |
---|
| 29 | var _organization_unit = _target.firstChild; |
---|
| 30 | while ( _organization_unit ) |
---|
| 31 | { |
---|
| 32 | _config(_organization_unit, 'onclick', _members); |
---|
| 33 | _config(_organization_unit, 'onmouseover', _highlight); |
---|
| 34 | _config(_organization_unit, 'onmouseout', _highlight); |
---|
| 35 | _organization_unit = _organization_unit.nextSibling; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | _config(_win_add.wc.childNodes[2].childNodes[0], |
---|
| 39 | 'onclick', |
---|
| 40 | function() |
---|
| 41 | { |
---|
| 42 | var _name = top.document.getElementById('im_name'); |
---|
| 43 | var _group = top.document.getElementById('im_group'); |
---|
| 44 | var _jid = top.document.getElementById('im_jid').value; |
---|
| 45 | var _status = top.document.getElementById('im_status_add'); |
---|
| 46 | |
---|
| 47 | _status.innerHTML = ''; |
---|
| 48 | _name.previousSibling.style.color = "#000"; |
---|
| 49 | _group.previousSibling.style.color = "#000"; |
---|
| 50 | |
---|
| 51 | if ( !_jid ) |
---|
| 52 | { |
---|
[311] | 53 | _status.innerHTML = 'Selecione uma organização no campo da esquerda e em<br/>' |
---|
| 54 | + ' seguida, no campo da direita, um membro da organização<br/>' |
---|
[305] | 55 | + ' para adicionar como contato'; |
---|
| 56 | } |
---|
| 57 | else |
---|
| 58 | { |
---|
| 59 | _name.value = _name.value.replace(/^( )*|( )*$/g, ''); |
---|
| 60 | _group.value = _group.value.replace(/^( )*|( )*$/g, ''); |
---|
| 61 | |
---|
| 62 | if ( !(_name.value) || !(_group.value) ) |
---|
| 63 | { |
---|
[311] | 64 | _status.innerHTML = '<br/>O campo destacado em vermelho é obrigatório!<br/>'; |
---|
[305] | 65 | |
---|
| 66 | if ( !(_name.value) ) |
---|
| 67 | { |
---|
| 68 | _name.previousSibling.style.color = "#f00"; |
---|
| 69 | _status.innerHTML += '<br/>** Informe um "NOME" para o contato.'; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if ( !(_group.value) ) |
---|
| 73 | { |
---|
| 74 | _group.previousSibling.style.color = "#f00"; |
---|
| 75 | _status.innerHTML += '<br/>** Informe um "GRUPO" para o contato.'; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | else |
---|
| 79 | { |
---|
| 80 | var _uid; |
---|
| 81 | |
---|
| 82 | if ( (_uid = top.document.getElementById('im_uid')) ) |
---|
| 83 | _uid = _uid.value; |
---|
| 84 | else |
---|
| 85 | _uid = _jid.substr(0, (_jid.indexOf('@') - 1)); |
---|
| 86 | |
---|
| 87 | _name.parentNode.style.display = 'none'; |
---|
| 88 | _name.parentNode.nextSibling.style.display = 'none'; |
---|
| 89 | _status.innerHTML = '<br/>Adicionado contanto, aguarde.<br/>'; |
---|
| 90 | |
---|
| 91 | _conn.go( |
---|
| 92 | '$this.Ujabber.addContact', |
---|
| 93 | function() |
---|
| 94 | { |
---|
| 95 | _status.innerHTML = '<br/>Contato adicionado com "SUCESSO"!<br/>'; |
---|
| 96 | }, |
---|
| 97 | 'uid='+_uid+'&name='+_name.value+'&group='+_group.value |
---|
| 98 | ); |
---|
| 99 | |
---|
| 100 | _name.value = ''; |
---|
| 101 | _group.value = ''; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | ); |
---|
| 106 | |
---|
| 107 | _config(_win_add.wc.childNodes[2].childNodes[1], |
---|
| 108 | 'onclick', |
---|
| 109 | function() |
---|
| 110 | { |
---|
| 111 | _win_add.button(_win_add.bc); |
---|
| 112 | } |
---|
| 113 | ); |
---|
| 114 | } |
---|
| 115 | _organizations(_handler); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | function _config(pObj, pEvent, pHandler) |
---|
| 119 | { |
---|
| 120 | if ( typeof pObj == 'object' ) |
---|
| 121 | { |
---|
| 122 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
| 123 | pEvent = pEvent.substring(2, pEvent.length); |
---|
| 124 | |
---|
| 125 | if ( pObj.addEventListener ) |
---|
| 126 | pObj.addEventListener(pEvent, pHandler, false); |
---|
| 127 | else if ( pObj.attachEvent ) |
---|
| 128 | pObj.attachEvent('on' + pEvent, pHandler); |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | function _highlight(e) |
---|
| 133 | { |
---|
| 134 | var el = ( e.target ) ? e.target : e.srcElement; |
---|
| 135 | var color = "#fff"; |
---|
| 136 | if ( e.type.indexOf('mouseover') != -1 ) |
---|
| 137 | color = "#b4cfe5"; |
---|
| 138 | el.style.backgroundColor = color; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | function _organizations(_handler) |
---|
| 142 | { |
---|
| 143 | _conn.go('$this.ldap_im.list_organizations_ldap', _handler); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | function _photo(_pId, _target) |
---|
| 147 | { |
---|
| 148 | if ( _pId.indexOf('/') > -1 ) |
---|
| 149 | _pId = _pId.substr(0, _pId.indexOf('/')); |
---|
| 150 | |
---|
| 151 | function _handler(_thereIsUserPhoto) |
---|
| 152 | { |
---|
| 153 | if ( _thereIsUserPhoto == "true" ) |
---|
| 154 | _target.style.backgroundImage = 'url(' + path_im + 'inc/class.ldap_im.inc.php?user=' + _pId + ')'; |
---|
| 155 | } |
---|
| 156 | _conn.go('$this.ldap_im.photo_ldap', _handler,'uid='+_pId); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | function _members(e) |
---|
| 160 | { |
---|
| 161 | var el = ( e.target ) ? e.target : e.srcElement; |
---|
| 162 | var _organization = false; |
---|
| 163 | var _target = false; |
---|
| 164 | var _action = false; |
---|
| 165 | var _over = false; |
---|
| 166 | var _out = false; |
---|
| 167 | switch ( el.nodeName.toLowerCase() ) |
---|
| 168 | { |
---|
| 169 | case 'span' : |
---|
| 170 | _organization = el.firstChild.nodeValue; |
---|
| 171 | _target = top.document.getElementById('im_ldap_user'); |
---|
| 172 | function _show(m) |
---|
| 173 | { |
---|
| 174 | m = ( m.target ) ? m.target : m.srcElement; |
---|
| 175 | m = m.getAttribute('value'); |
---|
| 176 | |
---|
| 177 | top.document.getElementById('im_jid').value = m.substr(0, m.indexOf(';')); |
---|
| 178 | top.document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1)); |
---|
| 179 | |
---|
| 180 | var _name = top.document.getElementById('im_name'); |
---|
| 181 | _name.value = m.substr(0, m.indexOf('@')); |
---|
| 182 | _name.previousSibling.style.color = "#000"; |
---|
| 183 | |
---|
| 184 | _name.parentNode.style.display = 'block'; |
---|
| 185 | _name.parentNode.nextSibling.style.display = 'block'; |
---|
| 186 | _name.parentNode.nextSibling.nextSibling.innerHTML = ''; |
---|
| 187 | |
---|
| 188 | var _group = top.document.getElementById('im_group'); |
---|
| 189 | _group.value = ''; |
---|
| 190 | _group.focus(); |
---|
| 191 | } |
---|
| 192 | _action = _show; |
---|
| 193 | _over = _out = _highlight; |
---|
| 194 | break; |
---|
| 195 | } |
---|
| 196 | if ( _organization ) |
---|
| 197 | { |
---|
| 198 | var _loading = top.document.getElementById('__span_load_im'); |
---|
| 199 | _loading.style.display = "block"; |
---|
| 200 | _conn.go( |
---|
| 201 | '$this.contacts_im.list_contacts', |
---|
| 202 | function(_data) |
---|
| 203 | { |
---|
| 204 | _target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl'); |
---|
| 205 | |
---|
| 206 | var _member = _target.firstChild; |
---|
| 207 | while ( _member ) |
---|
| 208 | { |
---|
| 209 | if ( _action ) |
---|
| 210 | _config(_member, 'onclick', _action); |
---|
| 211 | |
---|
| 212 | if ( _over ) |
---|
| 213 | _config(_member, 'onmouseover', _over); |
---|
| 214 | |
---|
| 215 | if ( _out ) |
---|
| 216 | _config(_member, 'onmouseout', _out); |
---|
| 217 | |
---|
| 218 | _member = _member.nextSibling; |
---|
| 219 | } |
---|
| 220 | _loading.style.display = "none"; |
---|
| 221 | }, |
---|
| 222 | 'ou='+_organization |
---|
| 223 | ); |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | function LDAP() |
---|
| 228 | { |
---|
| 229 | _conn = arguments[0]; |
---|
| 230 | _xtools = arguments[1]; |
---|
| 231 | _window = arguments[2]; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | LDAP.prototype.photo = _photo; |
---|
| 235 | LDAP.prototype.add = _add_user; |
---|
| 236 | window.InstantMessengerLDAP = LDAP; |
---|
| 237 | } |
---|
| 238 | )(); |
---|