Skip to content

Commit 1e1276f

Browse files
10341: Use different picker for content types (#10896)
* 10341: Use different picker for content types * use es6 where possible (inc removing underscore for teeny tiny performance improvement) Co-authored-by: Nathan Woulfe <[email protected]>
1 parent 46e6f05 commit 1e1276f

File tree

2 files changed

+52
-64
lines changed

2 files changed

+52
-64
lines changed

src/Umbraco.Web.UI.Client/src/views/documenttypes/views/permissions/permissions.controller.js

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* @description
77
* The controller for the content type editor property dialog
88
*/
9-
(function() {
9+
(function () {
1010
'use strict';
1111

12-
function PermissionsController($scope, $timeout, contentTypeResource, iconHelper, contentTypeHelper, localizationService, overlayService) {
12+
function PermissionsController($scope, $timeout, contentTypeResource, iconHelper, contentTypeHelper, editorService) {
1313

1414
/* ----------- SCOPE VARIABLES ----------- */
1515

@@ -34,22 +34,22 @@
3434

3535
function init() {
3636

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);
3939

4040
// convert legacy icons
4141
iconHelper.formatContentTypeIcons(vm.contentTypes);
4242

4343
vm.selectedChildren = contentTypeHelper.makeObjectArrayFromId($scope.model.allowedContentTypes, contentTypes);
4444

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);
4747
}
4848
});
4949

5050
// 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 => {
5353
vm.canToggleIsElement = !result;
5454
});
5555
} else {
@@ -58,48 +58,42 @@
5858
}
5959

6060
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();
7475
},
75-
close: function() {
76-
overlayService.close();
77-
}
76+
close: () => editorService.close()
7877
};
7978

80-
localizationService.localize("contentTypeEditor_chooseChildNode").then(value => {
81-
dialog.title = value;
82-
overlayService.open(dialog);
83-
});
79+
editorService.contentTypePicker(editor);
8480
}
8581

8682
function removeChild(selectedChild, index) {
87-
// remove from vm
88-
vm.selectedChildren.splice(index, 1);
83+
// remove from vm
84+
vm.selectedChildren.splice(index, 1);
8985

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);
9389
}
9490

9591
function sortChildren() {
9692
// 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));
10094
}
10195

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
10397

10498
function toggleAllowAsRoot() {
10599
$scope.model.allowAsRoot = $scope.model.allowAsRoot ? false : true;
@@ -119,5 +113,5 @@
119113

120114
}
121115

122-
angular.module("umbraco").controller("Umbraco.Editors.DocumentType.PermissionsController", PermissionsController);
116+
angular.module('umbraco').controller('Umbraco.Editors.DocumentType.PermissionsController', PermissionsController);
123117
})();

src/Umbraco.Web.UI.Client/src/views/mediatypes/views/permissions/permissions.controller.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function() {
22
'use strict';
33

4-
function PermissionsController($scope, $timeout, mediaTypeResource, iconHelper, contentTypeHelper, localizationService, overlayService) {
4+
function PermissionsController($scope, $timeout, mediaTypeResource, iconHelper, contentTypeHelper, editorService) {
55

66
/* ----------- SCOPE VARIABLES ----------- */
77

@@ -21,7 +21,7 @@
2121

2222
function init() {
2323

24-
mediaTypeResource.getAll().then(function(mediaTypes){
24+
mediaTypeResource.getAll().then(mediaTypes => {
2525

2626
vm.mediaTypes = mediaTypes;
2727

@@ -39,29 +39,25 @@
3939
}
4040

4141
function addChild($event) {
42-
43-
var dialog = {
44-
view: "itempicker",
45-
availableItems: vm.mediaTypes,
46-
selectedItems: vm.selectedChildren,
47-
position: "target",
48-
event: $event,
49-
submit: function (model) {
50-
if (model.selectedItem) {
51-
vm.selectedChildren.push(model.selectedItem);
52-
$scope.model.allowedContentTypes.push(model.selectedItem.id);
53-
}
54-
overlayService.close();
42+
43+
var editor = {
44+
multiPicker: true,
45+
filterCssClass: 'not-allowed not-published',
46+
filter: item =>
47+
!vm.mediaTypes.some(x => x.udi == item.udi) || vm.selectedChildren.some(x => x.udi === item.udi),
48+
submit: model => {
49+
model.selection.forEach(item =>
50+
mediaTypeResource.getById(item.id).then(contentType => {
51+
vm.selectedChildren.push(contentType);
52+
$scope.model.allowedContentTypes.push(item.id);
53+
}));
54+
55+
editorService.close();
5556
},
56-
close: function() {
57-
overlayService.close();
58-
}
57+
close: () => editorService.close()
5958
};
6059

61-
localizationService.localize("contentTypeEditor_chooseChildNode").then(value => {
62-
dialog.title = value;
63-
overlayService.open(dialog);
64-
});
60+
editorService.mediaTypePicker(editor);
6561
}
6662

6763
function removeChild(selectedChild, index) {
@@ -75,9 +71,7 @@
7571

7672
function sortChildren() {
7773
// we need to wait until the next digest cycle for vm.selectedChildren to be updated
78-
$timeout(function () {
79-
$scope.model.allowedContentTypes = _.pluck(vm.selectedChildren, "id");
80-
});
74+
$timeout(() => $scope.model.allowedContentTypes = vm.selectedChildren.map(x => x.id));
8175
}
8276

8377
/**
@@ -94,5 +88,5 @@
9488

9589
}
9690

97-
angular.module("umbraco").controller("Umbraco.Editors.MediaType.PermissionsController", PermissionsController);
91+
angular.module('umbraco').controller('Umbraco.Editors.MediaType.PermissionsController', PermissionsController);
9892
})();

0 commit comments

Comments
 (0)