To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / redmine_tags / assets / javascripts / tags_input.js @ 785:32d853e2e7ed

History | View | Annotate | Download (3.17 KB)

1 593:f12948591050 chris
/**
2
 * This file is a part of redmine_tags
3
 * redMine plugin, that adds tagging support.
4
 *
5
 * Copyright (c) 2010 Aleksey V Zapparov AKA ixti
6
 *
7
 * redmine_tags is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * redmine_tags is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with redmine_tags.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
var Redmine = Redmine || {};
22
23
Redmine.TagsInput = Class.create({
24 782:eb3e9e1ffc13 luis
  initialize: function(element, update) {
25 593:f12948591050 chris
    this.element  = $(element);
26
    this.input    = new Element('input', { 'type': 'text', 'autocomplete': 'off', 'size': 10 });
27
    this.button   = new Element('span', { 'class': 'tag-add icon icon-add' });
28
    this.tags     = new Hash();
29
30 782:eb3e9e1ffc13 luis
                this.update = update;
31
32 593:f12948591050 chris
    Event.observe(this.button, 'click', this.readTags.bind(this));
33
    Event.observe(this.input, 'keypress', this.onKeyPress.bindAsEventListener(this));
34
35
    this.element.insert({ 'after': this.input });
36
    this.input.insert({ 'after': this.button });
37
    this.addTagsList(this.element.value);
38
  },
39
40 782:eb3e9e1ffc13 luis
  readTags: function() {
41 593:f12948591050 chris
    this.addTagsList(this.input.value);
42
    this.input.value = '';
43 782:eb3e9e1ffc13 luis
                if(this.update){submitForm();};
44 593:f12948591050 chris
  },
45
46
  onKeyPress: function(event) {
47
    if (Event.KEY_RETURN == event.keyCode) {
48
      this.readTags(event);
49 782:eb3e9e1ffc13 luis
      Event.stop(event);
50 593:f12948591050 chris
    }
51
  },
52
53
  addTag: function(tag) {
54
    if (tag.blank() || this.tags.get(tag)) return;
55
56
    var button = new Element('span', { 'class': 'tag-delete icon icon-del' });
57
    var label  = new Element('span', { 'class': 'tag-label' }).insert(tag).insert(button);
58
59
    this.tags.set(tag, 1);
60
    this.element.value = this.getTagsList();
61
    this.element.insert({ 'before': label });
62
63 782:eb3e9e1ffc13 luis
                if(this.update){submitForm();};
64
65 593:f12948591050 chris
    Event.observe(button, 'click', function(){
66
      this.tags.unset(tag);
67
      this.element.value = this.getTagsList();
68
      label.remove();
69 782:eb3e9e1ffc13 luis
                  if(this.update){submitForm();};
70 593:f12948591050 chris
    }.bind(this));
71
  },
72
73
  addTagsList: function(tags_list) {
74
    var tags = tags_list.split(',');
75
    for (var i = 0; i < tags.length; i++) {
76
      this.addTag(tags[i].strip());
77
    }
78
  },
79
80
  getTagsList: function() {
81
    return this.tags.keys().join(',');
82
  },
83
84
  autocomplete: function(container, url) {
85
    new Ajax.Autocompleter(this.input, container, url, {
86
      'minChars': 1,
87
      'frequency': 0.5,
88
      'paramName': 'q',
89
      'updateElement': function(el) {
90
        this.input.value = el.getAttribute('name');
91
        this.readTags();
92
      }.bind(this)
93
    });
94
  }
95
});
96
97
98
function observeIssueTagsField(url) {
99 782:eb3e9e1ffc13 luis
  new Redmine.TagsInput('issue_tag_list', false).autocomplete('issue_tag_candidates', url);
100 593:f12948591050 chris
}
101 727:e3e958595e07 luis
102 782:eb3e9e1ffc13 luis
function observeProjectTagsField(url, update) {
103
        if(!update) {
104
                        var update = false;
105
                };
106
107
        new Redmine.TagsInput('project_tag_list', update).autocomplete('project_tag_candidates', url);
108 727:e3e958595e07 luis
}