wp/wp-admin/js/inline-edit-post.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
   176 	 *
   176 	 *
   177 	 * @memberof inlineEditPost
   177 	 * @memberof inlineEditPost
   178 	 */
   178 	 */
   179 	setBulk : function(){
   179 	setBulk : function(){
   180 		var te = '', type = this.type, c = true;
   180 		var te = '', type = this.type, c = true;
       
   181 		var checkedPosts = $( 'tbody th.check-column input[type="checkbox"]:checked' );
       
   182 		var categories = {};
   181 		this.revert();
   183 		this.revert();
   182 
   184 
   183 		$( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
   185 		$( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
   184 
   186 
   185 		// Insert the editor at the top of the table with an empty row above to maintain zebra striping.
   187 		// Insert the editor at the top of the table with an empty row above to maintain zebra striping.
   215 		}
   217 		}
   216 
   218 
   217 		// Populate the list of items to bulk edit.
   219 		// Populate the list of items to bulk edit.
   218 		$( '#bulk-titles' ).html( '<ul id="bulk-titles-list" role="list">' + te + '</ul>' );
   220 		$( '#bulk-titles' ).html( '<ul id="bulk-titles-list" role="list">' + te + '</ul>' );
   219 
   221 
       
   222 		// Gather up some statistics on which of these checked posts are in which categories.
       
   223 		checkedPosts.each( function() {
       
   224 			var id      = $( this ).val();
       
   225 			var checked = $( '#category_' + id ).text().split( ',' );
       
   226 
       
   227 			checked.map( function( cid ) {
       
   228 				categories[ cid ] || ( categories[ cid ] = 0 );
       
   229 				// Just record that this category is checked.
       
   230 				categories[ cid ]++;
       
   231 			} );
       
   232 		} );
       
   233 
       
   234 		// Compute initial states.
       
   235 		$( '.inline-edit-categories input[name="post_category[]"]' ).each( function() {
       
   236 			if ( categories[ $( this ).val() ] == checkedPosts.length ) {
       
   237 				// If the number of checked categories matches the number of selected posts, then all posts are in this category.
       
   238 				$( this ).prop( 'checked', true );
       
   239 			} else if ( categories[ $( this ).val() ] > 0 ) {
       
   240 				// If the number is less than the number of selected posts, then it's indeterminate.
       
   241 				$( this ).prop( 'indeterminate', true );
       
   242 				if ( ! $( this ).parent().find( 'input[name="indeterminate_post_category[]"]' ).length ) {
       
   243 					// Get the term label text.
       
   244 					var label = $( this ).parent().text();
       
   245 					// Set indeterminate states for the backend. Add accessible text for indeterminate inputs. 
       
   246 					$( this ).after( '<input type="hidden" name="indeterminate_post_category[]" value="' + $( this ).val() + '">' ).attr( 'aria-label', label.trim() + ': ' + wp.i18n.__( 'Some selected posts have this category' ) );
       
   247 				}
       
   248 			}
       
   249 		} );
       
   250 
       
   251 		$( '.inline-edit-categories input[name="post_category[]"]:indeterminate' ).on( 'change', function() {
       
   252 			// Remove accessible label text. Remove the indeterminate flags as there was a specific state change.
       
   253 			$( this ).removeAttr( 'aria-label' ).parent().find( 'input[name="indeterminate_post_category[]"]' ).remove();
       
   254 		} );
       
   255 
       
   256 		$( '.inline-edit-save button' ).on( 'click', function() {
       
   257 			$( '.inline-edit-categories input[name="post_category[]"]' ).prop( 'indeterminate', false );
       
   258 		} );
       
   259 
   220 		/**
   260 		/**
   221 		 * Binds on click events to handle the list of items to bulk edit.
   261 		 * Binds on click events to handle the list of items to bulk edit.
   222 		 *
   262 		 *
   223 		 * @listens click
   263 		 * @listens click
   224 		 */
   264 		 */
   226 			var $this = $( this ),
   266 			var $this = $( this ),
   227 				id = $this.attr( 'id' ).substr( 1 ),
   267 				id = $this.attr( 'id' ).substr( 1 ),
   228 				$prev = $this.parent().prev().children( '.ntdelbutton' ),
   268 				$prev = $this.parent().prev().children( '.ntdelbutton' ),
   229 				$next = $this.parent().next().children( '.ntdelbutton' );
   269 				$next = $this.parent().next().children( '.ntdelbutton' );
   230 
   270 
       
   271 			$( 'input#cb-select-all-1, input#cb-select-all-2' ).prop( 'checked', false );
   231 			$( 'table.widefat input[value="' + id + '"]' ).prop( 'checked', false );
   272 			$( 'table.widefat input[value="' + id + '"]' ).prop( 'checked', false );
   232 			$( '#_' + id ).parent().remove();
   273 			$( '#_' + id ).parent().remove();
   233 			wp.a11y.speak( wp.i18n.__( 'Item removed.' ), 'assertive' );
   274 			wp.a11y.speak( wp.i18n.__( 'Item removed.' ), 'assertive' );
   234 
   275 
   235 			// Move focus to a proper place when items are removed.
   276 			// Move focus to a proper place when items are removed.
   303 		// Populate fields in the quick edit window.
   344 		// Populate fields in the quick edit window.
   304 		rowData = $('#inline_'+id);
   345 		rowData = $('#inline_'+id);
   305 		if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
   346 		if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
   306 
   347 
   307 			// The post author no longer has edit capabilities, so we need to add them to the list of authors.
   348 			// The post author no longer has edit capabilities, so we need to add them to the list of authors.
   308 			$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
   349 			$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#post-' + id + ' .author').text() + '</option>');
   309 		}
   350 		}
   310 		if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) {
   351 		if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) {
   311 			$('label.inline-edit-author', editRow).hide();
   352 			$('label.inline-edit-author', editRow).hide();
   312 		}
   353 		}
   313 
   354 
   374 
   415 
   375 			textarea.wpTagsSuggest();
   416 			textarea.wpTagsSuggest();
   376 		});
   417 		});
   377 
   418 
   378 		// Handle the post status.
   419 		// Handle the post status.
       
   420 		var post_date_string = $(':input[name="aa"]').val() + '-' + $(':input[name="mm"]').val() + '-' + $(':input[name="jj"]').val();
       
   421 		post_date_string += ' ' + $(':input[name="hh"]').val() + ':' + $(':input[name="mn"]').val() + ':' + $(':input[name="ss"]').val();
       
   422 		var post_date = new Date( post_date_string );
   379 		status = $('._status', rowData).text();
   423 		status = $('._status', rowData).text();
   380 		if ( 'future' !== status ) {
   424 		if ( 'future' !== status && Date.now() > post_date ) {
   381 			$('select[name="_status"] option[value="future"]', editRow).remove();
   425 			$('select[name="_status"] option[value="future"]', editRow).remove();
       
   426 		} else {
       
   427 			$('select[name="_status"] option[value="publish"]', editRow).remove();
   382 		}
   428 		}
   383 
   429 
   384 		pw = $( '.inline-edit-password-input' ).prop( 'disabled', false );
   430 		pw = $( '.inline-edit-password-input' ).prop( 'disabled', false );
   385 		if ( 'private' === status ) {
   431 		if ( 'private' === status ) {
   386 			$('input[name="keep_private"]', editRow).prop('checked', true);
   432 			$('input[name="keep_private"]', editRow).prop('checked', true);