From e7b816a9582f19131cfe5a75bd3f15e9fcd08967 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 10 Jul 2013 18:48:14 +1000 Subject: [PATCH] All resources now converted to using resourcePromise. --- .../src/common/resources/mediatype.resource.js | 16 ++++------------ .../src/common/resources/section.resource.js | 14 ++++++-------- 2 files changed, 10 insertions(+), 20 deletions(-) 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 index ce72b406e5..e6e88577c8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/mediatype.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/mediatype.resource.js @@ -3,7 +3,7 @@ * @name umbraco.resources.mediaTypeResource * @description Loads in data for content types **/ -function mediaTypeResource($q, $http) { +function mediaTypeResource($q, $http, angularHelper) { /** internal method to get the api url */ function getChildContentTypesUrl(contentId) { @@ -15,18 +15,10 @@ function mediaTypeResource($q, $http) { //return all types allowed under given document getAllowedTypes: function (contentId) { - var deferred = $q.defer(); + return angularHelper.resourcePromise( + $http.get(getChildContentTypesUrl(contentId)), + 'Failed to retreive data for media id ' + contentId); - //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; } }; diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/section.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/section.resource.js index 1d4a84384a..9bd878778e 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/section.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/section.resource.js @@ -3,7 +3,7 @@ * @name umbraco.resources.section * @description Loads in data for section **/ -function sectionResource($q, $http) { +function sectionResource($q, $http, angularHelper) { /** internal method to get the tree app url */ function getSectionsUrl(section) { @@ -13,13 +13,11 @@ function sectionResource($q, $http) { //the factory object returned return { /** Loads in the data to display the section list */ - getSections: function (options) { - return $http.get(getSectionsUrl()) - .then(function (response) { - return response.data; - }, function (response) { - throw new Error('Failed to retreive data for content id ' + id); - }); + getSections: function () { + + return angularHelper.resourcePromise( + $http.get(getSectionsUrl()), + 'Failed to retreive data for sections'); } }; }