From 2c7b4338f1b12f05531b4e9687579a5834c6d90d Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Sat, 15 Apr 2023 13:31:09 +0100 Subject: [PATCH] FormBuilder, add a 'Copy' button --- .../admin/ang/afGuiEditor/afGuiEntity.component.js | 1 + .../afGuiEditor/elements/afGuiContainer.component.js | 10 ++++++++++ .../admin/ang/afGuiEditor/elements/afGuiContainer.html | 8 ++++++++ ext/afform/core/ang/af/afRepeat.directive.js | 10 +++++++++- ext/afform/core/ang/af/afRepeat.html | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js index 3b031a4165..8c2110e809 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js @@ -103,6 +103,7 @@ item['af-join'] = block.join_entity; item['#children'] = [{"#tag": directive}]; item['af-repeat'] = ts('Add'); + item['af-copy'] = ts('Copy'); item.min = '1'; if (typeof joinEntity.repeat_max === 'number') { item.max = '' + joinEntity.repeat_max; diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js index 79382e2ba4..9853d7fbe9 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js @@ -127,9 +127,13 @@ delete ctrl.node.min; delete ctrl.node['af-repeat']; delete ctrl.node['add-icon']; + delete ctrl.node['af-copy']; + delete ctrl.node['copy-icon']; + } else { ctrl.node.min = '1'; ctrl.node['af-repeat'] = ts('Add'); + ctrl.node['af-copy'] = ts('Copy'); delete ctrl.node.data; } }; @@ -188,6 +192,12 @@ }); }; + $scope.pickCopyIcon = function() { + afGui.pickIcon().then(function(val) { + ctrl.node['copy-icon'] = val; + }); + }; + function getBlockNode() { return !ctrl.join ? ctrl.node : (ctrl.node['#children'] && ctrl.node['#children'].length === 1 ? ctrl.node['#children'][0] : null); } diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.html b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.html index 9d6431cc08..c0503327a2 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.html +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.html @@ -46,3 +46,11 @@ {{ $ctrl.node['af-repeat'] }} +
+ +
diff --git a/ext/afform/core/ang/af/afRepeat.directive.js b/ext/afform/core/ang/af/afRepeat.directive.js index f294c20630..697ce10a75 100644 --- a/ext/afform/core/ang/af/afRepeat.directive.js +++ b/ext/afform/core/ang/af/afRepeat.directive.js @@ -10,7 +10,9 @@ min: '=', max: '=', addLabel: '@afRepeat', - addIcon: '@' + addIcon: '@', + copyLabel: '@afCopy', + copyIcon: '@' }, templateUrl: '~/af/afRepeat.html', link: function($scope, $el, $attr, ctrls) { @@ -40,6 +42,12 @@ $scope.getItems().push(getRepeatType() === 'join' ? {} : {fields: {}}); }; + $scope.copyItem = function() { + var data = $scope.getItems(); + var last = data[data.length-1]; + data.push(getRepeatType() === 'join' ? angular.copy(last) : {fields: angular.copy(last.fields)}); + }; + $scope.removeItem = function(index) { $scope.getItems().splice(index, 1); }; diff --git a/ext/afform/core/ang/af/afRepeat.html b/ext/afform/core/ang/af/afRepeat.html index 63cc10257e..e4a7502ede 100644 --- a/ext/afform/core/ang/af/afRepeat.html +++ b/ext/afform/core/ang/af/afRepeat.html @@ -3,3 +3,4 @@ + -- 2.25.1