Bläddra i källkod

HUE-4308 [editor] UX lock rows keep adding rows when clicking on the same

Enrico Berti 9 år sedan
förälder
incheckning
0dda68bc1d
1 ändrade filer med 27 tillägg och 25 borttagningar
  1. 27 25
      desktop/core/src/desktop/static/desktop/js/jquery.tableextender.js

+ 27 - 25
desktop/core/src/desktop/static/desktop/js/jquery.tableextender.js

@@ -184,31 +184,33 @@
   function drawLockedRow(plugin, rowNo) {
     var $pluginElement = $(plugin.element);
     var lockedRows = $pluginElement.data('lockedRows') || [];
-    lockedRows.push(rowNo);
-    $pluginElement.data('lockedRows', lockedRows);
-    var $header = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainer");
-    var $headerCounter = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainerCell");
-    var $clone = $pluginElement.find('tbody tr:eq('+ rowNo +')').clone();
-    $clone.addClass('locked');
-    $header.addClass('locked');
-    $headerCounter.addClass('locked');
-    $clone.appendTo($header.find('tbody'));
-    var $newTr = $('<tr>');
-    $newTr.addClass('locked').html('<td class="pointer">' + (rowNo+1) + '</td>').appendTo($headerCounter.find('tbody'));
-    $newTr.find('td').on('click', function(){
-      var idx = $(this).parent().index();
-      $header.find('tbody tr:eq('+ idx +')').remove();
-      var arrIdx = $pluginElement.data('lockedRows').indexOf(idx);
-      if (arrIdx > -1) {
-        $pluginElement.data('lockedRows').splice(arrIdx, 1);
-      }
-      $(this).parent().remove();
-      if ($header.find('tbody tr').length == 0){
-        $header.removeClass('locked');
-        $headerCounter.removeClass('locked');
-        $pluginElement.data('lockedRows', []);
-      }
-    });
+    if (lockedRows.indexOf(rowNo) === -1) {
+      lockedRows.push(rowNo);
+      $pluginElement.data('lockedRows', lockedRows);
+      var $header = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainer");
+      var $headerCounter = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainerCell");
+      var $clone = $pluginElement.find('tbody tr:eq(' + rowNo + ')').clone();
+      $clone.addClass('locked');
+      $header.addClass('locked');
+      $headerCounter.addClass('locked');
+      $clone.appendTo($header.find('tbody'));
+      var $newTr = $('<tr>');
+      $newTr.addClass('locked').html('<td class="pointer">' + (rowNo + 1) + '</td>').appendTo($headerCounter.find('tbody'));
+      $newTr.find('td').on('click', function () {
+        var idx = $(this).parent().index();
+        $header.find('tbody tr:eq(' + idx + ')').remove();
+        var arrIdx = $pluginElement.data('lockedRows').indexOf(idx);
+        if (arrIdx > -1) {
+          $pluginElement.data('lockedRows').splice(arrIdx, 1);
+        }
+        $(this).parent().remove();
+        if ($header.find('tbody tr').length == 0) {
+          $header.removeClass('locked');
+          $headerCounter.removeClass('locked');
+          $pluginElement.data('lockedRows', []);
+        }
+      });
+    }
   }
 
   function drawFirstColumn(plugin) {