Ignore:
Timestamp:
10/18/12 18:14:14 (12 years ago)
Author:
eduardow
Message:

Ticket #3167 - Melhoria na performance nas pesquisas de contatos dinamicos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.4/expressoMail1_2/js/draw_api.js

    r7380 r7444  
    38863886                if(parseInt(preferences.use_dynamic_contacts) && !input.hasClass("box-input")){ 
    38873887                        //SELECIONA O CONTATO E EVITA OUTROS COMANDOS 
    3888                         if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "catcomplete" ).menu.active ) { 
     3888                        if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) { 
    38893889                                e.preventDefault(); 
    38903890                                return false; 
     
    38923892                         
    38933893                        //FECHA OS CONTATOS DINÂMICOS 
    3894                         if( (e.keyCode == 27) && $( this ).data( "catcomplete" ).menu.active ){ 
     3894                        if( (e.keyCode == 27) && $( this ).data( "autocomplete" ).menu.active ){ 
    38953895                                   e.stopPropagation(); 
    38963896                                   e.preventDefault(); 
     
    38983898                         
    38993899                        //SELECIONA O CONTATO E EVITA OUTROS COMANDOS 
    3900                         if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "catcomplete" ).menu.active){ 
     3900                        if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "autocomplete" ).menu.active){ 
    39013901                                e.preventDefault(); 
    39023902                                return false; 
    39033903                        } 
    39043904                         
    3905                         if(e.keyCode == $.ui.keyCode.DELETE && $( this ).data( "catcomplete" ).menu.active){ 
    3906                                 if($($( this ).data( "catcomplete" ).menu.element).find(".ui-state-hover").parents("li:first").hasClass("dynamic-recent")) 
    3907                                         $($( this ).data( "catcomplete" ).menu.element).find(".ui-state-hover").next().trigger("click"); 
     3905                        if(e.keyCode == $.ui.keyCode.DELETE && $( this ).data( "autocomplete" ).menu.active){  
     3906                    if($($( this ).data( "autocomplete" ).menu.element).find(".ui-state-hover").parents("li:first").hasClass("dynamic-recent"))  
     3907                            $($( this ).data( "autocomplete" ).menu.element).find(".ui-state-hover").next().trigger("click"); 
    39083908                                return false; 
    39093909                        } 
     
    42794279} 
    42804280 
     4281dynamicData = false;  
     4282currentTypeContact = ''; 
    42814283 
    42824284//FUNÇÃO QUE "SETA" OS BINDS DOS CAMPOS PARA - CC - CCO 
     
    43244326        //VERIFICA PREFERENCIA DE CONTATOS DINÂMICOS ESTA ATIVA 
    43254327        if(parseInt(preferences.use_dynamic_contacts)){ 
     4328 
     4329        REST.get("/usercontacts", false, updateDynamicContact); 
     4330 
    43264331                //PREPARAÇÃO DA ARRAY DOS CONTATOS DINÂMICOS 
    43274332 
    4328                 $.widget( "custom.catcomplete", $.ui.autocomplete, { 
    4329                         _renderMenu: function( ul, items ) { 
    4330                                 var self = this, 
    4331                                 currentType = ""; 
    4332                                 $.each( items, function( index, item ) { 
    4333                                         if ( item.typel != currentType) { 
    4334                                                 if(item.typel == "/groups" && $(ul).find(".dynamic-recent").length) 
    4335                                                         self._renderItem( ul, {name:"", value:"", type:"linha"} ); 
    4336                                                 if(item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length)) 
    4337                                                         self._renderItem( ul, {name:"", value:"", type:"linha"} );       
    4338                                                 currentType = item.typel; 
    4339                                         } 
    4340                                         self._renderItem( ul, item ); 
    4341                                         $(ul).find("li:last").find(".dynamic-stars").raty({ 
    4342                                                 readOnly : true, 
    4343                                                 half : true, 
    4344                                                 hints : ['','','','',''], 
    4345                                                 score    : ((item.number_of_messages*5)/topContact) > 0.5 ? ((item.number_of_messages*5)/topContact) : 0.5, 
    4346                                                 starOn  : '../../prototype/plugins/jq-raty/img/star-on.png', 
    4347                                                 starOff : '../../prototype/plugins/jq-raty/img/star-off.png', 
    4348                                                 starHalf : '../../prototype/plugins/jq-raty/img/star-half.png' 
    4349                                         }); 
    4350                                 }); 
    4351                                 if($(ul).find("li:last").hasClass("dynamic-separator")){ 
    4352                                         $(ul).find("li:last").remove(); 
    4353                                 } 
    4354                                 $(ul).scroll(function(){ 
    4355                                         canMakeBox = false; 
    4356                                 }); 
    4357                         } 
    4358                 }); 
    4359                 //INSERÇÃO DO AUTO COMPLETE AO INPUT 
    4360                 div.find("textarea").catcomplete({ 
    4361                         minLength: 1,                    
    4362                         source: function(request, response){ 
    4363                                 if ( request.term in cache ) { 
    4364                                         response( cache[ request.term ] ); 
    4365                                         return; 
    4366                                 } 
    4367                                 dynamicContactsList = new Array(); 
    4368                                 REST.get("/usercontacts", false, function(data){ 
    4369                                         dynamicData = data.collection.itens; 
    4370                                         if(dynamicData){ 
    4371                                                 $.each(dynamicData, function(index, value){ 
    4372                                                         dynamic = {}; 
    4373                                                         $.each(value.data, function(index, value){ 
    4374                                                                 dynamic[value.name] = value.value; 
    4375                                                         }); 
    4376                                                         dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail; 
    4377                                                         dynamic['type'] = value.dataType; 
    4378                                                         dynamic['typel'] = (value.dataType.substring(0,7) == "/shared" ? "/"+value.dataType.substring(7,value.dataType.length)+"s" : value.dataType) ; 
    4379                                                         dynamicContactsList.push(dynamic); 
    4380                                                 }); 
    4381                                         } 
    4382                                         var data = $.ui.autocomplete.filter(dynamicContactsList, request.term ); 
    4383                                         cache[ request.term ] = data; 
    4384                                         response( data ); 
    4385                                 }); 
    4386                         }, 
    4387                         focus: function() { 
    4388                                 return false; 
    4389                         }, 
    4390                          
    4391                         //EVENTO AO SELECIONAR UM CONTATO DINÂMICO 
    4392                         select: function( event, ui ) { 
    4393                                 canMakeBox = false; 
    4394                                 event.preventDefault(); 
    4395                                 $(this).val(""); 
    4396                                 if(ui.item.typel == "/personalContact") 
    4397                                         draw_email_box(""+ui.item.id, $(this), true, (ui.item.type.substring(0,7) == "/shared" ? true : false)); 
    4398                                 else if(ui.item.typel == "/groups") 
    4399                                         draw_email_box(""+ui.item.id, $(this), "G", (ui.item.type.substring(0,7) == "/shared" ? true : false)); 
    4400                                 else 
    4401                                         draw_email_box(ui.item.name ? "\""+ui.item.name+"\" <"+ui.item.mail+">" : ui.item.mail, $(this)); 
    4402                                 return false; 
    4403                         }, 
    4404                         autoFocus: true, 
    4405                         position : { my: "left top", at: "left bottom", collision: "fit" }, 
    4406                         delay : 400 
    4407                 }).bind('catcompleteopen', function(event, ui) { 
    4408                         $(this).data('is_open',true); 
    4409                 }).bind('catcompleteclose', function(event, ui) { 
    4410                         canMakeBox = true; 
    4411                         $(this).data('is_open',false); 
    4412                 }) 
    4413                  
    4414                 //MONTAGEM DA LISTA DE CONTATOS DINÂMICOS DO AUTO COMPLETE 
    4415                 .data( "catcomplete" )._renderItem = function( ul, item ) { 
    4416                         if($(ul).find("li").length < 50){ 
    4417                                 var autocomplete = $(this)[0].element; 
    4418                                 //cálculo dinâmico da largura da lista 
    4419                                 var minwidth = 450; 
    4420                                 var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 30 ))); 
    4421                                 width = (is_ie ? width*2 : (is_webkit && !is_mozilla ? width*4 : width*5)) + 30; 
    4422                                 if (width < minwidth) 
    4423                                         width = minwidth;                                
    4424                                 ul.css({"min-width":width,"max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"}); 
    4425                                 var listContacts = DataLayer.render("../prototype/modules/mail/templates/listContacts.ejs", item); 
    4426                                 return $(listContacts).data( "item.autocomplete", item ).appendTo( ul ).find("span:last").button({ 
    4427                                                 icons : { 
    4428                                                 primary : "ui-icon-close" 
    4429                                         }, 
    4430                                         text: false 
    4431                                 }).click(function(event){ 
    4432                                         var removeLi = $(this).parents("li:first"); 
    4433                                         if(!event.keyCode) 
    4434                                                 autocomplete.catcomplete( "close" ); 
    4435                                         canMakeBox = false; 
    4436                                         $.Zebra_Dialog('Deseja remover <b>'+(item.name ? (item.name.length <=30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'</b>?', { 
    4437                                                         'type':     'question', 
    4438                                                         'custom_class': (is_ie ? 'configure-zebra-dialog' : ''), 
    4439                                                         'title':    'Atenção', 
    4440                                                         'buttons': ['Sim','Não'],                
    4441                                                         'overlay_opacity': '0.5', 
    4442                                                         'onClose':  function(caption) { 
    4443                                                                 if(caption == 'Sim'){ 
    4444                                                                         $(removeLi).remove(); 
    4445                                                                         REST['delete']("/dynamiccontact/"+item.id); 
    4446                                                                         updateDynamicContact(); 
    4447                                                                         cache = new Array(); 
    4448                                                                 }else if(caption == 'Não'){ 
    4449                                                                         $(focusIn).focus(); 
    4450                                                                 } 
    4451                                                         } 
    4452                                         }); 
    4453                                 }); 
    4454                         } 
    4455                         return; 
    4456                 }; 
    4457         } 
     4333        var decodeType = {  
     4334        '/dynamiccontacts': {  
     4335            css: 'recent',  
     4336            img: 'recent',  
     4337            text: 'Contato Recente'  
     4338            },  
     4339        '/personalContact':{  
     4340            css: 'personal',  
     4341            img: 'personal',  
     4342            text: 'Contato pessoal'  
     4343                },  
     4344        '/sharedcontact':{  
     4345            css: 'personal',  
     4346            img: 'sharedcontact',  
     4347            text: 'Contato compartilhado'  
     4348        },  
     4349        '/groups':{  
     4350            css: 'group',  
     4351            img: 'group',  
     4352            text: 'Grupo pessoal'  
     4353        },  
     4354        '/sharedgroup':{  
     4355            css: 'group',  
     4356            img: 'sharedgroup',  
     4357            text: 'Grupo compartilhado'  
     4358        }  
     4359        }  
     4360 
     4361    div.find("textarea").autocomplete({  
     4362        source: function(request, response){  
     4363            if ( request.term in cache ) {  
     4364                response( cache[ request.term ] );  
     4365                return;  
     4366            }  
     4367 
     4368            if(dynamicData === false){  
     4369                updateDynamicContact();  
     4370            }  
     4371 
     4372            var data = $.ui.autocomplete.filter(dynamicData, request.term ).slice(0, 50);  
     4373            cache[ request.term ] = data;  
     4374            response( data );  
     4375 
     4376        },  
     4377        focus: function() {  
     4378            return false;  
     4379        },  
     4380 
     4381        //EVENTO AO SELECIONAR UM CONTATO DINÂMICO  
     4382        select: function( event, ui ) {  
     4383            canMakeBox = false;  
     4384 
     4385            event.preventDefault();  
     4386            $(this).val("");  
     4387 
     4388            var isShared = (ui.item.type.substring(0,7) == "/shared");  
     4389 
     4390            switch (ui.item.typel){  
     4391                case '/personalContact':  
     4392                    draw_email_box(""+ui.item.id, $(this), true, isShared);  
     4393                    break;  
     4394                case '/groups':  
     4395                    draw_email_box(""+ui.item.id, $(this), "G", isShared);  
     4396                    break;  
     4397                default:  
     4398                    draw_email_box(ui.item.name ? ("\""+ui.item.name+"\" <"+ui.item.mail+">") : ui.item.mail, $(this));  
     4399            }  
     4400 
     4401            return false;  
     4402        },  
     4403        autoFocus: true,  
     4404        position : { my: "left top", at: "left bottom", collision: "fit" },  
     4405        delay : 120,  
     4406        minLength: 0  
     4407    }).bind('catcompleteopen', function(event, ui) {  
     4408 
     4409        $(this).data('is_open',true);  
     4410 
     4411    }).bind('catcompleteclose', function(event, ui) {  
     4412 
     4413        canMakeBox = true;  
     4414        $(this).data('is_open',false);  
     4415 
     4416    }).data( "autocomplete" )._renderItem = function( ul, item ) {  
     4417        var autocomplete = $(this)[0].element;  
     4418 
     4419        //cálculo dinâmico da largura da lista  
     4420        var minwidth = 450;  
     4421        var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 30 )));  
     4422        width = (is_ie ? width*2 : (is_webkit && !is_mozilla ? width*4 : width*5)) + 30;  
     4423        if (width < minwidth)  
     4424            width = minwidth;  
     4425 
     4426        ul.css({"min-width":width, "max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"});  
     4427 
     4428        item.raty = ((item.number_of_messages*10)/topContact) > 1 ? ((item.number_of_messages*10)/topContact) : 1;  
     4429 
     4430        if ( item.typel != currentTypeContact) {  
     4431            if((item.typel == "/groups" && $(ul).find(".dynamic-recent").length) || (item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))){  
     4432                currentTypeContact = item.typel;  
     4433                item.asDiv = true;  
     4434            }else{  
     4435                currentTypeContact = item.typel;  
     4436            }  
     4437        }  
     4438 
     4439        var li = '';  
     4440        if(item.asDiv){  
     4441            li = '<li class="dynamic-separator"><div class="line-separator">&nbsp;</div></li>';  
     4442        }  
     4443        li += '<li class="dynamic-'+ decodeType[item.type].css +'">';  
     4444        li += '<a style="width:'+(item.type == '/dynamiccontacts' ? '91%' : '97.5%')+';  display: inline-block; background: none;">';  
     4445        li += '<img style="position:relative; top:2px; "src="../prototype/modules/mail/img/'+ decodeType[item.type].img +'.png" title="'+ decodeType[item.type].text +'"/>';  
     4446        li += ($.trim(item.name) != "" ? ((item.name.length > 20 ? item.name.substring(0,17)+"..." : item.name) + " - " ) : '')  + item.mail;  
     4447        li += item.type == '/dynamiccontacts' ? '<div class="dynamic-stars" style="display: inline-block;float: right;" id="'+item.raty+'_'+item.id+'"/>' : ''  
     4448        li += '</a>';  
     4449        li += '<span style="width:16px; height:16px; top:1px; left:7px; '+ (item.type == '/dynamiccontacts' ? '': 'display:none') +'">Excluir contato recente</span>';  
     4450        li += '</li>';  
     4451 
     4452 
     4453        li = $( li )  
     4454            .data( "item.autocomplete", item )  
     4455            //.append( li )  
     4456            .appendTo( ul );  
     4457 
     4458        li.find("span").button({  
     4459            icons : {  
     4460                primary : "ui-icon-close"  
     4461            },  
     4462            text: false  
     4463        }).click(function(event){  
     4464                if(!event.keyCode)  
     4465                    autocomplete.autocomplete( "close" );  
     4466 
     4467                canMakeBox = false;  
     4468                $.Zebra_Dialog('Deseja remover <b>'+(item.name ? (item.name.length <= 30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'</b>?', {  
     4469                    'type':     'question',  
     4470                    'custom_class': (is_ie ? 'configure-zebra-dialog' : ''),  
     4471                    'buttons': ['Sim','Não'],  
     4472                    'overlay_opacity': '0.5',  
     4473                    'onClose':  function(caption) {  
     4474                        if(caption == 'Sim'){  
     4475 
     4476                            REST['delete']("/dynamiccontact/"+item.id);  
     4477                            updateDynamicContact();  
     4478                            cache = new Array();  
     4479                        }else if(caption == 'Não'){  
     4480                            $(focusIn).focus();  
     4481                        }  
     4482                    }  
     4483                });  
     4484            });  
     4485 
     4486        li.find(".dynamic-stars").jRating({  
     4487            step:true,  
     4488            length : 5, // nb of stars  
     4489            decimalLength: 2, // number of decimal in the rate  
     4490            rateMax: 10,  
     4491            isDisabled:true,  
     4492            bigStarsPath : '../prototype/plugins/jquery.jrating/icons/stars.png', // path of the icon stars.png  
     4493            smallStarsPath : '../prototype/plugins/jquery.jrating/icons/small.png' // path of the icon small.png  
     4494        });  
     4495 
     4496        if($(ul).find("li:last").hasClass("dynamic-separator")){  
     4497            $(ul).find("li:last").remove();  
     4498        }  
     4499 
     4500        $(ul).scroll(function(){  
     4501            canMakeBox = false;  
     4502        });  
     4503 
     4504        return li;  
     4505    };  
     4506    }    
    44584507         
    44594508        //FUNÇÃO DOS BOTÕES PARA - CC - CCO 
Note: See TracChangeset for help on using the changeset viewer.