Changeset 2342
- Timestamp:
- 01/20/2016 09:49:51 PM (9 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-budgets.css
r2309 r2342 15 15 } 16 16 17 .wcb-form li label {17 .wcb-form li > label { 18 18 display: table-cell; 19 19 margin-bottom: 1em; … … 37 37 } 38 38 39 /* Files */ 40 .wcb_no_files_uploaded.active { 41 display: block; 42 } 43 44 #wcb_files .description { 45 margin-bottom: 1em; 46 } 47 48 .wcb_files_list li { 49 list-style-type: disc; 50 margin-left: 15px; 51 } 52 53 .form-table td p.wcb_no_files_uploaded { 54 margin-bottom: 1em; 55 } 56 39 57 40 58 /* … … 43 61 44 62 /* Payment methods */ 45 .payment_method_fields.active, 46 .wcp_no_files_uploaded.active { 63 .payment_method_fields.active { 47 64 display: block; 48 65 } … … 50 67 tr#row-payment-method label { 51 68 margin-right: 20px; 52 }53 54 /* Files */55 #wcp_files .description {56 margin-bottom: 1em;57 }58 59 .wcp_files_list li {60 list-style-type: disc;61 margin-left: 15px;62 }63 64 .form-table td p.wcp_no_files_uploaded {65 margin-bottom: 1em;66 69 } 67 70 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/payment-request.php
r2331 r2342 387 387 */ 388 388 protected function render_files_input( $post, $label, $name, $description = '' ) { 389 $files = get_posts( array( 390 'post_parent' => $post->ID, 391 'post_type' => 'attachment', 392 'posts_per_page' => -1, 393 'orderby' => 'title', 394 'order' => 'ASC', 395 ) ); 396 397 foreach ( $files as &$file ) { 398 $file->filename = wp_basename( $file->guid ); 399 $file->url = wp_get_attachment_url( $file->ID ); 400 } 389 $files = WordCamp_Budgets::get_attached_files( $post ); 390 391 wp_localize_script( 'wcb-attached-files', 'wcbAttachedFiles', $files ); // todo merge into wordcampBudgets var 401 392 402 393 require( dirname( __DIR__ ) . '/views/payment-request/input-files.php' ); … … 765 756 766 757 // Attach existing files 767 $this->attach_existing_files( $post_id, $_POST ); 768 } 769 758 remove_action( 'save_post', array( $this, 'save_payment' ), 10 ); // avoid infinite recursion 759 WordCamp_Budgets::attach_existing_files( $post_id, $_POST ); 760 add_action( 'save_post', array( $this, 'save_payment' ), 10, 2 ); 761 } 762 763 /** 764 * Add log entries when the post status changes 765 * 766 * @param string $new 767 * @param string $old 768 * @param WP_Post $post 769 */ 770 770 public function transition_post_status( $new, $old, $post ) { 771 771 if ( $post->post_type != self::POST_TYPE ) … … 803 803 804 804 /** 805 * Attach unattached files to the payment request post806 *807 * Sometimes users will upload the files manually to the Media Library, instead of using the Add Files button,808 * and we need to attach them to the request so that they show up in the metabox.809 *810 * @param int $post_id811 * @param array $request812 */813 protected function attach_existing_files( $post_id, $request ) {814 if ( empty( $request['wcp_existing_files_to_attach'] ) ) {815 return;816 }817 818 if ( ! $files = json_decode( $request['wcp_existing_files_to_attach'] ) ) {819 return;820 }821 822 remove_action( 'save_post', array( $this, 'save_payment' ), 10 ); // avoid infinite recursion823 824 foreach( $files as $file_id ) {825 wp_update_post( array(826 'ID' => $file_id,827 'post_parent' => $post_id,828 ) );829 }830 831 add_action( 'save_post', array( $this, 'save_payment' ), 10, 2 );832 }833 834 /**835 805 * Define columns for the Payment Requests screen. 836 806 * -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/wordcamp-budgets.php
r2331 r2342 275 275 276 276 /** 277 * Get the files attached to a post 278 * 279 * @param WP_Post $post 280 * 281 * @return array 282 */ 283 public static function get_attached_files( $post ) { 284 $files = get_posts( array( 285 'post_parent' => $post->ID, 286 'post_type' => 'attachment', 287 'posts_per_page' => 100, 288 'orderby' => 'title', 289 'order' => 'ASC', 290 ) ); 291 292 foreach ( $files as &$file ) { 293 $file->filename = wp_basename( $file->guid ); 294 $file->url = wp_get_attachment_url( $file->ID ); 295 } 296 297 return $files; 298 } 299 300 /** 301 * Attach unattached files to the payment request post 302 * 303 * Sometimes users will upload the files manually to the Media Library, instead of using the Add Files button, 304 * and we need to attach them to the request so that they show up in the metabox. 305 * 306 * NOTE: The calling function must remove any of its save_post callbacks before calling this, in order to 307 * avoid infinite recursion 308 * 309 * @param int $post_id 310 * @param array $request 311 */ 312 public static function attach_existing_files( $post_id, $request ) { 313 if ( empty( $request['wcb_existing_files_to_attach'] ) ) { 314 return; 315 } 316 317 if ( ! $files = json_decode( $request['wcb_existing_files_to_attach'] ) ) { 318 return; 319 } 320 321 foreach( $files as $file_id ) { 322 wp_update_post( array( 323 'ID' => $file_id, 324 'post_parent' => $post_id, 325 ) ); 326 } 327 } 328 329 /** 277 330 * Insert an entry into a log for one of the custom post types 278 331 * -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/attached-files.js
r2328 r2342 28 28 app.AttachedFileView = Backbone.View.extend( { 29 29 tagName: 'li', 30 template: wp.template( 'wc p-attached-file' ),30 template: wp.template( 'wcb-attached-file' ), 31 31 32 32 initialize: function() { … … 44 44 */ 45 45 app.AttachedFilesView = Backbone.View.extend( { 46 el: $( '#wcp_files' ),47 48 46 initialize: function() { 49 47 _.bindAll( this, 'render', 'appendFile' ); … … 64 62 65 63 appendFile: function( file ) { 66 var noFilesUploaded = $( '.wc p_no_files_uploaded' );64 var noFilesUploaded = $( '.wcb_no_files_uploaded' ); 67 65 var attachedFileView = new app.AttachedFileView( { model: file } ); 68 66 69 $( '.wc p_files_list' ).append( attachedFileView.render().el );67 $( '.wcb_files_list' ).append( attachedFileView.render().el ); 70 68 noFilesUploaded.removeClass( 'active' ); 71 69 noFilesUploaded.addClass( 'hidden' ); … … 86 84 attachExistingFile: function( file ) { 87 85 var fileIDsToAttach, 88 existingFilesToAttach = $( '#wc p_existing_files_to_attach' );86 existingFilesToAttach = $( '#wcb_existing_files_to_attach' ); 89 87 90 88 try { -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/payment-requests.js
r2331 r2342 11 11 try { 12 12 app.registerEventHandlers(); 13 wcb.attachedFilesView = new wcb.AttachedFilesView( );13 wcb.attachedFilesView = new wcb.AttachedFilesView( { el: $( '#wcp_files' ) } ); 14 14 wcb.setupDatePicker( '#wcp_general_info' ); 15 15 } catch ( exception ) { … … 27 27 paymentCategory.change( app.toggleOtherCategoryDescription ); 28 28 paymentCategory.trigger( 'change' ); // Set the initial state 29 $( '#wcp_files' ).find( 'a.wc p-insert-media' ).click( wcb.showUploadModal );29 $( '#wcp_files' ).find( 'a.wcb-insert-media' ).click( wcb.showUploadModal ); 30 30 $( '#wcp_mark_incomplete_checkbox' ).click( app.requireNotes ); 31 31 }, -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/wordcamp-budgets.js
r2331 r2342 49 49 */ 50 50 addSelectedFilesToCollection : function() { 51 // app var needs to point to caller?52 53 51 var attachments = app.fileUploadFrame.state().get( 'selection' ).toJSON(); 54 52 -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/input-files.php
r2327 r2342 9 9 <?php endif; ?> 10 10 11 <?php // todo move to centralized view file ?> 12 <p> 13 <a class="button wcp-insert-media" role="button"> 14 <?php _e( 'Add files', 'wordcamporg' ); ?> 15 </a> 16 </p> 17 18 <h4><?php _e( 'Attached files:', 'wordcamporg' ); ?></h4> 19 20 <ul class="wcp_files_list"></ul> 21 22 <p class="wcp_no_files_uploaded <?php echo $files ? 'hidden' : 'active'; ?>"> 23 <?php _e( "You haven't uploaded any files yet.", 'wordcamporg' ); ?> 24 </p> 25 26 <script type="text/html" id="tmpl-wcp-attached-file"> 27 <a href="{{ data.url }}">{{ data.filename }}</a> 28 </script> 29 30 <?php wp_localize_script( 'wcb-attached-files', 'wcbAttachedFiles', $files ); // todo merge into wordcampBudgets var ?> 11 <?php require_once( dirname( __DIR__ ) . '/wordcamp-budgets/field-attached-files.php' ); ?> 31 12 </td> 32 13 </tr> -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-files.php
r1939 r2342 1 1 <table class="form-table"> 2 <input id="wcp_existing_files_to_attach" name="wcp_existing_files_to_attach" type="hidden" value="" />3 4 2 <?php $this->render_files_input( $post, 'Files', 'files', __( 'Attach supporting documentation including invoices, contracts, or other vendor correspondence. If no supporting documentation is available, please indicate the reason in the notes below.', 'wordcamporg' ) ); ?> 5 3 <?php $this->render_textarea_input( $post, 'Notes', 'file_notes' ); ?>
Note: See TracChangeset
for help on using the changeset viewer.