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