summaryrefslogtreecommitdiff
path: root/client/js/controls
diff options
context:
space:
mode:
authorHunternif <hunternif@gmail.com>2019-05-07 21:47:08 +0700
committerHunternif <hunternif@gmail.com>2019-05-07 21:47:08 +0700
commit684e5e5ddcb69cb80742dc6b43e5d6ea092d89d0 (patch)
tree9148e62774897437baf66eaa6ae952d4e8be3095 /client/js/controls
parent67ba7981b6eeb859bbb69277ec9bd77d16903c0d (diff)
client: tags with categories are saved immediately after input, in all places: upload page, post editor, bulk tag editor
Diffstat (limited to 'client/js/controls')
-rw-r--r--client/js/controls/post_edit_sidebar_control.js5
-rw-r--r--client/js/controls/tag_input_control.js38
2 files changed, 7 insertions, 36 deletions
diff --git a/client/js/controls/post_edit_sidebar_control.js b/client/js/controls/post_edit_sidebar_control.js
index 4699360..4088d8a 100644
--- a/client/js/controls/post_edit_sidebar_control.js
+++ b/client/js/controls/post_edit_sidebar_control.js
@@ -379,11 +379,6 @@ class PostEditSidebarControl extends events.EventTarget {
tags: this._tagInputNode ?
misc.splitByWhitespace(this._tagInputNode.value) :
undefined,
-
- newTags: this._tagControl ?
- this._tagControl.newTags :
- undefined,
-
relations: this._relationsInputNode ?
misc.splitByWhitespace(this._relationsInputNode.value)
.map(x => parseInt(x)) :
diff --git a/client/js/controls/tag_input_control.js b/client/js/controls/tag_input_control.js
index 2c03b44..133b582 100644
--- a/client/js/controls/tag_input_control.js
+++ b/client/js/controls/tag_input_control.js
@@ -85,7 +85,6 @@ class TagInputControl extends events.EventTarget {
constructor(hostNode, tagList, placeholder) {
super();
this.tags = tagList;
- this.newTags = new TagList();
this._hostNode = hostNode;
this._suggestions = new SuggestionList();
this._tagToListItemNode = new Map();
@@ -143,44 +142,27 @@ class TagInputControl extends events.EventTarget {
}
addTagByText(text, source) {
- // try to find category for new tags in the format "category:name"
- text = text.replace(/:\s+/, ':');
- for (let tagName of text.split(/\s+/).filter(word => word).reverse()) {
- let nameAndCat = tagName.split(':');
- if (nameAndCat.length > 1) {
- // "cat:my:tag" should parse to category "cat" and tag "my:tag"
- let categoryName = nameAndCat.shift();
- let joinedTagName = nameAndCat.join(':');
- this.addTagByCategoryAndName(categoryName, joinedTagName, source);
- } else {
- this.addTagByName(tagName, source);
- }
- }
+ tags.resolveTagAndCategory(text).then(
+ tag => this.addTag(tag, source),
+ error => window.alert(error.message));
}
addTagByName(name, source) {
- // use the default category
- return this.addTagByCategoryAndName(null, name, source);
- }
-
- addTagByCategoryAndName(category, name, source) {
- category = category ? category.trim() : null;
name = name.trim();
if (!name) {
return;
}
- // if tag with this name already exists, existing category will be used
return Tag.get(name).then(tag => {
return this.addTag(tag, source);
}, () => {
const tag = new Tag();
tag.names = [name];
- tag.category = category;
- return this.addTag(tag, source, true);
+ tag.category = null;
+ return this.addTag(tag, source);
});
}
- addTag(tag, source, isNew) {
+ addTag(tag, source) {
if (source != SOURCE_INIT && this.tags.isTaggedWith(tag.names[0])) {
const listItemNode = this._getListItemNode(tag);
if (source !== SOURCE_IMPLICATION) {
@@ -191,13 +173,8 @@ class TagInputControl extends events.EventTarget {
}
return this.tags.addByTag(tag, false).then(() => {
- // new tags with categories will be saved separately after the post
- return isNew && tag.category
- ? this.newTags.add(tag)
- : Promise.resolve();
- }).then( () => {
const listItemNode = this._createListItemNode(tag);
- if (isNew === true) {
+ if (!tag.category) {
listItemNode.classList.add('new');
}
if (source === SOURCE_IMPLICATION) {
@@ -223,7 +200,6 @@ class TagInputControl extends events.EventTarget {
if (!this.tags.isTaggedWith(tag.names[0])) {
return;
}
- this.newTags.removeByName(tag.names[0]);
this.tags.removeByName(tag.names[0]);
this._hideAutoComplete();