|
6 | 6 | * @description |
7 | 7 | * The controller for the content type editor property dialog |
8 | 8 | */ |
9 | | -(function() { |
| 9 | +(function () { |
10 | 10 | 'use strict'; |
11 | 11 |
|
12 | | - function PermissionsController($scope, $timeout, contentTypeResource, iconHelper, contentTypeHelper, localizationService, overlayService) { |
| 12 | + function PermissionsController($scope, $timeout, contentTypeResource, iconHelper, contentTypeHelper, editorService) { |
13 | 13 |
|
14 | 14 | /* ----------- SCOPE VARIABLES ----------- */ |
15 | 15 |
|
|
34 | 34 |
|
35 | 35 | function init() { |
36 | 36 |
|
37 | | - contentTypeResource.getAll().then(function(contentTypes){ |
38 | | - vm.contentTypes = _.where(contentTypes, {isElement: false}); |
| 37 | + contentTypeResource.getAll().then(contentTypes => { |
| 38 | + vm.contentTypes = contentTypes.filter(x => !x.isElement); |
39 | 39 |
|
40 | 40 | // convert legacy icons |
41 | 41 | iconHelper.formatContentTypeIcons(vm.contentTypes); |
42 | 42 |
|
43 | 43 | vm.selectedChildren = contentTypeHelper.makeObjectArrayFromId($scope.model.allowedContentTypes, contentTypes); |
44 | 44 |
|
45 | | - if($scope.model.id === 0) { |
46 | | - contentTypeHelper.insertChildNodePlaceholder(vm.contentTypes, $scope.model.name, $scope.model.icon, $scope.model.id); |
| 45 | + if ($scope.model.id === 0) { |
| 46 | + contentTypeHelper.insertChildNodePlaceholder(vm.contentTypes, $scope.model.name, $scope.model.icon, $scope.model.id); |
47 | 47 | } |
48 | 48 | }); |
49 | 49 |
|
50 | 50 | // Can only switch to an element type if there are no content nodes already created from the type. |
51 | | - if ($scope.model.id > 0 && !$scope.model.isElement ) { |
52 | | - contentTypeResource.hasContentNodes($scope.model.id).then(function (result) { |
| 51 | + if ($scope.model.id > 0 && !$scope.model.isElement) { |
| 52 | + contentTypeResource.hasContentNodes($scope.model.id).then(result => { |
53 | 53 | vm.canToggleIsElement = !result; |
54 | 54 | }); |
55 | 55 | } else { |
|
58 | 58 | } |
59 | 59 |
|
60 | 60 | function addChild($event) { |
61 | | - |
62 | | - const dialog = { |
63 | | - view: "itempicker", |
64 | | - availableItems: vm.contentTypes, |
65 | | - selectedItems: vm.selectedChildren, |
66 | | - position: "target", |
67 | | - event: $event, |
68 | | - submit: function (model) { |
69 | | - if (model.selectedItem) { |
70 | | - vm.selectedChildren.push(model.selectedItem); |
71 | | - $scope.model.allowedContentTypes.push(model.selectedItem.id); |
72 | | - } |
73 | | - overlayService.close(); |
| 61 | + |
| 62 | + var editor = { |
| 63 | + multiPicker: true, |
| 64 | + filterCssClass: 'not-allowed not-published', |
| 65 | + filter: item => |
| 66 | + !vm.contentTypes.some(x => x.udi == item.udi) || vm.selectedChildren.some(x => x.udi === item.udi), |
| 67 | + submit: model => { |
| 68 | + model.selection.forEach(item => |
| 69 | + contentTypeResource.getById(item.id).then(contentType => { |
| 70 | + vm.selectedChildren.push(contentType); |
| 71 | + $scope.model.allowedContentTypes.push(item.id); |
| 72 | + })); |
| 73 | + |
| 74 | + editorService.close(); |
74 | 75 | }, |
75 | | - close: function() { |
76 | | - overlayService.close(); |
77 | | - } |
| 76 | + close: () => editorService.close() |
78 | 77 | }; |
79 | 78 |
|
80 | | - localizationService.localize("contentTypeEditor_chooseChildNode").then(value => { |
81 | | - dialog.title = value; |
82 | | - overlayService.open(dialog); |
83 | | - }); |
| 79 | + editorService.contentTypePicker(editor); |
84 | 80 | } |
85 | 81 |
|
86 | 82 | function removeChild(selectedChild, index) { |
87 | | - // remove from vm |
88 | | - vm.selectedChildren.splice(index, 1); |
| 83 | + // remove from vm |
| 84 | + vm.selectedChildren.splice(index, 1); |
89 | 85 |
|
90 | | - // remove from content type model |
91 | | - var selectedChildIndex = $scope.model.allowedContentTypes.indexOf(selectedChild.id); |
92 | | - $scope.model.allowedContentTypes.splice(selectedChildIndex, 1); |
| 86 | + // remove from content type model |
| 87 | + var selectedChildIndex = $scope.model.allowedContentTypes.indexOf(selectedChild.id); |
| 88 | + $scope.model.allowedContentTypes.splice(selectedChildIndex, 1); |
93 | 89 | } |
94 | 90 |
|
95 | 91 | function sortChildren() { |
96 | 92 | // we need to wait until the next digest cycle for vm.selectedChildren to be updated |
97 | | - $timeout(function () { |
98 | | - $scope.model.allowedContentTypes = _.pluck(vm.selectedChildren, "id"); |
99 | | - }); |
| 93 | + $timeout(() => $scope.model.allowedContentTypes = vm.selectedChildren.map(x => x.id)); |
100 | 94 | } |
101 | 95 |
|
102 | | - // note: "safe toggling" here ie handling cases where the value is undefined, etc |
| 96 | + // note: 'safe toggling' here ie handling cases where the value is undefined, etc |
103 | 97 |
|
104 | 98 | function toggleAllowAsRoot() { |
105 | 99 | $scope.model.allowAsRoot = $scope.model.allowAsRoot ? false : true; |
|
119 | 113 |
|
120 | 114 | } |
121 | 115 |
|
122 | | - angular.module("umbraco").controller("Umbraco.Editors.DocumentType.PermissionsController", PermissionsController); |
| 116 | + angular.module('umbraco').controller('Umbraco.Editors.DocumentType.PermissionsController', PermissionsController); |
123 | 117 | })(); |
0 commit comments