0013236: Use filepicker for filemanager relations
[tine20] / tine20 / Filemanager / js / SearchCombo.js
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);