Changeset 2327
- Timestamp:
- 01/19/2016 08:44:53 PM (9 years ago)
- Location:
- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/payment-request.php
r2309 r2327 182 182 'payment-requests', 183 183 plugins_url( 'javascript/payment-requests.js', __DIR__ ), 184 array( ' jquery', 'jquery-ui-datepicker', 'media-upload', 'media-views' ),184 array( 'wordcamp-budgets', 'wcb-attached-files', 'jquery' ), 185 185 WordCamp_Budgets::VERSION, 186 186 true 187 187 ); 188 188 189 wp_register_script(190 'wcp-attached-files',191 plugins_url( 'javascript/attached-files.js', __DIR__ ),192 array( 'payment-requests', 'backbone', 'wp-util' ),193 WordCamp_Budgets::VERSION,194 true195 );196 197 189 // Enqueue our assets if they're needed on the current screen 198 190 $current_screen = get_current_screen(); … … 206 198 if ( isset( $post->ID ) ) { 207 199 wp_enqueue_media( array( 'post' => $post->ID ) ); 208 wp_enqueue_script( 'wc p-attached-files' );200 wp_enqueue_script( 'wcb-attached-files' ); 209 201 } 210 202 211 203 wp_localize_script( 212 204 'payment-requests', 213 'wcpLocalizedStrings', // todo merge into paymentRequests var205 'wcpLocalizedStrings', // todo merge into WordCampBudgets var 214 206 array( 215 207 'uploadModalTitle' => __( 'Attach Supporting Documentation', 'wordcamporg' ), 216 'uploadModalButton' => __( 'Attach Files', 'wordcamporg' ),217 208 ) 218 209 ); -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/sponsor-invoice.php
r2309 r2327 147 147 'sponsor-invoices', 148 148 plugins_url( 'javascript/sponsor-invoices.js', __DIR__ ), 149 array( ' jquery', 'jquery-ui-datepicker', 'underscore', 'wp-util' ),149 array( 'wordcamp-budgets', 'jquery', 'underscore', 'wp-util' ), 150 150 \WordCamp_Budgets::VERSION, 151 151 true -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/wordcamp-budgets.php
r2309 r2327 38 38 */ 39 39 public function enqueue_common_assets() { 40 // todo setup grunt to concat/minify js and css? 40 // todo setup grunt to concat/minify js 41 42 wp_enqueue_script( 43 'wordcamp-budgets', 44 plugins_url( 'javascript/wordcamp-budgets.js', __DIR__ ), 45 array( 'jquery', 'jquery-ui-datepicker', 'media-upload', 'media-views' ), 46 self::VERSION, 47 true 48 ); 49 50 wp_register_script( 51 'wcb-attached-files', 52 plugins_url( 'javascript/attached-files.js', __DIR__ ), 53 array( 'wordcamp-budgets', 'backbone', 'wp-util' ), 54 WordCamp_Budgets::VERSION, 55 true 56 ); 57 58 wp_localize_script( 59 'wordcamp-budgets', 60 'wcbLocalizedStrings', // todo merge into WordCampBudgets var 61 array( 62 'uploadModalButton' => __( 'Attach Files', 'wordcamporg' ), 63 ) 64 ); 41 65 42 66 // Let's still include our .css file even if these are unavailable. -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/attached-files.js
r2276 r2327 1 1 jQuery( document ).ready( function( $ ) { 2 // todo strict mode 3 4 var app = window.WordCampBudgets; 2 5 3 6 /* 4 7 * Model for an attached file 5 8 */ 6 $.paymentRequests.AttachedFile = Backbone.Model.extend( {9 app.AttachedFile = Backbone.Model.extend( { 7 10 defaults: { 8 11 'ID': 0, … … 16 19 * Collection of attached files 17 20 */ 18 $.paymentRequests.AttachedFiles = Backbone.Collection.extend( {19 model: $.paymentRequests.AttachedFile21 app.AttachedFiles = Backbone.Collection.extend( { 22 model: app.AttachedFile 20 23 } ); 21 24 … … 23 26 * View for a single attached file 24 27 */ 25 $.paymentRequests.AttachedFileView = Backbone.View.extend( {28 app.AttachedFileView = Backbone.View.extend( { 26 29 tagName: 'li', 27 30 template: wp.template( 'wcp-attached-file' ), … … 40 43 * View for a collection of attached files 41 44 */ 42 $.paymentRequests.AttachedFilesView = Backbone.View.extend( {45 app.AttachedFilesView = Backbone.View.extend( { 43 46 el: $( '#wcp_files' ), 44 47 … … 46 49 _.bindAll( this, 'render', 'appendFile' ); 47 50 48 this.collection = new $.paymentRequests.AttachedFiles( wcpAttachedFiles );51 this.collection = new app.AttachedFiles( wcbAttachedFiles ); 49 52 this.collection.bind( 'add', this.appendFile ); 50 53 … … 62 65 appendFile: function( file ) { 63 66 var noFilesUploaded = $( '.wcp_no_files_uploaded' ); 64 var attachedFileView = new $.paymentRequests.AttachedFileView( { model: file } );67 var attachedFileView = new app.AttachedFileView( { model: file } ); 65 68 66 69 $( '.wcp_files_list' ).append( attachedFileView.render().el ); … … 79 82 * Files that are already attached to other posts are ignored. 80 83 * 81 * @param { paymentRequests.AttachedFile} file84 * @param {app.AttachedFile} file 82 85 */ 83 86 attachExistingFile: function( file ) { … … 98 101 } ); 99 102 100 $.paymentRequests.attachedFilesView = new $.paymentRequests.AttachedFilesView();101 102 103 } ); -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/payment-requests.js
r2276 r2327 1 1 jQuery( document ).ready( function( $ ) { 2 2 3 $.paymentRequests = {3 // todo add try/catch and log 4 4 5 var wcb = window.WordCampBudgets; 6 var app = wcb.PaymentRequests = { 7 5 8 /** 6 9 * Main entry point 7 10 */ 8 11 init: function () { 9 $.paymentRequests.registerEventHandlers(); 10 $.paymentRequests.setupDatePicker(); 12 app.registerEventHandlers(); 13 wcb.attachedFilesView = new wcb.AttachedFilesView(); 14 wcb.setupDatePicker( '#wcp_general_info' ); 11 15 }, 12 16 … … 15 19 */ 16 20 registerEventHandlers : function() { 17 $( '#wcp_payment_details' ).find( 'input[name=payment_method]' ).change( $.paymentRequests.togglePaymentMethodFields ); 18 $( '#payment_category' ).change( $.paymentRequests.toggleOtherCategoryDescription ); 19 $( '#wcp_files' ).find( 'a.wcp-insert-media' ).click( $.paymentRequests.showUploadModal ); 20 $( '#wcp_mark_incomplete_checkbox' ).click( $.paymentRequests.requireNotes ); 21 $( '#wcp_payment_details' ).find( 'input[name=payment_method]' ).change( wcb.togglePaymentMethodFields ); 22 $( '#payment_category' ).change( app.toggleOtherCategoryDescription ); 23 // todo this needs to fire onLoad too, otherwise the field is hidden 24 $( '#wcp_files' ).find( 'a.wcp-insert-media' ).click( { title : wcpLocalizedStrings.uploadModalTitle }, wcb.showUploadModal ); 25 $( '#wcp_mark_incomplete_checkbox' ).click( app.requireNotes ); 21 26 }, 22 27 23 28 /** 24 * Toggle the payment method fields based on which method is selected 25 * 26 * @param {object} event 27 */ 28 togglePaymentMethodFields : function( event ) { 29 var active_fields_container = '#' + $( this ).attr( 'id' ) + '_fields'; 30 var payment_method_fields = '.payment_method_fields'; 31 32 $( payment_method_fields ).removeClass( 'active' ); 33 $( payment_method_fields ).addClass( 'hidden' ); 34 $( active_fields_container ).removeClass( 'hidden' ); 35 $( active_fields_container ).addClass( 'active' ); 36 37 // todo make the transition smoother 38 }, 39 40 /** 41 * Example event handler 29 * Toggle the extra input field when the user selects the Other category 42 30 * 43 31 * @param {object} event … … 56 44 57 45 /** 58 * Initialize Core's Media Picker59 *60 * @param {object} event61 */62 showUploadModal : function( event ) {63 if ( 'undefined' == typeof $.paymentRequests.fileUploadFrame ) {64 // Create the frame65 $.paymentRequests.fileUploadFrame = wp.media( {66 title: wcpLocalizedStrings.uploadModalTitle,67 multiple: true,68 button: {69 text: wcpLocalizedStrings.uploadModalButton70 }71 } );72 73 // Add models to the collection for each selected attachment74 $.paymentRequests.fileUploadFrame.on( 'select', $.paymentRequests.addSelectedFilesToCollection );75 }76 77 $.paymentRequests.fileUploadFrame.open();78 return false;79 },80 81 /**82 * Add files selected from the Media Picker to the current collection of files83 */84 addSelectedFilesToCollection : function() {85 var attachments = $.paymentRequests.fileUploadFrame.state().get( 'selection' ).toJSON();86 87 $.each( attachments, function( index, attachment ) {88 var newFile = new $.paymentRequests.AttachedFile( {89 'ID': attachment.id,90 'post_parent': attachment.uploadedTo,91 'filename': attachment.filename,92 'url': attachment.url93 } );94 95 $.paymentRequests.attachedFilesView.collection.add( newFile );96 } );97 },98 99 /**100 * Fallback to the jQueryUI datepicker if the browser doesn't support <input type="date">101 */102 setupDatePicker : function() {103 var browserTest = document.createElement( 'input' );104 browserTest.setAttribute( 'type', 'date' );105 106 if ( 'text' === browserTest.type ) {107 $( '#wcp_general_info' ).find( 'input[type=date]' ).not( '[readonly="readonly"]' ).datepicker( {108 dateFormat : 'yy-mm-dd',109 changeMonth: true,110 changeYear : true111 } );112 }113 },114 115 /**116 46 * Require notes when the request is being marked as incomplete 117 47 */ … … 127 57 }; 128 58 129 $.paymentRequests.init();59 app.init(); 130 60 } ); -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/sponsor-invoices.js
r2303 r2327 2 2 'use strict'; 3 3 4 $.sponsorInvoices = { 4 var wcb = window.WordCampBudgets; 5 var app = wcb.SponsorInvoices = { 5 6 6 7 /** … … 9 10 init: function() { 10 11 try { 11 $.sponsorInvoices.registerEventHandlers();12 app.registerEventHandlers(); 12 13 $( '#_wcbsi_sponsor_id' ).trigger( 'change' ); // Populate the initial sponsor information 13 $.sponsorInvoices.setupDatePicker();14 wcb.setupDatePicker( '#wcbsi_sponsor_invoice' ); 14 15 } catch ( exception ) { 15 $.sponsorInvoices.log( exception );16 wcb.log( exception ); 16 17 } 17 18 }, … … 21 22 */ 22 23 registerEventHandlers : function() { 23 $( '#_wcbsi_sponsor_id' ).change( $.sponsorInvoices.populateSponsorInformation ); 24 25 // todo detect when invoice fields incomplete, disable submit button (but not draft), and show notice 24 $( '#_wcbsi_sponsor_id' ).change( app.populateSponsorInformation ); 26 25 }, 27 26 … … 42 41 sendInvoiceButton.prop( 'disabled', true ); 43 42 return; 43 44 44 } else if ( info.requiredFieldsComplete ) { 45 // todo add info.hasOwnProperty() check 45 46 infoTemplate = wp.template( 'wcbsi-sponsor-information' ); 46 47 sendInvoiceButton.prop( 'disabled', false ); 48 47 49 } else { 48 50 infoTemplate = wp.template( 'wcbsi-required-fields-incomplete' ); … … 52 54 infoContainer.html( infoTemplate( info ) ); 53 55 } catch ( exception ) { 54 $.sponsorInvoices.log( exception ); 55 } 56 }, 57 58 /** 59 * Fallback to the jQueryUI datepicker if the browser doesn't support <input type="date"> 60 * 61 * todo this is mostly duplicate of same function in payment-requests.js. should make DRY 62 */ 63 setupDatePicker : function() { 64 var browserTest = document.createElement( 'input' ); 65 browserTest.setAttribute( 'type', 'date' ); 66 67 if ( 'text' === browserTest.type ) { 68 $( '#wcbsi_sponsor_invoice' ).find( 'input[type=date]' ).not( '[readonly="readonly"]' ).datepicker( { 69 dateFormat : 'yy-mm-dd', 70 changeMonth: true, 71 changeYear : true 72 } ); 73 } 74 }, 75 76 /** 77 * Log a message to the console 78 * 79 * @todo centralize this for all modules to use 80 * 81 * @param {*} error 82 */ 83 log : function( error ) { 84 if ( ! window.console ) { 85 return; 86 } 87 88 if ( 'string' === typeof error ) { 89 console.log( 'WordCamp Sponsor Invoices: ' + error ); 90 } else { 91 console.log( 'WordCamp Sponsor Invoices: ', error ); 56 wcb.log( exception ); 92 57 } 93 58 } 94 59 }; 95 60 96 $.sponsorInvoices.init();61 app.init(); 97 62 } ); -
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/input-files.php
r2272 r2327 9 9 <?php endif; ?> 10 10 11 <?php // todo move to centralized view file ?> 11 12 <p> 12 13 <a class="button wcp-insert-media" role="button"> … … 27 28 </script> 28 29 29 <?php wp_localize_script( 'wc p-attached-files', 'wcpAttachedFiles', $files ); // todo merge into wordcampBudgets var ?>30 <?php wp_localize_script( 'wcb-attached-files', 'wcbAttachedFiles', $files ); // todo merge into wordcampBudgets var ?> 30 31 </td> 31 32 </tr>
Note: See TracChangeset
for help on using the changeset viewer.