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 8e8bc72d43..cec9cf191e 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 @@ -3,17 +3,17 @@ * @name umbraco.resources.contentTypeResource * @description Loads in data for content types **/ -function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { +function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter, localizationService, notificationsService) { return { getCount: function () { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetCount")), - 'Failed to retrieve count'); + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetCount")), + 'Failed to retrieve count'); }, getAvailableCompositeContentTypes: function (contentTypeId, filterContentTypes, filterPropertyTypes) { @@ -31,32 +31,32 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { }; return umbRequestHelper.resourcePromise( - $http.post( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetAvailableCompositeContentTypes"), - query), - 'Failed to retrieve data for content type id ' + contentTypeId); + $http.post( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetAvailableCompositeContentTypes"), + query), + 'Failed to retrieve data for content type id ' + contentTypeId); }, - /** - * @ngdoc method - * @name umbraco.resources.contentTypeResource#getWhereCompositionIsUsedInContentTypes - * @methodOf umbraco.resources.contentTypeResource - * - * @description - * Returns a list of content types which use a specific composition with a given id - * - * ##usage - *
-         * contentTypeResource.getWhereCompositionIsUsedInContentTypes(1234)
-         *    .then(function(contentTypeList) {
-         *        console.log(contentTypeList);
-         *    });
-         * 
- * @param {Int} contentTypeId id of the composition content type to retrieve the list of the content types where it has been used - * @returns {Promise} resourcePromise object. - * - */ + /** + * @ngdoc method + * @name umbraco.resources.contentTypeResource#getWhereCompositionIsUsedInContentTypes + * @methodOf umbraco.resources.contentTypeResource + * + * @description + * Returns a list of content types which use a specific composition with a given id + * + * ##usage + *
+        * contentTypeResource.getWhereCompositionIsUsedInContentTypes(1234)
+        *    .then(function(contentTypeList) {
+        *        console.log(contentTypeList);
+        *    });
+        * 
+ * @param {Int} contentTypeId id of the composition content type to retrieve the list of the content types where it has been used + * @returns {Promise} resourcePromise object. + * + */ getWhereCompositionIsUsedInContentTypes: function (contentTypeId) { var query = { contentTypeId: contentTypeId @@ -92,12 +92,12 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { getAllowedTypes: function (contentTypeId) { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetAllowedChildren", - [{ contentId: contentTypeId }])), - 'Failed to retrieve data for content id ' + contentTypeId); + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetAllowedChildren", + [{ contentId: contentTypeId }])), + 'Failed to retrieve data for content id ' + contentTypeId); }, @@ -115,64 +115,64 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { getAllPropertyTypeAliases: function () { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetAllPropertyTypeAliases")), - 'Failed to retrieve property type aliases'); + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetAllPropertyTypeAliases")), + 'Failed to retrieve property type aliases'); }, getAllStandardFields: function () { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetAllStandardFields")), - 'Failed to retrieve standard fields'); + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetAllStandardFields")), + 'Failed to retrieve standard fields'); }, - getPropertyTypeScaffold : function (id) { - return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetPropertyTypeScaffold", - [{ id: id }])), - 'Failed to retrieve property type scaffold'); + getPropertyTypeScaffold: function (id) { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetPropertyTypeScaffold", + [{ id: id }])), + 'Failed to retrieve property type scaffold'); }, getById: function (id) { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetById", - [{ id: id }])), - 'Failed to retrieve content type'); + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetById", + [{ id: id }])), + 'Failed to retrieve content type'); }, deleteById: function (id) { return umbRequestHelper.resourcePromise( - $http.post( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "DeleteById", - [{ id: id }])), - 'Failed to delete content type'); + $http.post( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "DeleteById", + [{ id: id }])), + 'Failed to delete content type'); }, deleteContainerById: function (id) { return umbRequestHelper.resourcePromise( - $http.post( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "DeleteContainer", - [{ id: id }])), - 'Failed to delete content type contaier'); + $http.post( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "DeleteContainer", + [{ id: id }])), + 'Failed to delete content type contaier'); }, /** @@ -189,21 +189,21 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { getAll: function () { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetAll")), - 'Failed to retrieve all content types'); + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetAll")), + 'Failed to retrieve all content types'); }, getScaffold: function (parentId) { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentTypeApiBaseUrl", - "GetEmpty", { parentId: parentId })), - 'Failed to retrieve content type scaffold'); + $http.get( + umbRequestHelper.getApiUrl( + "contentTypeApiBaseUrl", + "GetEmpty", { parentId: parentId })), + 'Failed to retrieve content type scaffold'); }, /** @@ -223,7 +223,7 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { var saveModel = umbDataFormatter.formatContentTypePostData(contentType); return umbRequestHelper.resourcePromise( - $http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostSave"), saveModel), + $http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "PostSave"), saveModel), 'Failed to save data for content type id ' + contentType.id); }, @@ -270,7 +270,7 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { 'Failed to move content'); }, - copy: function(args) { + copy: function (args) { if (!args) { throw "args cannot be null"; } @@ -301,12 +301,12 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { createCollection: function (parentId, collectionName, collectionItemName, 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, collectionItemName: collectionItemName, collectionIcon: collectionIcon, collectionItemIcon: collectionItemIcon })), 'Failed to create collection under ' + parentId); }, - renameContainer: function(id, name) { + renameContainer: function (id, name) { return umbRequestHelper.resourcePromise( $http.post(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", @@ -322,13 +322,17 @@ function contentTypeResource($q, $http, umbRequestHelper, umbDataFormatter) { throw "id cannot be null"; } - return window.open(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", - "Export", - { - id: id - }), - '_blank', - ''); + var url = umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "Export", { id: id }); + + return umbRequestHelper.downloadFile(url).then(function () { + localizationService.localize("speechBubbles_documentTypeExportedSuccess").then(function(value) { + notificationsService.success(value); + }); + }, function (data) { + localizationService.localize("speechBubbles_documentTypeExportedError").then(function(value) { + notificationsService.error(value); + }); + }); } }; } diff --git a/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml b/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml index ee18248997..3de05dbbbf 100644 --- a/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml +++ b/src/Umbraco.Web.UI/Umbraco/config/lang/en.xml @@ -1445,6 +1445,8 @@ To manage your website, simply open the Umbraco back office and start adding con User %0% was deleted Invite user Invitation has been re-sent to %0% + Document type was exported to file + An error occurred while exporting the document type Uses CSS syntax ex: h1, .redHeader, .blueTex diff --git a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml index e61c406fae..0ecfb9c979 100644 --- a/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml +++ b/src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml @@ -1455,6 +1455,8 @@ To manage your website, simply open the Umbraco back office and start adding con Cannot publish the document since the required '%0%' is not published Validation failed for language '%0%' Unexpected validation failed for language '%0%' + Document type was exported to file + An error occurred while exporting the document type Uses CSS syntax ex: h1, .redHeader, .blueTex diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 57113d8e7b..4bd74bcbd3 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -419,6 +419,7 @@ namespace Umbraco.Web.Editors Services.DataTypeService, Services.ContentTypeService, contentType); + var response = new HttpResponseMessage { Content = new StringContent(xml.ToDataString()) @@ -430,10 +431,14 @@ namespace Umbraco.Web.Editors FileName = $"{contentType.Alias}.udt" }, ContentType = new MediaTypeHeaderValue( "application/octet-stream") + } } }; + // Set custom header so umbRequestHelper.downloadFile can save the correct filename + response.Headers.Add("x-filename", $"{contentType.Alias}.udt"); + return response; } }