| 21 |
21 |
var Redmine = Redmine || {};
|
| 22 |
22 |
|
| 23 |
23 |
Redmine.TagsInput = Class.create({
|
| 24 |
|
initialize: function(element) {
|
|
24 |
initialize: function(element, update) {
|
| 25 |
25 |
this.element = $(element);
|
| 26 |
26 |
this.input = new Element('input', { 'type': 'text', 'autocomplete': 'off', 'size': 10 });
|
| 27 |
27 |
this.button = new Element('span', { 'class': 'tag-add icon icon-add' });
|
| 28 |
28 |
this.tags = new Hash();
|
| 29 |
29 |
|
|
30 |
this.update = update;
|
|
31 |
|
|
32 |
var uri_params = window.location.href.toQueryParams();
|
|
33 |
if (uri_params["project[tag_list]"] != undefined){
|
|
34 |
this.addTag(uri_params["project[tag_list]"].stripTags(), true);
|
|
35 |
};
|
|
36 |
|
| 30 |
37 |
Event.observe(this.button, 'click', this.readTags.bind(this));
|
| 31 |
38 |
Event.observe(this.input, 'keypress', this.onKeyPress.bindAsEventListener(this));
|
| 32 |
39 |
|
| ... | ... | |
| 35 |
42 |
this.addTagsList(this.element.value);
|
| 36 |
43 |
},
|
| 37 |
44 |
|
| 38 |
|
readTags: function() {
|
|
45 |
readTags: function() {
|
| 39 |
46 |
this.addTagsList(this.input.value);
|
| 40 |
47 |
this.input.value = '';
|
|
48 |
if(this.update){
|
|
49 |
submitForm();
|
|
50 |
};
|
| 41 |
51 |
},
|
| 42 |
52 |
|
| 43 |
53 |
onKeyPress: function(event) {
|
| 44 |
54 |
if (Event.KEY_RETURN == event.keyCode) {
|
| 45 |
55 |
this.readTags(event);
|
| 46 |
|
Event.stop(event);
|
|
56 |
Event.stop(event);
|
| 47 |
57 |
}
|
| 48 |
58 |
},
|
| 49 |
59 |
|
| 50 |
|
addTag: function(tag) {
|
|
60 |
addTag: function(tag, noSubmit) {
|
| 51 |
61 |
if (tag.blank() || this.tags.get(tag)) return;
|
| 52 |
62 |
|
|
63 |
if(noSubmit==undefined){noSubmit=false;}
|
|
64 |
|
| 53 |
65 |
var button = new Element('span', { 'class': 'tag-delete icon icon-del' });
|
| 54 |
66 |
var label = new Element('span', { 'class': 'tag-label' }).insert(tag).insert(button);
|
| 55 |
67 |
|
| ... | ... | |
| 57 |
69 |
this.element.value = this.getTagsList();
|
| 58 |
70 |
this.element.insert({ 'before': label });
|
| 59 |
71 |
|
|
72 |
if(noSubmit==false){
|
|
73 |
if(this.update){
|
|
74 |
submitForm();
|
|
75 |
};
|
|
76 |
};
|
|
77 |
|
| 60 |
78 |
Event.observe(button, 'click', function(){
|
| 61 |
79 |
this.tags.unset(tag);
|
| 62 |
80 |
this.element.value = this.getTagsList();
|
| 63 |
81 |
label.remove();
|
|
82 |
if(this.update){submitForm();};
|
| 64 |
83 |
}.bind(this));
|
| 65 |
84 |
},
|
| 66 |
85 |
|
| ... | ... | |
| 90 |
109 |
|
| 91 |
110 |
|
| 92 |
111 |
function observeIssueTagsField(url) {
|
| 93 |
|
new Redmine.TagsInput('issue_tag_list').autocomplete('issue_tag_candidates', url);
|
|
112 |
new Redmine.TagsInput('issue_tag_list', false).autocomplete('issue_tag_candidates', url);
|
| 94 |
113 |
}
|
| 95 |
114 |
|
| 96 |
|
|
| 97 |
|
function observeProjectTagsField(url) {
|
| 98 |
|
new Redmine.TagsInput('project_tag_list').autocomplete('project_tag_candidates', url);
|
|
115 |
function observeProjectTagsField(url, update) {
|
|
116 |
if(!update) {
|
|
117 |
var update = false;
|
|
118 |
};
|
|
119 |
|
|
120 |
new Redmine.TagsInput('project_tag_list', update).autocomplete('project_tag_candidates', url);
|
| 99 |
121 |
}
|