Advertisement
Adam_Martin

Untitled

Feb 15th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var $_widgetName = 'source_selector';
  2.  
  3. widgetControls[ $_widgetName ] =
  4. {
  5.     input_control__input :
  6.     {
  7.         events :
  8.         {
  9.             keyup   : function()
  10.             {
  11.                 this.ready()
  12.             }
  13.         },
  14.  
  15.         actions :
  16.         {
  17.             ready : function()
  18.             {
  19.                 var self = this;
  20.                 setTimeout
  21.                 (
  22.                     function ()
  23.                     {
  24.                         var val = self.template.val();
  25.                         if ( prevInput != val )
  26.                         {
  27.                             if ( val.length >= 3 )
  28.                             {
  29.                                 prevInput = val;
  30.                                 self.getPersonList();
  31.                             } else
  32.                             {
  33.                                 self.bricks('list_container').hide();
  34.                             }
  35.                         }
  36.                     },
  37.                     2000
  38.                 );
  39.             },
  40.  
  41.             getPersonList : function ()
  42.             {
  43.                 this.bricks('list_container').getPersonList();
  44.             }
  45.         }
  46.     },
  47.     list_container :
  48.     {
  49.         events :
  50.         {
  51.  
  52.         },
  53.  
  54.         actions :
  55.         {
  56.             show          : function()
  57.             {
  58.                 this.template.css( 'display', 'block' )
  59.             },
  60.  
  61.             hide          : function()
  62.             {
  63.                 this.template.css( 'display', 'none' )
  64.             },
  65.  
  66.             getPersonList : function ()
  67.             {
  68.                 var self = this;
  69.                 $.getJSON
  70.                 (
  71.                     '/cp/ajax/get-person-by-mask',
  72.                     //'/cp/ajax/get-' + source + '-by-mask',
  73.                     {
  74.                         mask: this.bricks( 'input_control__input' )
  75.                                   .template.val()
  76.                     },
  77.                     function ( data )
  78.                     {
  79.                         if ( data.length > 0 )
  80.                         {
  81.                             //console.log( 100 )
  82.                             self.bricks( 'list_container__listing' )
  83.                                 .createListing( data );
  84.                         } else
  85.                         {
  86.                             self.hide();
  87.                         }
  88.                     }
  89.                 )
  90.             }
  91.         }
  92.     },
  93.  
  94.     list_container__listing :
  95.     {
  96.         events :
  97.         {
  98.  
  99.         },
  100.  
  101.         actions :
  102.         {
  103.             clear           : function ()
  104.             {
  105.                 this.template.html('');
  106.             },
  107.  
  108.             createListing   : function ( data )
  109.             {
  110.  
  111.                 this.bricks( 'list_container' ).template.hide();
  112.                 this.clear();
  113.                 for ( var key in data )
  114.                 {
  115.                     var name = data[ key ][ 'name' ];
  116.                     var id   = data[ key ][ 'id' ];
  117.  
  118.                     name = name.replace(
  119.                         new RegExp
  120.                         (
  121.                             this.bricks( 'input_control__input' )
  122.                                 .template.val(),
  123.                             'i'
  124.                         ),
  125.                         '<font color=red>$&</font>'
  126.                     );
  127.  
  128.                     var list_item = new Brick( 'list_container__listing_item', this.widget)
  129.                         .template
  130.                         .attr( 'id', id )
  131.                         .html( name );
  132.  
  133.                     this.template.append( list_item );
  134.                 }
  135.                 this.bricks( 'list_container' ).show();
  136.             }
  137.  
  138.         }
  139.     },
  140.  
  141.     list_container__listing_item :
  142.     {
  143.         events :
  144.         {
  145.             mouseover   : function ()
  146.             {
  147.                 //console.log( 666 )
  148.                 this.itemBacklightOn( this.template );
  149.             },
  150.  
  151.             mouseout    : function ()
  152.             {
  153.                 this.itemBacklightOff( this.template );
  154.             },
  155.  
  156.             click       : function ()
  157.             {
  158.                 this.bricks( 'list_container' ).template.hide();
  159.                 this.setInputSelector( this.template );
  160.  
  161.                 this.widget.callback( this.template.attr( 'id' ) );
  162.             }
  163.  
  164.         },
  165.         actions :
  166.         {
  167.             itemBacklightOn : function ( item )
  168.             {
  169.                 $( item ).css( 'background-color', '#00ff00' );
  170.             },
  171.  
  172.             itemBacklightOff : function ( item )
  173.             {
  174.                 $( item ).css( 'background-color', '#fff' );
  175.             },
  176.  
  177.             setInputSelector : function ( item )
  178.             {
  179.                 var self = this;
  180.                 $.getJSON
  181.                 (
  182.                     '/cp/ajax/get-person-by-id',
  183. //                    '/cp/ajax/get-' + source + '-by-id',
  184.                     {
  185.                         id: $( item ).attr( 'id' )
  186.                     },
  187.                     function( data )
  188.                     {
  189.                         self.bricks( 'input_control__input' ).template
  190.                             .val( data[ 'name' ] )
  191.                             .attr( 'disabled', 'disabled' );
  192.                         //fn( data );
  193.                     }
  194.                 )
  195.             }
  196.         }
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement