Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align template picking more towards the other pickers #11363

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,30 @@
};

scope.openItemPicker = function ($event) {
var dialogModel = {
view: "itempicker",
title: "Choose " + scope.itemLabel,
availableItems: scope.availableItems,
selectedItems: scope.selectedItems,
position: "target",
event: $event,
submit: function (model) {
scope.selectedItems.push(model.selectedItem);
// if no default item - set item as default
if (scope.defaultItem === null) {
scope.setAsDefaultItem(model.selectedItem);
if (scope.itemPicker) {
scope.itemPicker();
} else {
var dialogModel = {
view: "itempicker",
title: "Choose " + scope.itemLabel,
availableItems: scope.availableItems,
selectedItems: scope.selectedItems,
position: "target",
event: $event,
submit: function (model) {
scope.selectedItems.push(model.selectedItem);
// if no default item - set item as default
if (scope.defaultItem === null) {
scope.setAsDefaultItem(model.selectedItem);
}
overlayService.close();
},
close: function () {
overlayService.close();
}
overlayService.close();
},
close: function() {
overlayService.close();
}
};
overlayService.open(dialogModel);
};
overlayService.open(dialogModel);
}
};

scope.openTemplate = function (selectedItem) {
Expand Down Expand Up @@ -156,7 +160,8 @@
availableItems: "=",
defaultItem: "=",
itemName: "@",
updatePlaceholder: "="
updatePlaceholder: "=",
itemPicker: "="
},
link: link
};
Expand Down
25 changes: 24 additions & 1 deletion src/Umbraco.Web.UI.Client/src/common/services/editor.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ When building a custom infinite editor view you can use the same components as a
} else {
focus();
}
});
});

/**
* @ngdoc method
Expand Down Expand Up @@ -927,6 +927,28 @@ When building a custom infinite editor view you can use the same components as a
open(editor);
}

/**
* @ngdoc method
* @name umbraco.services.editorService#templatePicker
* @methodOf umbraco.services.editorService
*
* @description
* Opens a template 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 templatePicker(editor) {
editor.view = "views/common/infiniteeditors/treepicker/treepicker.html";
if (!editor.size) editor.size = "small";
editor.section = "settings";
editor.treeAlias = "templates";
open(editor);
}

/**
* @ngdoc method
* @name umbraco.services.editorService#macroPicker
Expand Down Expand Up @@ -1087,6 +1109,7 @@ When building a custom infinite editor view you can use the same components as a
templateSections: templateSections,
userPicker: userPicker,
itemPicker: itemPicker,
templatePicker: templatePicker,
macroPicker: macroPicker,
memberGroupPicker: memberGroupPicker,
memberPicker: memberPicker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
});
}
}
else if (vm.treeAlias === "templates") {
vm.entityType = "Template";
}

// 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(function () {
'use strict';

function TemplatesController($scope, entityResource, contentTypeHelper, templateResource, contentTypeResource, $routeParams) {
function TemplatesController($scope, entityResource, contentTypeHelper, templateResource, contentTypeResource, editorService, $routeParams) {

/* ----------- SCOPE VARIABLES ----------- */

Expand All @@ -22,6 +22,7 @@
vm.isElement = $scope.model.isElement;

vm.createTemplate = createTemplate;
vm.openItemPicker = openItemPicker;

/* ---------- INIT ---------- */

Expand Down Expand Up @@ -81,6 +82,29 @@
vm.canCreateTemplate = existingTemplate ? false : true;
}

function openItemPicker() {
const editor = {
title: "Choose template",
filterCssClass: 'not-allowed',
multiPicker: true,
filter: item => {
return !vm.availableTemplates.some(template => template.id == item.id) ||
$scope.model.allowedTemplates.some(template => template.id == item.id);
},
submit: model => {
model.selection.forEach(item => {
$scope.model.allowedTemplates.push(item);
});
editorService.close();
},
close: function() {
editorService.close();
}
}

editorService.templatePicker(editor);
}

var unbindWatcher = $scope.$watch("model.isElement",
function(newValue, oldValue) {
vm.isElement = newValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ <h5><localize key="contentTypeEditor_allowedTemplatesHeading"></localize></h5>
item-name="template"
name="model.name"
alias="model.alias"
update-placeholder="vm.updateTemplatePlaceholder">
update-placeholder="vm.updateTemplatePlaceholder"
item-picker="vm.openItemPicker">
</umb-grid-selector>

<umb-button
Expand Down
23 changes: 12 additions & 11 deletions src/Umbraco.Web.UI.Client/src/views/templates/edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,15 @@
});

localizationService.localize("template_mastertemplate").then(function (value) {
var title = value;
var masterTemplate = {
const title = value;
const editor = {
title: title,
availableItems: availableMasterTemplates,
submit: function (model) {
var template = model.selectedItem;
filterCssClass: 'not-allowed',
filter: item => {
return !availableMasterTemplates.some(template => template.id == item.id);
},
submit: model => {
var template = model.selection[0];
if (template && template.alias) {
vm.template.masterTemplateAlias = template.alias;
setLayout(template.alias + ".cshtml");
Expand All @@ -575,14 +578,12 @@
}
editorService.close();
},
close: function (oldModel) {
// close dialog
close: function () {
editorService.close();
// focus editor
vm.editor.focus();
}
};
editorService.itemPicker(masterTemplate);
}

editorService.templatePicker(editor);
});

}
Expand Down
18 changes: 18 additions & 0 deletions src/Umbraco.Web/Editors/EntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,15 @@ private EntityBasic GetResultForKey(Guid key, UmbracoEntityTypes entityType)

case UmbracoEntityTypes.Macro:

case UmbracoEntityTypes.Template:
var template = Services.FileService.GetTemplate(key);
if (template is null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}

return Mapper.Map<ITemplate, EntityBasic>(template);

default:
throw new NotSupportedException("The " + typeof(EntityController) + " does not currently support data for the type " + entityType);
}
Expand Down Expand Up @@ -985,6 +994,15 @@ private EntityBasic GetResultForId(int id, UmbracoEntityTypes entityType)

case UmbracoEntityTypes.Macro:

case UmbracoEntityTypes.Template:
var template = Services.FileService.GetTemplate(id);
if (template is null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}

return Mapper.Map<ITemplate, EntityBasic>(template);

default:
throw new NotSupportedException("The " + typeof(EntityController) + " does not currently support data for the type " + entityType);
}
Expand Down