0013080: Extend document preview
authorMichael Spahn <m.spahn@metaways.de>
Wed, 17 May 2017 13:15:37 +0000 (15:15 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 23 May 2017 12:45:15 +0000 (14:45 +0200)
https://forge.tine20.org/view.php?id=13080

Change-Id: Iba9020e4d8227498e1e2bf3507fca2dcd17ebe21
Reviewed-on: http://gerrit.tine20.com/customers/4689
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Filemanager/Preference.php [new file with mode: 0644]
tine20/Filemanager/js/NodeGridPanel.js
tine20/Filemanager/js/nodeActions.js
tine20/Tinebase/css/Tinebase.css

diff --git a/tine20/Filemanager/Preference.php b/tine20/Filemanager/Preference.php
new file mode 100644 (file)
index 0000000..a12a884
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Filemanager
+ * @subpackage  Preference
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Michael Spahn <m.spahn@metaways.de>
+ * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * backend for Filemanager preferences
+ *
+ * @package     Filemanager
+ * @subpackage  Preference
+ */
+class Filemanager_Preference extends Tinebase_Preference_Abstract
+{
+    /**
+     * Preference for row double click default action
+     */
+    const DB_CLICK_ACTION = 'dbClickAction';
+
+    /**
+     * Filemanager_Preference constructor.
+     * @param null $_dbAdapter
+     * @param array $_options
+     * @throws \Tinebase_Exception_Backend_Database
+     */
+    public function __construct($_dbAdapter = null, array $_options = array())
+    {
+        $this->_application = 'Filemanager';
+        parent::__construct($_dbAdapter, $_options);
+    }
+
+    /**
+     * get all possible application prefs
+     *
+     * @return  array   all application prefs
+     */
+    public function getAllApplicationPreferences()
+    {
+        $preferences = [];
+        $preferences[] = self::DB_CLICK_ACTION;
+
+        return $preferences;
+    }
+
+    /**
+     * get translated right descriptions
+     *
+     * @return  array with translated descriptions for this applications preferences
+     */
+    public function getTranslatedPreferences()
+    {
+        $translate = Tinebase_Translation::getTranslation($this->_application);
+
+        $prefDescriptions = array(
+            self::DB_CLICK_ACTION => array(
+                'label' => $translate->_('Row double click default'),
+                'description' => $translate->_('Defines which action should be executed on double click by default?'),
+            )
+        );
+
+        return $prefDescriptions;
+    }
+
+    /**
+     * @param string $_preferenceName
+     * @param null $_accountId
+     * @param string $_accountType
+     * @return Tinebase_Model_Preference
+     * @throws Tinebase_Exception_NotFound
+     */
+    public function getApplicationPreferenceDefaults(
+        $_preferenceName,
+        $_accountId = null,
+        $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER
+    ) {
+        $preference = $this->_getDefaultBasePreference($_preferenceName);
+        $translate = Tinebase_Translation::getTranslation($this->_application);
+
+        switch ($_preferenceName) {
+            case self::DB_CLICK_ACTION:
+                $preference->value = 'download';
+
+                $downloadOption = '<option>
+                            <value>download</value>
+                            <label>' . $translate->_('Download') . '</label>
+                        </option>';
+
+                if (Tinebase_Config::getInstance()->{Tinebase_Config::FILESYSTEM}->{Tinebase_Config::FILESYSTEM_CREATE_PREVIEWS}) {
+                    $previewOption = '<option>
+                            <value>preview</value>
+                            <label>' . $translate->_('Preview') . '</label>
+                        </option>';
+                } else {
+                    $previewOption = '';
+                }
+
+                $preference->options = \sprintf('<?xml version="1.0" encoding="UTF-8"?>
+                    <options>
+                    %s
+                    %s
+                    </options>', $downloadOption,  $previewOption);
+                break;
+
+            default:
+                throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.');
+        }
+
+        return $preference;
+    }
+}
index 5759783..9d9de9e 100644 (file)
@@ -63,6 +63,8 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
      */
     selectOnly: false,
 
+    previewsEnabled: false,
+
     /**
      * inits this cmp
      * @private
@@ -84,6 +86,8 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
             this.gridConfig.enableDragDrop = false;
         }
 
+        this.previewsEnabled = Tine.Tinebase.configManager.get('filesystem').createPreviews;
+
         this.recordProxy = Tine.Filemanager.fileRecordBackend;
 
         this.gridConfig.cm = this.getColumnModel();
@@ -323,14 +327,14 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
     onKeyDown: function(e) {
         Tine.Filemanager.NodeGridPanel.superclass.onKeyDown.apply(this, arguments);
 
-        var sm = this.selectionModel,
-            node = sm.getSelected();
+
+        if (!this.previewsEnabled) {
+            return true;
+        }
 
         // Open preview on space if a node is selected and the node type equals file
-        if (e.getKey() === 32 && node && node.get('type') === 'file') {
-            Tine.Filemanager.DocumentPreview.openWindow({
-                record: node
-            });
+        if (e.getKey() === 32) {
+            this.action_preview.execute()
         }
     },
 
@@ -441,6 +445,10 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
         this.action_moveRecord = Tine.Filemanager.nodeActionsMgr.get('move');
         this.action_publish = Tine.Filemanager.nodeActionsMgr.get('publish');
 
+        if (this.previewsEnabled) {
+            this.action_preview = Tine.Filemanager.nodeActionsMgr.get('preview');
+        }
+
         // grid only actions - work on node which is displayed (this.currentFolderNode)
         // @TODO: fixme - ux problems with filterselect / initialData
         this.action_upload = new Ext.Action(this.getAddAction());
@@ -460,9 +468,15 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
             }.createDelegate(this)
         });
 
+        var contextActions = [this.action_deleteRecord, 'rename', this.action_moveRecord, this.action_download, 'resume', 'pause', this.action_editFile, this.action_publish];
+
+        if (this.previewsEnabled) {
+            contextActions.push(this.action_preview);
+        }
+
         this.contextMenu = Tine.Filemanager.nodeContextMenu.getMenu({
             nodeName: Tine.Filemanager.Model.Node.getRecordName(),
-            actions: [this.action_deleteRecord, 'rename', this.action_moveRecord, this.action_download, 'resume', 'pause', this.action_editFile, this.action_publish],
+            actions: contextActions,
             scope: this,
             backend: 'Filemanager',
             backendModel: 'Node'
@@ -479,7 +493,7 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
         this.actionUpdater.addActions(this.contextMenu.items);
         this.actionUpdater.addActions(this.folderContextMenu.items);
 
-        this.actionUpdater.addActions([
+        var actions = [
             this.action_upload,
             this.action_createFolder,
             this.action_goUpFolder,
@@ -487,7 +501,13 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
             this.action_deleteRecord,
             this.action_editFile,
             this.action_publish
-        ]);
+        ];
+
+        if (this.previewsEnabled) {
+            actions.push(this.action_preview);
+        }
+
+        this.actionUpdater.addActions(actions);
     },
 
     /**
@@ -507,6 +527,70 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
      */
     getActionToolbar: function() {
         if (! this.actionToolbar) {
+            var items = [
+                this.splitAddButton ?
+                    Ext.apply(new Ext.SplitButton(this.action_upload), {
+                        scale: 'medium',
+                        rowspan: 2,
+                        iconAlign: 'top',
+                        arrowAlign:'right',
+                        menu: new Ext.menu.Menu({
+                            items: [],
+                            plugins: [{
+                                ptype: 'ux.itemregistry',
+                                key:   'Tine.widgets.grid.GridPanel.addButton'
+                            }, {
+                                ptype: 'ux.itemregistry',
+                                key:   'Tinebase-MainContextMenu'
+                            }]
+                        })
+                    }) :
+                    Ext.apply(new Ext.Button(this.action_upload), {
+                        scale: 'medium',
+                        rowspan: 2,
+                        iconAlign: 'top'
+                    }),
+
+                Ext.apply(new Ext.Button(this.action_editFile), {
+                    scale: 'medium',
+                    rowspan: 2,
+                    iconAlign: 'top'
+                }),
+                Ext.apply(new Ext.Button(this.action_deleteRecord), {
+                    scale: 'medium',
+                    rowspan: 2,
+                    iconAlign: 'top'
+                }),
+                Ext.apply(new Ext.Button(this.action_createFolder), {
+                    scale: 'medium',
+                    rowspan: 2,
+                    iconAlign: 'top'
+                }),
+                Ext.apply(new Ext.Button(this.action_goUpFolder), {
+                    scale: 'medium',
+                    rowspan: 2,
+                    iconAlign: 'top'
+                }),
+                Ext.apply(new Ext.Button(this.action_download), {
+                    scale: 'medium',
+                    rowspan: 2,
+                    iconAlign: 'top'
+                }),
+                Ext.apply(new Ext.Button(this.action_publish), {
+                    scale: 'medium',
+                    rowspan: 2,
+                    iconAlign: 'top'
+                })
+            ];
+
+            if (this.previewsEnabled) {
+                items.push(Ext.apply(new Ext.Button(this.action_preview), {
+                    scale: 'medium',
+                    rowspan: 2,
+                    iconAlign: 'top'
+                }));
+            }
+
             this.actionToolbar = new Ext.Toolbar({
                 defaults: {height: 55},
                 items: [{
@@ -515,61 +599,7 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
                     buttonAlign: 'left',
                     columns: 8,
                     defaults: {minWidth: 60},
-                    items: [
-                        this.splitAddButton ?
-                        Ext.apply(new Ext.SplitButton(this.action_upload), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top',
-                            arrowAlign:'right',
-                            menu: new Ext.menu.Menu({
-                                items: [],
-                                plugins: [{
-                                    ptype: 'ux.itemregistry',
-                                    key:   'Tine.widgets.grid.GridPanel.addButton'
-                                }, {
-                                    ptype: 'ux.itemregistry',
-                                    key:   'Tinebase-MainContextMenu'
-                                }]
-                            })
-                        }) :
-                        Ext.apply(new Ext.Button(this.action_upload), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top'
-                        }),
-
-                        Ext.apply(new Ext.Button(this.action_editFile), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top'
-                        }),
-                        Ext.apply(new Ext.Button(this.action_deleteRecord), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top'
-                        }),
-                        Ext.apply(new Ext.Button(this.action_createFolder), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top'
-                        }),
-                        Ext.apply(new Ext.Button(this.action_goUpFolder), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top'
-                        }),
-                        Ext.apply(new Ext.Button(this.action_download), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top'
-                        }),
-                        Ext.apply(new Ext.Button(this.action_publish), {
-                            scale: 'medium',
-                            rowspan: 2,
-                            iconAlign: 'top'
-                        })
-                 ]
+                    items: items
                 }, this.getActionToolbarItems()]
             });
 
@@ -591,26 +621,28 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
      * @param {} row record
      * @param {Ext.EventObjet} e
      */
-    onRowDblClick: function(grid, row, e) {
+    onRowDblClick: function (grid, row, e) {
         var app = this.app;
         var rowRecord = grid.getStore().getAt(row);
+        var _ = window.lodash;
+        var prefs = this.app.getRegistry().get('preferences');
 
-        if(rowRecord.data.type == 'file' && !this.readOnly) {
+        if (prefs.get('dbClickAction') === 'download' && rowRecord.data.type == 'file' && !this.readOnly && _.get(rowRecord, 'data.account_grants.downloadGrant', false)) {
             Tine.Filemanager.downloadFile(rowRecord);
-        }
-
-        else if (rowRecord.data.type == 'folder'){
+        } else if (this.previewsEnabled && prefs.get('dbClickAction') === 'preview' && rowRecord.data.type == 'file' && !this.readOnly && _.get(rowRecord, 'data.account_grants.readGrant', false)) {
+            this.action_preview.execute();
+        } else if (rowRecord.data.type == 'folder') {
             var treePanel = this.treePanel || app.getMainScreen().getWestPanel().getContainerTreePanel();
 
             var currentFolderNode = treePanel.getNodeById(rowRecord.id);
 
-            if(currentFolderNode) {
+            if (currentFolderNode) {
                 currentFolderNode.select();
                 currentFolderNode.expand();
                 this.currentFolderNode = currentFolderNode;
             } else {
-                // get ftb path filter
-                this.filterToolbar.filterStore.each(function(filter) {
+                // get   ftb path filter
+                this.filterToolbar.filterStore.each(function (filter) {
                     var field = filter.get('field');
                     if (field === 'path') {
                         filter.set('value', '');
index ee78688..57200c0 100644 (file)
@@ -274,7 +274,28 @@ Tine.Filemanager.nodeActions.Download = {
 /**
  * one file node with readGrant
  */
-// Tine.Filemanager.nodeActions.Preview = {};
+Tine.Filemanager.nodeActions.Preview = {
+    app: 'Filemanager',
+    allowMultiple: false,
+    requiredGrant: 'readGrant',
+    text: 'Preview', // _('Preview')
+    disabled: true,
+    iconCls: 'previewIcon',
+    scope: this,
+    handler: function () {
+        var selections = this.initialConfig.selections;
+
+        if (selections.length > 0) {
+            var selection = selections[0];
+
+            if (selection && selection.get('type') === 'file') {
+                Tine.Filemanager.DocumentPreview.openWindow({
+                    record: selection
+                });
+            }
+        }
+    }
+};
 
 /**
  * one node with publish grant
index ce9d9df..ca3ed6f 100644 (file)
@@ -676,6 +676,16 @@ html, body {
    background-image:url(../../images/oxygen/32x32/apps/kwrite.png) !important;
 }
 
+.previewIcon {
+    background-image:url(../../images/oxygen/16x16/actions/fileview-preview.png) !important;
+}
+.x-btn-medium .previewIcon {
+    background-image:url(../../images/oxygen/22x22/actions/fileview-preview.png) !important;
+}
+.x-btn-large .previewIcon {
+    background-image:url(../../images/oxygen/32x32/actions/fileview-preview.png) !important;
+}
+
 /* ----- mainmenu ------------------------------------------------------------*/
 /*
 .tine-mainscreen-mainmenu .x-toolbar {