Implement download function for temp files in fileupload
authorMichael Spahn <kontakt@michaelspahn.de>
Mon, 18 May 2015 13:03:25 +0000 (15:03 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 28 May 2015 13:57:54 +0000 (15:57 +0200)
Change-Id: I3eff37589b13972d03476a9f727f5c118bc93ed2
Reviewed-on: http://gerrit.tine20.com/customers/1935
Tested-by: Jenkins CI (http://ci.tine20.com/)
Tested-by: sstamer <s.stamer@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Frontend/Http.php
tine20/Tinebase/js/widgets/grid/FileUploadGrid.js

index 440528b..811632a 100644 (file)
@@ -790,4 +790,16 @@ class Tinebase_Frontend_Http extends Tinebase_Frontend_Http_Abstract
         $this->_downloadFileNode($node, $path);
         exit;
     }
+
+    /**
+     * Download temp file to review
+     *
+     * @param $tmpfileId
+     */
+    public function downloadTempfile($tmpfileId)
+    {
+        $tmpFile = Tinebase_TempFile::getInstance()->getTempFile($tmpfileId);
+        $this->_downloadFileNode($tmpFile, $tmpFile->path);
+        exit;
+    }
 }
index 18a003f..c92a77c 100644 (file)
@@ -85,7 +85,7 @@ Tine.widgets.grid.FileUploadGrid = Ext.extend(Ext.grid.GridPanel, {
         this.enableHdMenu = false;
       
         Tine.widgets.grid.FileUploadGrid.superclass.initComponent.call(this);
-        
+
         this.on('rowcontextmenu', function (grid, row, e) {
             e.stopEvent();
             var selModel = grid.getSelectionModel();
@@ -94,6 +94,13 @@ Tine.widgets.grid.FileUploadGrid = Ext.extend(Ext.grid.GridPanel, {
             }
             this.contextMenu.showAt(e.getXY());
         }, this);
+
+        if (! this.record || this.record.id == 0) {
+            this.on('rowdblclick', function (grid, row, e) {
+                e.stopEvent();
+                this.onDownload()
+            }, this);
+        }
     },
     
     /**
@@ -206,9 +213,9 @@ Tine.widgets.grid.FileUploadGrid = Ext.extend(Ext.grid.GridPanel, {
         
         this.contextMenu = new Ext.menu.Menu({
             items:  [
-                     this.action_remove,
-                     this.action_pause,
-                     this.action_resume
+                 this.action_remove,
+                 this.action_pause,
+                 this.action_resume
             ]
         });
         
@@ -230,7 +237,24 @@ Tine.widgets.grid.FileUploadGrid = Ext.extend(Ext.grid.GridPanel, {
         
         this.loadRecord(this.record);
     },
-    
+
+    /**
+     * On download attached file from panel
+     */
+    onDownload: function() {
+        var selectedRows = this.getSelectionModel().getSelections();
+
+        selectedRows.forEach(function (attachement) {
+            new Ext.ux.file.Download({
+                params: {
+                    requestType: 'HTTP',
+                    method: 'Tinebase.downloadTempfile',
+                    tmpFileId: attachement.get('id')
+                }
+            }).start();
+        });
+    },
+
     /**
      * returns add action
      * 
@@ -252,7 +276,7 @@ Tine.widgets.grid.FileUploadGrid = Ext.extend(Ext.grid.GridPanel, {
     
     /**
      * populate grid store
-     * 
+     *
      * @param {} record
      */
     loadRecord: function (record) {