diff --git a/src/Umbraco.Web.UI.Client/docs/html/using-promises-resources.html b/src/Umbraco.Web.UI.Client/docs/html/using-promises-resources.html
index 04643f916d..2d03233e67 100644
--- a/src/Umbraco.Web.UI.Client/docs/html/using-promises-resources.html
+++ b/src/Umbraco.Web.UI.Client/docs/html/using-promises-resources.html
@@ -113,7 +113,7 @@
Using AngularJS Promises and Umbraco Resources
Promises in Umbraco Resources
All Umbraco resource methods utilize a helper method:
-angularHelper.resourcePromise
+umbRequestHelper.resourcePromise
This method accepts 2 arguments:
- The angular HttpPromise which is created with a call to $http.get (post, etc..)
@@ -123,13 +123,13 @@
/** Loads in the data to display the nodes menu */
loadMenu: function (node) {
- return angularHelper.resourcePromise(
+ return umbRequestHelper.resourcePromise(
$http.get(getTreeMenuUrl(node)),
"Failed to retreive data for a node's menu " + node.id);
}
-HTTP error handling is performed automatically inside of the angularHelper.resourcePromise and inside of Umbraco's response interceptors.
+HTTP error handling is performed automatically inside of the umbRequestHelper.resourcePromise and inside of Umbraco's response interceptors.
Consuming Umbraco resources
-When consuming Umbraco resources, a normal angular promise will be returned based on the above angularHelper.resourcePromise. The success callback will always receive the RAW json data from the server and the error callback will always receive an object containing these properties:
+When consuming Umbraco resources, a normal angular promise will be returned based on the above umbRequestHelper.resourcePromise. The success callback will always receive the RAW json data from the server and the error callback will always receive an object containing these properties:
- erroMsg = the error message that can be used to show in the UI
- data = the original data object used to create the promise
diff --git a/src/Umbraco.Web.UI.Client/docs/src/using-promises-resources.md b/src/Umbraco.Web.UI.Client/docs/src/using-promises-resources.md
index ad84149dd3..ad3abc740b 100644
--- a/src/Umbraco.Web.UI.Client/docs/src/using-promises-resources.md
+++ b/src/Umbraco.Web.UI.Client/docs/src/using-promises-resources.md
@@ -4,7 +4,7 @@
All Umbraco resource methods utilize a helper method:
- angularHelper.resourcePromise
+ umbRequestHelper.resourcePromise
This method accepts 2 arguments:
@@ -16,16 +16,16 @@ Here's an example of the usage in an Umbraco resource. This example is the metho
/** Loads in the data to display the nodes menu */
loadMenu: function (node) {
- return angularHelper.resourcePromise(
+ return umbRequestHelper.resourcePromise(
$http.get(getTreeMenuUrl(node)),
"Failed to retreive data for a node's menu " + node.id);
}
-HTTP error handling is performed automatically inside of the `angularHelper.resourcePromise` and inside of Umbraco's response interceptors.
+HTTP error handling is performed automatically inside of the `umbRequestHelper.resourcePromise` and inside of Umbraco's response interceptors.
##Consuming Umbraco resources
-When consuming Umbraco resources, a normal angular promise will be returned based on the above `angularHelper.resourcePromise`. The success callback will always receive the RAW json data from the server and the error callback will always receive an object containing these properties:
+When consuming Umbraco resources, a normal angular promise will be returned based on the above `umbRequestHelper.resourcePromise`. The success callback will always receive the RAW json data from the server and the error callback will always receive an object containing these properties:
* erroMsg = the error message that can be used to show in the UI
* data = the original data object used to create the promise
diff --git a/src/Umbraco.Web.UI.Client/package.json b/src/Umbraco.Web.UI.Client/package.json
index a61d47fcbb..b67efaa92b 100644
--- a/src/Umbraco.Web.UI.Client/package.json
+++ b/src/Umbraco.Web.UI.Client/package.json
@@ -1,6 +1,6 @@
{
"author": "Umbraco HQ",
- "name": "umbraco 7",
+ "name": "umbraco",
"homepage": "https://github.com/umbraco/umbraco-cms/tree/7.0.0",
"version": "0.0.1-TechnicalPReview",
"repository": {
diff --git a/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js b/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js
index 943f780f03..836c928294 100644
--- a/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js
+++ b/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js
@@ -1,22 +1,18 @@
-//TODO: This would be nicer as an angular module so it can be injected into stuff... that'd be heaps nicer, but
-// how to do that when this is not a regular JS file, it is a server side JS file and RequireJS seems to only want
-// to force load JS files ?
-
//create the namespace (NOTE: This loads before any dependencies so we don't have a namespace mgr so we just create it manually)
var Umbraco = {};
Umbraco.Sys = {};
//define a global static object
Umbraco.Sys.ServerVariables = {
- "umbracoPath": "/umbraco",
- "contentApiBaseUrl": "/umbraco/UmbracoApi/Content/",
- "mediaApiBaseUrl": "/umbraco/UmbracoApi/Media/",
- "sectionApiBaseUrl": "/umbraco/UmbracoApi/Section/",
- "treeApplicationApiBaseUrl": "/umbraco/UmbracoTrees/ApplicationTreeApi/",
- "contentTypeApiBaseUrl": "/umbraco/Api/ContentType/",
- "mediaTypeApiBaseUrl": "/umbraco/Api/MediaTypeApi/",
- "authenticationApiBaseUrl": "/umbraco/UmbracoApi/Authentication/",
-
- "MyPackage": {
- "serverEnvironmentView": "/Belle/PropertyEditors/ServerSidePropertyEditors/ServerEnvironment"
+ umbracoUrls: {
+ "contentApiBaseUrl": "/umbraco/UmbracoApi/Content/",
+ "mediaApiBaseUrl": "/umbraco/UmbracoApi/Media/",
+ "sectionApiBaseUrl": "/umbraco/UmbracoApi/Section/",
+ "treeApplicationApiBaseUrl": "/umbraco/UmbracoTrees/ApplicationTreeApi/",
+ "contentTypeApiBaseUrl": "/umbraco/Api/ContentType/",
+ "mediaTypeApiBaseUrl": "/umbraco/Api/MediaTypeApi/",
+ "authenticationApiBaseUrl": "/umbraco/UmbracoApi/Authentication/"
+ },
+ umbracoSettings: {
+ "umbracoPath": "/umbraco"
}
};
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js
index 18d78a8789..4a05d2200f 100644
--- a/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js
+++ b/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js
@@ -3,37 +3,32 @@
* @name umbraco.resources.authResource
* @description Loads in data for authentication
**/
-function authResource($q, $http, angularHelper) {
-
- /** internal method to get the api url */
- function getLoginUrl(username, password) {
- return Umbraco.Sys.ServerVariables.authenticationApiBaseUrl + "PostLogin?username=" + username + "&password=" + password;
- }
-
- /** internal method to get the api url */
- function getIsAuthUrl() {
- return Umbraco.Sys.ServerVariables.authenticationApiBaseUrl + "GetCurrentUser";
- }
-
- //var currentUser;
-
+function authResource($q, $http, umbRequestHelper) {
return {
//currentUser: currentUser,
/** Logs the user in if the credentials are good */
- performLogin: function (username, password) {
- return angularHelper.resourcePromise(
- $http.post(getLoginUrl(username, password)),
- 'Login failed for user ' + username);
+ performLogin: function (username, password) {
+
+ return umbRequestHelper.resourcePromise(
+ $http.post(
+ umbRequestHelper.getApiUrl(
+ "authenticationApiBaseUrl",
+ "PostLogin",
+ [{ username: username }, { password: password }])),
+ 'Login failed for user ' + username);
},
/** Sends a request to the server to check if the current cookie value is valid for the user */
isAuthenticated: function () {
- return angularHelper.resourcePromise(
- $http.get(getIsAuthUrl()),
- 'Server call failed for checking authorization');
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "authenticationApiBaseUrl",
+ "GetCurrentUser")),
+ 'Server call failed for checking authorization');
}
};
}
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 23d71bc891..07f2d1c966 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
@@ -3,52 +3,55 @@
* @name umbraco.resources.contentResource
* @description Loads/saves in data for content
**/
-function contentResource($q, $http, umbDataFormatter, umbRequestHelper, angularHelper) {
+function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
- /** internal method to get the api url */
- function getContentUrl(contentId) {
- return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetById?id=" + contentId;
- }
- /** internal method to get the api url */
- function getByIdsUrl(ids) {
- var idQuery = "";
- _.each(ids, function(item) {
- idQuery += "ids=" + item + "&";
- });
- return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetById?" + idQuery;
- }
- /** internal method to get the api url */
- function getEmptyContentUrl(contentTypeAlias, parentId) {
- return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetEmpty?contentTypeAlias=" + contentTypeAlias + "&parentId=" + parentId;
- }
- /** internal method to get the api url for publishing */
- function getSaveUrl() {
- return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "PostSave";
- }
/** internal method process the saving of data and post processing the result */
function saveContentItem(content, action, files) {
- return umbRequestHelper.postSaveContent(getSaveUrl(content.id), content, action, files);
+ return umbRequestHelper.postSaveContent(
+ umbRequestHelper.getApiUrl(
+ "contentApiBaseUrl",
+ "PostSave"),
+ content, action, files);
}
return {
- getById: function (id) {
- return angularHelper.resourcePromise(
- $http.get(getContentUrl(id)),
- 'Failed to retreive data for content id ' + id);
+ getById: function (id) {
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "contentApiBaseUrl",
+ "GetById",
+ [{ id: id }])),
+ 'Failed to retreive data for content id ' + id);
},
getByIds: function (ids) {
- return angularHelper.resourcePromise(
- $http.get(getByIdsUrl(ids)),
- 'Failed to retreive data for content ids ' + ids);
+
+ var idQuery = "";
+ _.each(ids, function(item) {
+ idQuery += "ids=" + item + "&";
+ });
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "contentApiBaseUrl",
+ "GetByIds",
+ idQuery)),
+ 'Failed to retreive data for content id ' + id);
},
/** 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) {
- return angularHelper.resourcePromise(
- $http.get(getEmptyContentUrl(alias, parentId)),
- 'Failed to retreive data for empty content item type ' + alias);
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "contentApiBaseUrl",
+ "GetEmpty",
+ [{ contentTypeAlias: contentTypeAlias }, { parentId: parentId }])),
+ 'Failed to retreive data for empty content item type ' + alias);
},
getChildren: function (parentId, options) {
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 446f3fd037..10ad5751af 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,12 +3,7 @@
* @name umbraco.resources.contentTypeResource
* @description Loads in data for content types
**/
-function contentTypeResource($q, $http, $rootScope, angularHelper) {
-
- /** internal method to get the api url */
- function getChildContentTypesUrl(contentId) {
- return Umbraco.Sys.ServerVariables.contentTypeApiBaseUrl + "GetAllowedChildren?contentId=" + contentId;
- }
+function contentTypeResource($q, $http, umbRequestHelper) {
return {
@@ -44,9 +39,13 @@ function contentTypeResource($q, $http, $rootScope, angularHelper) {
//return all types allowed under given document
getAllowedTypes: function (contentId) {
- return angularHelper.resourcePromise(
- $http.get(getChildContentTypesUrl(contentId)),
- 'Failed to retreive data for content id ' + contentId);
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "contentTypeApiBaseUrl",
+ "GetAllowedChildren",
+ [{ contentId: contentId }])),
+ 'Failed to retreive data for content id ' + contentId);
}
};
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 381928ff5a..af1f34c3a1 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
@@ -1,65 +1,65 @@
/**
* @ngdoc service
- * @name umbraco.resources.treeResource
- * @description Loads in data for trees
+ * @name umbraco.resources.mediaResource
+ * @description Loads in data for media
**/
-function mediaResource($q, $http, umbDataFormatter, umbRequestHelper, angularHelper) {
-
- /** internal method to get the api url */
- 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";
- }
-
- /** internal method to get the api url */
- function getChildrenMediaUrl(parentId) {
- return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetChildren?parentId=" + parentId;
- }
-
- /** internal method to get the api url for publishing */
- function getSaveUrl() {
- return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "PostSave";
- }
+function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
/** internal method process the saving of data and post processing the result */
function saveMediaItem(content, action, files) {
- return umbRequestHelper.postSaveContent(getSaveUrl(content.id), content, action, files);
+ return umbRequestHelper.postSaveContent(
+ umbRequestHelper.getApiUrl(
+ "mediaApiBaseUrl",
+ "PostSave"),
+ content, action, files);
}
return {
getById: function (id) {
- return angularHelper.resourcePromise(
- $http.get(getMediaUrl(id)),
- 'Failed to retreive data for media id ' + id);
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "mediaApiBaseUrl",
+ "GetById",
+ [{ id: id }])),
+ 'Failed to retreive data for media id ' + id);
},
/** 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) {
- return angularHelper.resourcePromise(
- $http.get(getEmptyMediaUrl(alias, parentId)),
- 'Failed to retreive data for empty content item type ' + alias);
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "mediaApiBaseUrl",
+ "GetEmpty",
+ [{ contentTypeAlias: contentTypeAlias }, { parentId: parentId }])),
+ 'Failed to retreive data for empty media item type ' + alias);
+
},
rootMedia: function () {
- return angularHelper.resourcePromise(
- $http.get(getRootMediaUrl()),
- 'Failed to retreive data for application tree ' + section);
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "mediaApiBaseUrl",
+ "GetRootMedia")),
+ 'Failed to retreive data for root media');
+
},
getChildren: function (parentId) {
- return angularHelper.resourcePromise(
- $http.get(getChildrenMediaUrl(parentId)),
- 'Failed to retreive data for application tree ' + section);
+
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "mediaApiBaseUrl",
+ "GetChildren",
+ [{ parentId: parentId }])),
+ 'Failed to retreive data for root media');
},
/** saves or updates a media object */
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 e6e88577c8..b1949d1c86 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
@@ -1,24 +1,22 @@
/**
* @ngdoc service
* @name umbraco.resources.mediaTypeResource
- * @description Loads in data for content types
+ * @description Loads in data for media types
**/
-function mediaTypeResource($q, $http, angularHelper) {
-
- /** internal method to get the api url */
- function getChildContentTypesUrl(contentId) {
- return Umbraco.Sys.ServerVariables.mediaTypeApiBaseUrl + "GetAllowedChildren?contentId=" + contentId;
- }
+function mediaTypeResource($q, $http, umbRequestHelper) {
return {
//return all types allowed under given document
getAllowedTypes: function (contentId) {
- return angularHelper.resourcePromise(
- $http.get(getChildContentTypesUrl(contentId)),
- 'Failed to retreive data for media id ' + contentId);
-
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "mediaTypeApiBaseUrl",
+ "GetAllowedChildren",
+ [{ contentId: contentId }])),
+ 'Failed to retreive data for media id ' + contentId);
}
};
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 9bd878778e..4374d2e4d0 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
@@ -1,9 +1,9 @@
/**
* @ngdoc service
- * @name umbraco.resources.section
+ * @name umbraco.resources.sectionResource
* @description Loads in data for section
**/
-function sectionResource($q, $http, angularHelper) {
+function sectionResource($q, $http, umbRequestHelper) {
/** internal method to get the tree app url */
function getSectionsUrl(section) {
@@ -15,9 +15,13 @@ function sectionResource($q, $http, angularHelper) {
/** Loads in the data to display the section list */
getSections: function () {
- return angularHelper.resourcePromise(
- $http.get(getSectionsUrl()),
- 'Failed to retreive data for sections');
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "sectionApiBaseUrl",
+ "GetSections")),
+ 'Failed to retreive data for sections');
+
}
};
}
diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js
index 441d8788ab..02b825ca91 100644
--- a/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js
+++ b/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js
@@ -3,12 +3,7 @@
* @name umbraco.resources.treeResource
* @description Loads in data for trees
**/
-function treeResource($q, $http, angularHelper) {
-
- /** internal method to get the tree app url */
- function getTreeAppUrl(section) {
- return Umbraco.Sys.ServerVariables.treeApplicationApiBaseUrl + "GetApplicationTrees?application=" + section;
- }
+function treeResource($q, $http, umbRequestHelper) {
/** internal method to get the tree node's children url */
function getTreeNodesUrl(node) {
@@ -31,8 +26,8 @@ function treeResource($q, $http, angularHelper) {
/** Loads in the data to display the nodes menu */
loadMenu: function (node) {
-
- return angularHelper.resourcePromise(
+
+ return umbRequestHelper.resourcePromise(
$http.get(getTreeMenuUrl(node)),
"Failed to retreive data for a node's menu " + node.id);
},
@@ -44,8 +39,12 @@ function treeResource($q, $http, angularHelper) {
throw "The object specified for does not contain a 'section' property";
}
- return angularHelper.resourcePromise(
- $http.get(getTreeAppUrl(options.section)),
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl(
+ "treeApplicationApiBaseUrl",
+ "GetApplicationTrees",
+ [{ application: options.section }])),
'Failed to retreive data for application tree ' + options.section);
},
@@ -56,7 +55,7 @@ function treeResource($q, $http, angularHelper) {
throw "The options parameter object does not contain the required properties: 'node' and 'section'";
}
- return angularHelper.resourcePromise(
+ return umbRequestHelper.resourcePromise(
$http.get(getTreeNodesUrl(options.node)),
'Failed to retreive data for child nodes ' + options.node.nodeId);
}
diff --git a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js
index f2cbd113be..893c9f585f 100644
--- a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js
+++ b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js
@@ -162,8 +162,8 @@ angular.module('umbraco.services')
self.ui.currentNode = args.node;
//ensure the current dialog is cleared before creating another!
- if (this.ui.currentDialog) {
- dialogService.close(this.ui.currentDialog);
+ if (self.ui.currentDialog) {
+ dialogService.close(self.ui.currentDialog);
}
var dialog = self.showDialog({
diff --git a/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js b/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js
index 96185f360b..b3b9807223 100644
--- a/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js
+++ b/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js
@@ -32,79 +32,6 @@ angular.module('umbraco.services').factory('legacyJsLoader', legacyJsLoader);
function angularHelper($log, $q) {
return {
- /**
- * @ngdoc function
- * @name resourcePromise
- * @methodOf umbraco.services.angularHelper
- * @function
- *
- * @description
- * This returns a promise with an underlying http call, it is a helper method to reduce
- * the amount of duplicate code needed to query http resources and automatically handle any
- * Http errors. See /docs/source/using-promises-resources.md
- *
- * @param {object} opts A mixed object which can either be a string representing the error message to be
- * returned OR an object containing either:
- * { success: successCallback, errorMsg: errorMessage }
- * OR
- * { success: successCallback, error: errorCallback }
- * In both of the above, the successCallback must accept these parameters: data, status, headers, config
- * If using the errorCallback it must accept these parameters: data, status, headers, config
- * The success callback must return the data which will be resolved by the deferred object.
- * The error callback must return an object containing: {errorMsg: errorMessage, data: originalData }
- */
- resourcePromise: function (httpPromise, opts) {
- var deferred = $q.defer();
-
- /** The default success callback used if one is not supplied in the opts */
- function defaultSuccess(data, status, headers, config) {
- //when it's successful, just return the data
- return data;
- }
-
- /** The default error callback used if one is not supplied in the opts */
- function defaultError(data, status, headers, config) {
- return {
- //NOTE: the default error message here should never be used based on the above docs!
- errorMsg: (angular.isString(opts) ? opts : 'An error occurred!'),
- data: data
- };
- }
-
- //create the callbacs based on whats been passed in.
- var callbacks = {
- success: (!opts.success ? defaultSuccess : opts.success),
- error: (!opts.error ? defaultError : opts.error)
- };
-
- httpPromise.success(function (data, status, headers, config) {
-
- //invoke the callback
- var result = callbacks.success.apply(this, [data, status, headers, config]);
-
- //when it's successful, just return the data
- deferred.resolve(result);
-
- }).error(function(data, status, headers, config) {
-
- //invoke the callback
- var result = callbacks.error.apply(this, [data, status, headers, config]);
-
- //when there's an erorr...
- // TODO: Deal with the error in a global way
-
- //return an error object including the error message for UI
- deferred.reject({
- errorMsg: result.errorMsg,
- data: result.data
- });
-
- });
-
- return deferred.promise;
-
- },
-
/**
* @ngdoc function
* @name safeApply
@@ -333,6 +260,140 @@ angular.module('umbraco.services').factory('umbImageHelper', umbImageHelper);
function umbRequestHelper($http, $q, umbDataFormatter, angularHelper) {
return {
+ /**
+ * @ngdoc method
+ * @name umbRequestHelper#dictionaryToQueryString
+ * @methodOf umbRequestHelper
+ * @function
+ *
+ * @description
+ * This will turn an array of key/value pairs into a query string
+ *
+ * @param {Array} queryStrings An array of key/value pairs
+ */
+ dictionaryToQueryString: function(queryStrings) {
+
+ if (!angular.isArray(queryStrings)) {
+ throw "The queryString parameter is not an array of key value pairs";
+ }
+
+ return _.map(queryStrings, function (item) {
+ var key = null;
+ var val = null;
+ for (var k in item) {
+ key = k;
+ val = item[k];
+ break;
+ }
+ if (key == null || val == null) {
+ throw "The object in the array was not formatted as a key/value pair";
+ }
+ return key + "=" + val;
+ }).join("&");
+
+ },
+
+ /**
+ * @ngdoc method
+ * @name umbRequestHelper#getApiUrl
+ * @methodOf umbRequestHelper
+ * @function
+ *
+ * @description
+ * This will return the webapi Url for the requested key based on the servervariables collection
+ *
+ * @param {string} apiName The webapi name that is found in the servervariables["umbracoUrls"] dictionary
+ * @param {string} actionName The webapi action name
+ * @param {object} queryStrings Can be either a string or an array containing key/value pairs
+ */
+ getApiUrl: function(apiName, actionName, queryStrings) {
+ if (!Umbraco || !Umbraco.Sys || !Umbraco.Sys.ServerVariables || !Umbraco.Sys.ServerVariables["umbracoUrls"]) {
+ throw "No server variables defined!";
+ }
+
+ if (!Umbraco.Sys.ServerVariables["umbracoUrls"][apiName]) {
+ throw "No url found for api name " + apiName;
+ }
+
+ return Umbraco.Sys.ServerVariables["umbracoUrls"][apiName] + actionName +
+ (!queryStrings ? "" : "?" + (angular.isString(queryStrings) ? queryStrings : this.dictionaryToQueryString(queryStrings)));
+
+ },
+
+ /**
+ * @ngdoc function
+ * @name resourcePromise
+ * @methodOf umbraco.services.angularHelper
+ * @function
+ *
+ * @description
+ * This returns a promise with an underlying http call, it is a helper method to reduce
+ * the amount of duplicate code needed to query http resources and automatically handle any
+ * Http errors. See /docs/source/using-promises-resources.md
+ *
+ * @param {object} opts A mixed object which can either be a string representing the error message to be
+ * returned OR an object containing either:
+ * { success: successCallback, errorMsg: errorMessage }
+ * OR
+ * { success: successCallback, error: errorCallback }
+ * In both of the above, the successCallback must accept these parameters: data, status, headers, config
+ * If using the errorCallback it must accept these parameters: data, status, headers, config
+ * The success callback must return the data which will be resolved by the deferred object.
+ * The error callback must return an object containing: {errorMsg: errorMessage, data: originalData }
+ */
+ resourcePromise: function (httpPromise, opts) {
+ var deferred = $q.defer();
+
+ /** The default success callback used if one is not supplied in the opts */
+ function defaultSuccess(data, status, headers, config) {
+ //when it's successful, just return the data
+ return data;
+ }
+
+ /** The default error callback used if one is not supplied in the opts */
+ function defaultError(data, status, headers, config) {
+ return {
+ //NOTE: the default error message here should never be used based on the above docs!
+ errorMsg: (angular.isString(opts) ? opts : 'An error occurred!'),
+ data: data
+ };
+ }
+
+ //create the callbacs based on whats been passed in.
+ var callbacks = {
+ success: (!opts.success ? defaultSuccess : opts.success),
+ error: (!opts.error ? defaultError : opts.error)
+ };
+
+ httpPromise.success(function (data, status, headers, config) {
+
+ //invoke the callback
+ var result = callbacks.success.apply(this, [data, status, headers, config]);
+
+ //when it's successful, just return the data
+ deferred.resolve(result);
+
+ }).error(function (data, status, headers, config) {
+
+ //invoke the callback
+ var result = callbacks.error.apply(this, [data, status, headers, config]);
+
+ //when there's an erorr...
+ // TODO: Deal with the error in a global way
+
+ //return an error object including the error message for UI
+ deferred.reject({
+ errorMsg: result.errorMsg,
+ data: result.data
+ });
+
+ });
+
+ return deferred.promise;
+
+ },
+
+ /** Used for saving media/content specifically */
postSaveContent: function (restApiUrl, content, action, files) {
var deferred = $q.defer();
diff --git a/src/Umbraco.Web.UI.Client/test/unit/common/services/umbrequesthelper.spec.js b/src/Umbraco.Web.UI.Client/test/unit/common/services/umbrequesthelper.spec.js
new file mode 100644
index 0000000000..11b5bdcab0
--- /dev/null
+++ b/src/Umbraco.Web.UI.Client/test/unit/common/services/umbrequesthelper.spec.js
@@ -0,0 +1,26 @@
+describe('umbRequestHelper tests', function () {
+ var umbRequestHelper;
+
+ beforeEach(module('umbraco.services'));
+
+ beforeEach(inject(function ($injector) {
+ umbRequestHelper = $injector.get('umbRequestHelper');
+ }));
+
+ describe('formatting Urls', function () {
+
+ it('can create a query string from name value pairs', function () {
+
+ expect(umbRequestHelper.dictionaryToQueryString(
+ [{ key1: "value1" }, { key2: "value2" }, { key3: "value3" }])).toBe(
+ "key1=value1&key2=value2&key3=value3");
+ });
+
+ it('can create a url based on server vars', function () {
+
+ expect(umbRequestHelper.getApiUrl("contentTypeApiBaseUrl", "GetAllowedChildren", [{contentId: 123}])).toBe(
+ "/umbraco/Api/ContentType/GetAllowedChildren?contentId=123");
+ });
+
+ });
+});
\ No newline at end of file
diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs
index 37f6e9f3cb..fa603d985a 100644
--- a/src/Umbraco.Web/Editors/BackOfficeController.cs
+++ b/src/Umbraco.Web/Editors/BackOfficeController.cs
@@ -48,15 +48,26 @@ namespace Umbraco.Web.Editors
//now we need to build up the variables
var d = new Dictionary
{
- {"umbracoPath", GlobalSettings.Path},
- {"legacyTreeJs", Url.Action("LegacyTreeJs", "BackOffice")},
- {"contentApiBaseUrl", Url.GetUmbracoApiService("PostSave").TrimEnd("PostSave")},
- {"mediaApiBaseUrl", Url.GetUmbracoApiService("GetRootMedia").TrimEnd("GetRootMedia")},
- {"sectionApiBaseUrl", Url.GetUmbracoApiService("GetSections").TrimEnd("GetSections")},
- {"treeApplicationApiBaseUrl", Url.GetUmbracoApiService("GetApplicationTrees").TrimEnd("GetApplicationTrees")},
- {"contentTypeApiBaseUrl", Url.GetUmbracoApiService("GetAllowedChildren").TrimEnd("GetAllowedChildren")},
- {"mediaTypeApiBaseUrl", Url.GetUmbracoApiService("GetAllowedChildren").TrimEnd("GetAllowedChildren")},
- {"authenticationApiBaseUrl", Url.GetUmbracoApiService("PostLogin").TrimEnd("PostLogin")}
+ {
+ "umbracoUrls", new Dictionary
+ {
+ {"legacyTreeJs", Url.Action("LegacyTreeJs", "BackOffice")},
+ //API URLs
+ {"contentApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl("PostSave")},
+ {"mediaApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl("GetRootMedia")},
+ {"sectionApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl("GetSections")},
+ {"treeApplicationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl("GetApplicationTrees")},
+ {"contentTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl("GetAllowedChildren")},
+ {"mediaTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl("GetAllowedChildren")},
+ {"authenticationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl("PostLogin")}
+ }
+ },
+ {
+ "umbracoSettings", new Dictionary
+ {
+ {"umbracoPath", GlobalSettings.Path}
+ }
+ }
};
return JavaScript(ServerVariablesParser.Parse(d));
diff --git a/src/Umbraco.Web/Editors/LegacyController.cs b/src/Umbraco.Web/Editors/LegacyController.cs
index 8692294b89..9b2e018763 100644
--- a/src/Umbraco.Web/Editors/LegacyController.cs
+++ b/src/Umbraco.Web/Editors/LegacyController.cs
@@ -1,4 +1,10 @@
-using Umbraco.Web.Mvc;
+using System.Net;
+using System.Net.Http;
+using System.Web;
+using System.Web.Http;
+using Umbraco.Core;
+using Umbraco.Web.Mvc;
+using Umbraco.Web.UI;
using Umbraco.Web.WebApi;
namespace Umbraco.Web.Editors
@@ -16,7 +22,7 @@ namespace Umbraco.Web.Editors
///
public LegacyController()
: this(UmbracoContext.Current)
- {
+ {
}
///
@@ -28,15 +34,30 @@ namespace Umbraco.Web.Editors
{
}
- /////
- ///// This will perform the delete operation for legacy items which include any item that
- ///// has functionality included in the ui.xml structure.
- /////
- /////
- //public HttpResponseMessage DeleteLegacyItem(string nodeId, string nodeType)
- //{
-
- //}
+ ///
+ /// This will perform the delete operation for legacy items which include any item that
+ /// has functionality included in the ui.xml structure.
+ ///
+ ///
+ public HttpResponseMessage DeleteLegacyItem(string nodeId, string nodeType, string nodeText)
+ {
+ //In order to process this request we MUST have an HttpContext available
+ var httpContextAttempt = TryGetHttpContext();
+ if (httpContextAttempt.Success)
+ {
+ int id;
+ if (int.TryParse(nodeId, out id))
+ {
+ LegacyDialogHandler.Delete(httpContextAttempt.Result, UmbracoUser, nodeType, id, nodeText);
+ return new HttpResponseMessage(HttpStatusCode.OK);
+ }
+ //We must have an integer id for this to work
+ throw new HttpResponseException(HttpStatusCode.PreconditionFailed);
+ }
+ //We must have an HttpContext available for this to work.
+ throw new HttpResponseException(HttpStatusCode.PreconditionFailed);
+
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/UrlHelperExtensions.cs b/src/Umbraco.Web/UrlHelperExtensions.cs
index a60d765f87..3a966d858f 100644
--- a/src/Umbraco.Web/UrlHelperExtensions.cs
+++ b/src/Umbraco.Web/UrlHelperExtensions.cs
@@ -37,6 +37,19 @@ namespace Umbraco.Web
return url.GetUmbracoApiService(actionName, typeof (T));
}
+ ///
+ /// Return the Base Url (not including the action) for a Web Api service
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string GetUmbracoApiServiceBaseUrl(this UrlHelper url, string actionName)
+ where T : UmbracoApiController
+ {
+ return url.GetUmbracoApiService(actionName).TrimEnd(actionName);
+ }
+
///
/// Return the Url for a Web Api service
///
diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs
index 55e138b1bf..4694f6d96c 100644
--- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs
+++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs
@@ -1,4 +1,5 @@
using System;
+using System.Web;
using System.Web.Http;
using Umbraco.Core;
using Umbraco.Core.Services;
@@ -21,6 +22,24 @@ namespace Umbraco.Web.WebApi
Umbraco = new UmbracoHelper(umbracoContext);
}
+ ///
+ /// Tries to retreive the current HttpContext if one exists.
+ ///
+ ///
+ protected Attempt TryGetHttpContext()
+ {
+ object context;
+ if (Request.Properties.TryGetValue("MS_HttpContext", out context))
+ {
+ var httpContext = context as HttpContext;
+ if (httpContext != null)
+ {
+ return new Attempt(true, new HttpContextWrapper(httpContext));
+ }
+ }
+ return Attempt.False;
+ }
+
///
/// Returns the current ApplicationContext
///