Commit | Line | Data |
---|---|---|
b15070eb CW |
1 | // https://civicrm.org/licensing |
2 | (function(angular, $, _) { | |
3 | "use strict"; | |
4 | ||
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(), | |
10 | ctrl = this; | |
11 | ||
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); | |
17 | }); | |
18 | $scope.originalLabels = _.transform(ctrl.field.getDefn().options || [], function (originalLabels, item) { | |
19 | originalLabels[item.key] = item.label; | |
20 | }, {}); | |
21 | }; | |
22 | ||
23 | $scope.deleteOption = function(option, $index) { | |
24 | $scope.options.splice($index, 1); | |
25 | $scope.deletedOptions.push(option); | |
26 | }; | |
27 | ||
28 | $scope.restoreOption = function(option, $index) { | |
29 | $scope.deletedOptions.splice($index, 1); | |
30 | $scope.options.push(option); | |
31 | }; | |
32 | ||
33 | $scope.save = function() { | |
34 | ctrl.field.getSet('options', JSON.parse(angular.toJson($scope.options))); | |
35 | $scope.close(); | |
36 | }; | |
37 | ||
38 | $scope.close = function() { | |
39 | ctrl.field.setEditingOptions(false); | |
40 | $('#afGuiEditor').removeClass('af-gui-editing-content'); | |
41 | }; | |
42 | } | |
43 | }); | |
44 | ||
45 | })(angular, CRM.$, CRM._); |