1 import draggable from 'vuedraggable';
2 import autosuggest from './components/autosuggest';
10 const components = {draggable, autosuggest};
11 const directives = {};
16 this.tags.push({name: '', value: '', key: Math.random().toString(36).substring(7)});
20 * When an tag changes check if another empty editable field needs to be added onto the end.
24 let tagPos = this.tags.indexOf(tag);
25 if (tagPos === this.tags.length-1 && (tag.name !== '' || tag.value !== '')) this.addEmptyTag();
29 * When an tag field loses focus check the tag to see if its
30 * empty and therefore could be removed from the list.
34 let isLast = (this.tags.indexOf(tag) === this.tags.length-1);
35 if (tag.name !== '' || tag.value !== '' || isLast) return;
36 let cPos = this.tags.indexOf(tag);
37 this.tags.splice(cPos, 1);
41 let tagPos = this.tags.indexOf(tag);
42 if (tagPos === -1) return;
43 this.tags.splice(tagPos, 1);
46 getTagFieldName(index, key) {
47 return `tags[${index}][${key}]`;
52 this.entityId = Number(this.$el.getAttribute('entity-id'));
53 this.entityType = this.$el.getAttribute('entity-type');
55 let url = window.baseUrl(`/ajax/tags/get/${this.entityType}/${this.entityId}`);
56 this.$http.get(url).then(response => {
57 let tags = response.data;
58 for (let i = 0, len = tags.length; i < len; i++) {
59 tags[i].key = Math.random().toString(36).substring(7);
67 data, methods, mounted, components, directives