Allow import without any container specification
authorMichael Spahn <m.spahn@metaways.de>
Tue, 4 Jul 2017 10:05:30 +0000 (12:05 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Tue, 4 Jul 2017 11:32:59 +0000 (13:32 +0200)
Change-Id: I18a59466a16ba31aed087480cb35540f38e12c8f
Reviewed-on: http://gerrit.tine20.com/customers/5009
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Tested-by: Michael Spahn <m.spahn@metaways.de>
tine20/Tinebase/js/widgets/dialog/ImportDialog.js
tine20/Tinebase/js/widgets/grid/GridPanel.js

index 73827e6..4d65471 100644 (file)
@@ -178,7 +178,7 @@ Tine.widgets.dialog.ImportDialog = Ext.extend(Tine.widgets.dialog.WizardPanel, {
                 tempFileId: this.uploadButton.getTempFileId(),
                 definitionId: this.definitionCombo.getValue(),
                 importOptions: Ext.apply({
-                    container_id: this.containerCombo.getValue(),
+                    container_id: this.containerCombo ? this.containerCombo.getValue() : null,
                     autotags: this.tagsPanel.getFormField().getValue()
                 }, importOptions || {}),
                 clientRecordData: clientRecordData
@@ -356,16 +356,11 @@ Tine.widgets.dialog.ImportDialog = Ext.extend(Tine.widgets.dialog.WizardPanel, {
         if (this.optionsPanel) {
             return this.optionsPanel;
         }
-        
-        return {
-            title: i18n._('Set Import Options'),
-            layout: 'fit',
-            border: false,
-            xtype: 'form',
-            frame: true,
-            ref: '../optionsPanel',
-            canonicalName: 'ImportOptions',
-            items: [{
+
+        var items = [];
+
+        if (null !== this.recordClass.getContainerName()) {
+            items = items.concat([{
                 xtype: 'label',
                 html: '<p>' + String.format(i18n._('Select {0} to add you {1} to:'), this.recordClass.getContainerName(), this.recordClass.getRecordsName()) + '</p>'
             }, new Tine.widgets.container.SelectionComboBox({
@@ -380,20 +375,33 @@ Tine.widgets.dialog.ImportDialog = Ext.extend(Tine.widgets.dialog.WizardPanel, {
                 value: this.defaultImportContainer,
                 listeners: {
                     scope: this,
-                    select: function() {
+                    select: function () {
                         this.manageButtons();
                     }
                 },
                 requiredGrant: false // 'add' ?
-            }), new Tine.widgets.tags.TagPanel({
-                canonicalName: 'ImportTags',
-                app: this.appName,
-                ref: '../tagsPanel',
-                style: 'margin-top: 15px; border: 1px solid silver; border-top: none;',
-                border: true,
-                collapsible: false,
-                height: 200
-            })],
+            })]);
+        }
+
+        items.push(new Tine.widgets.tags.TagPanel({
+            canonicalName: 'ImportTags',
+            app: this.appName,
+            ref: '../tagsPanel',
+            style: 'margin-top: 15px; border: 1px solid silver; border-top: none;',
+            border: true,
+            collapsible: false,
+            height: 200
+        }));
+
+        return {
+            title: i18n._('Set Import Options'),
+            layout: 'fit',
+            border: false,
+            xtype: 'form',
+            frame: true,
+            ref: '../optionsPanel',
+            canonicalName: 'ImportOptions',
+            items: items,
             
             listeners: {
                 scope: this,
@@ -410,8 +418,10 @@ Tine.widgets.dialog.ImportDialog = Ext.extend(Tine.widgets.dialog.WizardPanel, {
                         
                         this.tagsPanel.getFormField().setValue(tags);
                     }
-                    
-                    this.containerCombo.setValue(options.container_id ? options.container_id : this.defaultImportContainer);
+
+                    if (this.containerCombo) {
+                        this.containerCombo.setValue(options.container_id ? options.container_id : this.defaultImportContainer);
+                    }
                 }
             },
             
@@ -419,7 +429,11 @@ Tine.widgets.dialog.ImportDialog = Ext.extend(Tine.widgets.dialog.WizardPanel, {
              * check if next button is allowed
              */
             nextIsAllowed: (function() {
-                return this.containerCombo && this.containerCombo.getValue();
+                if (null !== this.recordClass.getContainerName()) {
+                    return this.containerCombo && this.containerCombo.getValue();
+                }
+
+                return true;
             }).createDelegate(this),
             
             /**
@@ -778,10 +792,10 @@ Tine.widgets.dialog.ImportDialog = Ext.extend(Tine.widgets.dialog.WizardPanel, {
         }, this);
         
         var tags = this.tagsPanel.getFormField().getValue(),
-            container = this.containerCombo.selectedContainer,
+            container = this.containerCombo ? this.containerCombo.selectedContainer : null,
             info = [String.format(i18n._('In total we found {0} records in your import file.'), rsp.totalcount + rsp.duplicatecount + rsp.failcount)];
             
-            if (totalcount) {
+            if (totalcount && null !== this.recordClass.getContainerName()) {
                 info.push(String.format(i18n._('{0} of them will be added as new records into: "{1}".'),
                     totalcount, 
                     Tine.Tinebase.common.containerRenderer(container).replace('<div', '<span').replace('</div>', '</span>')
index ac49d59..3920958 100644 (file)
@@ -857,11 +857,19 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
      * @param {Button} btn
      */
     onImport: function(btn) {
-        var treePanel = this.treePanel || this.app.getMainScreen().getWestPanel().getContainerTreePanel();
-        var popupWindow = Tine.widgets.dialog.ImportDialog.openWindow({
+        var treePanel = this.treePanel || this.app.getMainScreen().getWestPanel().getContainerTreePanel(),
+            _ = window.lodash;
+
+        var container = _.get(this.modelConfig, 'import.defaultImportContainerRegistryKey', false);
+
+        if (container) {
+            container = treePanel.getDefaultContainer(container);
+        }
+
+        Tine.widgets.dialog.ImportDialog.openWindow({
             appName: this.app.name,
             modelName: this.recordClass.getMeta('modelName'),
-            defaultImportContainer: treePanel.getDefaultContainer(this.modelConfig['import'].defaultImportContainerRegistryKey),
+            defaultImportContainer: container,
             listeners: {
                 scope: this,
                 'finish': function() {
@@ -1260,34 +1268,6 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
     },
 
     /**
-     * import records
-     *
-     * @param {Button} btn
-     */
-    onImport: function(btn) {
-        var treePanel = this.treePanel || this.app.getMainScreen().getWestPanel().getContainerTreePanel();
-        Tine.widgets.dialog.ImportDialog.openWindow({
-            appName: this.app.appName,
-            modelName: this.recordClass.getMeta('modelName'),
-            defaultImportContainer: Ext.isFunction(this.getDefaultContainer)
-                ? this.getDefaultContainer()
-                : treePanel.getDefaultContainer(),
-            // update grid after import
-            listeners: {
-                scope: this,
-                'finish': function() {
-                    this.loadGridData({
-                        preserveCursor:     false,
-                        preserveSelection:  false,
-                        preserveScroller:   false,
-                        removeStrategy:     'default'
-                    });
-                }
-            }
-        });
-    },
-
-    /**
      * perform the initial load of grid data
      */
     initialLoad: function() {