UserManager.js 8.73 KB
function update_listing_preference() {
    var pref = jQuery('#profile_preference').val();
    if (pref == "Work") {
        jQuery('.work-only').show();
    } else {
        jQuery('.work-only').hide();
    }
}

jQuery(function($) {
    
    Date.firstDayOfWeek = 0;
    Date.format = 'yyyy-mm-dd';
    
    if (jQuery('.datepicker').length > 0) {
        jQuery('.datepicker').datePicker(
    		{
    			startDate: '1920-01-01',
    			endDate: (new Date()).asString()
    		}
    	);
	}
	
	$('#invoice_type').change(function() {
	   if ($('#invoice_type').val() == "invoice") {
	       $('.invoice_only').show();
	   } else {
	       $('.invoice_only').hide();
	   }
	});
	
	jQuery('#creditNotBtn').click(function(e) {
	   jQuery('#credit_note').slideToggle('fast');
	   
	   var InvoiceType = $('#invoice_type');
	   if (InvoiceType.val() == "invoice") {
	       $('.invoice_only').show();
	   } else {
	       $('.invoice_only').hide();
	   }
	   
	   jQuery('#creditForm').ajaxForm({
	       url: '/wp-admin/admin-ajax.php'
	     , data:   ({ajax:"yes", action: 'create_invoice_note'})
	     , dateType:   'json'
	     , type:       'POST'
	     , success: function(data) {
	           // reload, cannot use reload() because then the form values get re-applied.
	           document.location.href = document.location.href;
	           
	       }
	   });
	   e.preventDefault();
	   return false;
	});
	
	jQuery('.remove-user').colorbox({onComplete: function() {
        
        var cb = this;
        var options = {
              beforeSubmit: function() {}
            , success:      function(data) {
                document.location.href = document.location.href;      
              }
            , error: function(XMLHttpRequest, textStatus, errorThrown) {
                document.location.href = document.location.href;
              }
            , data: ({ajax:"yes", action: 'remove_user'})
            , dataType: 'json'
            , url: '/wp-admin/admin-ajax.php'
        };
        jQuery('#remove-user-form').ajaxForm(options);
        
    }});

    jQuery('#admin-edit-user-profile').ajaxForm({
        url: '/wp-admin/admin-ajax.php'
      , data: ({ajax:"yes", action: 'update_edit_profile'})
      , dataType: 'json'
      , type: 'post'
      , beforeSubmit: function(formData, jqForm, options) {
            var $error_container = jQuery('.validation-errors');
            $error_container.hide();
        }
      , success: function(data) {
            if (data.success == "true") {
                jQuery('.update-placeholder').html('Update Successful.');
            } else {
                //$('.register-form :input').removeAttr('disabled');
                var $error_container = jQuery('.validation-errors');
                jQuery('h6',$error_container).html("OOPS...");
                jQuery('ul',$error_container).html(data.msg);
                $error_container.show();
            }
        }
      , error: function(XMLHttpRequest, textStatus, errorThrown) {
            var $error_container = jQuery('.validation-errors');
            jQuery('h6',$error_container).html("OOPS...");
            jQuery('ul',$error_container).html("<li>Please check all required fields and be sure they are the right format.</li>");
            $error_container.show();
        }
    });

    // overview ajaxForm...
    jQuery('#overview_form').ajaxForm({
        url: '/wp-admin/admin-ajax.php'
      , data: ({ajax:"yes", action: 'update_account'})
      , dataType: 'json'
      , type: 'post'
      , beforeSubmit:   function(formData, jqForm, options) {
            var $error_container = jQuery('.validation-errors');
            $error_container.hide();
        }
      , success:      function(data) {
      
            if (data.success == "true") {
                jQuery('.update-placeholder').html('Update Successful.');
            } else {
                //$('.register-form :input').removeAttr('disabled');
                var $error_container = jQuery('.validation-errors');
                jQuery('h6',$error_container).html("OOPS...");
                jQuery('ul',$error_container).html(data.msg);
                $error_container.show();
            }
        }
      , error: function(XMLHttpRequest, textStatus, errorThrown) {
            var $error_container = jQuery('.validation-errors');
            jQuery('h6',$error_container).html("A server error has occurred.");
            jQuery('ul',$error_container).html("<li>"+errorThrown+"</li>");
            $error_container.show();
        }
    });
    
    jQuery('.event-edit').colorbox({onComplete: function() {
        var cb = this;
        var options = {
              beforeSubmit: function() {}
            , success:      function(data) {
            
                if (data.refresh == "true") {
                    document.location.href = document.location.href;
                } else {
                    jQuery.colorbox.close();
                }
                
              }
            , data: ({ajax:"yes", action: 'update_registration'})
            , dataType: 'json'
            , url: '/wp-admin/admin-ajax.php'
        };
        jQuery('#edit-event-form').ajaxForm(options);
    }});
    
    jQuery('#admin_add_new_cehours').colorbox({onComplete: function() {
        jQuery('.datepicker').datePicker(
    		{
    			startDate: '1920-01-01',
    			endDate: (new Date()).asString()
    		}
    	);
    	
    	var options = {
    	   success:    function(data) {
    	       document.location.href = document.location.href;
    	   }
    	   , data:     ({ajax:"yes", action: 'admin_update_cehours'})
    	   , dataType: 'json'
    	   , url:      '/wp-admin/admin-ajax.php'
    	};
    	jQuery('#edit-cehours-form').ajaxForm(options);
    	
    }});
    
    
    jQuery('.cehours-edit').colorbox({onComplete: function() {
        jQuery('.datepicker').datePicker(
    		{
    			startDate: '1920-01-01',
    			endDate: (new Date()).asString()
    		}
    	);
    	
    	var options = {
    	   success:    function(data) {
    	       document.location.href = document.location.href;
    	   }
    	   , data:     ({ajax:"yes", action: 'admin_update_cehours'})
    	   , dataType: 'json'
    	   , url:      '/wp-admin/admin-ajax.php'
    	};
    	jQuery('#edit-cehours-form').ajaxForm(options);
    	
    }});
    
    
    jQuery('.cehours-remove').click(function(e) {
        
        var ds = jQuery(this).attr('rel');
        
        jConfirm('Are you sure?', 'Remove CE Hours?', function(c) {
            if (c) {
                jQuery.ajax({
                    url: '/wp-admin/admin-ajax.php'
                  , data: ({ajax:"yes", action: 'admin_remove_cehours', uid:user_id, indexed: ds})
                  , type: 'post'
                  , dataType: 'json'
                  , success: function(data) {
                        document.location.href = document.location.href;
                    }
                });
            }
        });
        
        e.preventDefault();
        return false;
        
    });
    
    jQuery('.event-cancel').click(function(e) {
        var eventcontainer = jQuery(this).parent();
        var link = jQuery(this);
    
        jConfirm('Are you sure?', 'Cancel Registration', function(c) {
        
            if (c) {
                eventcontainer.empty().addClass('spinner');
                
                jQuery.ajax({
                    url: '/wp-admin/admin-ajax.php'
                  , data: ({ajax:"yes", action: 'cancel_registration', uid: user_id, eid: link.attr('rel')})
                  , type: 'post'
                  , success: function(data) {
                        
                        if (data.ask_credit=="true") {                  
                            // ask if they want to credit....
                            jPrompt('How much (if any) would you like to credit their account?', '0.00', 'Registration has been cancelled', function(r) {
                                if( r ) {
                                    jQuery.ajax({
                                        url: '/wp-admin/admin-ajax.php'  
                                      , data: ({ajax:"yes", action: 'post_credit', uid:user_id, post_id: link.attr('rel'), amount:r})
                                      , type: 'POST'
                                      , dataType: 'json'
                                    });
                                }
                                document.location.href = document.location.href;
                            });
                        } else {
                            document.location.href = document.location.href;
                        }
                        
                    }
                  , dataType: 'json'
                });

            }
        
        });
            
        e.preventDefault();
        return false;
    });

    

});