[2397] | 1 | (function() |
---|
| 2 | { |
---|
[2411] | 3 | var Xtools = null; |
---|
| 4 | var conn = null; |
---|
[2397] | 5 | |
---|
[2437] | 6 | function addContact() |
---|
[2397] | 7 | { |
---|
[2577] | 8 | if( arguments.length > 0 ) |
---|
[2471] | 9 | { |
---|
[2670] | 10 | var jidFrom = loadscript.getUserCurrent().jid; |
---|
[2577] | 11 | var jidTo = arguments[0]; |
---|
| 12 | var indexTo = arguments[1]; |
---|
| 13 | var group = ""; |
---|
| 14 | var name = jidTo.substring(0, jidTo.indexOf('@')); |
---|
| 15 | |
---|
| 16 | // Name |
---|
| 17 | if(( name = prompt("Informe um nome para " + name + "!", name ))) |
---|
| 18 | if(( name = name.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) |
---|
| 19 | name = ""; |
---|
| 20 | |
---|
| 21 | if( name == null || name == "") |
---|
| 22 | name = ""; |
---|
| 23 | |
---|
| 24 | // Group |
---|
| 25 | if((group = prompt("Informe um grupo ou deixe em branco"))) |
---|
| 26 | if(( group = group.replace(/^\s+|\s+$|^\n|\n$/g,"")) == "" ) |
---|
| 27 | group = ""; |
---|
| 28 | |
---|
| 29 | if( group == null || group == "") |
---|
| 30 | group = ""; |
---|
| 31 | |
---|
| 32 | // Remove Element html; |
---|
[2670] | 33 | loadscript.removeElement( getElement('itenContact_' + jidTo + '_' + indexTo) ); |
---|
| 34 | loadscript.removeElement( getElement('span_show_itenContact_' + jidTo + '_' + indexTo) ); |
---|
[2584] | 35 | TrophyIM.rosterObj.removeContact(jidTo); |
---|
[2471] | 36 | } |
---|
| 37 | else |
---|
[2577] | 38 | { |
---|
[2670] | 39 | var jidFrom = loadscript.getUserCurrent().jid; |
---|
[2577] | 40 | var jidTo = document.getElementById('user_jid_jabberIM').value; |
---|
| 41 | var name = document.getElementById('user_name_jabberIM').value; |
---|
| 42 | var group = document.getElementById('user_group_jabberIM').value; |
---|
| 43 | |
---|
| 44 | _winBuild('add_user_info','remove'); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | if( jidFrom != jidTo ) |
---|
[2584] | 48 | TrophyIM.addContact( jidTo, name, group ); |
---|
[2577] | 49 | else |
---|
[2471] | 50 | alert("Mesmo Usuário !"); |
---|
[2397] | 51 | } |
---|
| 52 | |
---|
[2577] | 53 | function getElement( elementId ) |
---|
| 54 | { |
---|
| 55 | return document.getElementById( elementId ); |
---|
| 56 | } |
---|
| 57 | |
---|
[2411] | 58 | function search() |
---|
| 59 | { |
---|
| 60 | var _input = document.getElementById('search_user_jabber'); |
---|
| 61 | var _span = document.getElementById('span_searching_im'); |
---|
| 62 | var _div = document.getElementById('list_users_ldap_im'); |
---|
| 63 | |
---|
| 64 | _span.style.display = "block"; |
---|
| 65 | |
---|
[2421] | 66 | if( _input.value.substring((_input.value.length-1),_input.value.length) === "*" ) |
---|
| 67 | _input.value = _input.value.substring(0, ( _input.value.length - 1 )); |
---|
| 68 | |
---|
| 69 | if( _input.value.substring(0 ,1) === "*" ) |
---|
| 70 | _input.value = _input.value.substring( 1, _input.value.length ); |
---|
| 71 | |
---|
[2411] | 72 | conn.go('p.cc.getListContacts', |
---|
| 73 | function(data) |
---|
| 74 | { |
---|
| 75 | var _paramsVar = |
---|
| 76 | { |
---|
| 77 | 'lang_addContact' : 'Adicionar Contatos', |
---|
| 78 | 'lang_empty' : 'None result was found.', |
---|
| 79 | 'lang_many_results' : 'Many results. Please, try to refine your search.' |
---|
| 80 | }; |
---|
| 81 | |
---|
| 82 | _div.innerHTML = Xtools.parse( data, 'listLdapContacts.xsl', _paramsVar ); |
---|
| 83 | |
---|
[2421] | 84 | var _newUser = _div.firstChild; |
---|
[2411] | 85 | |
---|
[2421] | 86 | while ( _newUser ) |
---|
[2411] | 87 | { |
---|
[2421] | 88 | if( _newUser.getAttribute('photo') === '1' ) |
---|
[2411] | 89 | { |
---|
[2421] | 90 | var jid = _newUser.getAttribute('jid'); |
---|
| 91 | var ou = _newUser.getAttribute('ou'); |
---|
[2471] | 92 | |
---|
| 93 | var _img_path = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date ); |
---|
[2511] | 94 | _img_path += '&photo_session=' + jid + '&ou=' + ou; |
---|
[2471] | 95 | |
---|
[2421] | 96 | _newUser.style.backgroundImage = 'url(' + _img_path + ')'; |
---|
[2411] | 97 | } |
---|
| 98 | |
---|
[2670] | 99 | loadscript.configEvents(_newUser, 'onclick', showContact); |
---|
[2411] | 100 | |
---|
[2421] | 101 | _newUser = _newUser.nextSibling; |
---|
[2411] | 102 | } |
---|
| 103 | |
---|
| 104 | _input.focus(); |
---|
| 105 | _input.value = ""; |
---|
| 106 | _span.style.display = "none"; |
---|
| 107 | |
---|
[2421] | 108 | },'name=' + _input.value ); |
---|
[2411] | 109 | } |
---|
| 110 | |
---|
[2421] | 111 | function showContact(Element) |
---|
| 112 | { |
---|
| 113 | var element = ( Element.target ) ? Element.target : Element.srcElement; |
---|
| 114 | var infoUser = null; |
---|
[2437] | 115 | var img = document.createElement('img'); |
---|
[2634] | 116 | var _groups = "Sem Grupos"; |
---|
| 117 | |
---|
| 118 | if( TrophyIM.rosterObj) |
---|
| 119 | { |
---|
| 120 | _groups = ""; |
---|
| 121 | |
---|
| 122 | for (var group in TrophyIM.rosterObj.groups) |
---|
| 123 | { |
---|
| 124 | _groups += group + ";"; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | _groups = _groups.substring(0, ( _groups.length - 1) ); |
---|
| 128 | } |
---|
[2421] | 129 | |
---|
| 130 | if( element.getAttribute('value') ) |
---|
| 131 | { |
---|
| 132 | var infoUser = |
---|
| 133 | { |
---|
| 134 | 'email' : element.getAttribute('value').substring( 0, element.getAttribute('value').indexOf(';')), |
---|
| 135 | 'jid' : element.getAttribute('jid'), |
---|
| 136 | 'lang_group' : "Grupo", |
---|
| 137 | 'lang_name_contact' : "Contato", |
---|
| 138 | 'group' : element.getAttribute('ou'), |
---|
| 139 | 'name' : element.getAttribute('name').substring( 0, element.getAttribute('name').indexOf(' ')), |
---|
[2437] | 140 | 'ou' : element.getAttribute('ou'), |
---|
[2634] | 141 | 'selectBoxOptions' : _groups, |
---|
[2421] | 142 | 'uid' : element.getAttribute('value').substring( element.getAttribute('value').indexOf(';') + 1 ) |
---|
| 143 | }; |
---|
| 144 | } |
---|
| 145 | else if( element.parentNode.getAttribute('value') ) |
---|
| 146 | { |
---|
| 147 | var infoUser = |
---|
| 148 | { |
---|
| 149 | 'email' : element.parentNode.getAttribute('value').substring( 0, element.parentNode.getAttribute('value').indexOf(';')), |
---|
| 150 | 'jid' : element.parentNode.getAttribute('jid'), |
---|
| 151 | 'lang_group' : "Grupo", |
---|
| 152 | 'lang_name_contact' : "Contato", |
---|
| 153 | 'group' : element.parentNode.getAttribute('ou'), |
---|
[2437] | 154 | 'name' : element.parentNode.getAttribute('name').substring( 0, element.parentNode.getAttribute('name').indexOf(' ')), |
---|
| 155 | 'ou' : element.parentNode.getAttribute('ou'), |
---|
[2634] | 156 | 'selectBoxOptions' : _groups, |
---|
[2421] | 157 | 'uid' : element.parentNode.getAttribute('value').substring( element.parentNode.getAttribute('value').indexOf(';') + 1) |
---|
| 158 | }; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | var winAddUser = |
---|
| 162 | { |
---|
| 163 | id_window : "add_user_info", |
---|
[2437] | 164 | width : 370, |
---|
[2634] | 165 | height : 200, |
---|
[2421] | 166 | top : 85, |
---|
| 167 | left : 220, |
---|
| 168 | draggable : true, |
---|
| 169 | visible : "display", |
---|
| 170 | resizable : true, |
---|
[2670] | 171 | zindex : loadscript.getZIndex(), |
---|
[2421] | 172 | title : 'Expresso Messenger - Add Contact', |
---|
| 173 | closeAction : "remove", |
---|
| 174 | content : Xtools.parse( Xtools.xml('adduser'), 'addUser.xsl', infoUser ) |
---|
| 175 | }; |
---|
| 176 | |
---|
| 177 | _winBuild( winAddUser ); |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | var _pButtons = |
---|
| 181 | { |
---|
| 182 | 'lang1' : 'Adicionar', |
---|
| 183 | 'lang2' : 'Fechar', |
---|
| 184 | 'onclickClose' : '_winBuild("' + winAddUser.id_window + '","remove");', |
---|
[2670] | 185 | 'onclickSubmit' : 'loadscript.addContact(this);' |
---|
[2421] | 186 | }; |
---|
| 187 | |
---|
[2437] | 188 | // Add Buttons |
---|
| 189 | document.getElementById('buttons_adduser').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons); |
---|
| 190 | |
---|
| 191 | // Select Editable |
---|
[2670] | 192 | loadscript.setSelectEditable(document.getElementById('user_group_jabberIM')); |
---|
[2437] | 193 | |
---|
[2634] | 194 | // Load Photo; |
---|
| 195 | var _img = null; |
---|
| 196 | |
---|
[2437] | 197 | if( element.style.backgroundImage ) |
---|
[2634] | 198 | _img = element.cloneNode( false ); |
---|
| 199 | |
---|
| 200 | if( element.parentNode.style.backgroundImage ) |
---|
| 201 | _img = element.parentNode.cloneNode( false ); |
---|
| 202 | |
---|
| 203 | if( _img != null ) |
---|
[2437] | 204 | { |
---|
| 205 | _img.style.width = '60px'; |
---|
| 206 | _img.style.height = '80px'; |
---|
| 207 | _img.style.display = 'block'; |
---|
| 208 | _img.style.backgroundRepeat = 'no-repeat'; |
---|
[2634] | 209 | |
---|
[2437] | 210 | } |
---|
| 211 | else |
---|
| 212 | { |
---|
[2634] | 213 | _img = document.createElement("img"); |
---|
[2437] | 214 | _img.style.width = '60px'; |
---|
| 215 | _img.style.height = '80px'; |
---|
| 216 | _img.style.display = 'block'; |
---|
| 217 | _img.src = path_jabberit + "templates/default/images/photo.png"; |
---|
| 218 | } |
---|
| 219 | |
---|
[2634] | 220 | |
---|
[2437] | 221 | with ( document.getElementById('photo_user_ldap_jabber') ) |
---|
| 222 | { |
---|
| 223 | if( hasChildNodes( ) ) |
---|
| 224 | while( hasChildNodes( ) ) |
---|
| 225 | { |
---|
| 226 | removeNode( firstChild ); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | appendChild( _img ); |
---|
| 230 | } |
---|
[2421] | 231 | } |
---|
| 232 | |
---|
[2397] | 233 | function showForm() |
---|
| 234 | { |
---|
[2641] | 235 | |
---|
[2397] | 236 | var _paramsWindAddUser = |
---|
| 237 | { |
---|
[2411] | 238 | 'lang_group' : 'Grupo', |
---|
| 239 | 'lang_load' : 'Carregando', |
---|
| 240 | 'lang_name_contact' : 'Nome do Contato', |
---|
| 241 | 'lang_result' : 'Resultado da Busca', |
---|
| 242 | 'path' : path_jabberit |
---|
[2397] | 243 | }; |
---|
| 244 | |
---|
| 245 | var windAddUser = |
---|
| 246 | { |
---|
| 247 | id_window : "add_user_im", |
---|
| 248 | width : 440, |
---|
| 249 | height : 350, |
---|
| 250 | top : 80, |
---|
| 251 | left : 200, |
---|
| 252 | draggable : true, |
---|
| 253 | visible : "display", |
---|
| 254 | resizable : true, |
---|
[2670] | 255 | zindex : loadscript.getZIndex(), |
---|
[2397] | 256 | title : 'Expresso Messenger - Search users', |
---|
| 257 | closeAction : "remove", |
---|
| 258 | content : Xtools.parse( Xtools.xml('userinfo'), 'addUser.xsl', _paramsWindAddUser ) |
---|
| 259 | }; |
---|
| 260 | |
---|
| 261 | _winBuild( windAddUser ); |
---|
[2437] | 262 | |
---|
[2397] | 263 | } |
---|
| 264 | |
---|
| 265 | function loadAddUser() |
---|
| 266 | { |
---|
| 267 | if( arguments.length > 0 ) |
---|
| 268 | { |
---|
[2411] | 269 | Xtools = arguments[0]; |
---|
| 270 | conn = arguments[1]; |
---|
[2397] | 271 | } |
---|
| 272 | } |
---|
| 273 | |
---|
[2437] | 274 | loadAddUser.prototype.add = addContact; |
---|
[2411] | 275 | loadAddUser.prototype.search = search; |
---|
[2397] | 276 | loadAddUser.prototype.show = showForm; |
---|
[2411] | 277 | |
---|
[2397] | 278 | window.addUserIM = loadAddUser; |
---|
| 279 | })(); |
---|