From d4cfa57b2a38b155c373a6a766d92fc68560f2f8 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 11 Jun 2013 14:30:37 +0200 Subject: [PATCH] Got media creation working and fixed updating node names. --- .../umbraco/googlemaps/editor.html | 2 +- .../src/common/resources/content.resource.js | 4 +- .../common/resources/contenttype.resource.js | 2 +- .../src/common/resources/media.resource.js | 32 +++++++++++++ .../common/resources/mediatype.resource.js | 34 +++++++++++++ .../views/content/contentedit.controller.js | 2 +- .../src/views/media/mediacreate.controller.js | 4 +- .../src/views/media/mediaedit.controller.js | 2 +- .../Views/FileUploadEditor.html | 4 +- .../Editors/BackOfficeController.cs | 3 +- src/Umbraco.Web/Editors/ContentController.cs | 2 +- .../Editors/ContentTypeApiController.cs | 48 ++++++++++++++++++- src/Umbraco.Web/Editors/MediaController.cs | 24 +++++++++- .../Models/Mapping/BaseContentModelMapper.cs | 2 +- .../Models/Mapping/ContentTypeModelMapper.cs | 22 +++++++++ .../WebApi/Binders/ContentItemBaseBinder.cs | 28 +++++++---- .../WebApi/Binders/ContentItemBinder.cs | 2 +- .../WebApi/Binders/MediaItemBinder.cs | 2 +- .../ContentItemValidationFilterAttribute.cs | 2 +- 19 files changed, 195 insertions(+), 26 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/resources/mediatype.resource.js diff --git a/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/googlemaps/editor.html b/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/googlemaps/editor.html index 0f576c3124..9effacac9e 100644 --- a/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/googlemaps/editor.html +++ b/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/googlemaps/editor.html @@ -1,3 +1,3 @@ 
-
+
\ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js index b358c6d490..e7de992f94 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js @@ -11,7 +11,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { } /** internal method to get the api url */ function getEmptyContentUrl(contentTypeAlias, parentId) { - return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetEmptyContent?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId; + return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetEmpty?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId; } /** internal method to get the api url for publishing */ function getSaveUrl() { @@ -49,7 +49,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { /** returns an empty content object which can be persistent on the content service requires the parent id and the alias of the content type to base the scaffold on */ - getContentScaffold: function (parentId, alias) { + getScaffold: function (parentId, alias) { var deferred = $q.defer(); diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js index 177602be76..f69e42dc2c 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js @@ -7,7 +7,7 @@ function contentTypeResource($q, $http) { /** internal method to get the api url */ function getChildContentTypesUrl(contentId) { - return Umbraco.Sys.ServerVariables.contentTypeApiBaseUrl + "GetAllowedChildrenForContent?contentId=" + contentId; + return Umbraco.Sys.ServerVariables.contentTypeApiBaseUrl + "GetAllowedChildren?contentId=" + contentId; } return { diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js index 628fc6ee91..51373415a8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js @@ -9,6 +9,12 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) { function getMediaUrl(contentId) { return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetById?id=" + contentId; } + + /** internal method to get the api url */ + function getEmptyMediaUrl(contentTypeAlias, parentId) { + return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetEmpty?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId; + } + /** internal method to get the api url */ function getRootMediaUrl() { return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetRootMedia"; @@ -54,6 +60,32 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) { return deferred.promise; }, + /** returns an empty content object which can be persistent on the content service + requires the parent id and the alias of the content type to base the scaffold on */ + getScaffold: function (parentId, alias) { + + var deferred = $q.defer(); + + //go and get the data + $http.get(getEmptyMediaUrl(alias, parentId)). + success(function (data, status, headers, config) { + //set the first tab to active + _.each(data.tabs, function (item) { + item.active = false; + }); + if (data.tabs.length > 0) { + data.tabs[0].active = true; + } + + deferred.resolve(data); + }). + error(function (data, status, headers, config) { + deferred.reject('Failed to retreive data for empty content item type ' + alias); + }); + + return deferred.promise; + }, + rootMedia: function () { var deferred = $q.defer(); diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/mediatype.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/mediatype.resource.js new file mode 100644 index 0000000000..c5a00c6760 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/resources/mediatype.resource.js @@ -0,0 +1,34 @@ +/** + * @ngdoc factory + * @name umbraco.resources.mediaTypeResource + * @description Loads in data for content types + **/ +function mediaTypeResource($q, $http) { + + /** internal method to get the api url */ + function getChildContentTypesUrl(contentId) { + return Umbraco.Sys.ServerVariables.mediaTypeApiBaseUrl + "GetAllowedChildren?contentId=" + contentId; + } + + return { + + //return all types allowed under given document + getAllowedTypes: function (contentId) { + + var deferred = $q.defer(); + + //go and get the tree data + $http.get(getChildContentTypesUrl(contentId)). + success(function (data, status, headers, config) { + deferred.resolve(data); + }). + error(function (data, status, headers, config) { + deferred.reject('Failed to retreive data for media id ' + contentId); + }); + + return deferred.promise; + } + + }; +} +angular.module('umbraco.resources').factory('mediaTypeResource', mediaTypeResource); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js index a8bc16e44d..c2a3570203 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/contentedit.controller.js @@ -4,7 +4,7 @@ angular.module("umbraco") if ($routeParams.create) { - contentResource.getContentScaffold($routeParams.id, $routeParams.doctype) + contentResource.getScaffold($routeParams.id, $routeParams.doctype) .then(function (data) { $scope.content = data; }); diff --git a/src/Umbraco.Web.UI.Client/src/views/media/mediacreate.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/mediacreate.controller.js index d474d1f620..318935368f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/mediacreate.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/mediacreate.controller.js @@ -1,5 +1,5 @@ -function mediaCreateController ($scope, $routeParams,contentTypeResource) { - $scope.allowedTypes = contentTypeResource.getAllowedTypes($scope.currentNode.id); +function mediaCreateController ($scope, $routeParams,mediaTypeResource) { + $scope.allowedTypes = mediaTypeResource.getAllowedTypes($scope.currentNode.id); } angular.module('umbraco') diff --git a/src/Umbraco.Web.UI.Client/src/views/media/mediaedit.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/mediaedit.controller.js index 1078f58eee..476ecd3adf 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/mediaedit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/mediaedit.controller.js @@ -2,7 +2,7 @@ function mediaEditController($scope, $routeParams, mediaResource, notificationsS if ($routeParams.create) { - mediaResource.getContentScaffold($routeParams.id, $routeParams.doctype) + mediaResource.getScaffold($routeParams.id, $routeParams.doctype) .then(function (data) { $scope.content = data; }); diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html index 419454f433..586304e3ce 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html @@ -11,8 +11,8 @@

Current files

-