rasvaan / accurator

Accurator cpack
7 stars 3 forks source link

Write interface for tag list #207

Closed rasvaan closed 8 years ago

rasvaan commented 8 years ago

Add functions allowing the interaction with the tag list from #197. Base partially on:

        addTags : function(o) {
        this.renderTags(o.added, o.index);

        },

        updateTags : function(o) {
                this.renderTags(o.updated, o.index);
            },

        removeTags : function(o) {
            var tagNodes = this.tagList.all("li");
            for (var i=o.index; i < o.index+o.range; i++) {
                var node = tagNodes.item(i);
                node.one('.taglabel').detach('hover');
                node.remove();
            }
        },

        renderTags : function(tags, index) {
            var tagList = this.tagList;
            var tagStyle = this.get('tagStyle');
            var tagNodes = this.tagList.all("li");
            if (index < tagNodes.size()) {
                this.removeTags({index:index, range:tags.length});
            }
            // format the tags
            for(var i=0; i < tags.length; i++) {
                var tag=tags[i].getValue();
                var target = this.findTarget(tag);
                var node = Y.Node.create('<li class="tagitem">'+this.formatTag(tags[i], tagStyle)+'</li>');
                node.setAttribute('targetId', target['@id']);
                node.all('.judgeButton').addClass(tagStyle);
                tagList.insert(node, index+i);
                if (tagStyle == 'overlay')
                    node.one('.taglabel').on('hover', this.onTagHover, this.onTagHover, this, tags[i]);
                else if (tagStyle == 'inline') {
                    this.rebindButtons(node, tags[i]);
                }
            };
        },