Skip to content
This repository was archived by the owner on Jun 18, 2018. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,51 @@ angular.module("umbraco.filters").filter("ncNodeName", function (editorState, en
return ncNodeNameCache.keys[input];
}

});
});

// Filter to take a node id and grab it's name instead
// Usage: {{ pickerAlias | ncMediaName }}

// Cache for node names so we don't make a ton of requests
var ncMediaNameCache = {
id: "",
keys: {}
}

angular.module("umbraco.filters").filter("ncMediaName", function (editorState, entityResource) {

return function (input) {

// Check we have a value at all
if (input == "" || input.toString() == "0")
return "";

var currentNode = editorState.getCurrent();

// Ensure a unique cache per editor instance
var key = "ncMediaName_" + currentNode.key;
if (ncMediaNameCache.id != key) {
ncMediaNameCache.id = key;
ncMediaNameCache.keys = {};
}

// See if there is a value in the cache and use that
if (ncMediaNameCache.keys[input]) {
return ncMediaNameCache.keys[input];
}

// No value, so go fetch one
// We'll put a temp value in the cache though so we don't
// make a load of requests while we wait for a response
ncMediaNameCache.keys[input] = "Loading...";

entityResource.getById(input, "Media")
.then(function (ent) {
ncMediaNameCache.keys[input] = ent.name;
});

// Return the current value for now
return ncMediaNameCache.keys[input];
}

});