Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
Last active August 29, 2015 14:22
Show Gist options
  • Save mattbrailsford/9798004ea3c7b647222e to your computer and use it in GitHub Desktop.
Save mattbrailsford/9798004ea3c7b647222e to your computer and use it in GitHub Desktop.
CountryAppender.js
angular.module("umbraco").config(["$provide", function ($provide) {
$provide.decorator("entityResource", function ($delegate, $q) {
var getByIdsFn = $delegate.getByIds;
$delegate.getByIds = function (ids, type) {
var result = getByIdsFn.apply(null, arguments);
var loadRegionInfo = function(data, idx, def) {
var path = data[idx].path.split(',');
if (path.length > 3) {
getByIdsFn.apply(null, [[path[2], path[3]], type]).then(function(data2) {
data[idx].name += " [" + data2[0].name + "/" + data2[1].name + "]";
if (idx == data.length - 1) {
return def.resolve(data);
} else {
loadRegionInfo(data, idx + 1, def);
}
});
} else {
if (idx == data.length - 1) {
return def.resolve(data);
} else {
loadRegionInfo(data, idx + 1, def);
}
}
};
if (type == "Document" && ids.length > 0) {
var d = $q.defer();
result.then(function (data) {
loadRegionInfo(data, 0, d);
});
return d.promise;
} else {
return result;
}
};
return $delegate;
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment