1 // https://civicrm.org/licensing
2 (function(angular
, $, _
) {
5 angular
.module('afGuiEditor').component('afGuiEditOptions', {
6 templateUrl
: '~/afGuiEditor/afGuiEditOptions.html',
7 require
: {field
: '^^afGuiField'},
8 controller: function($scope
) {
9 var ts
= $scope
.ts
= CRM
.ts(),
12 this.$onInit = function() {
13 $scope
.options
= JSON
.parse(angular
.toJson(ctrl
.field
.getOptions()));
14 var optionKeys
= _
.map($scope
.options
, 'key');
15 $scope
.deletedOptions
= _
.filter(JSON
.parse(angular
.toJson(ctrl
.field
.getDefn().options
|| [])), function (item
) {
16 return !_
.contains(optionKeys
, item
.key
);
18 $scope
.originalLabels
= _
.transform(ctrl
.field
.getDefn().options
|| [], function (originalLabels
, item
) {
19 originalLabels
[item
.key
] = item
.label
;
23 $scope
.deleteOption = function(option
, $index
) {
24 $scope
.options
.splice($index
, 1);
25 $scope
.deletedOptions
.push(option
);
28 $scope
.restoreOption = function(option
, $index
) {
29 $scope
.deletedOptions
.splice($index
, 1);
30 $scope
.options
.push(option
);
33 $scope
.save = function() {
34 ctrl
.field
.getSet('options', JSON
.parse(angular
.toJson($scope
.options
)));
38 $scope
.close = function() {
39 ctrl
.field
.setEditingOptions(false);
40 $('#afGuiEditor').removeClass('af-gui-editing-content');
45 })(angular
, CRM
.$, CRM
._
);