Răsfoiți Sursa

[home2] Enable export functionality of either current folder or selected entries

Johan Ahlen 10 ani în urmă
părinte
comite
cd2314c

+ 30 - 0
desktop/core/src/desktop/static/desktop/js/fileBrowser/hueFileEntry.js

@@ -59,6 +59,16 @@
 
     self.entries = ko.observableArray([]);
 
+    self.selectedEntryIds = ko.pureComputed(function () {
+      var ids = [];
+      $.each(self.entries(), function (idx, entry) {
+        if (entry.selected()) {
+          ids.push(entry.definition.id);
+        }
+      });
+      return ids;
+    });
+
     self.breadcrumbs = [];
     var lastParent = self.parent;
     while (lastParent) {
@@ -92,6 +102,7 @@
       self.assistHelper.fetchDocuments({
         path: self.path,
         successCallback: function(data) {
+          self.definition = data.file;
           self.hasErrors(false);
           var cleanEntries = $.grep(data.documents, function (definition) {
             return definition.name !== '/';
@@ -166,6 +177,25 @@
     }
   };
 
+  HueFileEntry.prototype.showUploadModal = function () {
+    if (self.app = 'documents') {
+      $('#importDocumentsModal').modal('show');
+    }
+  };
+
+  HueFileEntry.prototype.download = function () {
+    var self = this;
+    if (self.app = 'documents') {
+      console.log(self.selectedEntryIds());
+      if (self.selectedEntryIds().length > 0) {
+        console.log('here');
+        window.location.href = '/desktop/api2/doc/export?documents=' + ko.mapping.toJSON(self.selectedEntryIds());
+      } else {
+        window.location.href = '/desktop/api2/doc/export?documents=' + ko.mapping.toJSON([ self.definition.id ]);
+      }
+    };
+  };
+
   HueFileEntry.prototype.createDirectory = function (name) {
     var self = this;
     if (self.app === 'documents') {

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

@@ -265,10 +265,8 @@ from desktop.views import _ko
           <a class="inactive-action fb-action" href="javascript:void(0);" data-bind="click: function () { $('#deleteDirectoryModal').modal('show'); }"><i class="fa fa-fw fa-times"></i></a>
           <!-- /ko -->
           <a class="inactive-action fb-action" href="javascript:void(0);"><i class="fa fa-fw fa-users"></i></a>
-          <a class="inactive-action fb-action" href="javascript:void(0);"><i class="fa fa-fw fa-download"></i></a>
-          <!-- ko if: app === 'documents' -->
-          <a class="inactive-action fb-action" href="javascript:void(0);" data-bind="click: function () { $('#importDocumentsModal').modal('show'); }"><i class="fa fa-fw fa-upload"></i></a>
-          <!-- /ko -->
+          <a class="inactive-action fb-action" href="javascript:void(0);" data-bind="click: download"><i class="fa fa-fw fa-download"></i></a>
+          <a class="inactive-action fb-action" href="javascript:void(0);" data-bind="click: showUploadModal"><i class="fa fa-fw fa-upload"></i></a>
         </div>
       </div>
       <div class="fb-header">