From bdc2fc7906d0c64e36601f8579de1cb60c1bbfd6 Mon Sep 17 00:00:00 2001
From: dcz <dcz@ipipan.waw.pl>
Date: Wed, 4 Oct 2023 11:40:23 +0200
Subject: [PATCH] Accept/reject slowal frames with a status C/B on the edit
 view.

---
 .../Unification/LexicalUnitEdit.vue           | 45 ++++++++++++++++---
 1 file changed, 38 insertions(+), 7 deletions(-)

diff --git a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
index cc2e375..41aa644 100644
--- a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
+++ b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
@@ -690,14 +690,29 @@ Object.assign(LexicalUnitEdit, {
         alert(gettext("Wybierz ramę, dla której chcesz zmienić status."));
       }
     },
+    slowal_frame_status_change_with_confirmation(api_method) {
+      this.select_slowal_frame_req(() => {
+        const frame = this.active_slowal_frame;
+        $.ajax({
+          type: 'post',
+          url: `/${lang}/semantics/${api_method}/${frame.id}/`,
+          dataType: 'json',
+          timeout: 60000,
+        }).then(() => {
+          show_info('Status ramy został zmieniony');
+          this.$emit('refreshEntriesList');
+          this.loadFrame();
+        });
+      });
+    },
     change_slowal_frame_status(status) {
       this.select_slowal_frame_req(() => {
         let frame = this.active_slowal_frame;
 
-        if (status === 'B') {
+        if (status === 'C') {
           this.setup_notes_slowal_frame_with_title_and_body("Niedopasowana jednostka (identyfikator jednostki)", "Do zatwierdzenia uznanie ramy Walentego jednostek (lista jednostek)" +
               "za niedopasowana do zunifikowanej ramy (identyfikator) przez (Leksykograf).");
-        } else if (status === 'Z') {
+        } else if (status === 'B') {
           this.setup_notes_slowal_frame_with_title_and_body("Błędna jednostka (identyfikator jednostki)", "Do zatwierdzenia uznanie ramy Walentego jednostek (lista jednostek)" +
               "za niedopasowana do zunifikowanej ramy (identyfikator) przez (Leksykograf).");
         }
@@ -926,6 +941,22 @@ Object.assign(LexicalUnitEdit, {
       const readyFrames = this.frames.filter(frame => frame.status == 'G');
       return readyFrames.length;
     },
+    getSlowalVerifiedFrameCnt() {
+      const readyFrames = this.frames.filter(frame => frame.status == 'S');
+      return readyFrames.length;
+    },
+    createSlowalVerifiedButtonLabel() {
+      return 'Ukryj ' +(!this.isSuperLeksykograf() ? 'gotowe' : 'sprawdzone') +
+              (this.showVerifiedFrames ? '' :
+                      !this.isSuperLeksykograf() ? (this.getSlowalReadyFrameCnt() > 0 ? ' (ukrytych: ' + this.getSlowalReadyFrameCnt() + ')' : '') :
+                              (this.getSlowalVerifiedFrameCnt() > 0 ? ' (ukrytych: ' + this.getSlowalVerifiedFrameCnt() + ')' : ''));
+    },
+    createSlowalContestedStatusButtonLabel() {
+      return this.isSuperLeksykograf() ? this.active_slowal_frame && this.active_slowal_frame.status === 'C' ? 'Potwierdź niepasująca' : 'Nowa' : 'Niepasująca';
+    },
+    createSlowalBadStatusButtonLabel() {
+      return this.isSuperLeksykograf() ? this.active_slowal_frame && this.active_slowal_frame.status === 'B' ? 'Potwierdź zła' : 'Zła' : 'Błędna';
+    },
     frames2lexical_units(frames) {
       const lexical_units = []
       for (let i in frames) {
@@ -1257,14 +1288,14 @@ export default LexicalUnitEdit;
       <div :id="'semantics-slowal-frames-pane' + (readOnly ? '-preview' : '')" class="col w-100 p-0 overflow-auto">
         <table v-if="!readOnly && unified_frame.id && !isReadOnlyForSuperLeksykograf()" class="table-button-menu sticky-top" cellspacing="1">
           <tr style="background-color: white;">
-            <td id="wrong-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="change_slowal_frame_status('B')">{{this.isSuperLeksykograf() ? 'Zła' : 'Błędna'}}</td>
-            <td id="hide-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"  @click="changeShowVerifiedFrames(false)">Ukryj gotowe {{showVerifiedFrames ? '' : getSlowalReadyFrameCnt() > 0 ? '(ukrytych: ' + getSlowalReadyFrameCnt() + ')' : ''}}</td>
+            <td id="wrong-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="!this.isSuperLeksykograf() ? change_slowal_frame_status('B') : slowal_frame_status_change_with_confirmation('frame_confirm_invalid')">{{createSlowalBadStatusButtonLabel()}}</td>
+            <td id="hide-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"  @click="changeShowVerifiedFrames(false)">{{createSlowalVerifiedButtonLabel()}}</td>
             <td id="ready-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="slowal_frame_ready_rollback">{{ statusButtonTitle }}</td>
             <td id="attach-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="attachSlowalFrame">Podepnij</td>
           </tr>
           <tr style="background-color: white;">
-            <td id="inccorect-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="change_slowal_frame_status('C')">
-              {{this.isSuperLeksykograf() ? 'Nowa' : 'NiepasujÄ…ca'}}
+            <td id="inccorect-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="!this.isSuperLeksykograf() ? change_slowal_frame_status('C') : slowal_frame_status_change_with_confirmation('frame_confirm_as_not_matching_unified_frame')">
+              {{createSlowalContestedStatusButtonLabel()}}
             </td>
             <td id="show-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;" @click="changeShowVerifiedFrames(true)">
                 Pokaż wszystkie {{this.hidden_frames.length > 0 ? '(ukrytych: ' + this.hidden_frames.length + ')' : ''}}
@@ -1273,7 +1304,7 @@ export default LexicalUnitEdit;
                 @click="extract_frame_to_preview_frame">
                 Przerzuć
             </td>
-            <td v-if="this.isSuperLeksykograf()" id="reject-button" @click="frame_reject_as_not_matching_unified_frame" style="padding: 10px 15px 10px 15px; color: #000000;">Zwróć</td>
+            <td v-if="this.isSuperLeksykograf() && this.active_slowal_frame && (this.active_slowal_frame.status === 'B' || this.active_slowal_frame.status === 'C')" id="reject-button" @click="frame_reject_as_not_matching_unified_frame" style="padding: 10px 15px 10px 15px; color: #000000;">Zwróć</td>
             <td v-else id="empty-2" style="padding: 10px 15px 10px 15px; color: #000000;"></td>
           </tr>
         </table>
-- 
GitLab