Merge branch 'mvanhelmont-U4-11589' into dev-v7
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,38 @@ 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 = CreateTemplateForContentType(itemDocType.Alias, itemDocType.Name);
|
||||
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 = CreateTemplateForContentType(collectionDocType.Alias, collectionDocType.Name);
|
||||
collectionDocType.SetDefaultTemplate(template);
|
||||
}
|
||||
|
||||
// save collection doctype
|
||||
Services.ContentTypeService.Save(collectionDocType);
|
||||
|
||||
// test if the parent id exist and then allow the collection underneath
|
||||
@@ -252,8 +270,6 @@ namespace Umbraco.Web.Editors
|
||||
allowedCts.Add(new ContentTypeSort(collectionDocType.Id, allowedCts.Count()));
|
||||
parentCt.AllowedContentTypes = allowedCts;
|
||||
Services.ContentTypeService.Save(parentCt);
|
||||
} else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,19 +292,7 @@ namespace Umbraco.Web.Editors
|
||||
//create a default template if it doesnt exist -but only if default template is == to the content type
|
||||
if (ctSave.DefaultTemplate.IsNullOrWhiteSpace() == false && ctSave.DefaultTemplate == ctSave.Alias)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(ctSave.Alias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(ctSave.Alias, ctSave.Name);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => ctSave.Alias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
var template = CreateTemplateForContentType(ctSave.Alias, ctSave.Name);
|
||||
|
||||
// If the alias has been manually updated before the first save,
|
||||
// make sure to also update the first allowed template, as the
|
||||
@@ -318,6 +322,26 @@ namespace Umbraco.Web.Editors
|
||||
return display;
|
||||
}
|
||||
|
||||
private ITemplate CreateTemplateForContentType(string contentTypeAlias, string contentTypeName)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(contentTypeAlias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(contentTypeAlias, contentTypeName);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => contentTypeAlias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an empty content type for use as a scaffold when creating a new type
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user