From bc6e7a5603fd1ad91c72e57b7fb7e3241938d9b8 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 27 Jan 2021 15:13:04 -0500 Subject: [PATCH] Afform Gui - Support cloning existing forms --- ext/afform/admin/ang/afAdmin.js | 12 ++++++++++++ ext/afform/admin/ang/afAdmin/afAdminList.html | 1 + .../admin/ang/afGuiEditor/afGuiEditor.component.js | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/ext/afform/admin/ang/afAdmin.js b/ext/afform/admin/ang/afAdmin.js index 4d8a856700..a298306d32 100644 --- a/ext/afform/admin/ang/afAdmin.js +++ b/ext/afform/admin/ang/afAdmin.js @@ -42,6 +42,18 @@ } } }); + $routeProvider.when('/clone/:name', { + controller: 'afAdminGui', + template: '', + resolve: { + // Load data for gui editor + data: function($route, crmApi4) { + return crmApi4('Afform', 'loadAdminData', { + definition: {name: $route.current.params.name} + }, 0); + } + } + }); }); })(angular, CRM.$, CRM._); diff --git a/ext/afform/admin/ang/afAdmin/afAdminList.html b/ext/afform/admin/ang/afAdmin/afAdminList.html index 5ab6d0cc12..c4b0901d18 100644 --- a/ext/afform/admin/ang/afAdmin/afAdminList.html +++ b/ext/afform/admin/ang/afAdmin/afAdminList.html @@ -57,6 +57,7 @@ {{afform.is_public ? ts('Frontend') : ts('Backend')}} {{ ts('Edit') }} + {{ ts('Clone') }} {{ afform.has_base ? ts('Revert') : ts('Delete') }} diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js index 80ce49a798..092505cb20 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js @@ -31,6 +31,10 @@ if (!$scope.afform) { alert('Error: unknown form'); } + if (editor.mode === 'clone') { + delete $scope.afform.name; + $scope.afform.title += ' ' + ts('(copy)'); + } $scope.canvasTab = 'layout'; $scope.layoutHtml = ''; editor.layout = {'#children': []}; -- 2.25.1