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