Ticket #22607: 22607.3.diff
| File 22607.3.diff, 7.4 KB (added by , 13 years ago) |
|---|
-
wp-admin/admin-ajax.php
56 56 'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post', 57 57 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 58 58 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 59 'send-attachment-to-editor', 59 'send-attachment-to-editor', 'save-attachment-order', 60 60 ); 61 61 62 62 // Register core Ajax calls. -
wp-admin/includes/ajax-actions.php
1927 1927 wp_send_json_success( $attachment ); 1928 1928 } 1929 1929 1930 function wp_ajax_save_attachment_order() { 1931 if ( ! isset( $_REQUEST['post_id'] ) ) 1932 wp_send_json_error(); 1933 1934 if ( ! $post_id = absint( $_REQUEST['post_id'] ) ) 1935 wp_send_json_error(); 1936 1937 if ( empty( $_REQUEST['attachments'] ) ) 1938 wp_send_json_error(); 1939 1940 check_ajax_referer( 'update-post_' . $post_id, 'nonce' ); 1941 1942 $attachments = $_REQUEST['attachments']; 1943 1944 if ( ! current_user_can( 'edit_post', $post_id ) ) 1945 wp_send_json_error(); 1946 1947 $post = get_post( $post_id, ARRAY_A ); 1948 1949 foreach ( $attachments as $attachment_id => $menu_order ) { 1950 if ( ! current_user_can( 'edit_post', $attachment_id ) ) 1951 continue; 1952 if ( ! $attachment = get_post( $attachment_id ) ) 1953 continue; 1954 if ( 'attachment' != $attachment->post_type ) 1955 continue; 1956 1957 wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) ); 1958 } 1959 1960 wp_send_json_success(); 1961 } 1962 1930 1963 /** 1931 1964 * Generates the HTML to send an attachment to the editor. 1932 1965 * Backwards compatible with the media_send_to_editor filter and the chain -
wp-includes/js/media-models.js
523 523 _requery: function() { 524 524 if ( this.props.get('query') ) 525 525 this.mirror( Query.get( this.props.toJSON() ) ); 526 }, 527 528 // If this collection is sorted by `menuOrder`, recalculates and saves 529 // the menu order to the database. 530 saveMenuOrder: function() { 531 if ( 'menuOrder' !== this.props.get('orderby') ) 532 return; 533 534 // Removes any uploading attachments, updates each attachment's 535 // menu order, and returns an object with an { id: menuOrder } 536 // mapping to pass to the request. 537 var attachments = this.chain().filter( function( attachment ) { 538 return ! _.isUndefined( attachment.id ); 539 }).map( function( attachment, index ) { 540 // Indices start at 1. 541 index = index + 1; 542 attachment.set( 'menuOrder', index ); 543 return [ attachment.id, index ]; 544 }).object().value(); 545 546 if ( _.isEmpty( attachments ) ) 547 return; 548 549 return media.post( 'save-attachment-order', { 550 nonce: media.model.settings.updatePostNonce, 551 post_id: media.model.settings.postId, 552 attachments: attachments 553 }); 526 554 } 527 555 }, { 528 556 comparator: function( a, b, options ) { -
wp-includes/js/media-views.js
14 14 15 15 // Copy the `postId` setting over to the model settings. 16 16 media.model.settings.postId = media.view.settings.postId; 17 media.model.settings.updatePostNonce = media.view.settings.nonce.updatePost; 17 18 18 19 // Check if the browser supports CSS 3.0 transitions 19 20 $.support.transition = (function(){ … … 267 268 content: 'browse', 268 269 searchable: true, 269 270 filterable: false, 270 uploads: true 271 uploads: true, 272 sortable: true 271 273 }, 272 274 273 275 initialize: function() { … … 2690 2692 this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value(); 2691 2693 2692 2694 this.initSortable(); 2693 this.collection.props.on( 'change:orderby', this.refreshSortable, this );2694 2695 2695 2696 _.bindAll( this, 'css' ); 2696 2697 this.model.on( 'change:edge change:gutter', this.css, this ); … … 2734 2735 }, 2735 2736 2736 2737 initSortable: function() { 2737 var collection = this.collection, 2738 var view = this, 2739 collection = this.collection, 2738 2740 from; 2739 2741 2740 2742 if ( ! this.options.sortable || ! $.fn.sortable ) … … 2760 2762 // Update the model's index in the collection. 2761 2763 // Do so silently, as the view is already accurate. 2762 2764 update: function( event, ui ) { 2763 var model = collection.at( from ); 2765 var model = collection.at( from ), 2766 comparator = collection.comparator; 2764 2767 2768 // Temporarily disable the comparator to prevent `add` 2769 // from re-sorting. 2770 delete collection.comparator; 2771 2772 // Silently shift the model to its new index. 2765 2773 collection.remove( model, { 2766 2774 silent: true 2767 2775 }).add( model, { 2768 2776 at: ui.item.index(), 2769 2777 silent: true 2770 2778 }); 2779 2780 // Restore the comparator. 2781 collection.comparator = comparator; 2782 2783 // If the collection is sorted by menu order, 2784 // update the menu order. 2785 view.saveMenuOrder(); 2786 2787 // Make sure any menu-order-related callbacks are bound. 2788 view.refreshSortable(); 2771 2789 } 2772 2790 }); 2773 2791 … … 2776 2794 collection.props.on( 'change:orderby', function() { 2777 2795 this.$el.sortable( 'option', 'disabled', !! collection.comparator ); 2778 2796 }, this ); 2797 2798 this.collection.props.on( 'change:orderby', this.refreshSortable, this ); 2799 this.refreshSortable(); 2779 2800 }, 2780 2801 2781 2802 refreshSortable: function() { … … 2783 2804 return; 2784 2805 2785 2806 // If the `collection` has a `comparator`, disable sorting. 2786 this.$el.sortable( 'option', 'disabled', !! this.collection.comparator ); 2807 var collection = this.collection, 2808 orderby = collection.props.get('orderby'), 2809 enabled = 'menuOrder' === orderby || ! collection.comparator, 2810 hasMenuOrder; 2811 2812 this.$el.sortable( 'option', 'disabled', ! enabled ); 2813 2814 // Check if any attachments have a specified menu order. 2815 hasMenuOrder = this.collection.any( function( attachment ) { 2816 return attachment.get('menuOrder'); 2817 }); 2818 2819 // Always unbind the `saveMenuOrder` callback to prevent multiple 2820 // callbacks stacking up. 2821 this.collection.off( 'change:uploading', this.saveMenuOrder, this ); 2822 2823 if ( hasMenuOrder ) 2824 this.collection.on( 'change:uploading', this.saveMenuOrder, this ); 2825 2787 2826 }, 2788 2827 2828 saveMenuOrder: function() { 2829 this.collection.saveMenuOrder(); 2830 }, 2831 2789 2832 createAttachmentView: function( attachment ) { 2790 2833 var view = new this.options.AttachmentView({ 2791 2834 controller: this.controller, … … 3049 3092 }).render() ); 3050 3093 } 3051 3094 3052 if ( this.options.sortable ) {3095 if ( this.options.sortable && ! this.options.filters ) { 3053 3096 this.toolbar.set( 'dragInfo', new media.View({ 3054 3097 el: $( '<div class="instructions">' + l10n.dragInfo + '</div>' )[0], 3055 3098 priority: -40 -
wp-includes/media.php
1433 1433 if ( isset( $args['post'] ) ) { 1434 1434 $post = get_post( $args['post'] ); 1435 1435 $settings['postId'] = $post->ID; 1436 $settings['nonce']['updatePost'] = wp_create_nonce( 'update-post_' . $post->ID ); 1436 1437 } 1437 1438 1438 1439 $hier = $post && is_post_type_hierarchical( $post->post_type );