From 9789d0ec6efcb3ff08f2c7dc8eaaf1e6c37b193b Mon Sep 17 00:00:00 2001
From: dcz <dcz@ipipan.waw.pl>
Date: Thu, 14 Sep 2023 14:33:38 +0200
Subject: [PATCH] Check empty arguments before unified frame status change to
 ready.

---
 .../Unification/LexicalUnitEdit.vue           | 62 +++++++++++++------
 1 file changed, 42 insertions(+), 20 deletions(-)

diff --git a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
index 7cfdf51..8dc6a37 100644
--- a/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
+++ b/frontend/src/components/unification/Unification/LexicalUnitEdit.vue
@@ -510,7 +510,7 @@ Object.assign(LexicalUnitEdit, {
       const duplicate_popup = {
         state0: {
           title: 'Podaj nazwÄ™ zduplikowanej ramy',
-          html: '<input type="text" size="32" value="KOPIA_' + title + '" name="title" />',
+          html: '<input type="text" size="32" value="" name="title" />',
           buttons: {Anuluj: 0, Zapisz: 1},
           focus: -1,
           submit: function (e, v, m, f) {
@@ -597,25 +597,30 @@ Object.assign(LexicalUnitEdit, {
         }
         if (Object.keys(roleDict).length === this.unified_frame_arguments.length && hasPreferenceSelected) {
           //all roles are set, and are uniq
-          //TODO: aktywne preferencje w argumencie nie znajdujÄ… siÄ™ w relacji hipo-/hiperonimii.
-          const data = {'unified_frame_id': this.unified_frame.id};
-          $.ajax({
-            type: 'post',
-            url: '/' + lang + '/unifier/' + url_path + '/',
-            dataType: 'json',
-            data: data,
-            timeout: 60000,
-            success: function (response) {
-              alert(gettext("Status ramy zunifikowanej został zmieniony."));
-              show_info('Status ramy został zmieniony');
-              this.$emit('refreshEntriesList');
-              this.loadFrame();
-            }.bind(this),
-            error: function (request, errorType, errorMessage) {
-              alert(gettext("Wystąpił błąd: " + errorType + ' (' + errorMessage + ')'));
-              show_error(errorType + ' (' + errorMessage + ')');
-            }
-          });
+
+          if(!this.has_full_empty_arguments()) {
+            //TODO: aktywne preferencje w argumencie nie znajdujÄ… siÄ™ w relacji hipo-/hiperonimii.
+            const data = {'unified_frame_id': this.unified_frame.id};
+            $.ajax({
+              type: 'post',
+              url: '/' + lang + '/unifier/' + url_path + '/',
+              dataType: 'json',
+              data: data,
+              timeout: 60000,
+              success: function (response) {
+                alert(gettext("Status ramy zunifikowanej został zmieniony."));
+                show_info('Status ramy został zmieniony');
+                this.$emit('refreshEntriesList');
+                this.loadFrame();
+              }.bind(this),
+              error: function (request, errorType, errorMessage) {
+                alert(gettext("Wystąpił błąd: " + errorType + ' (' + errorMessage + ')'));
+                show_error(errorType + ' (' + errorMessage + ')');
+              }
+            });
+          } else {
+            alert(gettext("Rama posiada agrument, dla którego wszystkie ramy walentego są typu 'Empty'. Należy usunąć taki argument."));
+          }
         } else {
           alert(gettext("Role dla wszystkich argumentów powinny być ustawione oraz unikalne. Preferencje selekcyjne dla wszystkich argumentów powinny być ustawione."));
         }
@@ -938,6 +943,23 @@ Object.assign(LexicalUnitEdit, {
         }
       }
     },
+    has_full_empty_arguments() {
+      let non_empty_unified_frame_arguments = {}
+      for (let i in this.unified_frame.slowal_frame_mapping) {
+        const slowal_frame_mapping = this.unified_frame.slowal_frame_mapping[i];
+        let slowal_frame = this.frames.find(o => o.id === slowal_frame_mapping.slowal_frame_id);
+        if(slowal_frame != null) {
+          for (let j in this.unified_frame.arguments) {
+            const unified_frame_argument = this.unified_frame.arguments[j];
+            let unified_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping.find(o => o.unified_frame_agrument_id === unified_frame_argument.id);
+            if (unified_frame_argument_mapping) {
+              non_empty_unified_frame_arguments[unified_frame_argument.id] = unified_frame_argument;
+            }
+          }
+        }
+      }
+      return Object.keys(non_empty_unified_frame_arguments).length !== this.unified_frame.arguments.length;
+    },
     hideLexicalUnits() {
       this.lexicalUnitsVisible = false;
     },
-- 
GitLab