From 6fbafcfc36b974c0ab0adf429e0e62a6805f2ab6 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 3 Apr 2020 17:56:55 +0300 Subject: [PATCH] import support history navigation --- client/src/controllers/import.js | 41 +++++++++++++++++++++++++++++--- client/src/views/import/index.js | 25 +++++++++++++++++-- client/src/views/import/step1.js | 3 +++ client/src/views/import/step2.js | 6 +++-- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/client/src/controllers/import.js b/client/src/controllers/import.js index e7bf8c4c08..c13fc1e407 100644 --- a/client/src/controllers/import.js +++ b/client/src/controllers/import.js @@ -46,9 +46,44 @@ define('controllers/import', 'controllers/record', function (Dep) { return false; }, - actionIndex: function () { - this.main('views/import/index', null); - } + actionIndex: function (o, d) { + o = o || {}; + + var step = null; + + if (o.step) { + step = parseInt(step); + } + + var formData = null; + var fileContents = null; + + if (this.storedData) { + formData = this.storedData.formData; + fileContents = this.storedData.fileContents; + } + + if (!formData) { + step = null; + } + + this.main('views/import/index', { + step: step, + formData: formData, + fileContents: fileContents, + }, function (view) { + this.listenTo(view, 'change', function () { + this.storedData = { + formData: view.formData, + fileContents: view.fileContents, + }; + }); + this.listenTo(view, 'done', function () { + delete this.storedData; + }); + view.render(); + }.bind(this)); + }, }); }); diff --git a/client/src/views/import/index.js b/client/src/views/import/index.js index fcccb30f35..3acca8beef 100644 --- a/client/src/views/import/index.js +++ b/client/src/views/import/index.js @@ -42,10 +42,25 @@ define('views/import/index', 'view', function (Dep) { fileContents: null, setup: function () { - this.entityType = this.options.entityType || false; + this.entityType = this.options.entityType || null; + + this.startFromStep = 1; + + if (this.options.formData && this.options.fileContents) { + this.formData = this.options.formData; + this.fileContents = this.options.fileContents; + + this.entityType = this.formData.entityType || null; + + if (this.options.step) { + this.startFromStep = this.options.step; + } + } }, changeStep: function (num, result) { + this.step = num; + this.createView('step', 'views/import/step' + num.toString(), { el: this.options.el + ' > .import-container', entityType: this.entityType, @@ -54,10 +69,16 @@ define('views/import/index', 'view', function (Dep) { }, function (view) { view.render(); }); + + var url = '#Import'; + if (this.step > 1) { + url += '/index/step=' + this.step; + } + this.getRouter().navigate(url, {trigger: false}) }, afterRender: function () { - this.changeStep(1); + this.changeStep(this.startFromStep); }, updatePageTitle: function () { diff --git a/client/src/views/import/step1.js b/client/src/views/import/step1.js index 9642c79791..c5c64a28fb 100644 --- a/client/src/views/import/step1.js +++ b/client/src/views/import/step1.js @@ -194,6 +194,9 @@ define('views/import/step1', ['view', 'model'], function (Dep, Model) { this.formData.skipDuplicateChecking = this.model.get('skipDuplicateChecking'); this.getParentView().formData = this.formData; + + this.getParentView().trigger('change'); + this.getParentView().changeStep(2); }, diff --git a/client/src/views/import/step2.js b/client/src/views/import/step2.js index 4c9bd127da..cb81cb56d4 100644 --- a/client/src/views/import/step2.js +++ b/client/src/views/import/step2.js @@ -26,7 +26,7 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('views/import/step2', 'view', function (Dep) { +define('views/import/step2', 'view', function (Dep) { return Dep.extend({ @@ -385,7 +385,6 @@ Espo.define('views/import/step2', 'view', function (Dep) { this.getParentView().changeStep(1); }, - next: function () { if (!this.fetch()) { return; @@ -412,6 +411,8 @@ Espo.define('views/import/step2', 'view', function (Dep) { this.getParentView().formData = this.formData; + this.getParentView().trigger('change'); + this.disableButtons(); this.notify('File uploading...'); @@ -444,6 +445,7 @@ Espo.define('views/import/step2', 'view', function (Dep) { timeout: 0, success: function (result) { var id = result.id; + this.getParentView().trigger('done'); if (id) { this.getRouter().navigate('#Import/view/' + id, {trigger: true}); } else {