Merge pull request #922 from engern/U4-6340

Fixes U4-6340 : Partial view macro with parameters not working in RTE and Grid (backend)
This commit is contained in:
Shannon Deminick
2015-11-26 09:54:24 +01:00
2 changed files with 27 additions and 29 deletions

View File

@@ -36,7 +36,7 @@ function macroResource($q, $http, umbRequestHelper) {
* @methodOf umbraco.resources.macroResource
*
* @description
* Gets the result of a macro as html to display in the rich text editor
* Gets the result of a macro as html to display in the rich text editor or in the Grid
*
* @param {int} macroId The macro id to get parameters for
* @param {int} pageId The current page id
@@ -45,39 +45,16 @@ function macroResource($q, $http, umbRequestHelper) {
*/
getMacroResultAsHtmlForEditor: function (macroAlias, pageId, macroParamDictionary) {
//need to format the query string for the custom dictionary
var query = "macroAlias=" + macroAlias + "&pageId=" + pageId;
if (macroParamDictionary) {
var counter = 0;
_.each(macroParamDictionary, function (val, key) {
//check for null
val = val ? val : "";
//need to detect if the val is a string or an object
if (!angular.isString(val)) {
//if it's not a string we'll send it through the json serializer
var json = angular.toJson(val);
//then we need to url encode it so that it's safe
val = encodeURIComponent(json);
}
else {
//we still need to encode the string, it could contain line breaks, etc...
val = encodeURIComponent(val);
}
query += "&macroParams[" + counter + "].key=" + key + "&macroParams[" + counter + "].value=" + val;
counter++;
});
}
return umbRequestHelper.resourcePromise(
$http.get(
$http.post(
umbRequestHelper.getApiUrl(
"macroApiBaseUrl",
"GetMacroResultAsHtmlForEditor",
query)),
"GetMacroResultAsHtmlForEditorUsingHttpPost",
query), JSON.stringify(macroParamDictionary)),
'Failed to retrieve macro result for macro with alias ' + macroAlias);
}
};
}