From e9484b9179e3b93126f9ab61ca4cdf80ca191a55 Mon Sep 17 00:00:00 2001
From: dcz <dcz@ipipan.waw.pl>
Date: Tue, 28 Jun 2022 20:19:44 +0200
Subject: [PATCH] +extract_frames_to_new_frame +extract_frames_to_frame

---
 .../entries/js/components/LexicalUnitEdit.js  | 83 +++++++++++++++++--
 entries/static/entries/js/unification.js      | 22 -----
 unifier/models.py                             |  1 +
 3 files changed, 78 insertions(+), 28 deletions(-)

diff --git a/entries/static/entries/js/components/LexicalUnitEdit.js b/entries/static/entries/js/components/LexicalUnitEdit.js
index 507a781..a8aeeb8 100644
--- a/entries/static/entries/js/components/LexicalUnitEdit.js
+++ b/entries/static/entries/js/components/LexicalUnitEdit.js
@@ -447,6 +447,7 @@ export default {
               data: data,
               timeout: 60000,
               success: function (response) {
+                show_info('Argumenty w ramie zostały zmienione');
                 this.loadFrame();
               }.bind(this),
               error: function (request, errorType, errorMessage) {
@@ -456,8 +457,6 @@ export default {
           }
         },
         change_slowal2unified_mapping_verification(slowal_frame_id, verified) {
-          // check_import_status();
-          // show_entry_spinners();
           var data = {
             'unified_frame_id': this.unified_frame.id,
             'slowal_frame_id': slowal_frame_id,
@@ -470,13 +469,85 @@ export default {
             data: data,
             timeout: 60000,
             success: function (response) {
-              this.loadFrame();
+                show_info('Status ramy został zmieniony');
+                this.loadFrame();
             }.bind(this),
             error: function (request, errorType, errorMessage) {
               show_error(errorType + ' (' + errorMessage + ')');
             }
           });
         },
+        slowalFrameSelected(frame) {
+            if (this.active_slowal_frame === frame) {
+                this.active_slowal_frame = null;
+            } else {
+                this.active_slowal_frame = frame;
+            }
+        },
+        extract_frames_to_new_frame() {
+
+            var existingSelect = function () {
+                return this.frames.map(frame => {
+                    return `<label><input type="checkbox" name="frames" value="${frame.id}" /> ${lexical_units2dom(frame.lexical_units)}</label><br />`;
+                }).join("");
+            }.bind(this);
+
+            var extract_frames_to_new_frame_popup = {
+                state0: {
+                    title: 'Podaj nazwÄ™ zduplikowanej ramy',
+                    html: existingSelect,
+                    buttons: {Anuluj: 0, Wydziel: 1},
+                    focus: -1,
+                    submit: function (e, v, m, f) {
+                        if (v == 0) {
+                            e.preventDefault();
+                            $.prompt.close();
+                        }
+                        if (v === 1) {
+                            e.preventDefault();
+                            let frame_ids = normalizeFormData(f.frames);
+                            var data = { 'unified_frame_id' : this.unified_frame.id, 'slowal_frame_ids' : JSON.stringify(frame_ids),
+                                    'target_unified_frame_id': ''};
+                            $.ajax({
+                                type     : 'post',
+                                url      : '/' + lang + '/unifier/extract_frames_to_new_frame/',
+                                dataType : 'json',
+                                data     : data,
+                                timeout  : 60000,
+                                success  : function(response) {
+                                    show_info('Ramy zostały wydzielone do nowej ramy zunifikowanej.');
+                                    this.loadFrame();
+                                    $.prompt.close();
+                                }.bind(this),
+                                error: function(request, errorType, errorMessage) {
+                                    show_error(errorType + ' (' + errorMessage + ')');
+                                    $.prompt.close();
+                                }
+                            });
+                        }
+                    }.bind(this)
+                }
+            }
+            $.prompt(extract_frames_to_new_frame_popup);
+        },
+        extract_frames_to_frame(target_unified_frame_id) {
+            var data = { 'unified_frame_id' : this.unified_frame.id, 'slowal_frame_ids' : JSON.stringify([this.active_slowal_frame.id]),
+                'target_unified_frame_id': target_unified_frame_id };
+            $.ajax({
+                type     : 'post',
+                url      : '/' + lang + '/unifier/extract_frames_to_new_frame/',
+                dataType : 'json',
+                data     : data,
+                timeout  : 60000,
+                success  : function(response) {
+                    show_info('Zaznaczona rama została przeniosiona.');
+                    this.loadFrame();
+                },
+                error: function(request, errorType, errorMessage) {
+                    show_error(errorType + ' (' + errorMessage + ')');
+                }
+            });
+        }
     },
     mounted() {
         Split(['#semantics-frames-pane', '#semantics-schemata-pane'], {
@@ -596,7 +667,7 @@ export default {
           <td id="wrong-frame" style="padding: 10px 15px 10px 15px; color: #000000;">Błędna</td>
           <td
             style="padding: 10px 15px 10px 15px; color: #000000;"
-            onclick="extract_frames_to_new_frame(1, [104274,104238], null)"
+            @click="extract_frames_to_new_frame()"
           >
             Rozdziel
           </td>
@@ -609,7 +680,7 @@ export default {
               NiepasujÄ…ca
           </td>
           <td id="move-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;"
-              onclick="extract_frames_to_new_frame(3, [104274], 1)">
+              @click="extract_frames_to_frame(1)">
               Przerzuć
           </td>
           <td id="show-slowal-frame" style="padding: 10px 15px 10px 15px; color: #000000;">
@@ -630,7 +701,7 @@ export default {
             <tbody>
             <tr>
                 <th scope="row">
-                    <div v-html="slowal_frame_html(frame)"></div>
+                    <div v-html="slowal_frame_html(frame)" @click="slowalFrameSelected(frame)"></div>
                 </th>
                 <th scope="row">
                     <div>
diff --git a/entries/static/entries/js/unification.js b/entries/static/entries/js/unification.js
index b6e9574..be5e65c 100644
--- a/entries/static/entries/js/unification.js
+++ b/entries/static/entries/js/unification.js
@@ -108,25 +108,3 @@ function frames2lexical_units(frames) {
     }
     return lexical_units;
 }
-
-function extract_frames_to_new_frame(unified_frame_id, slowal_frame_ids, target_unified_frame_id) {
-    check_import_status();
-    clear_entry();
-    show_entry_spinners();
-    var data = { 'unified_frame_id' : unified_frame_id, 'slowal_frame_ids' : JSON.stringify(slowal_frame_ids),
-        'target_unified_frame_id': target_unified_frame_id };
-    $.ajax({
-        type     : 'post',
-        url      : '/' + lang + '/unifier/extract_frames_to_new_frame/',
-        dataType : 'json',
-        data     : data,
-        timeout  : 60000,
-        success  : function(response) {
-            unified_frame_id = response.unified_frame_id;
-
-        },
-        error: function(request, errorType, errorMessage) {
-            show_error(errorType + ' (' + errorMessage + ')');
-        }
-    });
-}
diff --git a/unifier/models.py b/unifier/models.py
index 5b0c636..7890f77 100644
--- a/unifier/models.py
+++ b/unifier/models.py
@@ -121,6 +121,7 @@ class UnifiedRelationalSelectionalPreference(models.Model):
 
 class UnifiedFrame2SlowalFrameMapping(models.Model):
     verified = models.BooleanField(default=False)
+    removed = models.BooleanField(default=False)
     unified_frame = models.ForeignKey(UnifiedFrame, related_name='unified_frame_2_slowal_frame', on_delete=models.PROTECT)
     slowal_frame = models.OneToOneField(Frame, related_name='slowal_frame_2_unified_frame', on_delete=models.PROTECT)
 
-- 
GitLab