Browse Source

[home2] Enable delete forever with alt + right-click on selected entries

Johan Ahlen 9 years ago
parent
commit
7f8adfb

+ 12 - 3
desktop/core/src/desktop/static/desktop/js/fileBrowser/hueFileEntry.js

@@ -329,6 +329,14 @@
     }
   };
 
+  HueFileEntry.prototype.moveToTrash = function () {
+    var self = this;
+    if (self.selectedEntries().length > 0) {
+      self.entriesToDelete(self.selectedEntries());
+      self.removeDocuments(false);
+    }
+  }
+
   HueFileEntry.prototype.showDeleteConfirmation = function () {
     var self = this;
     if (self.selectedEntries().length > 0) {
@@ -337,7 +345,7 @@
     }
   };
 
-  HueFileEntry.prototype.performDelete = function () {
+  HueFileEntry.prototype.removeDocuments = function (deleteForever) {
     var self = this;
     if (self.app === 'documents') {
       if (self.entriesToDelete().indexOf(self) !== -1) {
@@ -348,13 +356,14 @@
         if (self.entriesToDelete().length > 0) {
           var nextUuid = self.entriesToDelete().shift().definition().uuid;
           self.assistHelper.deleteDocument({
+            uuid: nextUuid,
+            skipTrash: deleteForever,
             successCallback: function () {
               deleteNext();
             },
             errorCallback: function () {
               self.activeEntry().load();
-            },
-            uuid: nextUuid
+            }
           });
         } else {
           self.activeEntry().load();

+ 10 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -244,6 +244,16 @@
       var $menu = $element.find(options.menuSelector);
       var active = false;
 
+      bindingContext.$altDown = ko.observable(false);
+
+      window.addEventListener("keydown", function (e) {
+        bindingContext.$altDown(e.altKey);
+      });
+
+      window.addEventListener("keyup", function (e) {
+        bindingContext.$altDown(false);
+      });
+
       element.addEventListener("contextmenu", function(e) {
         if(document.selection && document.selection.empty) {
           document.selection.empty();

+ 3 - 2
desktop/core/src/desktop/templates/file_browser.mako

@@ -414,7 +414,7 @@ from desktop.views import _ko
       </div>
       <div class="modal-footer">
         <input type="button" class="btn" data-dismiss="modal" value="${ _('Cancel') }">
-        <input type="submit" data-bind="click: performDelete" class="btn btn-danger" value="${_('Yes')}"/>
+        <input type="submit" data-bind="click: function() { removeDocuments(true); }" class="btn btn-danger" value="${_('Yes')}"/>
       </div>
       <!-- /ko -->
     </div>
@@ -519,7 +519,8 @@ from desktop.views import _ko
               <ul class="hue-context-menu">
                 <li data-bind="css: { 'disabled': $parent.selectedEntries().length !== 1 }"><a href="javascript:void(0);" data-bind="click: open, css: { 'disabled': $parent.selectedEntries().length !== 1 }"><i class="fa fa-file-o"></i> ${ _('Open') }</a></li>
                 <li><a href="javascript:void(0);" data-bind="click: contextMenuDownload"><i class="fa fa-download"></i> ${ _('Download') } <span data-bind="visible: $parent.selectedEntries().length > 1, text: '(' + $parent.selectedEntries().length + ')'"></span></a></li>
-                <li><a href="javascript:void(0);" data-bind="click: function() { $parent.showDeleteConfirmation(); }"><i class="fa fa-fw fa-times"></i> ${ _('Delete') } <span data-bind="visible: $parent.selectedEntries().length > 1, text: '(' + $parent.selectedEntries().length + ')'"></span></a></li>
+                <li data-bind="visible: ! $altDown()"><a href="javascript:void(0);" data-bind="click: function () { $parent.moveToTrash(); }"><i class="fa fa-fw fa-trash-o"></i> ${ _('Remove') } <span data-bind="visible: $parent.selectedEntries().length > 1, text: '(' + $parent.selectedEntries().length + ')'"></span></a></li>
+                <li data-bind="visible: $altDown()"><a href="javascript:void(0);" data-bind="click: function() { $parent.showDeleteConfirmation(); }"><i class="fa fa-fw fa-times"></i> ${ _('Delete') } <span data-bind="visible: $parent.selectedEntries().length > 1, text: '(' + $parent.selectedEntries().length + ')'"></span></a></li>
                 <li data-bind="css: { 'disabled': $parent.selectedEntries().length !== 1 }"><a href="javascript:void(0);" data-bind="click: function() { $parent.showSharingModal(); }, css: { 'disabled': $parent.selectedEntries().length !== 1 }"><i class="fa fa-fw fa-users"></i> ${ _('Share') }</a> </li>
               </ul>
               <div class="fb-primary-col">