Ignore:
Timestamp:
10/17/12 17:40:10 (12 years ago)
Author:
acoutinho
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/js/draw_api.js

    r7422 r7437  
    40504050                if(parseInt(preferences.use_dynamic_contacts) && !input.hasClass("box-input")){ 
    40514051                        //SELECIONA O CONTATO E EVITA OUTROS COMANDOS 
    4052                         if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "catcomplete" ).menu.active ) { 
     4052                        if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) { 
    40534053                                e.preventDefault(); 
    40544054                                return false; 
     
    40564056                         
    40574057                        //FECHA OS CONTATOS DINÂMICOS 
    4058                         if( (e.keyCode == 27) && $( this ).data( "catcomplete" ).menu.active ){ 
     4058                        if( (e.keyCode == 27) && $( this ).data( "autocomplete" ).menu.active ){ 
    40594059                                   e.stopPropagation(); 
    40604060                                   e.preventDefault(); 
     
    40624062                         
    40634063                        //SELECIONA O CONTATO E EVITA OUTROS COMANDOS 
    4064                         if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "catcomplete" ).menu.active){ 
     4064                        if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "autocomplete" ).menu.active){ 
    40654065                                e.preventDefault(); 
    40664066                                return false; 
    40674067                        } 
    40684068                         
    4069                         if(e.keyCode == $.ui.keyCode.DELETE && $( this ).data( "catcomplete" ).menu.active){ 
    4070                                 if($($( this ).data( "catcomplete" ).menu.element).find(".ui-state-hover").parents("li:first").hasClass("dynamic-recent")) 
    4071                                         $($( this ).data( "catcomplete" ).menu.element).find(".ui-state-hover").next().trigger("click"); 
     4069                        if(e.keyCode == $.ui.keyCode.DELETE && $( this ).data( "autocomplete" ).menu.active){ 
     4070                                if($($( this ).data( "autocomplete" ).menu.element).find(".ui-state-hover").parents("li:first").hasClass("dynamic-recent")) 
     4071                                        $($( this ).data( "autocomplete" ).menu.element).find(".ui-state-hover").next().trigger("click"); 
    40724072                                return false; 
    40734073                        } 
     
    44434443} 
    44444444 
     4445dynamicData = false; 
     4446currentTypeContact = ''; 
    44454447 
    44464448//FUNÇÃO QUE "SETA" OS BINDS DOS CAMPOS PARA - CC - CCO 
     
    44884490        //VERIFICA PREFERENCIA DE CONTATOS DINÂMICOS ESTA ATIVA 
    44894491        if(parseInt(preferences.use_dynamic_contacts)){ 
     4492 
     4493        REST.get("/usercontacts", false, updateDynamicContact); 
     4494 
    44904495                //PREPARAÇÃO DA ARRAY DOS CONTATOS DINÂMICOS 
    44914496 
    4492                 $.widget( "custom.catcomplete", $.ui.autocomplete, { 
    4493                         _renderMenu: function( ul, items ) { 
    4494                                 var self = this, 
    4495                                 currentType = ""; 
    4496                                 $.each( items, function( index, item ) { 
    4497                                         if ( item.typel != currentType) { 
    4498                                                 if(item.typel == "/groups" && $(ul).find(".dynamic-recent").length) 
    4499                                                         self._renderItem( ul, {name:"", value:"", type:"linha"} ); 
    4500                                                 if(item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length)) 
    4501                                                         self._renderItem( ul, {name:"", value:"", type:"linha"} );       
    4502                                                 currentType = item.typel; 
    4503                                         } 
    4504                                         self._renderItem( ul, item ); 
    4505                                         $(ul).find("li:last").find(".dynamic-stars").raty({ 
    4506                                                 readOnly : true, 
    4507                                                 half : true, 
    4508                                                 hints : ['','','','',''], 
    4509                                                 score    : ((item.number_of_messages*5)/topContact) > 0.5 ? ((item.number_of_messages*5)/topContact) : 0.5, 
    4510                                                 starOn  : '../../prototype/plugins/jq-raty/img/star-on.png', 
    4511                                                 starOff : '../../prototype/plugins/jq-raty/img/star-off.png', 
    4512                                                 starHalf : '../../prototype/plugins/jq-raty/img/star-half.png' 
    4513                                         }); 
    4514                                 }); 
    4515                                 if($(ul).find("li:last").hasClass("dynamic-separator")){ 
    4516                                         $(ul).find("li:last").remove(); 
    4517                                 } 
    4518                                 $(ul).scroll(function(){ 
    4519                                         canMakeBox = false; 
    4520                                 }); 
    4521                         } 
    4522                 }); 
    4523                 //INSERÇÃO DO AUTO COMPLETE AO INPUT 
    4524                 div.find("textarea").catcomplete({ 
    4525                         minLength: 1,                    
    4526                         source: function(request, response){ 
    4527                                 if ( request.term in cache ) { 
    4528                                         response( cache[ request.term ] ); 
    4529                                         return; 
    4530                                 } 
    4531                                 dynamicContactsList = new Array(); 
    4532                                 REST.get("/usercontacts", false, function(data){ 
    4533                                         dynamicData = data.collection.itens; 
    4534                                         if(dynamicData){ 
    4535                                                 $.each(dynamicData, function(index, value){ 
    4536                                                         dynamic = {}; 
    4537                                                         $.each(value.data, function(index, value){ 
    4538                                                                 dynamic[value.name] = value.value; 
    4539                                                         }); 
    4540                                                         dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail; 
    4541                                                         dynamic['type'] = value.dataType; 
    4542                                                         dynamic['typel'] = (value.dataType.substring(0,7) == "/shared" ? "/"+value.dataType.substring(7,value.dataType.length)+"s" : value.dataType) ; 
    4543                                                         dynamicContactsList.push(dynamic); 
    4544                                                 }); 
    4545                                         } 
    4546                                         var data = $.ui.autocomplete.filter(dynamicContactsList, request.term ); 
    4547                                         cache[ request.term ] = data; 
    4548                                         response( data ); 
    4549                                 }); 
    4550                         }, 
    4551                         focus: function() { 
    4552                                 return false; 
    4553                         }, 
    4554                          
    4555                         //EVENTO AO SELECIONAR UM CONTATO DINÂMICO 
    4556                         select: function( event, ui ) { 
    4557                                 canMakeBox = false; 
    4558                                 event.preventDefault(); 
    4559                                 $(this).val(""); 
    4560                                 if(ui.item.typel == "/personalContact") 
    4561                                         draw_email_box(""+ui.item.id, $(this), true, (ui.item.type.substring(0,7) == "/shared" ? true : false)); 
    4562                                 else if(ui.item.typel == "/groups") 
    4563                                         draw_email_box(""+ui.item.id, $(this), "G", (ui.item.type.substring(0,7) == "/shared" ? true : false)); 
    4564                                 else 
    4565                                         draw_email_box(ui.item.name ? "\""+ui.item.name+"\" <"+ui.item.mail+">" : ui.item.mail, $(this)); 
    4566                                 return false; 
    4567                         }, 
    4568                         autoFocus: true, 
    4569                         position : { my: "left top", at: "left bottom", collision: "fit" }, 
    4570                         delay : 400 
    4571                 }).bind('catcompleteopen', function(event, ui) { 
    4572                         $(this).data('is_open',true); 
    4573                 }).bind('catcompleteclose', function(event, ui) { 
    4574                         canMakeBox = true; 
    4575                         $(this).data('is_open',false); 
    4576                 }) 
    4577                  
    4578                 //MONTAGEM DA LISTA DE CONTATOS DINÂMICOS DO AUTO COMPLETE 
    4579                 .data( "catcomplete" )._renderItem = function( ul, item ) { 
    4580                         if($(ul).find("li").length < 50){ 
    4581                                 var autocomplete = $(this)[0].element; 
    4582                                 //cálculo dinâmico da largura da lista 
    4583                                 var minwidth = 450; 
    4584                                 var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 30 ))); 
    4585                                 width = (is_ie ? width*2 : (is_webkit && !is_mozilla ? width*4 : width*5)) + 30; 
    4586                                 if (width < minwidth) 
    4587                                         width = minwidth;                                
    4588                                 ul.css({"min-width":width,"max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"}); 
    4589                                 var listContacts = DataLayer.render("../prototype/modules/mail/templates/listContacts.ejs", item); 
    4590                                 return $(listContacts).data( "item.autocomplete", item ).appendTo( ul ).find("span:last").button({ 
    4591                                                 icons : { 
    4592                                                 primary : "ui-icon-close" 
    4593                                         }, 
    4594                                         text: false 
    4595                                 }).click(function(event){ 
    4596                                         var removeLi = $(this).parents("li:first"); 
    4597                                         if(!event.keyCode) 
    4598                                                 autocomplete.catcomplete( "close" ); 
    4599                                         canMakeBox = false; 
    4600                                         $.Zebra_Dialog('Deseja remover <b>'+(item.name ? (item.name.length <=30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'</b>?', { 
    4601                                                         'type':     'question', 
    4602                                                         'custom_class': (is_ie ? 'configure-zebra-dialog' : ''), 
    4603                                                         'title':    'Atenção', 
    4604                                                         'buttons': ['Sim','Não'],                
    4605                                                         'overlay_opacity': '0.5', 
    4606                                                         'onClose':  function(caption) { 
    4607                                                                 if(caption == 'Sim'){ 
    4608                                                                         $(removeLi).remove(); 
    4609                                                                         REST['delete']("/dynamiccontact/"+item.id); 
    4610                                                                         updateDynamicContact(); 
    4611                                                                         cache = new Array(); 
    4612                                                                 }else if(caption == 'Não'){ 
    4613                                                                         $(focusIn).focus(); 
    4614                                                                 } 
    4615                                                         } 
    4616                                         }); 
    4617                                 }); 
    4618                         } 
    4619                         return; 
    4620                 }; 
    4621         } 
    4622          
     4497        var decodeType = { 
     4498            '/dynamiccontacts': { 
     4499                css: 'recent', 
     4500                img: 'recent', 
     4501                text: 'Contato Recente' 
     4502                }, 
     4503            '/personalContact':{ 
     4504                css: 'personal', 
     4505                img: 'personal', 
     4506                text: 'Contato pessoal' 
     4507                    }, 
     4508            '/sharedcontact':{ 
     4509                css: 'personal', 
     4510                img: 'sharedcontact', 
     4511                text: 'Contato compartilhado' 
     4512            }, 
     4513            '/groups':{ 
     4514                css: 'group', 
     4515                img: 'group', 
     4516                text: 'Grupo pessoal' 
     4517            }, 
     4518            '/sharedgroup':{ 
     4519                css: 'group', 
     4520                img: 'sharedgroup', 
     4521                text: 'Grupo compartilhado' 
     4522            } 
     4523            } 
     4524 
     4525        div.find("textarea").autocomplete({ 
     4526            source: function(request, response){ 
     4527                if ( request.term in cache ) { 
     4528                    response( cache[ request.term ] ); 
     4529                    return; 
     4530                } 
     4531 
     4532                if(dynamicData === false){ 
     4533                    updateDynamicContact(); 
     4534                } 
     4535 
     4536                var data = $.ui.autocomplete.filter(dynamicData, request.term ).slice(0, 50); 
     4537                cache[ request.term ] = data; 
     4538                response( data ); 
     4539 
     4540            }, 
     4541            focus: function() { 
     4542                return false; 
     4543            }, 
     4544 
     4545            //EVENTO AO SELECIONAR UM CONTATO DINÂMICO 
     4546            select: function( event, ui ) { 
     4547                canMakeBox = false; 
     4548 
     4549                event.preventDefault(); 
     4550                $(this).val(""); 
     4551 
     4552                var isShared = (ui.item.type.substring(0,7) == "/shared"); 
     4553 
     4554                switch (ui.item.typel){ 
     4555                    case '/personalContact': 
     4556                        draw_email_box(""+ui.item.id, $(this), true, isShared); 
     4557                        break; 
     4558                    case '/groups': 
     4559                        draw_email_box(""+ui.item.id, $(this), "G", isShared); 
     4560                        break; 
     4561                    default: 
     4562                        draw_email_box(ui.item.name ? ("\""+ui.item.name+"\" <"+ui.item.mail+">") : ui.item.mail, $(this)); 
     4563                } 
     4564 
     4565                return false; 
     4566            }, 
     4567            autoFocus: true, 
     4568            position : { my: "left top", at: "left bottom", collision: "fit" }, 
     4569            delay : 120, 
     4570            minLength: 0 
     4571        }).bind('catcompleteopen', function(event, ui) { 
     4572 
     4573            $(this).data('is_open',true); 
     4574 
     4575        }).bind('catcompleteclose', function(event, ui) { 
     4576 
     4577            canMakeBox = true; 
     4578            $(this).data('is_open',false); 
     4579 
     4580        }).data( "autocomplete" )._renderItem = function( ul, item ) { 
     4581            var autocomplete = $(this)[0].element; 
     4582 
     4583            //cálculo dinâmico da largura da lista 
     4584            var minwidth = 450; 
     4585            var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 30 ))); 
     4586            width = (is_ie ? width*2 : (is_webkit && !is_mozilla ? width*4 : width*5)) + 30; 
     4587            if (width < minwidth) 
     4588                width = minwidth; 
     4589 
     4590            ul.css({"min-width":width, "max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"}); 
     4591 
     4592            item.raty = ((item.number_of_messages*10)/topContact) > 1 ? ((item.number_of_messages*10)/topContact) : 1; 
     4593 
     4594            if ( item.typel != currentTypeContact) { 
     4595                if((item.typel == "/groups" && $(ul).find(".dynamic-recent").length) || (item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))){ 
     4596                    currentTypeContact = item.typel; 
     4597                    item.asDiv = true; 
     4598                }else{ 
     4599                    currentTypeContact = item.typel; 
     4600                } 
     4601            } 
     4602 
     4603            var li = ''; 
     4604            if(item.asDiv){ 
     4605                li = '<li class="dynamic-separator"><div class="line-separator">&nbsp;</div></li>'; 
     4606            } 
     4607            li += '<li class="dynamic-'+ decodeType[item.type].css +'">'; 
     4608            li += '<a style="width:'+(item.type == '/dynamiccontacts' ? '91%' : '97.5%')+';  display: inline-block; background: none;">'; 
     4609            li += '<img style="position:relative; top:2px; "src="../prototype/modules/mail/img/'+ decodeType[item.type].img +'.png" title="'+ decodeType[item.type].text +'"/>'; 
     4610            li += ($.trim(item.name) != "" ? ((item.name.length > 20 ? item.name.substring(0,17)+"..." : item.name) + " - " ) : '')  + item.mail; 
     4611            li += item.type == '/dynamiccontacts' ? '<div class="dynamic-stars" style="display: inline-block;float: right;" id="'+item.raty+'_'+item.id+'"/>' : '' 
     4612            li += '</a>'; 
     4613            li += '<span style="width:16px; height:16px; top:1px; left:7px; '+ (item.type == '/dynamiccontacts' ? '': 'display:none') +'">Excluir contato recente</span>'; 
     4614            li += '</li>'; 
     4615 
     4616 
     4617            li = $( li ) 
     4618                .data( "item.autocomplete", item ) 
     4619                //.append( li ) 
     4620                .appendTo( ul ); 
     4621 
     4622            li.find("span").button({ 
     4623                icons : { 
     4624                    primary : "ui-icon-close" 
     4625                }, 
     4626                text: false 
     4627            }).click(function(event){ 
     4628                    if(!event.keyCode) 
     4629                        autocomplete.autocomplete( "close" ); 
     4630 
     4631                    canMakeBox = false; 
     4632                    $.Zebra_Dialog('Deseja remover <b>'+(item.name ? (item.name.length <= 30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'</b>?', { 
     4633                        'type':     'question', 
     4634                        'custom_class': (is_ie ? 'configure-zebra-dialog' : ''), 
     4635                        'buttons': ['Sim','Não'], 
     4636                        'overlay_opacity': '0.5', 
     4637                        'onClose':  function(caption) { 
     4638                            if(caption == 'Sim'){ 
     4639 
     4640                                REST['delete']("/dynamiccontact/"+item.id); 
     4641                                updateDynamicContact(); 
     4642                                cache = new Array(); 
     4643                            }else if(caption == 'Não'){ 
     4644                                $(focusIn).focus(); 
     4645                            } 
     4646                        } 
     4647                    }); 
     4648                }); 
     4649 
     4650            li.find(".dynamic-stars").jRating({ 
     4651                step:true, 
     4652                length : 5, // nb of stars 
     4653                decimalLength: 2, // number of decimal in the rate 
     4654                rateMax: 10, 
     4655                isDisabled:true, 
     4656                bigStarsPath : '../prototype/plugins/jquery.jrating/icons/stars.png', // path of the icon stars.png 
     4657                smallStarsPath : '../prototype/plugins/jquery.jrating/icons/small.png' // path of the icon small.png 
     4658            }); 
     4659 
     4660            if($(ul).find("li:last").hasClass("dynamic-separator")){ 
     4661                $(ul).find("li:last").remove(); 
     4662            } 
     4663 
     4664            $(ul).scroll(function(){ 
     4665                canMakeBox = false; 
     4666            }); 
     4667 
     4668            return li; 
     4669        }; 
     4670        } 
     4671 
    46234672        //FUNÇÃO DOS BOTÕES PARA - CC - CCO 
    46244673        div.parents("tr:first").find("button").button().click(function(){ 
Note: See TracChangeset for help on using the changeset viewer.