wp/wp-admin/js/user-profile.js
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
--- a/wp/wp-admin/js/user-profile.js	Mon Jun 08 16:11:51 2015 +0000
+++ b/wp/wp-admin/js/user-profile.js	Tue Jun 09 03:35:32 2015 +0200
@@ -1,7 +1,8 @@
+/* global ajaxurl, pwsL10n */
 (function($){
 
 	function check_pass_strength() {
-		var pass1 = $('#pass1').val(), user = $('#user_login').val(), pass2 = $('#pass2').val(), strength;
+		var pass1 = $('#pass1').val(), pass2 = $('#pass2').val(), strength;
 
 		$('#pass-strength-result').removeClass('short bad good strong');
 		if ( ! pass1 ) {
@@ -13,16 +14,16 @@
 
 		switch ( strength ) {
 			case 2:
-				$('#pass-strength-result').addClass('bad').html( pwsL10n['bad'] );
+				$('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
 				break;
 			case 3:
-				$('#pass-strength-result').addClass('good').html( pwsL10n['good'] );
+				$('#pass-strength-result').addClass('good').html( pwsL10n.good );
 				break;
 			case 4:
-				$('#pass-strength-result').addClass('strong').html( pwsL10n['strong'] );
+				$('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
 				break;
 			case 5:
-				$('#pass-strength-result').addClass('short').html( pwsL10n['mismatch'] );
+				$('#pass-strength-result').addClass('short').html( pwsL10n.mismatch );
 				break;
 			default:
 				$('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
@@ -30,10 +31,11 @@
 	}
 
 	$(document).ready( function() {
-		var select = $('#display_name');
+		var $colorpicker, $stylesheet, user_id, current_user_id,
+			select = $( '#display_name' );
 
-		$('#pass1').val('').keyup( check_pass_strength );
-		$('#pass2').val('').keyup( check_pass_strength );
+		$('#pass1').val('').on( 'input propertychange', check_pass_strength );
+		$('#pass2').val('').on( 'input propertychange', check_pass_strength );
 		$('#pass-strength-result').show();
 		$('.color-palette').click( function() {
 			$(this).siblings('input[name="admin_color"]').prop('checked', true);
@@ -50,8 +52,8 @@
 					};
 
 				if ( inputs.display_firstname && inputs.display_lastname ) {
-					inputs['display_firstlast'] = inputs.display_firstname + ' ' + inputs.display_lastname;
-					inputs['display_lastfirst'] = inputs.display_lastname + ' ' + inputs.display_firstname;
+					inputs.display_firstlast = inputs.display_firstname + ' ' + inputs.display_lastname;
+					inputs.display_lastfirst = inputs.display_lastname + ' ' + inputs.display_firstname;
 				}
 
 				$.each( $('option', select), function( i, el ){
@@ -59,12 +61,13 @@
 				});
 
 				$.each(inputs, function( id, value ) {
-					if ( ! value )
+					if ( ! value ) {
 						return;
+					}
 
 					var val = value.replace(/<\/?[a-z][^>]*>/gi, '');
 
-					if ( inputs[id].length && $.inArray( val, dub ) == -1 ) {
+					if ( inputs[id].length && $.inArray( val, dub ) === -1 ) {
 						dub.push(val);
 						$('<option />', {
 							'text': val
@@ -73,6 +76,74 @@
 				});
 			});
 		}
+
+		$colorpicker = $( '#color-picker' );
+		$stylesheet = $( '#colors-css' );
+		user_id = $( 'input#user_id' ).val();
+		current_user_id = $( 'input[name="checkuser_id"]' ).val();
+
+		$colorpicker.on( 'click.colorpicker', '.color-option', function() {
+			var colors,
+				$this = $(this);
+
+			if ( $this.hasClass( 'selected' ) ) {
+				return;
+			}
+
+			$this.siblings( '.selected' ).removeClass( 'selected' );
+			$this.addClass( 'selected' ).find( 'input[type="radio"]' ).prop( 'checked', true );
+
+			// Set color scheme
+			if ( user_id === current_user_id ) {
+				// Load the colors stylesheet.
+				// The default color scheme won't have one, so we'll need to create an element.
+				if ( 0 === $stylesheet.length ) {
+					$stylesheet = $( '<link rel="stylesheet" />' ).appendTo( 'head' );
+				}
+				$stylesheet.attr( 'href', $this.children( '.css_url' ).val() );
+
+				// repaint icons
+				if ( typeof wp !== 'undefined' && wp.svgPainter ) {
+					try {
+						colors = $.parseJSON( $this.children( '.icon_colors' ).val() );
+					} catch ( error ) {}
+
+					if ( colors ) {
+						wp.svgPainter.setColors( colors );
+						wp.svgPainter.paint();
+					}
+				}
+
+				// update user option
+				$.post( ajaxurl, {
+					action:       'save-user-color-scheme',
+					color_scheme: $this.children( 'input[name="admin_color"]' ).val(),
+					nonce:        $('#color-nonce').val()
+				}).done( function( response ) {
+					if ( response.success ) {
+						$( 'body' ).removeClass( response.data.previousScheme ).addClass( response.data.currentScheme );
+					}
+				});
+			}
+		});
+	});
+
+	$( '#destroy-sessions' ).on( 'click', function( e ) {
+		var $this = $(this);
+
+		wp.ajax.post( 'destroy-sessions', {
+			nonce: $( '#_wpnonce' ).val(),
+			user_id: $( '#user_id' ).val()
+		}).done( function( response ) {
+			$this.prop( 'disabled', true );
+			$this.siblings( '.notice' ).remove();
+			$this.before( '<div class="notice notice-success inline"><p>' + response.message + '</p></div>' );
+		}).fail( function( response ) {
+			$this.siblings( '.notice' ).remove();
+			$this.before( '<div class="notice notice-error inline"><p>' + response.message + '</p></div>' );
+		});
+
+		e.preventDefault();
 	});
 
 })(jQuery);