Browse Source

HUE-2563 [search] Copy/delete buttons are not disabled on dashboard page when nothing is selected

Added property to keep track of at least one selected
Enrico Berti 10 năm trước cách đây
mục cha
commit
c58adc19ee

+ 4 - 4
apps/search/src/search/templates/admin_collections.mako

@@ -45,8 +45,8 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
       </%def>
 
       <%def name="actions()">
-        <a class="btn" data-bind="visible: collections().length > 0 && !isLoading(), click: $root.copyCollections, clickBubble: false"><i class="fa fa-files-o"></i> ${_('Copy')}</a>
-        <a class="btn" data-bind="visible: collections().length > 0 && !isLoading(), click: $root.markManyForDeletion, clickBubble: false"><i class="fa fa-times"></i> ${_('Delete')}</a>
+        <a data-bind="visible: collections().length > 0 && !isLoading(), click: $root.copyCollections, clickBubble: false, css: {'btn': true, 'disabled': ! atLeastOneSelected()}"><i class="fa fa-files-o"></i> ${_('Copy')}</a>
+        <a data-bind="visible: collections().length > 0 && !isLoading(), click: $root.markManyForDeletion, clickBubble: false, css: {'btn': true, 'disabled': ! atLeastOneSelected()}"><i class="fa fa-times"></i> ${_('Delete')}</a>
       </%def>
 
       <%def name="creation()">
@@ -172,11 +172,11 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
     $(document).on("collectionDeleted", function () {
       $("#deleteModal").modal("hide");
       $("#deleteModalBtn").button("reset");
-      $(document).trigger("info", "${ _("Dashboard deleted successfully.") }");
+      $(document).trigger("info", "${ _("Dashboard(s) deleted successfully.") }");
     });
 
     $(document).on("collectionCopied", function () {
-      $(document).trigger("info", "${ _("Dashboard copied successfully.") }");
+      $(document).trigger("info", "${ _("Dashboard(s) copied successfully.") }");
     });
 
     $(document).on("confirmDelete", function () {

+ 32 - 22
apps/search/static/js/collections.ko.js

@@ -79,6 +79,10 @@ var SearchCollectionsModel = function (props) {
     });
   }, self);
 
+  self.atLeastOneSelected = ko.computed(function() {
+    return self.selectedCollections().length >= 1;
+  });
+
   self.selectedImportableCollections = ko.computed(function () {
     return ko.utils.arrayFilter(self.importableCollections(), function (imp) {
       return imp.selected();
@@ -115,34 +119,40 @@ var SearchCollectionsModel = function (props) {
   };
 
   self.markManyForDeletion = function (collections) {
-    self.collectionToDelete = collections;
-    $(document).trigger("confirmDelete")
+    if (self.atLeastOneSelected()){
+      self.collectionToDelete = collections;
+      $(document).trigger("confirmDelete")
+    }
   };
 
   self.deleteCollections = function () {
-    self.isLoading(true);
-    $(document).trigger("deleting");
-    $.post(self.DELETE_URL,
-      {
-        collections: ko.mapping.toJSON(self.selectedCollections())
-      },
-      function (data) {
-        self.updateCollections();
-      }, "json"
-    ).fail(function (xhr, textStatus, errorThrown) {});
-    $(document).trigger("collectionDeleted");
+    if (self.atLeastOneSelected()){
+      self.isLoading(true);
+      $(document).trigger("deleting");
+      $.post(self.DELETE_URL,
+        {
+          collections: ko.mapping.toJSON(self.selectedCollections())
+        },
+        function (data) {
+          self.updateCollections();
+        }, "json"
+      ).fail(function (xhr, textStatus, errorThrown) {});
+      $(document).trigger("collectionDeleted");
+    }
   };
 
   self.copyCollections = function (collections) {
-    $(document).trigger("copying");
-    $.post(self.COPY_URL,
-      {
-        collections: ko.mapping.toJSON(self.selectedCollections())
-      }, function (data) {
-        self.updateCollections();
-      }, "json"
-    ).fail(function (xhr, textStatus, errorThrown) {});
-    $(document).trigger("collectionCopied");
+    if (self.atLeastOneSelected()){
+      $(document).trigger("copying");
+      $.post(self.COPY_URL,
+        {
+          collections: ko.mapping.toJSON(self.selectedCollections())
+        }, function (data) {
+          self.updateCollections();
+        }, "json"
+      ).fail(function (xhr, textStatus, errorThrown) {});
+      $(document).trigger("collectionCopied");
+    }
   };
 
   self.updateCollections = function () {