Changeset 12205
- Timestamp:
- 11/04/2022 11:01:38 AM (23 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers
- Property svn:ignore
-
old new 10 10 phpunit.xml.dist 11 11 tests 12 bin
-
- Property svn:ignore
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/css/discussion.css
r12063 r12205 229 229 font-size: 1.1em; 230 230 } 231 .feedback-comment .note { 232 font-size: 0.8rem; 233 font-weight: normal; 234 display: inline-block; 235 margin-bottom: 1rem; 236 } 231 237 .status-actions details { 232 238 margin-bottom: 5px; … … 265 271 font-size: .8em; 266 272 } 273 .hide-textarea { 274 border: #dfe3e3 thin solid; 275 border-radius: 5px; 276 width: fit-content; 277 } 278 .hide-textarea summary { 279 padding: 5px 10px; 280 background-color: var(--gp-color-btn-primary-bg); 281 border-color: var(--gp-color-btn-primary-border); 282 color: var(--gp-color-btn-primary-text); 283 border-radius: 2px; 284 width: max-content; 285 font-size: 14px; 286 line-height: 20px; 287 font-weight: 500; 288 cursor: pointer; 289 } 290 .hide-textarea summary:hover { 291 background-color: var(--gp-color-btn-primary-hover-bg); 292 border-color: var(--gp-color-btn-primary-hover-border); 293 color: var(--gp-color-btn-primary-hover-text); 294 box-shadow: 0 0 0 1px var(--gp-color-canvas-default),0 0 0 2px var(--gp-color-btn-primary-hover-border); 295 } 296 h5#reply-title { 297 padding-left: 13px; 298 } 299 ul#glossary-item-list { 300 list-style-type: none; 301 border: #bcc3c3 thin solid; 302 padding: 10px; 303 border-radius: 3px; 304 background: #f2f2f2; 305 } 306 ul#glossary-item-list h6 { 307 margin-top: 3px; 308 margin-bottom: 8px 309 } 310 ul#glossary-item-list li label { 311 margin-left: 5px; 312 } 313 #glossary-item-list li label input[type="checkbox"].glossary-word-item { 314 margin-right: 5px; 315 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers-assets/templates/translation-discussion-comments.php
r12003 r12205 129 129 $_post_id = $post->ID; 130 130 } 131 ?> 132 133 <?php if ( $comments ) : ?> 134 <details class="hide-textarea"> 135 <summary>Start a new conversation</summary> 136 <?php endif; ?> 137 138 <?php 131 139 comment_form( 132 140 array( … … 164 172 ); 165 173 echo '</div>'; 174 ?> 175 176 <?php if ( $comments ) : ?> 177 </details> 178 <?php endif; ?> 179 180 <?php 166 181 } else { 167 182 /* translators: Log in URL. */ 168 183 echo sprintf( __( 'You have to be <a href="%s">logged in</a> to comment.' ), esc_html( wp_login_url() ) ); 169 184 } 170 171 185 ?> 172 186 </div><!-- .discussion-wrapper --> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers/helper-translation-discussion.php
r12071 r12205 161 161 'show_in_rest' => true, 162 162 'sanitize_callback' => array( $this, 'sanitize_comment_locale' ), 163 'rewrite' => false, 164 ) 165 ); 166 167 register_meta( 168 'comment', 169 'translation_status', 170 array( 171 'description' => 'Translation status as at when the comment was made', 172 'single' => true, 173 'show_in_rest' => true, 174 'sanitize_callback' => array( $this, 'sanitize_comment_translation_status' ), 163 175 'rewrite' => false, 164 176 ) … … 550 562 remove_action( 'comment_form_top', 'rosetta_comment_form_support_hint' ); 551 563 552 $post = self::maybe_get_temporary_post( self::get_shadow_post_id( $this->data['original_id'] ) ); 553 564 $post = self::maybe_get_temporary_post( self::get_shadow_post_id( $this->data['original_id'] ) ); 554 565 $output = gp_tmpl_get_output( 555 566 'translation-discussion-comments', … … 563 574 'project' => $this->data['project'], 564 575 'translation_set_slug' => $this->data['translation_set_slug'], 565 566 576 ), 567 577 $this->assets_dir . 'templates' … … 666 676 } 667 677 return $translation_id; 678 } 679 680 /** 681 * Sets the translation_status meta_key as "unknown" if is not in the accepted values. 682 * 683 * Used as sanitize callback in the register_meta for the "comment" object type, 684 * 'translation_status' meta_key 685 * 686 * @since 0.0.2 687 * 688 * @param string $translation_status The meta_value for the meta_key "translation_status". 689 * 690 * @return string 691 */ 692 public function sanitize_translation_status( string $translation_status ): string { 693 if ( ! in_array( $translation_status, array( 'approved', 'rejected', 'waiting', 'current', 'fuzzy', 'changesrequested' ), true ) ) { 694 $translation_status = 'unknown'; 695 } 696 return $translation_status; 697 668 698 } 669 699 … … 863 893 864 894 $comment_reason = get_comment_meta( $comment->comment_ID, 'reject_reason', true ); 895 896 $_translation_status = get_comment_meta( $comment->comment_ID, 'translation_status', true ); 865 897 866 898 $classes = array( 'comment-locale-' . $comment_locale ); … … 995 1027 if ( ! $is_linking_comment ) : 996 1028 if ( $comment_translation_id && $comment_translation_id !== $current_translation_id ) { 997 gth_print_translation( $comment_translation_id, $args, 'Translation: ' ); 1029 $translation_status = ''; 1030 if ( $_translation_status ) { 1031 $translation_status = ' (' . $_translation_status . ')'; 1032 } 1033 gth_print_translation( $comment_translation_id, $args, 'Translation' . $translation_status . ': ' ); 998 1034 } 999 1035 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-notifications.php
r12063 r12205 119 119 $translator = get_user_by( 'id', $translation->user_id_last_modified ); 120 120 } 121 if ( false ===$translator ) {121 if ( $translator ) { 122 122 self::send_emails( $comment, $comment_meta, array( $translator->user_email ) ); 123 123 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-translation-helpers.php
r12063 r12205 81 81 'gp_tmpl_load_locations', 82 82 function( $locations, $template, $args, $template_path ) { 83 if ( 'translation-row-editor-meta-status' === $template || 'locale-projects' === $template) {83 if ( 'translation-row-editor-meta-status' === $template ) { 84 84 array_unshift( $locations, dirname( dirname( __FILE__ ) ) . '/templates/gp-templates-overrides/' ); 85 85 } else { … … 413 413 $helper_discussion = new Helper_Translation_Discussion(); 414 414 $locale_slug = $helper_discussion->sanitize_comment_locale( sanitize_text_field( $_POST['data']['locale_slug'] ) ); 415 $translation_status = $helper_discussion->sanitize_translation_status( sanitize_text_field( $_POST['data']['translation_status'] ) ); 415 416 $translation_id_array = ! empty( $_POST['data']['translation_id'] ) ? array_map( array( $helper_discussion, 'sanitize_translation_id' ), $_POST['data']['translation_id'] ) : null; 416 417 $original_id_array = ! empty( $_POST['data']['original_id'] ) ? array_map( array( $helper_discussion, 'sanitize_original_id' ), $_POST['data']['original_id'] ) : null; … … 443 444 444 445 // Post comment on discussion page for the first string 445 $first_comment_id = $this->insert_comment( $comment, $first_original_id, $comment_reason, $first_translation_id, $locale_slug, $_SERVER );446 $first_comment_id = $this->insert_comment( $comment, $first_original_id, $comment_reason, $first_translation_id, $locale_slug, $_SERVER, $translation_status ); 446 447 447 448 if ( ! empty( $original_id_array ) && ! empty( $translation_id_array ) ) { … … 449 450 $comment = get_comment_link( $first_comment_id ); 450 451 foreach ( $original_id_array as $index => $single_original_id ) { 451 $comment_id = $this->insert_comment( $comment, $single_original_id, $comment_reason, $translation_id_array[ $index ], $locale_slug, $_SERVER );452 $comment_id = $this->insert_comment( $comment, $single_original_id, $comment_reason, $translation_id_array[ $index ], $locale_slug, $_SERVER, $translation_status ); 452 453 $comment = get_comment( $comment_id ); 453 454 GP_Notifications::add_related_comment( $comment ); … … 507 508 * @since 0.0.2 508 509 */ 509 private function insert_comment( $comment, $original_id, $reason, $translation_id, $locale_slug, $server ) {510 private function insert_comment( $comment, $original_id, $reason, $translation_id, $locale_slug, $server, $translation_status ) { 510 511 $post_id = Helper_Translation_Discussion::get_or_create_shadow_post_id( $original_id ); 511 512 $user = wp_get_current_user(); … … 521 522 'user_id' => $user->ID, 522 523 'comment_meta' => array( 523 'reject_reason' => $reason, 524 'translation_id' => $translation_id, 525 'locale' => $locale_slug, 524 'reject_reason' => $reason, 525 'translation_id' => $translation_id, 526 'locale' => $locale_slug, 527 'translation_status' => $translation_status, 526 528 ), 527 529 ) -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/reject-feedback.js
r12074 r12205 9 9 '<div id="reject-feedback-form" style="display:none;">' + 10 10 '<form>' + 11 '<h3> Reason</h3>' +11 '<h3>Type (Optional)</h3>' + 12 12 getReasonList() + 13 13 '<div class="modal-comment">' + 14 '< label>Comment </label>' +15 '<textarea name="modal_feedback_comment"></textarea>' +14 '<h3><label for="modal_feedback_comment">Comment (Optional)</label></h3>' + 15 '<textarea id="modal_feedback_comment" name="modal_feedback_comment"></textarea>' + 16 16 '</div>' + 17 '<button id="modal-reject-btn" class="modal-btn gp-btn-style">Reject </button>' +17 '<button id="modal-reject-btn" class="modal-btn gp-btn-style">Reject without Feedback</button>' + 18 18 '<button id="modal-requestchanges-btn" class="modal-btn gp-btn-style" style="display: none;" class="modal-btn">Request changes</button>' + 19 19 '</form>' + … … 25 25 $( $gp.editor.table ).off( 'click', 'summary' ); 26 26 27 $( '#bulk-actions-toolbar-top .button, #bulk-actions-toolbar-bottom .button' ).click( function( e ) { 28 rowIds = $( 'input:checked', $( 'table#translations th.checkbox' ) ).map( function() { 29 var selectedRow = $( this ).parents( 'tr.preview' ); 30 if ( ! selectedRow.hasClass( 'untranslated' ) ) { 31 return selectedRow.attr( 'row' ); 27 $( '#bulk-actions-toolbar-top .button, #bulk-actions-toolbar-bottom .button' ).click( 28 function( e ) { 29 rowIds = $( 'input:checked', $( 'table#translations th.checkbox' ) ).map( 30 function() { 31 var selectedRow = $( this ).parents( 'tr.preview' ); 32 if ( ! selectedRow.hasClass( 'untranslated' ) ) { 33 return selectedRow.attr( 'row' ); 34 } 35 $( this ).prop( 'checked', false ); 36 return null; 37 } 38 ).get(); 39 40 rowIds.forEach( 41 function( rowId ) { 42 var originalId = $gp.editor.original_id_from_row_id( rowId ); 43 var translationId = $gp.editor.translation_id_from_row_id( rowId ); 44 45 if ( originalId && translationId ) { 46 originalIds.push( originalId ); 47 translationIds.push( translationId ); 48 } 49 } 50 ); 51 52 if ( $( 'select[name="bulk[action]"]' ).val() === 'reject' ) { 53 e.preventDefault(); 54 e.stopImmediatePropagation(); 55 if ( ! translationIds.length ) { 56 $( 'form.filters-toolbar.bulk-actions, form#bulk-actions-toolbar-top' ).submit(); 57 return; 58 } 59 60 // eslint-disable-next-line no-undef 61 tb_show( 'Reject with Feedback', '#TB_inline?inlineId=reject-feedback-form' ); 32 62 } 33 $( this ).prop( 'checked', false ); 34 return null; 35 } ).get(); 36 37 rowIds.forEach( function( rowId ) { 38 var originalId = $gp.editor.original_id_from_row_id( rowId ); 39 var translationId = $gp.editor.translation_id_from_row_id( rowId ); 40 41 if ( originalId && translationId ) { 42 originalIds.push( originalId ); 43 translationIds.push( translationId ); 44 } 45 } ); 46 47 if ( $( 'select[name="bulk[action]"]' ).val() === 'reject' ) { 48 e.preventDefault(); 49 e.stopImmediatePropagation(); 50 if ( ! translationIds.length ) { 51 $( 'form.filters-toolbar.bulk-actions, form#bulk-actions-toolbar-top' ).submit(); 52 return; 53 } 54 55 // eslint-disable-next-line no-undef 56 tb_show( 'Reject with Feedback', '#TB_inline?inlineId=reject-feedback-form' ); 57 } 58 } ); 63 } 64 ); 59 65 60 66 /** … … 72 78 } 73 79 74 $( 'body' ).on( 'click', '#modal-reject-btn, #modal-requestchanges-btn', function( e ) { 75 var comment = ''; 76 var commentReason = []; 77 var commentData = {}; 78 var form = $( this ).closest( 'form' ); 79 80 form.find( 'input[name="modal_feedback_reason"]:checked' ).each( 81 function() { 82 commentReason.push( this.value ); 80 $( 'body' ).on( 81 'click', 82 '#modal-reject-btn, #modal-requestchanges-btn', 83 function( e ) { 84 var comment = ''; 85 var commentReason = []; 86 var commentData = {}; 87 var form = $( this ).closest( 'form' ); 88 89 form.find( 'input[name="modal_feedback_reason"]:checked' ).each( 90 function() { 91 commentReason.push( this.value ); 92 } 93 ); 94 95 comment = form.find( 'textarea[name="modal_feedback_comment"]' ).val(); 96 updateBulkRejectStatus( $( this ) ); 97 if ( ( ! comment.trim().length && ! commentReason.length ) || ( ! translationIds.length || ! originalIds.length ) ) { 98 $( 'form.filters-toolbar.bulk-actions, form#bulk-actions-toolbar-top' ).submit(); 83 99 } 84 ); 85 86 comment = form.find( 'textarea[name="modal_feedback_comment"]' ).val();87 updateBulkRejectStatus( $( this ) );88 if ( ( ! comment.trim().length && ! commentReason.length ) || ( ! translationIds.length || ! originalIds.length ) ) {89 $( 'form.filters-toolbar.bulk-actions, form#bulk-actions-toolbar-top' ).submit();90 }91 92 commentData.locale_slug = $gp_comment_feedback_settings.locale_slug;93 commentData.reason = commentReason;94 commentData.comment = comment;95 commentData.original_id = originalIds; 96 commentData.translation_id = translationIds;97 commentData.is_bulk_reject = true;98 commentWithFeedback( commentData, false, 'rejected' );99 e.preventDefault();100 } );101 102 $( '.feedback- reason-list' ).on( 'click', function( e ) {103 toggleButtons( $( this ), e );104 } );105 $( '.feedback-comment' ).on( 'input', function( e ) {106 toggleButtons( $( this ), e );107 });100 101 commentData.locale_slug = $gp_comment_feedback_settings.locale_slug; 102 commentData.reason = commentReason; 103 commentData.comment = comment; 104 commentData.original_id = originalIds; 105 commentData.translation_id = translationIds; 106 commentData.is_bulk_reject = true; 107 commentWithFeedback( commentData, false, 'rejected' ); 108 e.preventDefault(); 109 } 110 ); 111 112 $( '.feedback-reason-list' ).on( 113 'click', 114 function( e ) { 115 toggleButtons( $( this ), e ); 116 } 117 ); 118 $( '.feedback-comment' ).on( 119 'input', 120 function( e ) { 121 toggleButtons( $( this ), e ); 122 } 123 ); 108 124 109 125 /** … … 135 151 } 136 152 137 $( '.modal-item' ).on( 'click', function( e ) { 138 toggleModalButtons( $( this ), e ); 139 } ); 140 $( 'textarea[name="modal_feedback_comment"]' ).on( 'input', function( e ) { 141 toggleModalButtons( $( this ), e ); 142 } ); 153 $( '.modal-item' ).on( 154 'click', 155 function( e ) { 156 toggleModalButtons( $( this ), e ); 157 } 158 ); 159 $( 'textarea[name="modal_feedback_comment"]' ).on( 160 'input', 161 function( e ) { 162 toggleModalButtons( $( this ), e ); 163 } 164 ); 143 165 144 166 /** … … 170 192 } 171 193 172 $( '.tooltip' ).tooltip( { 173 tooltipClass: 'hoverTooltip', 174 } ); 194 $( '.tooltip' ).tooltip( 195 { 196 tooltipClass: 'hoverTooltip', 197 } 198 ); 199 200 $( 'input[name="feedback_reason"][value="glossary"]' ).change( 201 function() { 202 var glossaryWords = $( this ).closest( 'tr' ).find( '.original .glossary-word' ).get().map( function( word ) { 203 return word.innerText; 204 } ); 205 if ( $( this ).is( ':checked' ) && glossaryWords.length ) { 206 // eslint-disable-next-line vars-on-top 207 var glossaryList = document.createElement( 'ul' ); 208 glossaryList.innerHTML = '<h6>Glossary Words</h6>'; 209 $( glossaryList ).attr( 'id', 'glossary-item-list' ); 210 glossaryWords.forEach( 211 function( item ) { 212 var li = document.createElement( 'li' ); 213 var checkbox = $( '<input />', { type: 'checkbox', class: 'glossary-word-item', value: item } ); 214 $( '<label></label>' ).html( checkbox ).append( item ).appendTo( li ); 215 glossaryList.appendChild( li ); 216 } 217 ); 218 $( this ).closest( 'ul' ).after( glossaryList ); 219 } else { 220 $( '#glossary-item-list' ).remove(); 221 $( this ).closest( '.feedback-reason-list' ).siblings( '.feedback-comment' ).find( 'textarea' ).val( '' ); 222 } 223 } 224 ); 225 226 $( 'body' ).on( 227 'change', 228 'input.glossary-word-item', function( ) { 229 var textArea = $( this ).closest( 'ul' ).next().find( 'textarea' ); 230 if ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 0 ) { 231 textArea.val( '' ); 232 return; 233 } 234 // eslint-disable-next-line vars-on-top 235 var message = 'There is a problem with ' + ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 1 ? 'the glossary term' : 'the following glossary terms' ) + ': ' + $( this ).closest( 'ul' ).find( 'input:checked' ).get().map( function( word ) { 236 return word.defaultValue; 237 } ).join( ', ' ); 238 239 textArea.val( message ); 240 } ); 175 241 } 176 242 ); … … 217 283 feedbackData.original_id = [ $gp.editor.current.original_id ]; 218 284 feedbackData.translation_id = [ $gp.editor.current.translation_id ]; 285 feedbackData.translation_status = status; 219 286 220 287 commentWithFeedback( feedbackData, button, status ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/templates/translation-row-editor-meta-feedback.php
r12003 r12205 2 2 return; 3 3 } ?> 4 <details >4 <details open> 5 5 <summary class="feedback-summary"><?php esc_html_e( 'Give feedback', 'glotpress' ); ?></summary> 6 6 <div id="feedback-form"> … … 21 21 <textarea name="feedback_comment"></textarea> 22 22 </label> 23 <label class="note">Please note that all feedback is visible to the public.</label> 23 24 </div> 24 25 </form>
Note: See TracChangeset
for help on using the changeset viewer.