|
1 |
| -function configurationController($scope, umbracoCmsIntegrationsPimInriverService, umbracoCmsIntegrationsPimInriverResource) { |
| 1 | +function configurationController($scope, notificationsService, umbracoCmsIntegrationsPimInriverService, umbracoCmsIntegrationsPimInriverResource) { |
2 | 2 | var vm = this;
|
3 | 3 |
|
4 | 4 | const selEntityTypes = document.getElementById("selEntityTypes");
|
|
11 | 11 | vm.selectedEntityType = {};
|
12 | 12 | vm.selectedFieldTypes = [];
|
13 | 13 |
|
14 |
| - console.log($scope.model.value); |
| 14 | + vm.showToast = showToast; |
| 15 | + |
| 16 | + //vm.showToast({ |
| 17 | + // color: 'danger', |
| 18 | + // headline: 'Algolia', |
| 19 | + // message: 'Index name and content schema are required.' |
| 20 | + //}); |
15 | 21 |
|
16 | 22 | if ($scope.model.value == null) {
|
17 | 23 | $scope.model.value = {
|
18 | 24 | entityType: '',
|
19 | 25 | displayFieldTypeIds: []
|
20 | 26 | };
|
21 | 27 | }
|
22 |
| - $scope.$on('formSubmitting', function () { |
23 |
| - $scope.model.value.entityType = vm.selectedEntityType.value; |
24 |
| - $scope.model.value.displayFieldTypeIds = vm.selectedFieldTypes; |
| 28 | + $scope.$on('formSubmitting', function (ev) { |
| 29 | + if (vm.selectedEntityType != undefined |
| 30 | + || vm.selectedEntityType.value.length == 0 |
| 31 | + || vm.selectedFieldTypes.length == 0) { |
| 32 | + notificationsService.error("Inriver", "Entity type and display fields are required. Configuration was not saved."); |
| 33 | + ev.preventDefault(); |
| 34 | + return; |
| 35 | + } else { |
| 36 | + $scope.model.value.entityType = vm.selectedEntityType.value; |
| 37 | + $scope.model.value.displayFieldTypeIds = vm.selectedFieldTypes; |
| 38 | + } |
25 | 39 | });
|
26 | 40 |
|
27 | 41 | vm.entityTypeChange = function () {
|
|
54 | 68 | return option;
|
55 | 69 | });
|
56 | 70 |
|
57 |
| - vm.selectedFieldTypes = $scope.model.value.displayFieldTypeIds; |
| 71 | + if ($scope.model.value.displayFieldTypeIds != null) |
| 72 | + vm.selectedFieldTypes = $scope.model.value.displayFieldTypeIds; |
58 | 73 |
|
59 | 74 | bindValues();
|
60 | 75 | });
|
|
75 | 90 | selEntityTypes.options = vm.entityTypes;
|
76 | 91 | vm.fieldTypes = vm.selectedEntityType.fieldTypes;
|
77 | 92 |
|
78 |
| - $scope.model.value.displayFieldTypeIds.forEach(fieldTypeId => { |
79 |
| - umbracoCmsIntegrationsPimInriverService.waitForElement("#tr" + fieldTypeId) |
80 |
| - .then(element => element.setAttribute("selected", "")); |
81 |
| - }); |
| 93 | + if ($scope.model.value.displayFieldTypeIds != null) { |
| 94 | + $scope.model.value.displayFieldTypeIds.forEach(fieldTypeId => { |
| 95 | + umbracoCmsIntegrationsPimInriverService.waitForElement("#tr" + fieldTypeId) |
| 96 | + .then(element => element.setAttribute("selected", "")); |
| 97 | + }); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + /* Toast Config properties: |
| 102 | + * color |
| 103 | + * headline |
| 104 | + * message |
| 105 | + */ |
| 106 | + function showToast(config) { |
| 107 | + const con = document.querySelector('uui-toast-notification-container'); |
| 108 | + |
| 109 | + const toast = document.createElement('uui-toast-notification'); |
| 110 | + toast.color = config.color; |
| 111 | + |
| 112 | + const toastLayout = document.createElement('uui-toast-notification-layout'); |
| 113 | + toastLayout.headline = config.headline; |
| 114 | + toast.appendChild(toastLayout); |
| 115 | + |
| 116 | + const messageEl = document.createElement('span'); |
| 117 | + messageEl.innerHTML = config.message; |
| 118 | + toastLayout.appendChild(messageEl); |
| 119 | + |
| 120 | + if (con) { |
| 121 | + con.appendChild(toast); |
| 122 | + } |
82 | 123 | }
|
83 | 124 |
|
84 | 125 | /**
|
|
0 commit comments