Merge branch 'U4-11589' of https://github.com/mvanhelmont/Umbraco-CMS into mvanhelmont-U4-11589
This commit is contained in:
@@ -298,10 +298,10 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
|
||||
|
||||
},
|
||||
|
||||
createCollection: function (parentId, collectionName, collectionItemName, collectionIcon, collectionItemIcon) {
|
||||
createCollection: function (parentId, collectionName, collectionCreateTemplate, collectionItemName, collectionItemCreateTemplate, collectionIcon, collectionItemIcon) {
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostCreateCollection", { parentId: parentId, collectionName: collectionName, collectionItemName: collectionItemName, collectionIcon: collectionIcon, collectionItemIcon: collectionItemIcon})),
|
||||
$http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostCreateCollection", { parentId: parentId, collectionName: collectionName, collectionCreateTemplate: collectionCreateTemplate, collectionItemName: collectionItemName, collectionItemCreateTemplate: collectionItemCreateTemplate, collectionIcon: collectionIcon, collectionItemIcon: collectionItemIcon})),
|
||||
'Failed to create collection under ' + parentId);
|
||||
|
||||
},
|
||||
|
||||
@@ -27,6 +27,8 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
|
||||
|
||||
$scope.showCreateDocTypeCollection = function () {
|
||||
$scope.model.creatingDoctypeCollection = true;
|
||||
$scope.model.collectionCreateTemplate = true;
|
||||
$scope.model.collectionItemCreateTemplate = true;
|
||||
};
|
||||
|
||||
$scope.createContainer = function () {
|
||||
@@ -83,7 +85,7 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
|
||||
}
|
||||
}
|
||||
|
||||
contentTypeResource.createCollection(node.id, $scope.model.collectionName, $scope.model.collectionItemName, collectionIcon, collectionItemIcon).then(function (collectionData) {
|
||||
contentTypeResource.createCollection(node.id, $scope.model.collectionName, $scope.model.collectionCreateTemplate, $scope.model.collectionItemName, $scope.model.collectionItemCreateTemplate, collectionIcon, collectionItemIcon).then(function (collectionData) {
|
||||
|
||||
navigationService.hideMenu();
|
||||
$location.search('create', null);
|
||||
|
||||
@@ -80,10 +80,14 @@
|
||||
|
||||
<umb-control-group label="Name of the Parent Document Type" hide-label="false">
|
||||
<input type="text" name="collectionName" ng-model="model.collectionName" class="umb-textstring textstring input-block-level" umb-auto-focus required />
|
||||
<umb-toggle on-click="model.collectionCreateTemplate = !model.collectionCreateTemplate" checked="model.collectionCreateTemplate"></umb-toggle>
|
||||
<label>Create template for the Parent Document Type</label>
|
||||
</umb-control-group>
|
||||
|
||||
<umb-control-group label="Name of the Item Document Type" hide-label="false">
|
||||
<input type="text" name="collectionItemName" ng-model="model.collectionItemName" class="umb-textstring textstring input-block-level" required />
|
||||
<umb-toggle on-click="model.collectionItemCreateTemplate = !model.collectionItemCreateTemplate" checked="model.collectionItemCreateTemplate"></umb-toggle>
|
||||
<label>Create template for the Item Document Type</label>
|
||||
</umb-control-group>
|
||||
|
||||
<button type="submit" class="btn btn-primary"><localize key="general_create">Create</localize></button>
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace Umbraco.Web.Editors
|
||||
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
|
||||
}
|
||||
|
||||
public DocumentTypeCollectionDisplay PostCreateCollection(int parentId, string collectionName, string collectionItemName, string collectionIcon, string collectionItemIcon)
|
||||
public DocumentTypeCollectionDisplay PostCreateCollection(int parentId, string collectionName, bool collectionCreateTemplate, string collectionItemName, bool collectionItemCreateTemplate, string collectionIcon, string collectionItemIcon)
|
||||
{
|
||||
var storeInContainer = false;
|
||||
var allowUnderDocType = -1;
|
||||
@@ -226,20 +226,64 @@ namespace Umbraco.Web.Editors
|
||||
// create item doctype
|
||||
var itemDocType = new ContentType(parentId);
|
||||
itemDocType.Name = collectionItemName;
|
||||
itemDocType.Alias = collectionItemName.ToSafeAlias();
|
||||
itemDocType.Alias = collectionItemName.ToSafeAlias(true);
|
||||
itemDocType.Icon = collectionItemIcon;
|
||||
|
||||
// create item doctype template
|
||||
if (collectionItemCreateTemplate)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(itemDocType.Alias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(itemDocType.Alias, itemDocType.Name);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => itemDocType.Alias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
|
||||
itemDocType.SetDefaultTemplate(template);
|
||||
}
|
||||
|
||||
// save item doctype
|
||||
Services.ContentTypeService.Save(itemDocType);
|
||||
|
||||
// create collection doctype
|
||||
var collectionDocType = new ContentType(parentId);
|
||||
collectionDocType.Name = collectionName;
|
||||
collectionDocType.Alias = collectionName.ToSafeAlias();
|
||||
collectionDocType.Alias = collectionName.ToSafeAlias(true);
|
||||
collectionDocType.Icon = collectionIcon;
|
||||
collectionDocType.IsContainer = true;
|
||||
collectionDocType.AllowedContentTypes = new List<ContentTypeSort>()
|
||||
{
|
||||
new ContentTypeSort(itemDocType.Id, 0)
|
||||
};
|
||||
|
||||
// create collection doctype template
|
||||
if (collectionCreateTemplate)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(collectionDocType.Alias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(collectionDocType.Alias, collectionDocType.Name);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => collectionDocType.Alias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
|
||||
collectionDocType.SetDefaultTemplate(template);
|
||||
}
|
||||
|
||||
// save collection doctype
|
||||
Services.ContentTypeService.Save(collectionDocType);
|
||||
|
||||
// test if the parent id exist and then allow the collection underneath
|
||||
|
||||
Reference in New Issue
Block a user