Support "allow items of type" for all types in MNTP (#6177)

This commit is contained in:
Kenn Jacobsen
2019-09-16 16:32:29 +02:00
committed by Sebastiaan Janssen
parent be0d38f2af
commit 6467aae206
10 changed files with 186 additions and 66 deletions

View File

@@ -394,6 +394,52 @@ When building a custom infinite editor view you can use the same components as a
editor.treeAlias = "documentTypes";
open(editor);
}
/**
* @ngdoc method
* @name umbraco.services.editorService#mediaTypePicker
* @methodOf umbraco.services.editorService
*
* @description
* Opens a media type picker in infinite editing, the submit callback returns an array of selected items
*
* @param {Object} editor rendering options
* @param {Boolean} editor.multiPicker Pick one or multiple items
* @param {Function} editor.submit Callback function when the submit button is clicked. Returns the editor model object
* @param {Function} editor.close Callback function when the close button is clicked.
*
* @returns {Object} editor object
*/
function mediaTypePicker(editor) {
editor.view = "views/common/infiniteeditors/treepicker/treepicker.html";
editor.size = "small";
editor.section = "settings";
editor.treeAlias = "mediaTypes";
open(editor);
}
/**
* @ngdoc method
* @name umbraco.services.editorService#memberTypePicker
* @methodOf umbraco.services.editorService
*
* @description
* Opens a member type picker in infinite editing, the submit callback returns an array of selected items
*
* @param {Object} editor rendering options
* @param {Boolean} editor.multiPicker Pick one or multiple items
* @param {Function} editor.submit Callback function when the submit button is clicked. Returns the editor model object
* @param {Function} editor.close Callback function when the close button is clicked.
*
* @returns {Object} editor object
*/
function memberTypePicker(editor) {
editor.view = "views/common/infiniteeditors/treepicker/treepicker.html";
editor.size = "small";
editor.section = "settings";
editor.treeAlias = "memberTypes";
open(editor);
}
/**
* @ngdoc method
* @name umbraco.services.editorService#copy
@@ -908,6 +954,8 @@ When building a custom infinite editor view you can use the same components as a
contentEditor: contentEditor,
contentPicker: contentPicker,
contentTypePicker: contentTypePicker,
mediaTypePicker: mediaTypePicker,
memberTypePicker: memberTypePicker,
copy: copy,
move: move,
embed: embed,

View File

@@ -96,7 +96,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
});
}
}
if (vm.treeAlias === "documentTypes") {
else if (vm.treeAlias === "documentTypes") {
vm.entityType = "DocumentType";
if (!$scope.model.title) {
localizationService.localize("defaultdialogs_selectContentType").then(function(value){
@@ -107,9 +107,17 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
else if (vm.treeAlias === "member" || vm.section === "member") {
vm.entityType = "Member";
if (!$scope.model.title) {
localizationService.localize("defaultdialogs_selectMember").then(function(value){
localizationService.localize("defaultdialogs_selectMember").then(function(value) {
$scope.model.title = value;
})
});
}
}
else if (vm.treeAlias === "memberTypes") {
vm.entityType = "MemberType";
if (!$scope.model.title) {
localizationService.localize("defaultdialogs_selectMemberType").then(function(value){
$scope.model.title = value;
});
}
}
else if (vm.treeAlias === "media" || vm.section === "media") {
@@ -120,6 +128,14 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
});
}
}
else if (vm.treeAlias === "mediaTypes") {
vm.entityType = "MediaType";
if (!$scope.model.title) {
localizationService.localize("defaultdialogs_selectMediaType").then(function(value){
$scope.model.title = value;
});
}
}
// TODO: Seems odd this logic is here, i don't think it needs to be and should just exist on the property editor using this
if ($scope.model.minNumber) {

View File

@@ -1,54 +0,0 @@
function ContentTypePickerController($scope, contentTypeResource, editorService, angularHelper) {
var vm = this;
vm.loading = false;
vm.contentTypes = [];
vm.remove = remove;
vm.add = add;
var allContentTypes = null;
function init() {
vm.loading = true;
contentTypeResource.getAll().then(function (all) {
allContentTypes = all;
vm.loading = false;
// the model value is a comma separated list of content type aliases
var currentContentTypes = _.map(($scope.model.value || "").split(","), function (s) { return s.trim(); });
vm.contentTypes = _.filter(allContentTypes, function (contentType) {
return currentContentTypes.indexOf(contentType.alias) >= 0;
});
});
}
function add() {
editorService.contentTypePicker({
multiPicker: true,
submit: function (model) {
var newContentTypes = _.map(model.selection, function (selected) {
return _.findWhere(allContentTypes, {udi: selected.udi});
});
vm.contentTypes = _.uniq(_.union(vm.contentTypes, newContentTypes));
updateModel();
editorService.close();
},
close: function () {
editorService.close();
}
});
}
function remove(contentType) {
vm.contentTypes = _.without(vm.contentTypes, contentType);
updateModel();
}
function updateModel() {
// the model value is a comma separated list of content type aliases
$scope.model.value = _.pluck(vm.contentTypes, "alias").join();
angularHelper.getCurrentForm($scope).$setDirty();
}
init();
}
angular.module('umbraco').controller("Umbraco.PrevalueEditors.ContentTypePickerController", ContentTypePickerController);

View File

@@ -3,7 +3,7 @@
angular.module('umbraco')
.controller("Umbraco.PrevalueEditors.TreeSourceController",
function($scope, entityResource, iconHelper, editorService){
function($scope, $timeout, entityResource, iconHelper, editorService, eventsService){
if (!$scope.model) {
$scope.model = {};
@@ -23,7 +23,11 @@ angular.module('umbraco')
entityResource.getById($scope.model.value.id, entityType()).then(function(item){
populate(item);
});
}
}
$timeout(function () {
treeSourceChanged();
}, 100);
function entityType() {
var ent = "Document";
@@ -58,8 +62,13 @@ angular.module('umbraco')
$scope.model.value.id = null;
$scope.node = null;
$scope.model.value.query = null;
treeSourceChanged();
};
function treeSourceChanged() {
eventsService.emit("treeSourceChanged", { value: $scope.model.value.type });
}
//we always need to ensure we dont submit anything broken
var unsubscribe = $scope.$on("formSubmitting", function (ev, args) {

View File

@@ -0,0 +1,95 @@
function TreeSourceTypePickerController($scope, contentTypeResource, mediaTypeResource, memberTypeResource, editorService, eventsService, angularHelper) {
var vm = this;
vm.loading = false;
vm.itemTypes = [];
vm.remove = remove;
vm.add = add;
var allItemTypes = null;
var currentItemType = null;
var initialLoad = true;
function init() {
vm.loading = true;
switch (currentItemType) {
case "content":
contentTypeResource.getAll().then(getAllItemTypesCallback);
break;
case "media":
mediaTypeResource.getAll().then(getAllItemTypesCallback);
break;
case "member":
memberTypeResource.getTypes().then(getAllItemTypesCallback);
break;
}
}
function getAllItemTypesCallback(all) {
allItemTypes = all;
vm.loading = false;
// the model value is a comma separated list of content type aliases
var currentItemTypes = _.map(($scope.model.value || "").split(","), function (s) { return s.trim(); });
vm.itemTypes = _.filter(allItemTypes, function (itemType) {
return currentItemTypes.indexOf(itemType.alias) >= 0;
});
}
function add() {
if (!currentItemType) {
return;
}
var editor = {
multiPicker: true,
submit: function (model) {
var newItemTypes = _.map(model.selection,
function(selected) {
return _.findWhere(allItemTypes, { udi: selected.udi });
});
vm.itemTypes = _.uniq(_.union(vm.itemTypes, newItemTypes));
updateModel();
editorService.close();
},
close: function() {
editorService.close();
}
};
switch (currentItemType) {
case "content":
editorService.contentTypePicker(editor);
break;
case "media":
editorService.mediaTypePicker(editor);
break;
case "member":
editorService.memberTypePicker(editor);
break;
}
}
function remove(itemType) {
vm.itemTypes = _.without(vm.itemTypes, itemType);
updateModel();
}
function updateModel() {
// the model value is a comma separated list of content type aliases
$scope.model.value = _.pluck(vm.itemTypes, "alias").join();
angularHelper.getCurrentForm($scope).$setDirty();
}
eventsService.on("treeSourceChanged", function (e, args) {
currentItemType = args.value;
// reset the model value if we changed node type (but not on the initial load)
if (!initialLoad) {
vm.itemTypes = [];
updateModel();
}
initialLoad = false;
init();
});
}
angular.module('umbraco').controller("Umbraco.PrevalueEditors.TreeSourceTypePickerController", TreeSourceTypePickerController);

View File

@@ -1,15 +1,15 @@
<div ng-controller="Umbraco.PrevalueEditors.ContentTypePickerController as vm" class="umb-property-editor umb-contenttypepicker">
<div ng-controller="Umbraco.PrevalueEditors.TreeSourceTypePickerController as vm" class="umb-property-editor umb-contenttypepicker">
<umb-load-indicator ng-if="vm.loading"></umb-load-indicator>
<div ng-show="!vm.loading">
<umb-node-preview ng-repeat="contentType in vm.contentTypes"
<umb-node-preview ng-repeat="itemType in vm.itemTypes"
class="mt1"
icon="contentType.icon"
name="contentType.name"
icon="itemType.icon"
name="itemType.name"
allow-remove="true"
allow-edit="false"
on-remove="vm.remove(contentType)">
on-remove="vm.remove(itemType)">
</umb-node-preview>
<a class="umb-node-preview-add"

View File

@@ -432,6 +432,7 @@
<key alias="linkToMedia">Link til medie</key>
<key alias="selectContentStartNode">Vælg indhold startnode</key>
<key alias="selectMedia">Vælg medie</key>
<key alias="selectMediaType">Vælg medietype</key>
<key alias="selectIcon">Vælg ikon</key>
<key alias="selectItem">Vælg item</key>
<key alias="selectLink">Vælg link</key>
@@ -441,6 +442,7 @@
<key alias="selectMediaStartNode">Vælg medie startnode</key>
<key alias="selectMember">Vælg medlem</key>
<key alias="selectMemberGroup">Vælg medlemsgruppe</key>
<key alias="selectMemberType">Vælg medlemstype</key>
<key alias="selectNode">Vælg node</key>
<key alias="selectSections">Vælg sektioner</key>
<key alias="selectUsers">Vælg brugere</key>

View File

@@ -450,6 +450,7 @@
<key alias="linkToMedia">Link to media</key>
<key alias="selectContentStartNode">Select content start node</key>
<key alias="selectMedia">Select media</key>
<key alias="selectMediaType">Select media type</key>
<key alias="selectIcon">Select icon</key>
<key alias="selectItem">Select item</key>
<key alias="selectLink">Select link</key>
@@ -459,6 +460,7 @@
<key alias="selectMediaStartNode">Select media start node</key>
<key alias="selectMember">Select member</key>
<key alias="selectMemberGroup">Select member group</key>
<key alias="selectMemberType">Select member type</key>
<key alias="selectNode">Select node</key>
<key alias="selectSections">Select sections</key>
<key alias="selectUsers">Select users</key>

View File

@@ -453,6 +453,7 @@
<key alias="linkToMedia">Link to media</key>
<key alias="selectContentStartNode">Select content start node</key>
<key alias="selectMedia">Select media</key>
<key alias="selectMediaType">Select media type</key>
<key alias="selectIcon">Select icon</key>
<key alias="selectItem">Select item</key>
<key alias="selectLink">Select link</key>
@@ -462,6 +463,7 @@
<key alias="selectMediaStartNode">Select media start node</key>
<key alias="selectMember">Select member</key>
<key alias="selectMemberGroup">Select member group</key>
<key alias="selectMemberType">Select member type</key>
<key alias="selectNode">Select node</key>
<key alias="selectSections">Select sections</key>
<key alias="selectUsers">Select users</key>

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Web.PropertyEditors
[ConfigurationField("startNode", "Node type", "treesource")]
public MultiNodePickerConfigurationTreeSource TreeSource { get; set; }
[ConfigurationField("filter", "Allow items of type", "contenttypepicker", Description = "Select the applicable content types")]
[ConfigurationField("filter", "Allow items of type", "treesourcetypepicker", Description = "Select the applicable types")]
public string Filter { get; set; }
[ConfigurationField("minNumber", "Minimum number of items", "number")]