Allow to render preview for file attachments in records
authorMichael Spahn <m.spahn@metaways.de>
Fri, 23 Jun 2017 11:49:25 +0000 (13:49 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Tue, 27 Jun 2017 13:05:50 +0000 (15:05 +0200)
Change-Id: I18371d92f801b8edd1043afbed8d4953fe8f3296
Reviewed-on: http://gerrit.tine20.com/customers/4939
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Tested-by: Michael Spahn <m.spahn@metaways.de>
tine20/Calendar/Controller/MSEventFacade.php
tine20/Filemanager/Frontend/Http.php
tine20/Filemanager/js/DocumentPreview.js
tine20/Filemanager/js/NodeGridPanel.js
tine20/Filemanager/js/nodeActions.js
tine20/Tinebase/FileSystem/RecordAttachments.php
tine20/Tinebase/Frontend/Http.php
tine20/Tinebase/js/widgets/dialog/AttachmentsGridPanel.js

index 70768f8..98f5462 100644 (file)
@@ -500,11 +500,16 @@ class Calendar_Controller_MSEventFacade implements Tinebase_Controller_Record_In
                 $exceptionAttendee->displaycontainer_id = $_attendee->displaycontainer_id;
                 Calendar_Controller_Event::getInstance()->attenderStatusCreateRecurException($exception, $exceptionAttendee, $exceptionAttendee->status_authkey);
             } else {
-                if (! $exceptionAttendee) {
+                /*if (! $exceptionAttendee) {
                     // we would need to find out the users authkey to decline him -> not allowed!?
                     if (!isset($attendeeFound)) {
                         throw new Tinebase_Exception_UnexpectedValue('not an attendee');
                     }
+                }*/
+                if (! $exceptionAttendee) {
+                    // set user status to DECLINED
+                    $exceptionAttendee = clone $attendeeFound;
+                    $exceptionAttendee->status = Calendar_Model_Attender::STATUS_DECLINED;
                 }
                 $exceptionAttendee->displaycontainer_id = $_attendee->displaycontainer_id;
                 Calendar_Controller_Event::getInstance()->attenderStatusUpdate($exception, $exceptionAttendee, $exceptionAttendee->status_authkey);
index e535fc0..dcb67f8 100644 (file)
@@ -62,31 +62,4 @@ class Filemanager_Frontend_Http extends Tinebase_Frontend_Http_Abstract
 
         $this->_downloadFileNode($node, $pathRecord->streamwrapperpath, $revision);
     }
-
-    /**
-     * download file
-     *
-     * @param string $_path
-     * @param string $_type
-     * @param int $_num
-     * @param string $_revision
-     * @throws Tinebase_Exception_InvalidArgument
-     * @throws Tinebase_Exception_NotFound
-     */
-    public function downloadPreview($_path, $_type, $_num = 0, $_revision = null)
-    {
-        $_revision = $_revision ?: null;
-
-        $nodeController = Filemanager_Controller_Node::getInstance();
-        if ($_path) {
-            $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($_path));
-            $node = $nodeController->getFileNode($pathRecord, $_revision);
-        } else {
-            throw new Tinebase_Exception_InvalidArgument('A path is needed to download a preview file.');
-        }
-
-        $this->_downloadPreview($node, $_type, $_num);
-
-        exit;
-    }
 }
index a609414..a64d2e9 100644 (file)
@@ -12,6 +12,11 @@ Tine.Filemanager.DocumentPreview = Ext.extend(Ext.Panel, {
     app: null,
 
     /**
+     * App which triggered this action
+     */
+    initialApp: null,
+
+    /**
      * Required for overflow auto
      */
     autoScroll: true,
@@ -68,9 +73,10 @@ Tine.Filemanager.DocumentPreview = Ext.extend(Ext.Panel, {
                 revision = this.record.get('revision');
 
             var url = Ext.urlEncode({
-                method: 'Filemanager.downloadPreview',
+                method: 'Tinebase.downloadPreview',
                 frontend: 'http',
                 _path: path,
+                _appId: this.initialApp ? this.initialApp.id : this.app.id,
                 _type: 'previews',
                 _num: previewNumber,
                 _revision: revision
index 141cab5..5f1f714 100644 (file)
@@ -461,7 +461,7 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
         this.action_systemLink = Tine.Filemanager.nodeActionsMgr.get('systemLink');
 
         if (this.previewsEnabled) {
-            this.action_preview = Tine.Filemanager.nodeActionsMgr.get('preview');
+            this.action_preview = Tine.Filemanager.nodeActionsMgr.get('preview', {initialApp: this.app});
         }
 
         // grid only actions - work on node which is displayed (this.currentFolderNode)
index bc40890..2220877 100644 (file)
@@ -321,7 +321,8 @@ Tine.Filemanager.nodeActions.Preview = {
 
             if (selection && selection.get('type') === 'file') {
                 Tine.Filemanager.DocumentPreview.openWindow({
-                    record: selection
+                    record: selection,
+                    initialApp: this.initialConfig.initialApp || null
                 });
             }
         }
index 3114c69..c336a89 100644 (file)
@@ -72,9 +72,8 @@ class Tinebase_FileSystem_RecordAttachments
         
         try {
             $record->attachments = $this->_fsController->scanDir($parentPath);
-            $fileSystem = Tinebase_FileSystem::getInstance();
             foreach($record->attachments as $node) {
-                $nodePath = Tinebase_Model_Tree_Node_Path::createFromStatPath($fileSystem->getPathOfNode($node,
+                $nodePath = Tinebase_Model_Tree_Node_Path::createFromStatPath($this->_fsController->getPathOfNode($node,
                     true));
                 $node->path = Tinebase_Model_Tree_Node_Path::removeAppIdFromPath($nodePath->flatpath,
                     $record->getApplication());
index 2638d63..6992bd7 100644 (file)
@@ -838,4 +838,44 @@ class Tinebase_Frontend_Http extends Tinebase_Frontend_Http_Abstract
         echo $view->render('postal.xwindow.php');
         exit();
     }
+
+    /**
+     * download file
+     *
+     * @param string $_path
+     * @param string $_appId
+     * @param string $_type
+     * @param int $_num
+     * @param string $_revision
+     * @throws Tinebase_Exception_InvalidArgument
+     * @throws Tinebase_Exception_NotFound
+     */
+    public function downloadPreview($_path, $_appId, $_type, $_num = 0, $_revision = null)
+    {
+        $_revision = $_revision ?: null;
+
+        if ($_path) {
+            $path = ltrim($_path, '/');
+
+            if (strpos($path, 'records/') === 0) {
+                $pathParts = explode('/', $path);
+                $controller = Tinebase_Core::getApplicationInstance($pathParts[1]);
+
+                // ACL Check
+                $controller->get($pathParts[2]);
+
+                //$pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath();
+                $node = Tinebase_FileSystem::getInstance()->stat('/' . $_appId . '/folders/' . $path, $_revision);
+            } else {
+                $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath('/' . $_appId . '/folders/' . $path);
+                $node = Filemanager_Controller_Node::getInstance()->getFileNode($pathRecord, $_revision);
+            }
+        } else {
+            throw new Tinebase_Exception_InvalidArgument('A path is needed to download a preview file.');
+        }
+
+        $this->_downloadPreview($node, $_type, $_num);
+
+        exit;
+    }
 }
index 32e7d84..ee9565d 100644 (file)
@@ -140,13 +140,36 @@ Tine.widgets.dialog.AttachmentsGridPanel = Ext.extend(Tine.widgets.grid.FileUplo
             scope: this,
             disabled:true
         });
-        this.actionUpdater.addActions([this.action_download]);
+
+        this.action_preview = Tine.Filemanager.nodeActionsMgr.get('preview', {initialApp: this.app});
+
+        this.actionUpdater.addActions([this.action_download, this.action_preview]);
         this.getTopToolbar().addItem(this.action_download);
         this.contextMenu.addItem(this.action_download);
         
-        this.on('rowdblclick', this.onDownload.createDelegate(this), this);
+        this.on('rowdblclick', this.onRowDbClick.createDelegate(this), this);
     },
-    
+
+    onRowDbClick: function () {
+        var _ = window.lodash;
+
+        if (!Tine.Tinebase.appMgr.isEnabled('Filemanager')) {
+            this.onDownload();
+            return;
+        }
+
+        var prefs = Tine.Tinebase.appMgr.get('Filemanager').getRegistry().get('preferences');
+
+        var selectedRows = this.getSelectionModel().getSelections(),
+            rowRecord = selectedRows[0];
+
+        if (prefs.get('dbClickAction') === 'download' && rowRecord.data.type == 'file' && !this.readOnly) {
+            this.onDownload();
+        } else if (Tine.Tinebase.configManager.get('filesystem').createPreviews && prefs.get('dbClickAction') === 'preview' && rowRecord.data.type == 'file' && !this.readOnly) {
+            this.action_preview.execute();
+        }
+    },
+
     /**
      * is called from onApplyChanges of the edit dialog per save event
      *