|
@@ -10,12 +10,23 @@
|
10
|
10
|
*
|
11
|
11
|
*/
|
12
|
12
|
|
|
13
|
+
|
|
14
|
+
|
13
|
15
|
(function($) {
|
14
|
16
|
|
15
|
17
|
function TagBox(input, options) {
|
16
|
18
|
|
17
|
19
|
var self = this;
|
18
|
20
|
|
|
21
|
+ // Ce tableau contiendra les tags déjà ajoutés
|
|
22
|
+ if(typeof(tagsAddeds) === "undefined")
|
|
23
|
+ {
|
|
24
|
+ tagsAddeds = new Array();
|
|
25
|
+ }
|
|
26
|
+ // On permet de faire un tableau de tags ajoutés par formulaires
|
|
27
|
+ // TODO: Par 'champ' ce serais mieux.
|
|
28
|
+ tagsAddeds[options.form_name] = new Array();
|
|
29
|
+
|
19
|
30
|
self.options = options
|
20
|
31
|
self.delimit_key = 188
|
21
|
32
|
self.delimit_expr = /\s*,\s*/
|
|
@@ -80,39 +91,46 @@
|
80
|
91
|
self.addTag(values[tagid], tagid, options.form_name);
|
81
|
92
|
}
|
82
|
93
|
}
|
|
94
|
+
|
83
|
95
|
}
|
84
|
96
|
|
85
|
97
|
TagBox.prototype = {
|
86
|
98
|
|
87
|
99
|
addTag : function(label, id, form_name) {
|
88
|
100
|
|
89
|
|
- var self = this;
|
90
|
|
- var tag = $('<li class="tag">' + $('<div>').text(label).remove().html() + '</li>');
|
91
|
|
-
|
92
|
|
- this.tags.push(label);
|
|
101
|
+ // Nos conditions pour ajouter le tag:
|
|
102
|
+ // * N'a pas déjà été ajouté a ce champ
|
|
103
|
+ // * Est dans la liste des tags existants
|
|
104
|
+ if (id && !findKeyWithValue(tagsAddeds[form_name], id))
|
|
105
|
+ {
|
|
106
|
+ var self = this;
|
|
107
|
+ var tag = $('<li class="tag">' + $('<div>').text(label).remove().html() + '</li>');
|
93
|
108
|
|
94
|
|
- tag.append($('<a>', {
|
95
|
|
- "href" : "#",
|
96
|
|
- "class": "close",
|
97
|
|
- "text": "close",
|
98
|
|
- click: function(e) {
|
99
|
|
- e.preventDefault();
|
100
|
|
- var index = self.tagbox.find("li").index($(this).parent());
|
101
|
|
- self.removeTag(index);
|
102
|
|
- }
|
103
|
|
- })).append($('<input>', {
|
104
|
|
- 'type' : 'checkbox',
|
105
|
|
- 'style' : 'display: none;',
|
106
|
|
- 'value' : id,
|
107
|
|
- 'name' : form_name+'[tags]['+id+']',
|
108
|
|
- 'id' : form_name+'_tags_'+id,
|
109
|
|
- 'checked': 'checked'
|
110
|
|
- }));
|
111
|
|
-
|
112
|
|
- // <input type="checkbox" value="6373" name="group[tags][6373]" id="group_tags_6373">
|
|
109
|
+ this.tags.push(label);
|
|
110
|
+
|
|
111
|
+ tag.append($('<a>', {
|
|
112
|
+ "href" : "#",
|
|
113
|
+ "class": "close",
|
|
114
|
+ "text": "close",
|
|
115
|
+ click: function(e) {
|
|
116
|
+ e.preventDefault();
|
|
117
|
+ var index = self.tagbox.find("li").index($(this).parent());
|
|
118
|
+ self.removeTag(index);
|
|
119
|
+ }
|
|
120
|
+ })).append($('<input>', {
|
|
121
|
+ 'type' : 'checkbox',
|
|
122
|
+ 'style' : 'display: none;',
|
|
123
|
+ 'value' : id,
|
|
124
|
+ 'name' : form_name+'[tags]['+id+']',
|
|
125
|
+ 'id' : form_name+'_tags_'+id,
|
|
126
|
+ 'checked': 'checked'
|
|
127
|
+ }));
|
|
128
|
+
|
|
129
|
+ tagsAddeds[form_name][id] = id;
|
|
130
|
+ self.inputHolder.before(tag);
|
|
131
|
+ self.updateInput();
|
|
132
|
+ }
|
113
|
133
|
|
114
|
|
- self.inputHolder.before(tag);
|
115
|
|
- self.updateInput();
|
116
|
134
|
},
|
117
|
135
|
removeTag : function(index) {
|
118
|
136
|
|