From 119c2449cd4a77d4e90108954265a4da9080f904 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 18 Sep 2016 10:48:22 +0200 Subject: [PATCH] client/tags: fix tagging with aliases Fixes #93 --- client/js/controls/tag_input_control.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/client/js/controls/tag_input_control.js b/client/js/controls/tag_input_control.js index 5a19412..a579f15 100644 --- a/client/js/controls/tag_input_control.js +++ b/client/js/controls/tag_input_control.js @@ -135,6 +135,8 @@ class TagInputControl extends events.EventTarget { } isTaggedWith(tagName) { + let actualTag = null; + [tagName, actualTag] = this._transformTagName(tagName); return this.tags .map(t => t.toLowerCase()) .includes(tagName.toLowerCase()); @@ -153,6 +155,8 @@ class TagInputControl extends events.EventTarget { return; } + let actualTag = null; + [tagName, actualTag] = this._transformTagName(tagName); if (!this.isTaggedWith(tagName)) { this.tags.push(tagName); } @@ -177,6 +181,8 @@ class TagInputControl extends events.EventTarget { if (!tagName) { return; } + let actualTag = null; + [tagName, actualTag] = this._transformTagName(tagName); if (!this.isTaggedWith(tagName)) { return; } @@ -270,7 +276,17 @@ class TagInputControl extends events.EventTarget { } } + _transformTagName(tagName) { + const actualTag = tags.getTagByName(tagName); + if (actualTag) { + tagName = actualTag.names[0]; + } + return [tagName, actualTag]; + } + _getListItemNodeFromTagName(tagName) { + let actualTag = null; + [tagName, actualTag] = this._transformTagName(tagName); for (let listItemNode of this._tagListNode.querySelectorAll('li')) { if (listItemNode.getAttribute('data-tag').toLowerCase() === tagName.toLowerCase()) { @@ -281,13 +297,11 @@ class TagInputControl extends events.EventTarget { } _createListItemNode(tagName) { - const actualTag = tags.getTagByName(tagName); + let actualTag = null; + [tagName, actualTag] = this._transformTagName(tagName); const className = actualTag ? misc.makeCssName(actualTag.category, 'tag') : null; - if (actualTag) { - tagName = actualTag.names[0]; - } const tagLinkNode = document.createElement('a'); if (className) {