Last active
August 29, 2015 14:22
-
-
Save mattbrailsford/9798004ea3c7b647222e to your computer and use it in GitHub Desktop.
CountryAppender.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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