|
198 | 198 | component.addButtons = function() {
|
199 | 199 | var header = $( '#customize-header-actions' ),
|
200 | 200 | publishButton = header.find( '#save' ),
|
201 |
| - submitButton, data, setPreviewLinkHref, snapshotButtonText; |
| 201 | + submitButton, data, setPreviewLinkHref, snapshotButtonText, changeButtonText; |
| 202 | + |
| 203 | + component.dirtySnapshotPostSetting = new api.Value(); |
| 204 | + component.dirtyScheduleDate = new api.Value(); |
202 | 205 |
|
203 | 206 | // Save/update button.
|
204 | 207 | component.snapshotButton = wp.template( 'snapshot-save' );
|
|
267 | 270 | }
|
268 | 271 | } );
|
269 | 272 |
|
| 273 | + changeButtonText = function() { |
| 274 | + var date = component.getDateFromInputs(); |
| 275 | + if ( component.isFutureDate() && date && component.data.currentUserCanPublish ) { |
| 276 | + component.snapshotButton.text( component.data.i18n.scheduleButton ); |
| 277 | + } else { |
| 278 | + component.snapshotButton.text( api.state( 'snapshot-exists' ).get() ? component.data.i18n.updateButton : component.data.i18n.saveButton ); |
| 279 | + } |
| 280 | + }; |
| 281 | + |
| 282 | + component.dirtySnapshotPostSetting.bind( function( dirty ) { |
| 283 | + if ( dirty ) { |
| 284 | + component.snapshotButton.prop( 'disabled', false ); |
| 285 | + } else { |
| 286 | + component.snapshotButton.prop( 'disabled', ! component.data.dirty ); |
| 287 | + } |
| 288 | + changeButtonText(); |
| 289 | + } ); |
| 290 | + component.dirtyScheduleDate.bind( function( dirty ) { |
| 291 | + var date; |
| 292 | + if ( dirty ) { |
| 293 | + date = component.getDateFromInputs(); |
| 294 | + if ( ! date || ! component.data.currentUserCanPublish ) { |
| 295 | + return; |
| 296 | + } |
| 297 | + component.snapshotButton.text( component.data.i18n.scheduleButton ); |
| 298 | + } else { |
| 299 | + changeButtonText(); |
| 300 | + } |
| 301 | + } ); |
| 302 | + |
270 | 303 | // Preview link.
|
271 | 304 | component.previewLink = $( $.trim( wp.template( 'snapshot-preview-link' )() ) );
|
272 | 305 | component.previewLink.toggle( api.state( 'snapshot-saved' ).get() );
|
|
772 | 805 | var date = component.getDateFromInputs(),
|
773 | 806 | scheduled;
|
774 | 807 |
|
775 |
| - if ( ! date ) { |
776 |
| - component.snapshotButton.prop( 'disabled', component.data.title === component.snapshotTitle.val() ); |
| 808 | + if ( ! date || ! component.data.currentUserCanPublish ) { |
| 809 | + component.dirtySnapshotPostSetting.set( component.data.title !== component.snapshotTitle.val() ); |
777 | 810 | return;
|
778 | 811 | }
|
779 | 812 |
|
780 | 813 | date.setSeconds( 0 );
|
781 | 814 | scheduled = component.formatDate( date ) !== component.data.publishDate;
|
782 | 815 |
|
783 |
| - if ( component.snapshotButton.length ) { |
784 |
| - |
785 |
| - // Change update button to schedule. |
786 |
| - if ( component.isFutureDate() ) { |
787 |
| - component.snapshotButton.text( component.data.i18n.scheduleButton ); |
788 |
| - } else if ( api.state( 'snapshot-exists' ).get() ) { |
789 |
| - component.snapshotButton.text( component.data.i18n.updateButton ); |
790 |
| - } else { |
791 |
| - component.snapshotButton.text( component.data.i18n.updateButton ); |
792 |
| - } |
793 |
| - |
794 |
| - if ( scheduled || component.data.dirty || component.data.title !== component.snapshotTitle.val() ) { |
795 |
| - component.snapshotButton.prop( 'disabled', false ); |
796 |
| - } else { |
797 |
| - component.snapshotButton.prop( 'disabled', true ); |
798 |
| - } |
| 816 | + if ( component.data.title !== component.snapshotTitle.val() || scheduled ) { |
| 817 | + component.dirtySnapshotPostSetting.set( true ); |
| 818 | + } else { |
| 819 | + component.dirtySnapshotPostSetting.set( false ); |
799 | 820 | }
|
800 | 821 |
|
| 822 | + if ( scheduled && component.isFutureDate() ) { |
| 823 | + component.dirtyScheduleDate.set( true ); |
| 824 | + } else { |
| 825 | + component.dirtyScheduleDate.set( false ); |
| 826 | + } |
801 | 827 | component.updateCountdown();
|
802 | 828 | component.editContainer.find( '.reset-time' ).toggle( scheduled );
|
803 | 829 | };
|
|
0 commit comments