+ ngApp.directive('entityLinkSelector', [function($http) {
+ return {
+ restict: 'A',
+ link: function(scope, element, attrs) {
+
+ const selectButton = element.find('.entity-link-selector-confirm');
+ let callback = false;
+ let entitySelection = null;
+
+ // Handle entity selection change, Stores the selected entity locally
+ function entitySelectionChange(entity) {
+ entitySelection = entity;
+ if (entity === null) {
+ selectButton.attr('disabled', 'true');
+ } else {
+ selectButton.removeAttr('disabled');
+ }
+ }
+ events.listen('entity-select-change', entitySelectionChange);
+
+ // Handle selection confirm button click
+ selectButton.click(event => {
+ hide();
+ if (entitySelection !== null) callback(entitySelection);
+ });
+
+ // Show selector interface
+ function show() {
+ element.fadeIn(240);
+ }
+
+ // Hide selector interface
+ function hide() {
+ element.fadeOut(240);
+ }
+
+ // Listen to confirmation of entity selections (doubleclick)
+ events.listen('entity-select-confirm', entity => {
+ hide();
+ callback(entity);
+ });
+
+ // Show entity selector, Accessible globally, and store the callback
+ window.showEntityLinkSelector = function(passedCallback) {
+ show();
+ callback = passedCallback;
+ };
+
+ }
+ };
+ }]);
+