Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 30th, 2012  |  syntax: jQuery  |  size: 1.36 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $( function() {
  2.        
  3.         $( '.add_to_collection' ).click( function() {
  4.                
  5.                 $( this ).hide();
  6.                 $( '#element_collections' ).show( 'slow' );
  7.                
  8.                 return false;
  9.         });
  10.        
  11.         $( '#element_collections' ).submit( function() {
  12.                
  13.                 var form_data = $( this ).serialize();
  14.                
  15.                 console.log( form_data );
  16.                
  17.                 $.ajax({
  18.                         context: this,
  19.                         url: root_url + '?act=siteuser/add_to_collections',
  20.                         type: 'POST',
  21.                         dataType: 'json'',
  22.                         data: form_data,
  23.                         success: function( response ) {
  24.                                
  25.                                 console.log( response );
  26.                                
  27.                                 if ( response.status == true ) {
  28.                                        
  29.                                         $( this ).find( 'input[type=checkbox]:checked' ).attr( 'disabled', true );
  30.                                        
  31.                                         if ( response.new == true ) {
  32.                                                
  33.                                                 var new_element = $( '<input type="checkbox" id="collection' + response.collection_id + '" value="' + response.collection_id + '" name="collection_rel[]" checked="checked" disabled="disabled">' +
  34.                                                                                          '<label for="collection_' + response.collection_id + '">' + response.collection_name + '</label>' );
  35.                                                
  36.                                                 $( '.collections_assign' ).append( new_element );
  37.                                                
  38.                                                 $( '#element_collections input[name=collection_name]' ).val( '' );
  39.                                                 $( '#element_collections textarea' ).val( '' );
  40.                                         }
  41.                                        
  42.                                         $( this ).hide( 'slow', function() {
  43.                                                
  44.                                                 $( '.add_to_collection' ).show();
  45.                                         });
  46.                                 }
  47.                         }
  48.                 });
  49.                
  50.                 return false;
  51.         });
  52. });