diff --git a/client/modules/crm/src/views/meeting/modals/detail.js b/client/modules/crm/src/views/meeting/modals/detail.js index fb3dd79a95..d4b0227806 100644 --- a/client/modules/crm/src/views/meeting/modals/detail.js +++ b/client/modules/crm/src/views/meeting/modals/detail.js @@ -30,6 +30,8 @@ define('crm:views/meeting/modals/detail', 'views/modals/detail', function (Dep) return Dep.extend({ + duplicateAction: true, + setupAfterModelCreated: function () { Dep.prototype.setupAfterModelCreated.call(this); diff --git a/client/src/views/edit.js b/client/src/views/edit.js index 9780fe3785..c2b3c4b6e5 100644 --- a/client/src/views/edit.js +++ b/client/src/views/edit.js @@ -44,6 +44,7 @@ define('views/edit', 'views/main', function (Dep) { 'attributes', 'rootUrl', 'duplicateSourceId', + 'returnAfterCreate', ], headerView: 'views/header', diff --git a/client/src/views/modals/detail.js b/client/src/views/modals/detail.js index b9959f7b78..6833bbf95d 100644 --- a/client/src/views/modals/detail.js +++ b/client/src/views/modals/detail.js @@ -56,9 +56,9 @@ define('views/modals/detail', 'views/modal', function (Dep) { flexibleHeaderFontSize: true, - setup: function () { - var self = this; + duplicateAction: false, + setup: function () { this.scope = this.scope || this.options.scope; this.id = this.options.id; @@ -160,6 +160,13 @@ define('views/modals/detail', 'views/modal', function (Dep) { this.listenToOnce(this.getRouter(), 'routed', function () { this.remove(); }, this); + + if (this.duplicateAction && this.getAcl().checkScope(this.scope, 'create')) { + this.addDropdownItem({ + name: 'duplicate', + label: 'Duplicate', + }); + } }, setupAfterModelCreated: function () { @@ -500,6 +507,31 @@ define('views/modals/detail', 'views/modal', function (Dep) { this.trigger('leave'); this.dialog.close(); - } + }, + + actionDuplicate: function () { + Espo.Ui.notify(this.translate('pleaseWait', 'messages')); + + Espo.Ajax + .postRequest(this.scope + '/action/getDuplicateAttributes', { + id: this.model.id, + }) + .then(attributes => { + Espo.Ui.notify(false); + + let url = '#' + this.scope + '/create'; + + this.getRouter().dispatch(this.scope, 'create', { + attributes: attributes, + returnUrl: this.getRouter().getCurrentUrl(), + options: { + duplicateSourceId: this.model.id, + returnAfterCreate: true, + }, + }); + + this.getRouter().navigate(url, {trigger: false}); + }); + }, }); }); diff --git a/client/src/views/record/detail.js b/client/src/views/record/detail.js index fabeb86b9b..593219ebdf 100644 --- a/client/src/views/record/detail.js +++ b/client/src/views/record/detail.js @@ -1051,6 +1051,8 @@ define('views/record/detail', ['views/record/base', 'view-record-helper'], funct this.dropdownItemList = Espo.Utils.cloneDeep(this.dropdownItemList); this.dropdownEditItemList = Espo.Utils.cloneDeep(this.dropdownEditItemList); + this.returnAfterCreate = this.options.returnAfterCreate; + this.returnUrl = this.options.returnUrl || this.returnUrl; this.returnDispatchParams = this.options.returnDispatchParams || this.returnDispatchParams; @@ -2307,7 +2309,7 @@ define('views/record/detail', ['views/record/base', 'view-record-helper'], funct }, exitAfterCreate: function () { - if (this.model.id) { + if (!this.returnAfterCreate && this.model.id) { var url = '#' + this.scope + '/view/' + this.model.id; this.getRouter().navigate(url, {trigger: false}); @@ -2322,7 +2324,6 @@ define('views/record/detail', ['views/record/base', 'view-record-helper'], funct } }, - /** * Called after save or cancel. * By default redirects page. Can be orverridden in options.