|
@@ -0,0 +1,157 @@
|
|
1
|
+function TagPrompt()
|
|
2
|
+{
|
|
3
|
+
|
|
4
|
+ /* @var tags_selected array of Tag */
|
|
5
|
+ var tags_selected = new Array();
|
|
6
|
+ /* @var tags_proposed array of Tag */
|
|
7
|
+ var tags_proposed = new Array();
|
|
8
|
+
|
|
9
|
+ this.getProposedTagsForString = function(search_string, callback_success, callback_error)
|
|
10
|
+ {
|
|
11
|
+ JQueryJson(url_search_tag, {'string_search': search_string}, function(response){
|
|
12
|
+ if (response.status == 'error')
|
|
13
|
+ {
|
|
14
|
+ callback_error(response.error);
|
|
15
|
+ }
|
|
16
|
+ else if (response.status == 'success')
|
|
17
|
+ {
|
|
18
|
+ for (i in response.data)
|
|
19
|
+ {
|
|
20
|
+ var tag = new Tag(
|
|
21
|
+ response.data[i].id,
|
|
22
|
+ response.data[i].name,
|
|
23
|
+ true
|
|
24
|
+ );
|
|
25
|
+ tags_proposed.push(tag);
|
|
26
|
+ }
|
|
27
|
+ callback_success(tags_proposed, search_string);
|
|
28
|
+ }
|
|
29
|
+ });
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ this.selectProposedTag = function (tag_id)
|
|
33
|
+ {
|
|
34
|
+ // Selection d'un tag dans la liste de propositions
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ this.openTagSubmission = function (tag_string)
|
|
38
|
+ {
|
|
39
|
+ // Ouverture du dialogue pour proposer un nouveau tag
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ this.submitTag = function (tag_string, tag_arguments)
|
|
43
|
+ {
|
|
44
|
+ // Propotion d'un tag
|
|
45
|
+ }
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+function TagPromptConnector(input, output, proposition_list)
|
|
49
|
+{
|
|
50
|
+ var _input = input;
|
|
51
|
+ var _output = output;
|
|
52
|
+ var _tag_prompt = new TagPrompt();
|
|
53
|
+ var _tag_proposition_list = new TagPromptPropositionList(proposition_list);
|
|
54
|
+
|
|
55
|
+ var launchSearchTagsIdLastKeystroke = function(search_string)
|
|
56
|
+ {
|
|
57
|
+ if (search_string == _input.val())
|
|
58
|
+ {
|
|
59
|
+ displayTagsProposedSearchTags();
|
|
60
|
+ }
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ var displayTagsProposedSearchTags = function()
|
|
64
|
+ {
|
|
65
|
+ var string_search = _input.val();
|
|
66
|
+ tags = _tag_prompt.getProposedTagsForString(
|
|
67
|
+ string_search,
|
|
68
|
+ _tag_proposition_list.displayTagsPropositions,
|
|
69
|
+ _tag_proposition_list.displayError
|
|
70
|
+ );
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ $(_input).bind('keyup', function() {
|
|
74
|
+ setTimeout(launchSearchTagsIdLastKeystroke, 1000, [_input.val()]);
|
|
75
|
+ });
|
|
76
|
+}
|
|
77
|
+
|
|
78
|
+function TagPromptPropositionList(proposition_list, string_search)
|
|
79
|
+{
|
|
80
|
+ var _proposition_list = proposition_list;
|
|
81
|
+ var _list;
|
|
82
|
+
|
|
83
|
+ this.displayError = function(error_string)
|
|
84
|
+ {
|
|
85
|
+ initializeList();
|
|
86
|
+ var span_info = _proposition_list.find('span.info');
|
|
87
|
+ span_info.text(error_string);
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ this.displayTagsPropositions = function(tags, string_search)
|
|
91
|
+ {
|
|
92
|
+ initializeList();
|
|
93
|
+ displayMessage(str_replace('%string_search%', string_search, string_search_tag_title));
|
|
94
|
+ for (i in tags)
|
|
95
|
+ {
|
|
96
|
+ addTagToList(tags[i]);
|
|
97
|
+ // Bouton afficher tout les tags, tag hiddent quoi
|
|
98
|
+ }
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ var initializeList = function()
|
|
102
|
+ {
|
|
103
|
+ $(_proposition_list).show();
|
|
104
|
+ _list = _proposition_list.find('ul.search_tag_list');
|
|
105
|
+ _list.find('li').remove();
|
|
106
|
+ _proposition_list.find('a.more').hide();
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ var displayMessage = function(message)
|
|
110
|
+ {
|
|
111
|
+ var span_info = _proposition_list.find('span.info');
|
|
112
|
+ span_info.text(message);
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ var addTagToList = function(tag)
|
|
116
|
+ {
|
|
117
|
+ _list.append(getListLine(tag));
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ var getListLine = function(tag)
|
|
121
|
+ {
|
|
122
|
+ return '<li>'+tag.name+'</li>';
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+function Tag(id, name, knew)
|
|
128
|
+{
|
|
129
|
+ /* @var _id int */
|
|
130
|
+ this.id = id;
|
|
131
|
+ /* @var _name string */
|
|
132
|
+ this.name = name;
|
|
133
|
+ /* @var _knew boolean */
|
|
134
|
+ this.knew = knew;
|
|
135
|
+}
|
|
136
|
+
|
|
137
|
+Tag.prototype =
|
|
138
|
+{
|
|
139
|
+ isKnew: function()
|
|
140
|
+ {
|
|
141
|
+ if (this.knew)
|
|
142
|
+ {
|
|
143
|
+ return true;
|
|
144
|
+ }
|
|
145
|
+ return false;
|
|
146
|
+ }
|
|
147
|
+}
|
|
148
|
+
|
|
149
|
+$(document).ready(function(){
|
|
150
|
+ $('input.tag_prompt').each(function(){
|
|
151
|
+ new TagPromptConnector(
|
|
152
|
+ $(this),
|
|
153
|
+ $(this).parents('form').find('input.tag_prompt_selected_ids'),
|
|
154
|
+ $(this).parents('form').find('div.search_tag_list')
|
|
155
|
+ );
|
|
156
|
+ });
|
|
157
|
+});
|