editing blueprints now working
This commit is contained in:
@@ -49,14 +49,14 @@
|
||||
function syncTreeNode(content, path, initialLoad) {
|
||||
|
||||
if (!scope.content.isChildOfListView) {
|
||||
navigationService.syncTree({ tree: "content", path: path.split(","), forceReload: initialLoad !== true }).then(function (syncArgs) {
|
||||
navigationService.syncTree({ tree: scope.treeAlias, path: path.split(","), forceReload: initialLoad !== true }).then(function (syncArgs) {
|
||||
scope.page.menu.currentNode = syncArgs.node;
|
||||
});
|
||||
}
|
||||
else if (initialLoad === true) {
|
||||
|
||||
//it's a child item, just sync the ui node to the parent
|
||||
navigationService.syncTree({ tree: "content", path: path.substring(0, path.lastIndexOf(",")).split(","), forceReload: initialLoad !== true });
|
||||
navigationService.syncTree({ tree: scope.treeAlias, path: path.substring(0, path.lastIndexOf(",")).split(","), forceReload: initialLoad !== true });
|
||||
|
||||
//if this is a child of a list view and it's the initial load of the editor, we need to get the tree node
|
||||
// from the server so that we can load in the actions menu.
|
||||
@@ -134,7 +134,7 @@
|
||||
scope.page.loading = true;
|
||||
|
||||
//we are editing so get the content item from the server
|
||||
contentResource.getById(scope.contentId)
|
||||
scope.getMethod()(scope.contentId)
|
||||
.then(function (data) {
|
||||
|
||||
scope.content = data;
|
||||
@@ -200,7 +200,7 @@
|
||||
};
|
||||
|
||||
scope.save = function () {
|
||||
return performSave({ saveMethod: contentResource.save, statusMessage: "Saving...", action: "save" });
|
||||
return performSave({ saveMethod: scope.saveMethod(), statusMessage: "Saving...", action: "save" });
|
||||
};
|
||||
|
||||
scope.preview = function (content) {
|
||||
@@ -230,8 +230,11 @@
|
||||
templateUrl: 'views/components/content/edit.html',
|
||||
scope: {
|
||||
contentId: "=",
|
||||
treeAlias: "@",
|
||||
createOptions: "=?",
|
||||
page: "=?"
|
||||
page: "=?",
|
||||
saveMethod: "&",
|
||||
getMethod: "&"
|
||||
},
|
||||
link: link
|
||||
};
|
||||
|
||||
@@ -26,11 +26,9 @@
|
||||
function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
|
||||
/** internal method process the saving of data and post processing the result */
|
||||
function saveContentItem(content, action, files) {
|
||||
function saveContentItem(content, action, files, restApiUrl) {
|
||||
return umbRequestHelper.postSaveContent({
|
||||
restApiUrl: umbRequestHelper.getApiUrl(
|
||||
"contentApiBaseUrl",
|
||||
"PostSave"),
|
||||
restApiUrl: restApiUrl,
|
||||
content: content,
|
||||
action: action,
|
||||
files: files,
|
||||
@@ -277,7 +275,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
"DeleteBlueprint",
|
||||
[{ id: id }])),
|
||||
'Failed to delete blueprint ' + id);
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
@@ -310,6 +308,16 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
'Failed to retrieve data for content id ' + id);
|
||||
},
|
||||
|
||||
getBlueprintById: function (id) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"contentApiBaseUrl",
|
||||
"GetBlueprintById",
|
||||
[{ id: id }])),
|
||||
'Failed to retrieve data for content id ' + id);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.contentResource#getByIds
|
||||
@@ -574,9 +582,18 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
*
|
||||
*/
|
||||
save: function (content, isNew, files) {
|
||||
return saveContentItem(content, "save" + (isNew ? "New" : ""), files);
|
||||
var endpoint = umbRequestHelper.getApiUrl(
|
||||
"contentApiBaseUrl",
|
||||
"PostSave");
|
||||
return saveContentItem(content, "save" + (isNew ? "New" : ""), files, endpoint);
|
||||
},
|
||||
|
||||
saveBlueprint: function (content, isNew, files) {
|
||||
var endpoint = umbRequestHelper.getApiUrl(
|
||||
"contentApiBaseUrl",
|
||||
"PostSaveBlueprint");
|
||||
return saveContentItem(content, "save" + (isNew ? "New" : ""), files, endpoint);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
@@ -607,7 +624,10 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
*
|
||||
*/
|
||||
publish: function (content, isNew, files) {
|
||||
return saveContentItem(content, "publish" + (isNew ? "New" : ""), files);
|
||||
var endpoint = umbRequestHelper.getApiUrl(
|
||||
"contentApiBaseUrl",
|
||||
"PostSave");
|
||||
return saveContentItem(content, "publish" + (isNew ? "New" : ""), files, endpoint);
|
||||
},
|
||||
|
||||
|
||||
@@ -638,7 +658,10 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
*
|
||||
*/
|
||||
sendToPublish: function (content, isNew, files) {
|
||||
return saveContentItem(content, "sendPublish" + (isNew ? "New" : ""), files);
|
||||
var endpoint = umbRequestHelper.getApiUrl(
|
||||
"contentApiBaseUrl",
|
||||
"PostSave");
|
||||
return saveContentItem(content, "sendPublish" + (isNew ? "New" : ""), files, endpoint);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
* @description
|
||||
* The controller for the content editor
|
||||
*/
|
||||
function ContentEditController($scope, $routeParams) {
|
||||
function ContentEditController($scope, $routeParams, contentResource) {
|
||||
|
||||
$scope.contentId = $routeParams.id;
|
||||
$scope.saveMethod = contentResource.save;
|
||||
$scope.getMethod = contentResource.getById;
|
||||
$scope.page = $routeParams.page;
|
||||
$scope.createOptions = null;
|
||||
if ($routeParams.create && $routeParams.doctype) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<div ng-controller="Umbraco.Editors.Content.EditController">
|
||||
<content-editor create-options="createOptions"
|
||||
content-id="contentId"
|
||||
page="page">
|
||||
page="page"
|
||||
save-method="saveMethod"
|
||||
get-method="getMethod"
|
||||
tree-alias="content">
|
||||
</content-editor>
|
||||
</div>
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
* @description
|
||||
* The controller for the content editor
|
||||
*/
|
||||
function ContentBlueprintEditController($scope, $routeParams) {
|
||||
function ContentBlueprintEditController($scope, $routeParams, contentResource) {
|
||||
$scope.contentId = $routeParams.id;
|
||||
$scope.saveMethod = contentResource.saveBlueprint;
|
||||
$scope.getMethod = contentResource.getBlueprintById;
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.ContentBlueprint.EditController", ContentEditController);
|
||||
angular.module("umbraco").controller("Umbraco.Editors.ContentBlueprint.EditController", ContentBlueprintEditController);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<div ng-controller="Umbraco.Editors.ContentBlueprint.EditController">
|
||||
<content-editor content-id="contentId">
|
||||
<content-editor content-id="contentId"
|
||||
save-method="saveMethod"
|
||||
get-method="getMethod"
|
||||
tree-alias="contentblueprints">
|
||||
</content-editor>
|
||||
</div>
|
||||
|
||||
@@ -24,6 +24,7 @@ using Umbraco.Web.WebApi.Binders;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.presentation.preview;
|
||||
using Umbraco.Core.Events;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
@@ -104,6 +105,21 @@ namespace Umbraco.Web.Editors
|
||||
return display;
|
||||
}
|
||||
|
||||
public ContentItemDisplay GetBlueprintById(int id)
|
||||
{
|
||||
var foundContent = Services.ContentService.GetBlueprintById(id);
|
||||
if (foundContent == null)
|
||||
{
|
||||
HandleContentNotFound(id);
|
||||
}
|
||||
|
||||
var content = Mapper.Map<IContent, ContentItemDisplay>(foundContent);
|
||||
|
||||
content.AllowedActions = new[] {'A'};
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content json for the content id
|
||||
/// </summary>
|
||||
@@ -289,14 +305,14 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
var existing = Services.ContentService.GetBlueprintsForContentTypes(content.ContentTypeId);
|
||||
if (existing.Any(x => x.Name == name))
|
||||
{
|
||||
{
|
||||
//not allowed
|
||||
var notificationModel = new SimpleNotificationModel();
|
||||
notificationModel.AddSuccessNotification(
|
||||
"Error",
|
||||
"Another Blueprint with the same name already exists");
|
||||
return Request.CreateValidationErrorResponse(notificationModel);
|
||||
}
|
||||
}
|
||||
|
||||
var blueprint = Services.ContentService.CreateContentFromBlueprint(content, name, Security.GetUserId());
|
||||
|
||||
@@ -305,6 +321,24 @@ namespace Umbraco.Web.Editors
|
||||
return Request.CreateResponse(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves content
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[FileUploadCleanupFilter]
|
||||
[ContentPostValidate]
|
||||
public ContentItemDisplay PostSaveBlueprint(
|
||||
[ModelBinder(typeof(ContentItemBinder))] ContentItemSave contentItem)
|
||||
{
|
||||
return PostSaveInternal(contentItem,
|
||||
content =>
|
||||
{
|
||||
Services.ContentService.SaveBlueprint(contentItem.PersistedContent, Security.CurrentUser.Id);
|
||||
//we need to reuse the underlying logic so return the result that it wants
|
||||
return Attempt<OperationStatus>.Succeed(new OperationStatus(OperationStatusType.Success, new EventMessages()));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves content
|
||||
/// </summary>
|
||||
@@ -314,6 +348,12 @@ namespace Umbraco.Web.Editors
|
||||
public ContentItemDisplay PostSave(
|
||||
[ModelBinder(typeof(ContentItemBinder))]
|
||||
ContentItemSave contentItem)
|
||||
{
|
||||
return PostSaveInternal(contentItem,
|
||||
content => Services.ContentService.WithResult().Save(contentItem.PersistedContent, Security.CurrentUser.Id));
|
||||
}
|
||||
|
||||
private ContentItemDisplay PostSaveInternal(ContentItemSave contentItem, Func<IContent, Attempt<OperationStatus>> saveMethod)
|
||||
{
|
||||
//If we've reached here it means:
|
||||
// * Our model has been bound
|
||||
@@ -361,7 +401,7 @@ namespace Umbraco.Web.Editors
|
||||
if (contentItem.Action == ContentSaveAction.Save || contentItem.Action == ContentSaveAction.SaveNew)
|
||||
{
|
||||
//save the item
|
||||
var saveResult = Services.ContentService.WithResult().Save(contentItem.PersistedContent, Security.CurrentUser.Id);
|
||||
var saveResult = saveMethod(contentItem.PersistedContent);
|
||||
|
||||
wasCancelled = saveResult.Success == false && saveResult.Result.StatusType == OperationStatusType.FailedCancelledByEvent;
|
||||
}
|
||||
@@ -391,8 +431,8 @@ namespace Umbraco.Web.Editors
|
||||
if (wasCancelled == false)
|
||||
{
|
||||
display.AddSuccessNotification(
|
||||
Services.TextService.Localize("speechBubbles/editContentSavedHeader"),
|
||||
Services.TextService.Localize("speechBubbles/editContentSavedText"));
|
||||
Services.TextService.Localize("speechBubbles/editContentSavedHeader"),
|
||||
Services.TextService.Localize("speechBubbles/editContentSavedText"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -404,8 +444,8 @@ namespace Umbraco.Web.Editors
|
||||
if (wasCancelled == false)
|
||||
{
|
||||
display.AddSuccessNotification(
|
||||
Services.TextService.Localize("speechBubbles/editContentSendToPublish"),
|
||||
Services.TextService.Localize("speechBubbles/editContentSendToPublishText"));
|
||||
Services.TextService.Localize("speechBubbles/editContentSendToPublish"),
|
||||
Services.TextService.Localize("speechBubbles/editContentSendToPublishText"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -429,7 +469,7 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
|
||||
return display;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Publishes a document with a given ID
|
||||
|
||||
Reference in New Issue
Block a user