[903] | 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(440); |
---|
| 12 | _win_add.position(200,80); |
---|
| 13 | _win_add.wc.style.padding = "3px"; |
---|
| 14 | |
---|
| 15 | var _params = { |
---|
| 16 | 'lang1':jabberitGetLang('Name of Contacts'), |
---|
| 17 | 'lang2':jabberitGetLang('Search'), |
---|
| 18 | 'lang3':jabberitGetLang('member of organization'), |
---|
| 19 | 'lang4':jabberitGetLang('nickname'), |
---|
| 20 | 'lang5':jabberitGetLang('group'), |
---|
| 21 | 'lang6':jabberitGetLang('add'), |
---|
| 22 | 'lang7':jabberitGetLang('close') |
---|
| 23 | }; |
---|
| 24 | |
---|
| 25 | _win_add.bz.style.display = "none"; |
---|
| 26 | _win_add.bx.style.display = "none"; |
---|
| 27 | |
---|
| 28 | _win_add.content(_xtools.parse(_xtools.xml('adduser'), 'add_user.xsl', _params)); |
---|
| 29 | |
---|
| 30 | _config(_win_add.wc.childNodes[2].childNodes[0], |
---|
| 31 | 'onclick', |
---|
| 32 | function() |
---|
| 33 | { |
---|
| 34 | var _name = document.getElementById('im_name'); |
---|
| 35 | var _group = document.getElementById('im_group'); |
---|
| 36 | var _jid = document.getElementById('im_jid').value; |
---|
| 37 | var _status = document.getElementById('im_status_add'); |
---|
| 38 | |
---|
| 39 | _status.innerHTML = ''; |
---|
| 40 | _name.previousSibling.style.color = "#000"; |
---|
| 41 | |
---|
| 42 | if ( !_jid ) |
---|
| 43 | { |
---|
| 44 | _status.innerHTML = 'Selecione uma organização no campo da esquerda e em<br/>' |
---|
| 45 | + ' seguida, no campo da direita, um membro da organização<br/>' |
---|
| 46 | + ' para adicionar como contato'; |
---|
| 47 | } |
---|
| 48 | else |
---|
| 49 | { |
---|
| 50 | _name.value = _name.value.replace(/^( )*|( )*$/g, ''); |
---|
| 51 | _group.value = _group.value.replace(/^( )*|( )*$/g, ''); |
---|
| 52 | |
---|
| 53 | if ( !(_name.value) || !(_group.value) ) |
---|
| 54 | { |
---|
| 55 | _status.innerHTML = '<br/>O campo destacado em vermelho é obrigatório!<br/>'; |
---|
| 56 | |
---|
| 57 | if ( !(_name.value) ) |
---|
| 58 | { |
---|
| 59 | _name.previousSibling.style.color = "#f00"; |
---|
| 60 | _status.innerHTML += '<br/>** Informe um "NOME" para o contato.'; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if ( !(_group.value) ) |
---|
| 64 | { |
---|
| 65 | _status.innerHTML += '<br/>** Informe um "GRUPO" para o contato.'; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | { |
---|
| 70 | var _uid; |
---|
| 71 | |
---|
| 72 | if ( (_uid = document.getElementById('im_uid')) ) |
---|
| 73 | _uid = _uid.value; |
---|
| 74 | else |
---|
| 75 | _uid = _jid.substr(0, (_jid.indexOf('@') - 1)); |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | _name.parentNode.style.display = 'none'; |
---|
| 79 | _name.parentNode.nextSibling.style.display = 'none'; |
---|
| 80 | _status.innerHTML = '<br/>Adicionando contato, aguarde....<br/>'; |
---|
| 81 | |
---|
| 82 | _conn.go( |
---|
| 83 | '$this.ujabber.AddNewContact', |
---|
| 84 | function() |
---|
| 85 | { |
---|
| 86 | _status.innerHTML = '<br/>Contato adicionado !<br/>'; |
---|
| 87 | setTimeout('cleanStatusAddContactIM();',2500); |
---|
| 88 | }, |
---|
| 89 | 'uid='+_uid+'&name='+_name.value+'&group='+_group.value |
---|
| 90 | ); |
---|
| 91 | |
---|
| 92 | _name.value = ''; |
---|
| 93 | _group.value = ''; |
---|
| 94 | |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | ); |
---|
| 99 | |
---|
| 100 | _config(_win_add.wc.childNodes[2].childNodes[1], |
---|
| 101 | 'onclick', |
---|
| 102 | function() |
---|
| 103 | { |
---|
| 104 | _win_add.button(_win_add.bc); |
---|
| 105 | } |
---|
| 106 | ); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | function _config(pObj, pEvent, pHandler) |
---|
| 110 | { |
---|
| 111 | if ( typeof pObj == 'object' ) |
---|
| 112 | { |
---|
| 113 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
| 114 | pEvent = pEvent.substring(2, pEvent.length); |
---|
| 115 | |
---|
| 116 | if ( pObj.addEventListener ) |
---|
| 117 | pObj.addEventListener(pEvent, pHandler, false); |
---|
| 118 | else if ( pObj.attachEvent ) |
---|
| 119 | pObj.attachEvent('on' + pEvent, pHandler); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | function _highlight(e) |
---|
| 124 | { |
---|
| 125 | var el = ( e.target ) ? e.target : e.srcElement; |
---|
| 126 | var color = "#fff"; |
---|
| 127 | if ( e.type.indexOf('mouseover') != -1 ) |
---|
| 128 | color = "#dedede"; |
---|
| 129 | el.style.backgroundColor = color; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | function _search() |
---|
| 133 | { |
---|
| 134 | var _loading = document.getElementById('__span_load_im'); |
---|
| 135 | var _target = document.getElementById('im_ldap_user'); |
---|
| 136 | |
---|
| 137 | _loading.style.display = "block"; |
---|
| 138 | |
---|
| 139 | _conn.go( |
---|
| 140 | '$this.contacts_im.list_contacts', |
---|
| 141 | function(_data) |
---|
| 142 | { |
---|
| 143 | var _params = { |
---|
| 144 | 'many_results' : jabberitGetLang('More than 50 results. Please, try to refine your search.'), |
---|
| 145 | 'empty' : jabberitGetLang('None result was found.') |
---|
| 146 | }; |
---|
| 147 | |
---|
| 148 | _target.innerHTML = _xtools.parse(_data,'list_ldap_contacts.xsl', _params); |
---|
| 149 | |
---|
| 150 | function _show(m) |
---|
| 151 | { |
---|
| 152 | m = ( m.target ) ? m.target : m.srcElement; |
---|
| 153 | if ( m.getAttribute('value')) |
---|
| 154 | m = m.getAttribute('value'); |
---|
| 155 | else |
---|
| 156 | m = m.parentNode.getAttribute('value'); |
---|
| 157 | |
---|
| 158 | if ( !m ) |
---|
| 159 | return false; |
---|
| 160 | |
---|
| 161 | document.getElementById('__span_load_im_group').style.display = 'block'; |
---|
| 162 | document.getElementById('im_jid').value = m.substr(0, m.indexOf(';')); |
---|
| 163 | document.getElementById('im_uid').value = m.substr((m.indexOf(';')+1)); |
---|
| 164 | |
---|
| 165 | var _name = document.getElementById('im_name'); |
---|
| 166 | |
---|
| 167 | var first_name = document.getElementById(m).innerHTML; |
---|
| 168 | first_name = first_name.substr(0, first_name.indexOf(' ')); |
---|
| 169 | |
---|
| 170 | _name.value = first_name; |
---|
| 171 | _name.previousSibling.style.color = "#000"; |
---|
| 172 | _name.parentNode.style.display = 'block'; |
---|
| 173 | _name.parentNode.nextSibling.style.display = 'block'; |
---|
| 174 | _name.parentNode.nextSibling.nextSibling.innerHTML = ''; |
---|
| 175 | |
---|
| 176 | _conn.go('$this.ujabber.getGroupsJabber', |
---|
| 177 | function(data) |
---|
| 178 | { |
---|
| 179 | if( data = data.replace(/(^\s*)|(\s*$)/g,'')) |
---|
| 180 | { |
---|
| 181 | var _group = document.getElementById('im_group'); |
---|
| 182 | var _groupOptions = ''; |
---|
| 183 | |
---|
| 184 | _group.setAttribute('selectBoxOptions', data); |
---|
| 185 | if( document.getElementById('selectBox0') == null) |
---|
| 186 | editS.create(document.getElementById('im_group')); |
---|
| 187 | } |
---|
| 188 | document.getElementById('__span_load_im_group').style.display = 'none'; |
---|
| 189 | }); |
---|
| 190 | |
---|
| 191 | document.getElementById('im_group').value = ''; |
---|
| 192 | document.getElementById('im_group').focus(); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | var _member = _target.firstChild; |
---|
| 196 | |
---|
| 197 | while ( _member ) |
---|
| 198 | { |
---|
| 199 | if( _member.getAttribute('photo') === '1' ) |
---|
| 200 | { |
---|
| 201 | var uid = _member.getAttribute('value'); |
---|
| 202 | uid = uid.substr(uid.indexOf(';') + 1); |
---|
| 203 | _member.style.backgroundImage = 'url(' + path_jabberit + 'inc/getphoto.php?uid=' + uid + ')'; |
---|
| 204 | } |
---|
| 205 | _config(_member, 'onclick', _show); |
---|
| 206 | |
---|
| 207 | _member = _member.nextSibling; |
---|
| 208 | } |
---|
| 209 | _loading.style.display = "none"; |
---|
| 210 | }, |
---|
| 211 | 'name='+ arguments[0] |
---|
| 212 | ); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | function LDAP() |
---|
| 216 | { |
---|
| 217 | _conn = arguments[0]; |
---|
| 218 | _xtools = arguments[1]; |
---|
| 219 | _window = arguments[2]; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | LDAP.prototype.search = _search; |
---|
| 223 | LDAP.prototype.add = _add_user; |
---|
| 224 | window.JITLdap = LDAP; |
---|
| 225 | } |
---|
| 226 | )(); |
---|
| 227 | |
---|
| 228 | function cleanStatusAddContactIM() |
---|
| 229 | { |
---|
| 230 | document.getElementById('im_status_add').innerHTML = ''; |
---|
| 231 | } |
---|