0013236: Use filepicker for filemanager relations
authorMichael Spahn <m.spahn@metaways.de>
Mon, 19 Jun 2017 16:46:40 +0000 (18:46 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Fri, 23 Jun 2017 08:15:03 +0000 (10:15 +0200)
https://forge.tine20.org/view.php?id=13236

Change-Id: I54e747bf18709676b332d1d794673d7fca26c92e
Reviewed-on: http://gerrit.tine20.com/customers/4902
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Tested-by: Michael Spahn <m.spahn@metaways.de>
tine20/Filemanager/js/NotificationPanel.js
tine20/Filemanager/js/SearchCombo.js
tine20/Tinebase/js/widgets/relation/GenericPickerGridPanel.js

index 1253256..ef706b4 100644 (file)
@@ -30,7 +30,8 @@ Tine.Filemanager.NotificationPanel = Ext.extend(Ext.Panel, {
             idProperty: 'accountId'
         });
 
-        var disable = window.lodash.get(this.editDialog.record, 'data.notificationProps', []).length === 0;
+        var notificationProps = window.lodash.get(this.editDialog.record, 'data.notificationProps', []);
+        var disable = notificationProps === null || notificationProps.length === 0;
 
         this.notificationGrid = new Tine.Filemanager.NotificationGridPanel({
             store: store,
@@ -39,9 +40,19 @@ Tine.Filemanager.NotificationPanel = Ext.extend(Ext.Panel, {
             editDialog: this.editDialog
         });
 
+        var featureEnabled = _.get(Tine.Tinebase.configManager.get('filesystem'), 'enableNotifications', false);
+
+        var disabled = false;
+
+        if (!featureEnabled) {
+            disabled = true;
+        } else if (!_.get(this.editDialog, 'record.data.account_grants.adminGrant', false)) {
+            disabled = true;
+        }
+
         this.hasOwnNotificationSettings = new Ext.form.Checkbox({
             checked: !disable,
-            disabled: !_.get(this.editDialog, 'record.data.account_grants.adminGrant', false) && !disable,
+            disabled: disabled,
             boxLabel: this.app.i18n._('This folder has own notification settings'),
             listeners: {scope: this, check: this.onOwnNotificationCheck}
         });
index 7047405..e89f4af 100644 (file)
@@ -5,7 +5,8 @@
  * @package     Filemanager
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Alexander Stintzing <a.stintzing@metaways.de>
- * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Michael Spahn <m.spahn@metaways.de>
+ * @copyright   Copyright (c) 2012-2017 Metaways Infosystems GmbH (http://www.metaways.de)
  *
  */
 
@@ -16,71 +17,65 @@ Ext.ns('Tine.Filemanager');
  * 
  * @namespace   Tine.Filemanager
  * @class       Tine.Filemanager.SearchCombo
- * @extends     Ext.form.ComboBox
+ * @extends     Ext.form.TriggerField
  * 
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Alexander Stintzing <a.stintzing@metaways.de>
- * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Michael Spahn <m.spahn@metaways.de>
+ * @copyright   Copyright (c) 2012-2017 Metaways Infosystems GmbH (http://www.metaways.de)
  * 
  * @param       {Object} config
  * @constructor
  * Create a new Tine.Filemanager.SearchCombo
  */
-Tine.Filemanager.SearchCombo = Ext.extend(Tine.Tinebase.widgets.form.RecordPickerComboBox, {
+Tine.Filemanager.SearchCombo = Ext.extend(Ext.form.TriggerField, {
     
     allowBlank: false,
     itemSelector: 'div.search-item',
     minListWidth: 200,
+
+    app: null,
+    
+    recordClass: null,
+    recordProxy: null,
     
-    //private
     initComponent: function(){
         this.recordClass = Tine.Filemanager.Model.Node;
-        this.recordProxy = Tine.Filemanager.recordBackend;
-        this.additionalFilters = [
-            {field: 'recursive', operator: 'equals', value: true },
-            {field: 'path', operator: 'equals', value: '/' }
-        ];
-        this.initTemplate();
-        Tine.Filemanager.SearchCombo.superclass.initComponent.call(this);
-    },
-    
-    /**
-     * init template
-     * @private
-     */
-    initTemplate: function() {
-        // Custom rendering Template
-        // TODO move style def to css ?
-        if (! this.tpl) {
-            this.tpl = new Ext.XTemplate(
-                '<tpl for="."><div class="search-item">',
-                    '<table cellspacing="0" cellpadding="2" border="0" style="font-size: 11px;" width="100%">',
-                        '<tr>',
-                            '<td ext:qtip="{[this.renderPathName(values)]}" style="height:16px">{[this.renderFileName(values)]}</td>',
-                        '</tr>',
-                    '</table>',
-                '</div></tpl>',
-                {
-                    renderFileName: function(values) {
-                        return Ext.util.Format.htmlEncode(values.name);
-                    },
-                    renderPathName: function(values) {
-                        return Ext.util.Format.htmlEncode(values.path.replace(values.name, ''));
-                    }
-                    
-                }
-            );
+        this.recordProxy = Tine.Filemanager.fileRecordBackend;
+
+        if (null === this.app) {
+            this.app = Tine.Tinebase.appMgr.get('Filemanager');
         }
+
+        this.supr().initComponent.call(this);
+
+        this.addEvents(
+            /**
+             * @param selected node
+             */
+            'select'
+        );
     },
     
-    getValue: function() {
-            return Tine.Filemanager.SearchCombo.superclass.getValue.call(this);
-    },
+    onTriggerClick: function () {
+        var filepicker = new Tine.Filemanager.FilePickerDialog({
+            title: this.app.i18n._('Select a file'),
+            singleSelect: true,
+            constraint: 'file'
+        });
 
-    setValue: function (value) {
-        return Tine.Filemanager.SearchCombo.superclass.setValue.call(this, value);
-    }
+        filepicker.on('selected', function (node) {
+            if (!node || 0 === node.length) {
+                return true;
+            }
 
+            this.fireEvent('select', node[0]);
+            this.setValue(node[0].path);
+
+        }, this);
+
+        filepicker.openWindow();
+    }
 });
 
 Tine.widgets.form.RecordPickerManager.register('Filemanager', 'Node', Tine.Filemanager.SearchCombo);
index adc6a60..e806de0 100644 (file)
@@ -694,9 +694,15 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
     /**
      * is called when selecting a record in the searchCombo (relationpickercombo)
      */
-    onAddRecordFromCombo: function() {
-        var record = this.getActiveSearchCombo().store.getById(this.getActiveSearchCombo().getValue());
-        
+    onAddRecordFromCombo: function(node) {
+        var record = null;
+
+        if (this.getActiveSearchCombo().hasOwnProperty('store')) {
+            record = this.getActiveSearchCombo().store.getById(this.getActiveSearchCombo().getValue())
+        } else {
+            record = node;
+        }
+
         if (! record) {
             return;
         }
@@ -708,14 +714,18 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
         }
         
         this.onAddRecord(record, relconf);
-        
-        this.getActiveSearchCombo().collapse();
-        this.getActiveSearchCombo().reset();
+
+        if (this.getActiveSearchCombo().hasOwnProperty('collapse')) {
+            this.getActiveSearchCombo().collapse();
+            this.getActiveSearchCombo().reset();
+        }
     },
 
     /**
      * call to add relation from an external component
-     * 
+     *
+     *  @todo refactor this trash
+     *
      * @param {Tine.Tinebase.data.Record} record
      * @param {Object} relconf
      */
@@ -724,16 +734,16 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
             if (! relconf) {
                 relconf = {};
             }
-            if (record.data.hasOwnProperty('relations')) {
+            if (record.data && record.data.hasOwnProperty('relations')) {
                 record.data.relations = null;
                 delete record.data.relations;
             }
             var rc = this.getActiveSearchCombo().recordClass;
             var relatedPhpModel = rc.getPhpClassName();
-            
+
             var app = rc.getMeta('appName'), model = rc.getMeta('modelName'), f = app + model;
             var type = '';
-            
+
             if (this.constraintsConfig[f] && this.constraintsConfig[f].length) {
                 // per default the first defined type is used
                 var type = this.constraintsConfig[f][0].type;
@@ -747,7 +757,7 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
                 type = '';
 
             var relationRecord = new Tine.Tinebase.Model.Relation(Ext.apply(this.getRelationDefaults(), Ext.apply({
-                related_record: record.data,
+                related_record: record.data || record,
                 related_id: record.id,
                 related_model: relatedPhpModel,
                 type: type,
@@ -772,10 +782,6 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
                 this.onAddNewRelationToStore(relationRecord, record);
             }
         }
-        
-        // reset search combo
-        this.getActiveSearchCombo().collapse();
-        this.getActiveSearchCombo().reset();
     },
     
     /**
@@ -793,7 +799,7 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
         var relatedApp = Tine.Tinebase.appMgr.get(appName); 
         var relatedConstrainsConfig = relatedApp.getRegistry().get('relatableModels');
         var ownRecordClassName = this.editDialog.recordClass.getMeta('modelName');
-        var relatedRecordProxy = Tine[appName][(model.toLowerCase() + 'Backend')];
+        var relatedRecordProxy = this.getActiveSearchCombo().recordProxy || Tine[appName][(model.toLowerCase() + 'Backend')];
         
         if (! Ext.isFunction(record.get)) {
             record = relatedRecordProxy.recordReader({responseText: Ext.encode(record)});
@@ -894,9 +900,13 @@ Tine.widgets.relation.GenericPickerGridPanel = Ext.extend(Tine.widgets.grid.Pick
      * @param {Tine.Tinebase.data.Record} record
      */
     onAddNewRelationToStore: function(relationRecord, record) {
-        relationRecord.data.related_record.relations = null;
-        delete relationRecord.data.related_record.relations;
-        
+        var _ = window.lodash;
+
+        if (_.get(relationRecord, 'data.related_record.relations', false)) {
+            relationRecord.data.related_record.relations = null;
+            delete relationRecord.data.related_record.relations;
+        }
+
         if (this.relationCheck(relationRecord)) {
             Tine.log.debug('Adding new relation:');
             Tine.log.debug(relationRecord);