Changeset 29490
- Timestamp:
- 08/14/2014 06:30:49 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r29454 r29490 2162 2162 2163 2163 $query['post_type'] = 'attachment'; 2164 $query['post_status'] = 'inherit'; 2164 if ( MEDIA_TRASH 2165 && ! empty( $_REQUEST['query']['post_status'] ) 2166 && 'trash' === $_REQUEST['query']['post_status'] ) { 2167 $query['post_status'] = 'trash'; 2168 } else { 2169 $query['post_status'] = 'inherit'; 2170 } 2171 2165 2172 if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) 2166 2173 $query['post_status'] .= ',private'; … … 2216 2223 if ( isset( $changes['description'] ) ) 2217 2224 $post['post_content'] = $changes['description']; 2225 2226 if ( MEDIA_TRASH && isset( $changes['status'] ) ) 2227 $post['post_status'] = $changes['status']; 2218 2228 2219 2229 if ( isset( $changes['alt'] ) ) { … … 2244 2254 } 2245 2255 2246 wp_update_post( $post ); 2256 if ( MEDIA_TRASH && isset( $changes['status'] ) && 'trash' === $changes['status'] ) { 2257 wp_delete_post( $id ); 2258 } else { 2259 wp_update_post( $post ); 2260 } 2261 2247 2262 wp_send_json_success(); 2248 2263 } -
trunk/src/wp-includes/css/media-views.css
r29489 r29490 1604 1604 .attachment-info .refresh-attachment, 1605 1605 .attachment-info .delete-attachment, 1606 .attachment-info .trash-attachment { 1606 .attachment-info .trash-attachment, 1607 .attachment-info .untrash-attachment { 1607 1608 display: block; 1608 1609 text-decoration: none; … … 1621 1622 1622 1623 .media-modal .delete-attachment, 1623 .media-modal .trash-attachment { 1624 .media-modal .trash-attachment, 1625 .media-modal .untrash-attachment { 1624 1626 color: #bc0b0b; 1625 1627 } 1626 1628 1627 1629 .media-modal .delete-attachment:hover, 1628 .media-modal .trash-attachment:hover { 1630 .media-modal .trash-attachment:hover, 1631 .media-modal .untrash-attachment:hover { 1629 1632 color: red; 1630 1633 } … … 2744 2747 } 2745 2748 2746 .edit-attachment-frame .delete-attachment { 2749 .edit-attachment-frame .delete-attachment, 2750 .edit-attachment-frame .trash-attachment, 2751 .edit-attachment-frame .untrash-attachment { 2747 2752 float: right; 2748 2753 margin-top: 7px; -
trunk/src/wp-includes/js/media-grid.js
r29489 r29490 184 184 wp.media( { 185 185 frame: 'edit-attachments', 186 gridRouter: this.gridRouter,186 controller: this, 187 187 library: this.state().get('library'), 188 188 model: model … … 231 231 232 232 bindDeferred: function() { 233 if ( ! this.browserView.dfd ) { 234 return; 235 } 233 236 this.browserView.dfd.done( _.bind( this.startHistory, this ) ); 234 237 }, … … 353 356 354 357 events: { 355 'click': 'collapse',356 'click .delete-media-item': 'deleteMediaItem',357 358 'click .left': 'previousMediaItem', 358 359 'click .right': 'nextMediaItem' … … 360 361 361 362 initialize: function() { 362 var self = this;363 364 363 media.view.Frame.prototype.initialize.apply( this, arguments ); 365 364 … … 369 368 }); 370 369 371 this. gridRouter = this.options.gridRouter;372 370 this.controller = this.options.controller; 371 this.gridRouter = this.controller.gridRouter; 373 372 this.library = this.options.library; 374 373 … … 376 375 this.model = this.options.model; 377 376 } else { 377 // this is a hack 378 378 this.model = this.library.at( 0 ); 379 379 } 380 380 381 this.bindHandlers(); 382 this.createStates(); 383 this.createModal(); 384 385 this.title.mode( 'default' ); 386 387 this.options.hasPrevious = this.hasPrevious(); 388 this.options.hasNext = this.hasNext(); 389 }, 390 391 bindHandlers: function() { 392 // Bind default title creation. 393 this.on( 'title:create:default', this.createTitle, this ); 394 381 395 // Close the modal if the attachment is deleted. 382 this.listenTo( this.model, 'destroy', this.close, this ); 383 384 this.createStates(); 396 this.listenTo( this.model, 'change:status destroy', this.close, this ); 385 397 386 398 this.on( 'content:create:edit-metadata', this.editMetadataMode, this ); … … 388 400 this.on( 'content:render:edit-image', this.editImageModeRender, this ); 389 401 this.on( 'close', this.detach ); 390 391 // Bind default title creation. 392 this.on( 'title:create:default', this.createTitle, this ); 393 this.title.mode( 'default' ); 394 395 this.options.hasPrevious = this.hasPrevious(); 396 this.options.hasNext = this.hasNext(); 402 }, 403 404 createModal: function() { 405 var self = this; 397 406 398 407 // Initialize modal container view. … … 610 619 initialize: function() { 611 620 media.view.Button.prototype.initialize.apply( this, arguments ); 621 if ( this.options.filters ) { 622 this.listenTo( this.options.filters.model, 'change', this.filterChange ); 623 } 612 624 this.listenTo( this.controller, 'selection:toggle', this.toggleDisabled ); 613 625 }, 614 626 627 filterChange: function( model ) { 628 if ( 'trash' === model.get( 'status' ) ) { 629 this.model.set( 'text', l10n.untrashSelected ); 630 } else if ( media.view.settings.mediaTrash ) { 631 this.model.set( 'text', l10n.trashSelected ); 632 } else { 633 this.model.set( 'text', l10n.deleteSelected ); 634 } 635 }, 636 615 637 toggleDisabled: function() { 616 this. $el.attr( 'disabled', ! this.controller.state().get( 'selection' ).length );638 this.model.set( 'disabled', ! this.controller.state().get( 'selection' ).length ); 617 639 }, 618 640 619 641 render: function() { 620 642 media.view.Button.prototype.render.apply( this, arguments ); 621 this.$el.addClass( 'delete-selected-button hidden' ); 643 if ( this.controller.isModeActive( 'select' ) ) { 644 this.$el.addClass( 'delete-selected-button' ); 645 } else { 646 this.$el.addClass( 'delete-selected-button hidden' ); 647 } 622 648 return this; 623 649 } -
trunk/src/wp-includes/js/media-models.js
r29076 r29490 825 825 * @access private 826 826 */ 827 _requery: function() { 827 _requery: function( cache ) { 828 var props; 828 829 if ( this.props.get('query') ) { 829 this.mirror( Query.get( this.props.toJSON() ) ); 830 props = this.props.toJSON(); 831 props.cache = ( true !== cache ); 832 this.mirror( Query.get( props ) ); 830 833 } 831 834 }, … … 948 951 949 952 return uploadedTo === attachment.get('uploadedTo'); 953 }, 954 /** 955 * @static 956 * @param {wp.media.model.Attachment} attachment 957 * 958 * @this wp.media.model.Attachments 959 * 960 * @returns {Boolean} 961 */ 962 status: function( attachment ) { 963 var status = this.props.get('status'); 964 if ( _.isUndefined( status ) ) { 965 return true; 966 } 967 968 return status === attachment.get('status'); 950 969 } 951 970 } … … 1145 1164 'perPage': 'posts_per_page', 1146 1165 'menuOrder': 'menu_order', 1147 'uploadedTo': 'post_parent' 1166 'uploadedTo': 'post_parent', 1167 'status': 'post_status' 1148 1168 }, 1149 1169 /** … … 1170 1190 orderby = Query.orderby, 1171 1191 defaults = Query.defaultProps, 1172 query; 1192 query, 1193 cache = !! props.cache; 1173 1194 1174 1195 // Remove the `query` property. This isn't linked to a query, 1175 1196 // this *is* the query. 1176 1197 delete props.query; 1198 delete props.cache; 1177 1199 1178 1200 // Fill default args. … … 1208 1230 1209 1231 // Search the query cache for matches. 1210 query = _.find( queries, function( query ) { 1211 return _.isEqual( query.args, args ); 1212 }); 1232 if ( cache ) { 1233 query = _.find( queries, function( query ) { 1234 return _.isEqual( query.args, args ); 1235 }); 1236 } else { 1237 queries = []; 1238 } 1213 1239 1214 1240 // Otherwise, create a new query and add it to the cache. -
trunk/src/wp-includes/js/media-views.js
r29484 r29490 5672 5672 text: text, 5673 5673 props: { 5674 status: null, 5674 5675 type: key, 5675 5676 uploadedTo: null, … … 5683 5684 text: l10n.allMediaItems, 5684 5685 props: { 5686 status: null, 5685 5687 type: null, 5686 5688 uploadedTo: null, … … 5695 5697 text: l10n.uploadedToThisPost, 5696 5698 props: { 5699 status: null, 5697 5700 type: null, 5698 5701 uploadedTo: media.view.settings.post.id, … … 5707 5710 text: l10n.unattached, 5708 5711 props: { 5712 status: null, 5709 5713 uploadedTo: 0, 5710 5714 type: null, … … 5714 5718 priority: 50 5715 5719 }; 5720 5721 if ( media.view.settings.mediaTrash ) { 5722 filters.trash = { 5723 text: l10n.trash, 5724 props: { 5725 uploadedTo: null, 5726 status: 'trash', 5727 type: null, 5728 orderby: 'date', 5729 order: 'DESC' 5730 }, 5731 priority: 50 5732 }; 5733 } 5716 5734 5717 5735 this.filters = filters; … … 5766 5784 5767 5785 createToolbar: function() { 5768 var filters, 5769 LibraryViewSwitcher, 5770 FiltersConstructor; 5786 var LibraryViewSwitcher, Filters; 5771 5787 5772 5788 /** … … 5778 5794 5779 5795 this.views.add( this.toolbar ); 5796 5797 this.toolbar.set( 'spinner', new media.view.Spinner({ 5798 priority: -60 5799 }) ); 5800 5801 if ( -1 !== $.inArray( this.options.filters, [ 'uploaded', 'all' ] ) ) { 5802 // "Filters" will return a <select>, need to render 5803 // screen reader text before 5804 this.toolbar.set( 'filtersLabel', new media.view.Label({ 5805 value: l10n.filterByType, 5806 attributes: { 5807 'for': 'media-attachment-filters' 5808 }, 5809 priority: -80 5810 }).render() ); 5811 5812 if ( 'uploaded' === this.options.filters ) { 5813 this.toolbar.set( 'filters', new media.view.AttachmentFilters.Uploaded({ 5814 controller: this.controller, 5815 model: this.collection.props, 5816 priority: -80 5817 }).render() ); 5818 } else { 5819 Filters = new media.view.AttachmentFilters.All({ 5820 controller: this.controller, 5821 model: this.collection.props, 5822 priority: -80 5823 }); 5824 5825 this.toolbar.set( 'filters', Filters.render() ); 5826 } 5827 } 5780 5828 5781 5829 // Feels odd to bring the global media library switcher into the Attachment … … 5815 5863 5816 5864 this.toolbar.set( 'deleteSelectedButton', new media.view.DeleteSelectedButton({ 5865 filters: Filters, 5817 5866 style: 'primary', 5818 5867 disabled: true, 5819 text: l10n.deleteSelected,5868 text: media.view.settings.mediaTrash ? l10n.trashSelected : l10n.deleteSelected, 5820 5869 controller: this.controller, 5821 5870 priority: -60, 5822 5871 click: function() { 5823 while ( this.controller.state().get( 'selection' ).length > 0 ) { 5824 this.controller.state().get( 'selection' ).at( 0 ).destroy(); 5872 var model, changed = [], 5873 selection = this.controller.state().get( 'selection' ), 5874 library = this.controller.state().get( 'library' ); 5875 5876 while ( selection.length > 0 ) { 5877 model = selection.at( 0 ); 5878 if ( media.view.settings.mediaTrash && 'trash' === model.get( 'status' ) ) { 5879 model.set( 'status', 'inherit' ); 5880 changed.push( model.save() ); 5881 selection.remove( model ); 5882 } else if ( media.view.settings.mediaTrash ) { 5883 model.set( 'status', 'trash' ); 5884 changed.push( model.save() ); 5885 selection.remove( model ); 5886 } else { 5887 model.destroy(); 5888 } 5889 } 5890 5891 if ( changed.length ) { 5892 $.when( changed ).then( function() { 5893 library._requery( true ); 5894 } ); 5825 5895 } 5826 5896 } 5827 }).render() );5828 }5829 5830 this.toolbar.set( 'spinner', new media.view.Spinner({5831 priority: -605832 }) );5833 5834 filters = this.options.filters;5835 if ( 'uploaded' === filters ) {5836 FiltersConstructor = media.view.AttachmentFilters.Uploaded;5837 } else if ( 'all' === filters ) {5838 FiltersConstructor = media.view.AttachmentFilters.All;5839 }5840 5841 if ( FiltersConstructor ) {5842 // "FiltersConstructor" will return a <select>, need to render5843 // screen reader text before5844 this.toolbar.set( 'filtersLabel', new media.view.Label({5845 value: l10n.filterByType,5846 attributes: {5847 'for': 'media-attachment-filters'5848 },5849 priority: -805850 }).render() );5851 this.toolbar.set( 'filters', new FiltersConstructor({5852 controller: this.controller,5853 model: this.collection.props,5854 priority: -805855 5897 }).render() ); 5856 5898 } … … 6421 6463 'click .delete-attachment': 'deleteAttachment', 6422 6464 'click .trash-attachment': 'trashAttachment', 6465 'click .untrash-attachment': 'untrashAttachment', 6423 6466 'click .edit-attachment': 'editAttachment', 6424 6467 'click .refresh-attachment': 'refreshAttachment', … … 6454 6497 */ 6455 6498 trashAttachment: function( event ) { 6499 var library = this.controller.library; 6456 6500 event.preventDefault(); 6457 6501 6458 this.model.destroy(); 6502 if ( media.view.settings.mediaTrash ) { 6503 this.model.set( 'status', 'trash' ); 6504 this.model.save().done( function() { 6505 library._requery( true ); 6506 } ); 6507 } else { 6508 this.model.destroy(); 6509 } 6510 }, 6511 /** 6512 * @param {Object} event 6513 */ 6514 untrashAttachment: function( event ) { 6515 var library = this.controller.library; 6516 event.preventDefault(); 6517 6518 this.model.set( 'status', 'inherit' ); 6519 this.model.save().done( function() { 6520 library._requery( true ); 6521 } ); 6459 6522 }, 6460 6523 /** -
trunk/src/wp-includes/media-template.php
r29457 r29490 317 317 <# if ( ! data.uploading && data.can.remove ) { #> 318 318 <?php if ( MEDIA_TRASH ): ?> 319 <# if ( 'trash' === data.status ) { #> 320 <a class="untrash-attachment" href="#"><?php _e( 'Untrash' ); ?></a> 321 <# } else { #> 319 322 <a class="trash-attachment" href="#"><?php _e( 'Trash' ); ?></a> 323 <# } #> 320 324 <?php else: ?> 321 325 <a class="delete-attachment" href="#"><?php _e( 'Delete Permanently' ); ?></a> -
trunk/src/wp-includes/media.php
r29486 r29490 2870 2870 'contentWidth' => $content_width, 2871 2871 'months' => $months, 2872 'mediaTrash' => MEDIA_TRASH ? 1 : 0 2872 2873 ); 2873 2874 … … 2932 2933 'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ), 2933 2934 'unattached' => __( 'Unattached' ), 2935 'trash' => __( 'Trash' ), 2934 2936 'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ), 2935 2937 'warnDelete' => __( "You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete." ), … … 2937 2939 'bulkSelect' => __( 'Bulk Select' ), 2938 2940 'cancelSelection' => __( 'Cancel Selection' ), 2941 'trashSelected' => __( 'Trash Selected' ), 2942 'untrashSelected' => __( 'Untrash Selected' ), 2939 2943 'deleteSelected' => __( 'Delete Selected' ), 2940 2944 'deletePermanently' => __( 'Delete Permanently' ),
Note: See TracChangeset
for help on using the changeset viewer.