[2] | 1 | function emQuickCatalogSearch () |
---|
| 2 | { |
---|
| 3 | this.arrayWin = new Array(); |
---|
| 4 | this.el; |
---|
| 5 | this.cc_contacts = new Array(); |
---|
| 6 | this.cc_groups = new Array(); |
---|
| 7 | } |
---|
[5231] | 8 | |
---|
| 9 | $(document).ready(function(){ |
---|
| 10 | $('#combobox option').each(function(){ |
---|
| 11 | if($(this).val() == preferences.catalog_search){ |
---|
| 12 | $(this).attr('selected',true); |
---|
| 13 | } |
---|
| 14 | }); |
---|
| 15 | }); |
---|
[5134] | 16 | /* showlist */ |
---|
[5075] | 17 | emQuickCatalogSearch.prototype.showList = function(data, begin, end, ID, field) |
---|
| 18 | { |
---|
[5172] | 19 | data_ = data; |
---|
| 20 | id_ = ID; |
---|
| 21 | field_ = field; |
---|
| 22 | begin_ = begin; |
---|
| 23 | end_ = end; |
---|
[2] | 24 | |
---|
[5172] | 25 | keypress_read(data); |
---|
| 26 | configure_slider(data); |
---|
[5134] | 27 | create_list(data, true); |
---|
[5172] | 28 | details_results(data); |
---|
| 29 | |
---|
[5404] | 30 | this.showWindow(); |
---|
[5075] | 31 | } |
---|
[5172] | 32 | |
---|
| 33 | |
---|
[5134] | 34 | /* Leitura das teclas de atalho */ |
---|
| 35 | function keypress_read(data) { |
---|
[5172] | 36 | $("#dialog-modal").unbind('keydown').keydown(function (e) { |
---|
[5134] | 37 | var keyCode = e.keyCode; |
---|
[5172] | 38 | arrow = {left: 37, up: 38, right: 39, down: 40, enter: 13, esc: 27, space: 32}; |
---|
| 39 | var slider = $( "#slider" ); |
---|
[5075] | 40 | switch (keyCode) |
---|
| 41 | { |
---|
[5172] | 42 | case arrow.enter: |
---|
[5134] | 43 | if(!search_focus){ |
---|
| 44 | i = $(".ui-selected:last").attr("value") + 1; |
---|
[5172] | 45 | if($("#actions_"+i).clone().find(".ui-button-text").text() == '+') |
---|
| 46 | add_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i); |
---|
| 47 | else{ |
---|
| 48 | remove_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i); |
---|
| 49 | } |
---|
[5134] | 50 | document.getElementById("busca").value = ""; |
---|
[5395] | 51 | //Evita que o campo "para" receba o enter |
---|
| 52 | e.preventDefault(); |
---|
[5172] | 53 | $("#dialog-modal").dialog("close"); |
---|
[5134] | 54 | } |
---|
[5402] | 55 | if (is_webkit){ |
---|
| 56 | //Posiciona o cursor no final do texto no Chrome |
---|
| 57 | var txt_area = document.getElementById('to_'+id_); |
---|
| 58 | var len = txt_area.value.length; |
---|
| 59 | txt_area.setSelectionRange(len, len); |
---|
| 60 | } |
---|
[5075] | 61 | break; |
---|
| 62 | case arrow.left: |
---|
[5172] | 63 | if(!search_focus){ |
---|
| 64 | slider.slider("value", $( "#slider" ).slider( "value" ) - 1); |
---|
| 65 | create_list(data_, false); |
---|
| 66 | } |
---|
[5075] | 67 | break; |
---|
| 68 | case arrow.right: |
---|
[5172] | 69 | if(!search_focus){ |
---|
| 70 | if((($( "#slider" ).slider( "value" ))) == Math.ceil(data_.length/6)) |
---|
| 71 | break; |
---|
| 72 | slider.slider( "value", $( "#slider" ).slider( "value" ) + 1); |
---|
| 73 | create_list(data_, false); |
---|
| 74 | } |
---|
[5075] | 75 | break; |
---|
| 76 | case arrow.up: |
---|
[5172] | 77 | if(!search_focus){ |
---|
| 78 | show_detail(data_, "up"); |
---|
| 79 | } |
---|
[5134] | 80 | break; |
---|
| 81 | case arrow.down: |
---|
[5172] | 82 | if(!search_focus){ |
---|
| 83 | show_detail(data_, "down"); |
---|
| 84 | } |
---|
| 85 | break; |
---|
| 86 | case arrow.space: |
---|
| 87 | |
---|
| 88 | if(!search_focus){ |
---|
| 89 | i = $(".ui-selected:last").attr("value") + 1; |
---|
| 90 | if($("#actions_"+i).clone().find(".ui-button-text").text() == '+') |
---|
| 91 | { |
---|
| 92 | add_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i); |
---|
| 93 | }else{ |
---|
| 94 | remove_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i); |
---|
| 95 | } |
---|
| 96 | document.getElementById("busca").value = ""; |
---|
| 97 | } |
---|
| 98 | break; |
---|
| 99 | } |
---|
[5134] | 100 | }); |
---|
[5172] | 101 | } |
---|
[5134] | 102 | |
---|
| 103 | |
---|
| 104 | /* Mostra os detalhes do contato selecionado */ |
---|
| 105 | function show_detail(data_, direction) { |
---|
| 106 | id_contact = $(".ui-selected:last").attr("value"); |
---|
| 107 | if(direction == "down") { |
---|
| 108 | if((id_contact == (((((parseInt($( "#slider" ).slider( "value" )) - 1)*6))+6)-1)) || id_contact == data_.length - 1 || data_.length == 1) |
---|
| 109 | return; |
---|
| 110 | var line_contact = $('li.ui-selected'); |
---|
| 111 | $('li.ui-selected').next().addClass("ui-selected"); |
---|
| 112 | id_contact++; |
---|
[5172] | 113 | } |
---|
[5134] | 114 | else { |
---|
| 115 | if(id_contact == (($( "#slider" ).slider( "value" ) -1)*6)) |
---|
| 116 | return; |
---|
| 117 | var line_contact = $('li.ui-selected'); |
---|
| 118 | $('li.ui-selected').prev().addClass("ui-selected"); |
---|
| 119 | id_contact--; |
---|
[5172] | 120 | } |
---|
[5134] | 121 | line_contact.removeClass("ui-selected").addClass("ui-selectee"); |
---|
[5172] | 122 | var details = $("#detalhes_contato").empty(); |
---|
[5134] | 123 | switch(data_['type_catalog']) { |
---|
| 124 | case 'G': |
---|
[5456] | 125 | if(data['extra_ldap_fields'].length != 0) |
---|
| 126 | var extra_fields = (data['extra_ldap_fields']).split("#"); |
---|
| 127 | else |
---|
| 128 | var extra_fields = []; |
---|
[5134] | 129 | if(preferences.default_fields_quick_search != 0) { |
---|
| 130 | details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn[0]) + "</label>" + '<span class="value">' + data_[id_contact].mail[0] + '</span></p>'); |
---|
[5201] | 131 | if(data_[id_contact].telephonenumber[0] != null) |
---|
| 132 | details.append('<p><label class="attribute">Telefone </label>' + '<span class="value">' + data_[id_contact].telephonenumber[0] + '</span></p>'); |
---|
[5172] | 133 | } |
---|
[5134] | 134 | for (var i=0; i<=extra_fields.length-1; i++) |
---|
[5172] | 135 | { |
---|
| 136 | var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1); |
---|
| 137 | var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|"))); |
---|
[5134] | 138 | if(data_[id_contact][valor.toLowerCase()] != undefined) { |
---|
| 139 | var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ; |
---|
| 140 | for(j=0; j<data_[id_contact][valor.toLowerCase()].length; j++) { |
---|
| 141 | details.append(tmp_campo + '<span class="value">' + data_[id_contact][valor.toLowerCase()][j] + "</span></p>"); |
---|
| 142 | tmp_campo = ""; |
---|
[5172] | 143 | } |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | break; |
---|
[5134] | 147 | case 'P': |
---|
[5172] | 148 | if(utf8_decoder(data_[id_contact].cn) == 'undefined') |
---|
| 149 | details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].title) + '</label>' + '<span class="value">' + data_[id_contact].short_name + '</span></p>'); |
---|
| 150 | else |
---|
| 151 | details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn) + '</label>' + '<span class="value">' + data_[id_contact].mail + '</span></p>'); |
---|
[5134] | 152 | if(data_[id_contact].telephonenumber != null) |
---|
| 153 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data_[id_contact].telephonenumber + '</span></p>'); |
---|
[5172] | 154 | break; |
---|
[5134] | 155 | default: |
---|
[5456] | 156 | if(data['extra_ldap_fields'].length != 0) |
---|
| 157 | var extra_fields = (data['extra_ldap_fields']).split("#"); |
---|
| 158 | else |
---|
| 159 | var extra_fields = []; |
---|
[5134] | 160 | if(preferences.default_fields_quick_search != 0 || data_[id_contact].type_contact == "P") { |
---|
[5172] | 161 | if(utf8_decoder(data_[id_contact].cn) == 'undefined') |
---|
| 162 | details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].title) + '</label>' + '<span class="value">' + data_[id_contact].short_name + '</span></p>'); |
---|
| 163 | else |
---|
| 164 | details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn) + '</label>' + '<span class="value">' + data_[id_contact].mail + '</span></p>'); |
---|
[5134] | 165 | if(data_[id_contact].telephonenumber != null) |
---|
| 166 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data_[id_contact].telephonenumber + '</span></p>'); |
---|
[5172] | 167 | } |
---|
| 168 | if(data_[id_contact].mail[0] == 'undefined') |
---|
| 169 | break; |
---|
[5134] | 170 | if(data_[id_contact].mail[0].length > 1) { |
---|
| 171 | for (var i=0; i<=extra_fields.length-1; i++) { |
---|
[5172] | 172 | var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1); |
---|
| 173 | var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|"))); |
---|
[5134] | 174 | if(data_[id_contact][valor.toLowerCase()] != undefined) { |
---|
| 175 | var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ; |
---|
| 176 | for(j=0; j<data_[id_contact][valor.toLowerCase()].length; j++) { |
---|
| 177 | details.append(tmp_campo + '<span class="value">' + data_[id_contact][valor.toLowerCase()][j] + "</span></p>"); |
---|
| 178 | tmp_campo = ""; |
---|
[5172] | 179 | } |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | break; |
---|
| 184 | } |
---|
[5075] | 185 | } |
---|
[5172] | 186 | |
---|
[3718] | 187 | |
---|
[5172] | 188 | /* |
---|
| 189 | * Método que cria a lista de contatos |
---|
| 190 | */ |
---|
[5134] | 191 | function create_list(data, begin, uiValue) { |
---|
| 192 | var sliderValue = 1; |
---|
| 193 | if(typeof($( "#slider" ).slider( "value" )) != "object") |
---|
| 194 | sliderValue = $( "#slider" ).slider( "value" ); |
---|
| 195 | if(uiValue) |
---|
| 196 | sliderValue = uiValue; |
---|
[5172] | 197 | $("#detalhes_contato").empty(); |
---|
[5134] | 198 | var paginas = Math.ceil(data.length/6); |
---|
[5172] | 199 | $("#title_usuarios").html( get_lang("Results") ); |
---|
| 200 | var selectable = $("#selectable"); |
---|
| 201 | selectable.empty(); |
---|
| 202 | var acento = data.search_for; |
---|
| 203 | var Ul = document.createElement("ul"); |
---|
| 204 | var caracteresInvalidos = 'àèìòùâêîôûäëïöüáéíóúãõÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÁÉÍÓÚÃÕ'; |
---|
| 205 | var caracteresValidos = 'aeiouaeiouaeiouaeiouaoAEIOUAEIOUAEIOUAEIOUAO'; |
---|
| 206 | |
---|
| 207 | var i = new Number(); |
---|
| 208 | var j = new Number(); |
---|
| 209 | var cString = new String(); |
---|
| 210 | var varRes = ''; |
---|
| 211 | |
---|
| 212 | for (i = 0; i < data.search_for.length; i++) { |
---|
| 213 | cString = data.search_for.substring(i, i + 1); |
---|
| 214 | for (j = 0; j < caracteresInvalidos.length; j++) { |
---|
| 215 | if (caracteresInvalidos.substring(j, j + 1) == cString){ |
---|
| 216 | cString = caracteresValidos.substring(j, j + 1); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | varRes += cString; |
---|
| 220 | } |
---|
| 221 | data.search_for = varRes; |
---|
| 222 | |
---|
[5134] | 223 | for (i=((sliderValue -1)*6)+1; i<(((sliderValue -1)*6)+1)+6; i++) { |
---|
[5172] | 224 | var Op = document.createElement("li"); |
---|
[5134] | 225 | if(i > data.length) |
---|
[5172] | 226 | break; |
---|
| 227 | if (data['type_catalog'] != 'G' && (data[i-1].mail == null || data[i-1].mail == "")) |
---|
| 228 | data[i-1].mail = get_lang("No mail"); |
---|
[5134] | 229 | |
---|
| 230 | if(i == (((sliderValue -1)*6)+1)) { |
---|
[5172] | 231 | Op.setAttribute("class", "ui-selected"); |
---|
[5134] | 232 | Op.setAttribute("className", "ui-selected"); |
---|
[5172] | 233 | } |
---|
| 234 | else { |
---|
| 235 | Op.setAttribute("class", "ui-selectee"); |
---|
[5134] | 236 | Op.setAttribute("className", "ui-selectee"); |
---|
[5172] | 237 | } |
---|
| 238 | var contact_name = utf8_decoder(data[i-1].cn); |
---|
| 239 | if(contact_name == 'undefined'){ |
---|
| 240 | contact_name = utf8_decoder(data[i-1].title); |
---|
| 241 | if(contact_name != 'undefined'){ |
---|
| 242 | data[i-1].mail = data[i-1].short_name; |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | var exist = "add_contact_field"; |
---|
| 246 | var signal = "+"; |
---|
| 247 | var btnClass = "add"; |
---|
| 248 | var emailList = $("#" + field_ + "_" + id_).val(); |
---|
| 249 | var emails_adicionados = emailList.split(","); |
---|
| 250 | for(aux=0; aux<emails_adicionados.length -1; aux++) { |
---|
[5258] | 251 | if(emails_adicionados[aux].match(/<([^<]*)>[\s]*$/)){ |
---|
| 252 | if(emails_adicionados[aux].match(/<([^<]*)>[\s]*$/)[1].toLowerCase() == (utf8_decoder(data[i-1].mail)).toLowerCase()){ |
---|
| 253 | emails_adicionados[aux] = "%"; |
---|
| 254 | exist = "remove_contact_field"; |
---|
| 255 | signal = "x"; |
---|
| 256 | btnClass = "remove"; |
---|
| 257 | } |
---|
| 258 | }else{ |
---|
| 259 | if(emails_adicionados[aux].toLowerCase() == (utf8_decoder(data[i-1].mail)).toLowerCase()){ |
---|
| 260 | emails_adicionados[aux] = "%"; |
---|
| 261 | exist = "remove_contact_field"; |
---|
| 262 | signal = "x"; |
---|
| 263 | btnClass = "remove"; |
---|
| 264 | } |
---|
[5172] | 265 | } |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | if(contact_name.toLowerCase().indexOf(acento.toLowerCase()) != -1 && acento.indexOf(" ") == -1 && acento.indexOf("@") == -1) |
---|
| 269 | contact_name = contact_name.substring(0, contact_name.toLowerCase().indexOf(acento.toLowerCase())) + "<u>" + contact_name.substr(contact_name.toLowerCase().indexOf(acento.toLowerCase()), acento.length) + "</u>" + contact_name.substring(contact_name.toLowerCase().indexOf(acento.toLowerCase()) + acento.length); |
---|
| 270 | else if(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()) != -1 && data.search_for.indexOf(" ") == -1 && data.search_for.indexOf("@") == -1) |
---|
| 271 | contact_name = contact_name.substring(0, contact_name.toLowerCase().indexOf(data.search_for.toLowerCase())) + "<u>" + contact_name.substr(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()), data.search_for.length) + "</u>" + contact_name.substring(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()) + data.search_for.length); |
---|
| 272 | var line = '<span class="menu-control"><button class="'+btnClass+'" id="actions_'+i+'" onClick="'+exist+'(document.getElementById(\'contact_' + i + '\').innerHTML, this, \'contact_' + i + '\')">'+ signal +'</button></span><div id="contact_' + i + '" onDblClick="'+exist+'(this.innerHTML, document.getElementById(\'actions_'+i+'\'), \'contact_' + i + '\')"><div class="name_contact"><strong class="name">' + contact_name + '</strong><em class="email">' + utf8_decoder(data[i-1].mail) + '</em></div></div>'; |
---|
| 273 | Op.innerHTML = line; |
---|
| 274 | $(Op).val(i - 1); |
---|
[5134] | 275 | selectable.append(Op); |
---|
[5172] | 276 | $("#contact_"+i).click(function(){ |
---|
| 277 | document.getElementById("amount-text").focus(); |
---|
| 278 | }); |
---|
| 279 | } |
---|
[5134] | 280 | selectable.append(Ul); |
---|
| 281 | var first_contact; |
---|
| 282 | begin ? first_contact = 0 : first_contact = ((sliderValue* 6) -6); |
---|
[5172] | 283 | var details = $("#detalhes_contato").empty(); |
---|
| 284 | |
---|
[5134] | 285 | switch (data['type_catalog']) { |
---|
| 286 | case 'G': |
---|
[5456] | 287 | if(data['extra_ldap_fields'].length != 0) |
---|
| 288 | var extra_fields = (data['extra_ldap_fields']).split("#"); |
---|
| 289 | else |
---|
| 290 | var extra_fields = []; |
---|
[5134] | 291 | if(preferences.default_fields_quick_search != 0) { |
---|
| 292 | details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].cn[0]) + "</label>" + '<span class="value">' + data[first_contact].mail[0] + "</span></p>"); |
---|
| 293 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[first_contact].telephonenumber[0] + '</span></p>'); |
---|
[5456] | 294 | } |
---|
[5134] | 295 | for (var i=0; i<=extra_fields.length-1; i++) { |
---|
| 296 | var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1); |
---|
| 297 | var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|"))); |
---|
| 298 | if(data[0][valor.toLowerCase()] != undefined) |
---|
| 299 | { |
---|
| 300 | var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ; |
---|
| 301 | for(j=0; j<data[first_contact][valor.toLowerCase()].length; j++) { |
---|
[5251] | 302 | details.append(tmp_campo + '<span class="value">' + utf8_decoder(data[first_contact][valor.toLowerCase()][j]) + "</span></p>"); |
---|
[5134] | 303 | tmp_campo = ""; |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | break; |
---|
| 308 | case 'P': |
---|
[5172] | 309 | if(utf8_decoder(data[first_contact].cn) != 'undefined') |
---|
| 310 | details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].cn) + '</label>' + '<span class="value">' + data[first_contact].mail + '</span></p>'); |
---|
| 311 | else |
---|
| 312 | details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].title) + '</label>' + '<span class="value">' + data[first_contact].short_name + '</span></p>'); |
---|
[5134] | 313 | if(data[first_contact].telephonenumber != null) |
---|
| 314 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[first_contact].telephonenumber + '</span></p>'); |
---|
| 315 | break; |
---|
[5456] | 316 | default: |
---|
| 317 | if(data['extra_ldap_fields'].length != 0) |
---|
| 318 | var extra_fields = (data['extra_ldap_fields']).split("#"); |
---|
| 319 | else |
---|
| 320 | var extra_fields = []; |
---|
[5134] | 321 | if(preferences.default_fields_quick_search != 0 || data[first_contact].type_contact == "P") { |
---|
[5172] | 322 | if(utf8_decoder(data[first_contact].cn) != 'undefined') |
---|
| 323 | details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].cn) + '</label>' + '<span class="value">' + data[first_contact].mail + '</span></p>'); |
---|
| 324 | else |
---|
| 325 | details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].title) + '</label>' + '<span class="value">' + data[first_contact].short_name + '</span></p>'); |
---|
[5134] | 326 | if(data[first_contact].telephonenumber != null) |
---|
| 327 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[first_contact].telephonenumber + "</span></p>"); |
---|
| 328 | } |
---|
[5251] | 329 | if( data[first_contact].type_contact == "G") { |
---|
| 330 | if(data[first_contact].mail[0].length > 1) { |
---|
[5134] | 331 | for (var i=0; i<=extra_fields.length-1; i++) { |
---|
| 332 | var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1); |
---|
| 333 | var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|"))); |
---|
| 334 | if(data[first_contact][valor.toLowerCase()] != undefined) { |
---|
| 335 | var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ; |
---|
| 336 | for(j=0; j<data[first_contact][valor.toLowerCase()].length; j++) { |
---|
[5251] | 337 | details.append(tmp_campo + '<span class="value">' + utf8_decoder(data[first_contact][valor.toLowerCase()][j]) + "</span></p>"); |
---|
[5134] | 338 | tmp_campo = ""; |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | } |
---|
| 344 | break; |
---|
| 345 | } |
---|
| 346 | var string_results = sliderValue + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")"; |
---|
| 347 | $( "#amount-text" ).val( string_results ); |
---|
| 348 | $("button").button(); |
---|
[5172] | 349 | //$("button.remove").button({icons:{primary:"ui-icon-close"}, text: false}); |
---|
| 350 | //$("button.add").button({icons:{primary:"ui-icon-plus"}, text: false}); |
---|
[5134] | 351 | if(!is_ie) |
---|
| 352 | document.getElementById("amount-text").focus(); |
---|
[5172] | 353 | $("#selectable li:first").focus(); |
---|
[5134] | 354 | removeFocus(); |
---|
[5172] | 355 | } |
---|
[3305] | 356 | |
---|
[5075] | 357 | |
---|
[5134] | 358 | /* Método que configura os detalhes do resultado da busca */ |
---|
| 359 | function details_results(data) { |
---|
[5172] | 360 | $(function() { |
---|
| 361 | $( "#selectable" ).selectable({ |
---|
| 362 | stop: function() { |
---|
| 363 | var details = $("#detalhes_contato").empty(); |
---|
| 364 | $( ".ui-selected", this ).each(function() { |
---|
| 365 | if(data.length > 0){ |
---|
| 366 | switch(data['type_catalog']) { |
---|
| 367 | case 'G': |
---|
[5456] | 368 | if(data['extra_ldap_fields'].length != 0) |
---|
| 369 | var extra_fields = (data['extra_ldap_fields']).split("#"); |
---|
| 370 | else |
---|
| 371 | var extra_fields = []; |
---|
[5172] | 372 | if(preferences.default_fields_quick_search != 0) { |
---|
| 373 | details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn[0]) + "</label>" + '<span class="value">' + data[this.value].mail[0] + "</span></p>"); |
---|
| 374 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber[0] + "</span></p>"); |
---|
| 375 | } |
---|
[5134] | 376 | for (var i=0; i<=extra_fields.length-1; i++) { |
---|
[5172] | 377 | var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1); |
---|
| 378 | var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|"))); |
---|
[5134] | 379 | if(data[this.value][valor.toLowerCase()] != undefined) { |
---|
| 380 | var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ; |
---|
| 381 | for(j=0; j<data[this.value][valor.toLowerCase()].length; j++) { |
---|
[5251] | 382 | details.append(tmp_campo + '<span class="value">' + utf8_decoder(data[this.value][valor.toLowerCase()][j]) + "</span></p>"); |
---|
[5134] | 383 | tmp_campo = ""; |
---|
[5172] | 384 | } |
---|
| 385 | } |
---|
| 386 | } |
---|
| 387 | break; |
---|
| 388 | case 'P': |
---|
| 389 | if(utf8_decoder(data[this.value].cn) == 'undefined') |
---|
| 390 | details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].title) + "</label>" + '<span class="value">' + data[this.value].short_name + "</span></p>"); |
---|
| 391 | else |
---|
| 392 | details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn) + "</label>" + '<span class="value">' + data[this.value].mail + "</span></p>"); |
---|
| 393 | if(data[this.value].telephonenumber != null) |
---|
| 394 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber + "</span></p>"); |
---|
| 395 | break; |
---|
| 396 | default: |
---|
[5456] | 397 | if(data['extra_ldap_fields'].length != 0) |
---|
| 398 | var extra_fields = (data['extra_ldap_fields']).split("#"); |
---|
| 399 | else |
---|
| 400 | var extra_fields = []; |
---|
[5172] | 401 | if(preferences.default_fields_quick_search != 0 || data[this.value].type_contact == "P") { |
---|
| 402 | if(utf8_decoder(data[this.value].cn) == 'undefined') |
---|
| 403 | details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].title) + "</label>" + '<span class="value">' + data[this.value].short_name + "</span></p>"); |
---|
| 404 | else |
---|
| 405 | details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn) + "</label>" + '<span class="value">' + data[this.value].mail + "</span></p>"); |
---|
| 406 | if(data[this.value].telephonenumber != null) |
---|
| 407 | details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber + "</span></p>"); |
---|
| 408 | } |
---|
| 409 | if(data[this.value].mail[0] == 'undefined') |
---|
| 410 | break; |
---|
| 411 | if(data[this.value].mail[0] != get_lang("No mail")) { |
---|
| 412 | if(data[this.value].mail[0].length > 1) { |
---|
| 413 | for (var i=0; i<=extra_fields.length-1; i++) { |
---|
| 414 | var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1); |
---|
| 415 | var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|"))); |
---|
| 416 | if(data[this.value][valor.toLowerCase()] != undefined) { |
---|
| 417 | var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ; |
---|
| 418 | for(j=0; j<data[this.value][valor.toLowerCase()].length; j++) { |
---|
[5251] | 419 | details.append(tmp_campo + '<span class="value">' + utf8_decoder(data[this.value][valor.toLowerCase()][j]) + "</span></p>"); |
---|
[5172] | 420 | tmp_campo = ""; |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | break; |
---|
| 427 | } |
---|
[5075] | 428 | } |
---|
[5172] | 429 | }); |
---|
| 430 | } |
---|
| 431 | }); |
---|
| 432 | }); |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | |
---|
| 436 | /* |
---|
| 437 | * Método que configura o slider e os resultados |
---|
| 438 | */ |
---|
[5134] | 439 | function configure_slider(data) { |
---|
| 440 | var paginas = (Math.ceil(data.length/6)); |
---|
[5172] | 441 | $("#title_usuarios").html( get_lang("Results") ); |
---|
| 442 | $(function() { |
---|
| 443 | $( "#slider" ).slider({ |
---|
| 444 | value:1, |
---|
| 445 | min: 1, |
---|
| 446 | max: paginas, |
---|
| 447 | step: 1, |
---|
[5134] | 448 | slide: function( event, ui ) { |
---|
| 449 | create_list(data, false, ui.value); |
---|
[5172] | 450 | var string_results = ui.value + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")"; |
---|
[5134] | 451 | $( "#amount-text" ).val( string_results ); |
---|
[5172] | 452 | } |
---|
| 453 | }); |
---|
[5134] | 454 | $("#selectable li:first button:first").focus(); |
---|
[5172] | 455 | }); |
---|
| 456 | } |
---|
[5075] | 457 | |
---|
[5134] | 458 | var search_focus = false; |
---|
[5172] | 459 | |
---|
[5134] | 460 | function setFocus() {search_focus = true;return;} |
---|
[5172] | 461 | |
---|
[5134] | 462 | function removeFocus() {search_focus = false;return;} |
---|
| 463 | |
---|
| 464 | function checkEnter(e) { |
---|
[5172] | 465 | var kC = window.event ? event.keyCode : |
---|
| 466 | e && e.keyCode ? e.keyCode : |
---|
| 467 | e && e.which ? e.which : null; |
---|
[5134] | 468 | if (kC) |
---|
[5172] | 469 | return kC == 13; |
---|
[5134] | 470 | else |
---|
[5172] | 471 | return false; |
---|
| 472 | } |
---|
[5075] | 473 | |
---|
[5172] | 474 | |
---|
| 475 | /* |
---|
| 476 | * Faz a busca direto da tela modal |
---|
| 477 | */ |
---|
[5134] | 478 | function buscaContato(param) { |
---|
| 479 | $("#busca, #detalhes_contato, #selectable").empty(); |
---|
| 480 | if(param.length == 0) { |
---|
| 481 | alert(get_lang("Please enter a parameter to search")); |
---|
| 482 | return; |
---|
[5172] | 483 | } |
---|
[5134] | 484 | if(param.length < preferences.search_characters_number) { |
---|
[5172] | 485 | alert(get_lang("parameter must be at least") + " " + preferences.search_characters_number + " " + get_lang("characters")); |
---|
| 486 | return false; |
---|
| 487 | } |
---|
| 488 | var catalog = $("#combobox").val(); |
---|
| 489 | var handler_emQuickSearch = function(data) { |
---|
| 490 | data_ = data; |
---|
| 491 | if(data_.length > 0) { |
---|
| 492 | configure_slider(data_); |
---|
| 493 | create_list(data, true); |
---|
| 494 | details_results(data_); |
---|
[5075] | 495 | } |
---|
[5134] | 496 | else { |
---|
[5172] | 497 | $("#detalhes_contato, #selectable").empty(); |
---|
| 498 | var selectable = $("#selectable"); |
---|
| 499 | var Ul = document.createElement("ul"); |
---|
| 500 | Ul.onclick = function(){ |
---|
| 501 | }; |
---|
| 502 | var Op = document.createElement("li"); |
---|
| 503 | Op.innerHTML = '<span class="menu-control"></span><div id="no_results"><div class="name_contact"><strong class="name">Nenhum Resultado Encontrado</strong></div></div>'; |
---|
| 504 | selectable.append(Op); |
---|
| 505 | selectable.append(Ul); |
---|
| 506 | var string_results = "0 " + get_lang("of") + " 0 (0 " + get_lang("Results") + ")"; |
---|
| 507 | $( "#amount-text" ).val( string_results ); |
---|
| 508 | details_results(data); |
---|
| 509 | configure_slider(data); |
---|
[5075] | 510 | } |
---|
| 511 | } |
---|
[5172] | 512 | cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+param+"&field=TO&ID=0&catalog="+catalog, handler_emQuickSearch); |
---|
| 513 | } |
---|
[5075] | 514 | |
---|
[5172] | 515 | function verifyEmails(emailAux, contato) { |
---|
| 516 | var contact_id = contato.split("_"); |
---|
| 517 | if(contact_id[1] != 0) |
---|
| 518 | { |
---|
| 519 | var ini = parseInt((contact_id[1]/6).toFixed(0)); |
---|
| 520 | if(ini != 0 && ini != 1){ |
---|
| 521 | ini = ini * 6; |
---|
| 522 | var fim = ini+1; |
---|
| 523 | } |
---|
| 524 | else{ |
---|
| 525 | ini = 1; |
---|
| 526 | var fim = ini; |
---|
| 527 | } |
---|
| 528 | fim = fim +5; |
---|
| 529 | var contact2 = ""; |
---|
| 530 | for(aux = ini; aux <= fim; aux++){ |
---|
| 531 | if(contact_id[1] != aux){ |
---|
| 532 | if($("#"+contact_id[0]+"_"+aux).find('.email').text() == emailAux){ |
---|
| 533 | contact2 = contact_id[0]+"_"+aux; |
---|
| 534 | var button = document.getElementById("actions_"+aux); |
---|
| 535 | var div = document.getElementById(contact2); |
---|
| 536 | if($("#actions_"+aux).find('.ui-button-text').text() == '+'){ |
---|
| 537 | button.onclick = function(){ |
---|
| 538 | remove_contact_field(div.innerHTML, button, contact2); |
---|
| 539 | }; |
---|
| 540 | div.ondblclick = function(){ |
---|
| 541 | remove_contact_field(div.innerHTML, button, contact2); |
---|
| 542 | }; |
---|
| 543 | $("#actions_"+aux).find('.ui-button-text').text('x'); |
---|
| 544 | } |
---|
| 545 | else{ |
---|
| 546 | button.onclick = function(){ |
---|
| 547 | add_contact_field(div.innerHTML, button, contact2); |
---|
| 548 | }; |
---|
| 549 | div.ondblclick = function(){ |
---|
| 550 | add_contact_field(div.innerHTML, button, contact2); |
---|
| 551 | }; |
---|
| 552 | $("#actions_"+aux).find('.ui-button-text').text('+'); |
---|
| 553 | } |
---|
| 554 | } |
---|
| 555 | } |
---|
| 556 | } |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | /* |
---|
| 560 | * Método que adiciona o contato selecionado no campo do email (To, CC, CCo) |
---|
| 561 | */ |
---|
| 562 | function add_contact_field(contact, button, divs) { |
---|
| 563 | |
---|
| 564 | var nome = $(contact).clone().find('.name').text(); |
---|
| 565 | var email = $(contact).clone().find('.email').text(); |
---|
| 566 | |
---|
| 567 | if(email == get_lang("No mail")){ |
---|
| 568 | alert(get_lang("It is not possible to add this contact as a recipient because it does not have email")); |
---|
| 569 | if(!is_ie) |
---|
| 570 | document.getElementById("amount-text").focus(); |
---|
| 571 | return; |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | verifyEmails(email, divs); |
---|
| 575 | |
---|
| 576 | final_contact = "\""+nome +"\" <"+email+">, "; |
---|
| 577 | |
---|
[5395] | 578 | var emailList = document.getElementById(field_ + "_" + id_).value; |
---|
| 579 | //remove os caracteres da busca |
---|
| 580 | emailList = emailList.substr(0,emailList.lastIndexOf(',')+1); |
---|
[5172] | 581 | |
---|
[5134] | 582 | if (emailList[0] != '"' && emailList.indexOf(",") < 0) |
---|
[5172] | 583 | emailList = emailList.substr(end_); |
---|
[5383] | 584 | if(emailList.lastIndexOf(",") > 0){ |
---|
[5382] | 585 | if(emailList.substr(emailList.length-1, emailList.length) == "," || emailList.substr(emailList.length-2, 1) == ","){ |
---|
[5134] | 586 | emailList = emailList.substr(0, emailList.lastIndexOf(",") + 1); |
---|
[5382] | 587 | } else { |
---|
| 588 | emailList = emailList.substr(0, emailList.lastIndexOf("") + 1); |
---|
| 589 | final_contact = ","+final_contact; |
---|
| 590 | } |
---|
[5383] | 591 | } |
---|
[5382] | 592 | |
---|
[5134] | 593 | final_contact = final_contact.replace(/\/n/, ""); |
---|
[5172] | 594 | new_emailList = emailList + final_contact; |
---|
| 595 | document.getElementById(field_ + "_" + id_).value = new_emailList; |
---|
[5134] | 596 | |
---|
[5423] | 597 | $("#"+field_+"_"+id_+"").trigger("update"); |
---|
| 598 | |
---|
[5172] | 599 | button.onclick = function(){ |
---|
| 600 | remove_contact_field(document.getElementById(divs).innerHTML, button, divs); |
---|
| 601 | }; |
---|
| 602 | var div = document.getElementById(divs); |
---|
[5134] | 603 | |
---|
[5172] | 604 | div.ondblclick = function(){ |
---|
| 605 | remove_contact_field(div.innerHTML, button, divs); |
---|
| 606 | }; |
---|
[5134] | 607 | |
---|
[5172] | 608 | button.innerHTML = '<span class="ui-button-text" style="">x</span>'; |
---|
| 609 | } |
---|
[5134] | 610 | |
---|
[5075] | 611 | |
---|
[5172] | 612 | /* |
---|
| 613 | * Método que remove o contato selecionado no campo do email (To, CC, CCo) |
---|
| 614 | */ |
---|
| 615 | function remove_contact_field(contact, button, divs) { |
---|
| 616 | var email = $(contact).clone().find('.email').text(); |
---|
[5134] | 617 | var exist = false; |
---|
[5172] | 618 | |
---|
[5134] | 619 | var emailList = $("#" + field_ + "_" + id_).val(); |
---|
[5172] | 620 | var emails_adicionados = emailList.split(","); |
---|
| 621 | |
---|
| 622 | verifyEmails(email, divs); |
---|
| 623 | |
---|
[5134] | 624 | for(i=0; i<emails_adicionados.length -1; i++) { |
---|
[5172] | 625 | |
---|
[5258] | 626 | if(emails_adicionados[i].match(/<([^<]*)>[\s]*$/)){ |
---|
| 627 | if(emails_adicionados[i].match(/<([^<]*)>[\s]*$/)[1].toLowerCase() == email.toLowerCase()) { |
---|
| 628 | emails_adicionados[i] = "%"; |
---|
| 629 | exist = true; |
---|
| 630 | } |
---|
| 631 | }else{ |
---|
| 632 | if(emails_adicionados[i].toLowerCase() == email.toLowerCase()) { |
---|
| 633 | emails_adicionados[i] = "%"; |
---|
| 634 | exist = true; |
---|
| 635 | } |
---|
[5075] | 636 | } |
---|
[5172] | 637 | } |
---|
| 638 | |
---|
[5134] | 639 | if (exist == false) |
---|
[5172] | 640 | return false; |
---|
| 641 | var novos_contatos = emails_adicionados.join(","); |
---|
| 642 | novos_contatos = novos_contatos.replace(/%,/g, ""); |
---|
[5134] | 643 | $("#" + field_ + "_" + id_).val(novos_contatos); |
---|
[5172] | 644 | |
---|
| 645 | button.onclick = function(){ |
---|
| 646 | add_contact_field(document.getElementById(divs).innerHTML, button, divs); |
---|
| 647 | }; |
---|
| 648 | |
---|
| 649 | var div = document.getElementById(divs); |
---|
| 650 | |
---|
| 651 | div.ondblclick = function(){ |
---|
| 652 | add_contact_field(div.innerHTML, button, divs); |
---|
| 653 | }; |
---|
| 654 | |
---|
[5423] | 655 | $("#"+field_+"_"+id_+"").trigger("update"); |
---|
[5172] | 656 | button.innerHTML = '<span class="ui-button-text" style="">+</span>'; |
---|
| 657 | } |
---|
[5075] | 658 | |
---|
[5172] | 659 | |
---|
[5134] | 660 | /* Decoder utf8 */ |
---|
| 661 | function utf8_decoder ( str_data ) { |
---|
[5172] | 662 | var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0; |
---|
| 663 | str_data += ''; |
---|
[5134] | 664 | while ( i < str_data.length ) { |
---|
[5172] | 665 | c1 = str_data.charCodeAt(i); |
---|
[5134] | 666 | if (c1 < 128) { |
---|
[5172] | 667 | tmp_arr[ac++] = String.fromCharCode(c1); |
---|
| 668 | i++; |
---|
[5134] | 669 | } else if ((c1 > 191) && (c1 < 224)) { |
---|
[5172] | 670 | c2 = str_data.charCodeAt(i+1); |
---|
| 671 | tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63)); |
---|
| 672 | i += 2; |
---|
| 673 | } else { |
---|
| 674 | c2 = str_data.charCodeAt(i+1); |
---|
| 675 | c3 = str_data.charCodeAt(i+2); |
---|
| 676 | tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); |
---|
| 677 | i += 3; |
---|
| 678 | } |
---|
[5075] | 679 | } |
---|
[5172] | 680 | return tmp_arr.join(''); |
---|
| 681 | } |
---|
[5075] | 682 | |
---|
[5172] | 683 | |
---|
[5134] | 684 | /* Mostra tela de help */ |
---|
| 685 | function show_help() { |
---|
[5075] | 686 | $(function() { |
---|
| 687 | $( "#dialog-modal_help" ).dialog({ |
---|
| 688 | resizable: false, |
---|
| 689 | width: 540, |
---|
| 690 | modal: true, |
---|
[5172] | 691 | closeOnEscape: true, |
---|
| 692 | close : function (event, ui) { |
---|
| 693 | $( "#amount-text" ).focus(); |
---|
| 694 | event.stopPropagation(); |
---|
| 695 | } |
---|
[5075] | 696 | }); |
---|
| 697 | }); |
---|
| 698 | } |
---|
[5172] | 699 | |
---|
| 700 | $("#dialog-modal_help").live("dialogclose", function(){ |
---|
| 701 | if(!is_ie) |
---|
| 702 | $( "#amount-text" ).focus(); |
---|
| 703 | }); |
---|
| 704 | |
---|
| 705 | |
---|
[5404] | 706 | emQuickCatalogSearch.prototype.showWindow = function () { |
---|
[5134] | 707 | $(this).bind('keydown'); |
---|
[5172] | 708 | $(function() { |
---|
| 709 | $( "#dialog:ui-dialog" ).dialog( "destroy" ); |
---|
| 710 | $( "#dialog-modal" ).dialog({ |
---|
| 711 | resizable: false, |
---|
[5134] | 712 | // height: "auto", |
---|
| 713 | width: 780, |
---|
[5172] | 714 | modal: true, |
---|
[5134] | 715 | position: 'bottom', |
---|
[5172] | 716 | closeOnEscape: true, |
---|
| 717 | close: function (event, ui) { |
---|
| 718 | event.stopPropagation(); |
---|
[5134] | 719 | $(this).unbind('keydown'); |
---|
| 720 | if (is_ie) { |
---|
| 721 | var range= document.getElementById(field_ + "_" + id_).createTextRange(); |
---|
| 722 | range.collapse(false); |
---|
| 723 | range.select(); |
---|
| 724 | } else { |
---|
| 725 | document.getElementById(field_ + "_" + id_).focus(); |
---|
| 726 | } |
---|
| 727 | }, |
---|
| 728 | open: function () { |
---|
[5172] | 729 | removeFocus(); |
---|
| 730 | $("#selectable li:first").focus(); |
---|
| 731 | document.getElementById("amount-text").focus(); |
---|
| 732 | }, |
---|
| 733 | focus: function (event, ui) { |
---|
[5134] | 734 | //$(this).unbind('keydown'); |
---|
[5172] | 735 | }, |
---|
| 736 | beforeClose: function (event, ui) { |
---|
[5134] | 737 | $(this).unbind('keydown'); |
---|
[5172] | 738 | }, |
---|
[5134] | 739 | buttons:[ |
---|
| 740 | { |
---|
| 741 | text: "Fechar", |
---|
| 742 | click: function(){ |
---|
[5172] | 743 | $("#detalhes_contato, #selectable, #busca").empty(); |
---|
| 744 | $(this).dialog("close"); |
---|
[5134] | 745 | if (is_ie) { |
---|
| 746 | var range= document.getElementById(field_ + "_" + id_).createTextRange(); |
---|
| 747 | range.collapse(false); |
---|
| 748 | range.select(); |
---|
| 749 | } else { |
---|
| 750 | document.getElementById(field_ + "_" + id_).focus(); |
---|
[5172] | 751 | } |
---|
[5134] | 752 | }, |
---|
| 753 | style: "margin-top: -2.1em" |
---|
[5075] | 754 | } |
---|
[5134] | 755 | ] |
---|
[5172] | 756 | }); |
---|
| 757 | }); |
---|
[5134] | 758 | $(".ui-dialog .ui-dialog-titlebar") |
---|
| 759 | .append('<a href="#" class="ui-dialog-titlebar-minimize ui-corner-all" role="button"><span class="ui-icon ui-icon-minusthick">minimize</span></a>') |
---|
| 760 | .find('.ui-dialog-titlebar-minimize').click(function() { |
---|
| 761 | $(".ui-dialog-buttonpane, .ui-dialog-content").toggle(); |
---|
| 762 | $(".ui-icon-minusthick, .ui-icon-newwin").toggleClass('ui-icon-minusthick').toggleClass('ui-icon-newwin'); |
---|
| 763 | }); |
---|
[5172] | 764 | |
---|
[5134] | 765 | $("#dialog-modal button, input.button").button(); |
---|
[2] | 766 | } |
---|
[4034] | 767 | |
---|
[2] | 768 | |
---|
[5134] | 769 | /* Build the Object */ |
---|
[4761] | 770 | //QuickCatalogSearch; |
---|
[5382] | 771 | QuickCatalogSearch = new emQuickCatalogSearch(); |
---|