Ignore:
Timestamp:
01/09/13 13:40:01 (11 years ago)
Author:
adriano
Message:

Ticket #2523 - criado componente generico combobox utilizado na tela de sinalizacao para acompanhamento

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/mail/js/followupflag.js

    r7612 r7720  
    6060        folder = current_folder; 
    6161 
    62         /** 
    63          * Implementação do widget de input-combobox 
    64          */ 
    65   
    66         (function( $ ) { 
    67                 $.widget( "ui.combobox", { 
    68                         _create: function() { 
    69                                 var self = this, 
    70                                         select = this.element.hide(), 
    71                                         selected = select.children( ":selected" ), 
    72                                         value = selected.val() ? selected.text() : ""; 
    73                                 var input = this.input = $( "<input>" ) 
    74                                         .insertAfter( select ) 
    75                                         .val( value ) 
    76                                         .autocomplete({ 
    77                                                 delay: 0, 
    78                                                 minLength: 0, 
    79                                                 source: function( request, response ) { 
    80                                                         var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); 
    81                                                         response( select.children( "option" ).map(function() { 
    82                                                                 var text = $( this ).text(); 
    83                                                                 if ( this.value && ( !request.term || matcher.test(text) ) ) 
    84                                                                         return { 
    85                                                                                 label: text.replace( 
    86                                                                                         new RegExp( 
    87                                                                                                 "(?![^&;]+;)(?!<[^<>]*)(" + 
    88                                                                                                 $.ui.autocomplete.escapeRegex(request.term) + 
    89                                                                                                 ")(?![^<>]*>)(?![^&;]+;)", "gi" 
    90                                                                                         ), "<strong>$1</strong>" ), 
    91                                                                                 value: text, 
    92                                                                                 option: this 
    93                                                                         }; 
    94                                                         }) ); 
    95                                                 }, 
    96                                                 select: function( event, ui ) { 
    97                                                         ui.item.option.selected = true; 
    98                                                         self._trigger( "selected", event, { 
    99                                                                 item: ui.item.option 
    100                                                         }); 
    101                                                 }, 
    102                                                 change: function( event, ui ) { 
    103                                                         if ( !ui.item ) { 
    104                                                                 var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ), 
    105                                                                         valid = false; 
    106                                                                 select.children( "option" ).each(function() { 
    107                                                                         if ( $( this ).text().match( matcher ) ) { 
    108                                                                                 this.selected = valid = true; 
    109                                                                                 return false; 
    110                                                                         } 
    111                                                                 }); 
    112                                                                 /* 
    113                                                                 if ( !valid ) { 
    114                                                                         // remove invalid value, as it didn't match anything 
    115                                                                         $( this ).val( "" ); 
    116                                                                         select.val( "" ); 
    117                                                                         input.data( "autocomplete" ).term = ""; 
    118                                                                         return false; 
    119                                                                 } 
    120                                                                 */ 
    121                                                                 if ( !valid ) { 
    122                                                                         if(select.has('option[value="custom"]').length > 0) { 
    123                                                                                 select.find('option:last').val('custom').html($(this).val()).attr('selected', 'selected'); 
    124                                                                         } else { 
    125                                                                                 select.append(select.find('option:last').clone().val('custom').html($(this).val())); 
    126                                                                                 select.find('option[value="custom"]').attr('selected', 'selected'); 
    127                                                                         } 
    128                                                                 } 
    129                                                         } 
    130                                                 } 
    131                                         }) 
    132                                         .addClass( "ui-widget ui-widget-content ui-corner-left" ); 
    133  
    134                                 input.data( "autocomplete" )._renderItem = function( ul, item ) { 
    135                                         return $( "<li></li>" ) 
    136                                                 .data( "item.autocomplete", item ) 
    137                                                 .append( "<a>" + item.label + "</a>" ) 
    138                                                 .appendTo( ul ); 
    139                                 }; 
    140  
    141                                 this.button = $( "<button type='button'>&nbsp;</button>" ) 
    142                                         .attr( "tabIndex", -1 ) 
    143                                         .attr( "title", "Show All Items" ) 
    144                                         .insertAfter( input ) 
    145                                         .button({ 
    146                                                 icons: { 
    147                                                         primary: "ui-icon-triangle-1-s" 
    148                                                 }, 
    149                                                 text: false 
    150                                         }) 
    151                                         .removeClass( "ui-corner-all" ) 
    152                                         .addClass( "ui-corner-right ui-button-icon" ) 
    153                                         .click(function() { 
    154                                                 // close if already visible 
    155                                                 if ( input.autocomplete( "widget" ).is( ":visible" ) ) { 
    156                                                         input.autocomplete( "close" ); 
    157                                                         return; 
    158                                                 } 
    159  
    160                                                 // work around a bug (likely same cause as #5265) 
    161                                                 $( this ).blur(); 
    162  
    163                                                 // pass empty string as value to search for, displaying all results 
    164                                                 input.autocomplete( "search", "" ); 
    165                                                 input.focus(); 
    166                                         }); 
    167                         }, 
    168  
    169                         destroy: function() { 
    170                                 this.input.remove(); 
    171                                 this.button.remove(); 
    172                                 this.element.show(); 
    173                                 $.Widget.prototype.destroy.call( this ); 
    174                         } 
    175                 }); 
    176         })( jQuery ); 
    177         /** 
    178          * #END: Implementação do widget de input-combobox 
    179          */ 
    18062         winElement.find('input[name="alarmDate"]').change(function(event){ 
    18163                winElement.find('input[name="alarmTime"]').attr('disabled', ( $(this).val() == "" ? 'disabled' : false)); 
Note: See TracChangeset for help on using the changeset viewer.