1 | /** |
---|
2 | * @fileOverview This file contains model for building searchclausesets used in user queries. |
---|
3 | * Consists of two parts: |
---|
4 | * - SearchClause model [index,relation, value], with basic functionality - |
---|
5 | * creation, render, autocomplete. |
---|
6 | * - Searchclauseset - container of actually used searchclauses in app |
---|
7 | * with basic functionality for building container - add, remove, clear |
---|
8 | * and conversion functions - conversions from-to querystring |
---|
9 | * |
---|
10 | * @author |
---|
11 | * @version |
---|
12 | */ |
---|
13 | |
---|
14 | // client-side modelling of "business-objects": |
---|
15 | // SearchClause, SearchClauseset, |
---|
16 | |
---|
17 | |
---|
18 | //TODO use select-options or autocomplete ??? |
---|
19 | //var relation_autocomplete = new Array('any','all','=','>','<'); |
---|
20 | //var value_autocomplete = new Array(); |
---|
21 | |
---|
22 | /** |
---|
23 | * SearchClause model [index,relation, value], with basic functionality - |
---|
24 | * creation, render, autocomplete. |
---|
25 | * @constructor |
---|
26 | */ |
---|
27 | function SearchClause(index, relation, value ) { |
---|
28 | this.index = index; |
---|
29 | this.relation = relation; |
---|
30 | this.value = value; |
---|
31 | this.negation = false; |
---|
32 | |
---|
33 | this.is_category = false; |
---|
34 | this.category = ""; |
---|
35 | |
---|
36 | this.i = 0; |
---|
37 | this.j = 0; |
---|
38 | this.listid = ""; |
---|
39 | this.container = {}; |
---|
40 | |
---|
41 | if (this.relation == "") { |
---|
42 | this.relation = "="; |
---|
43 | } |
---|
44 | |
---|
45 | this.is_complex = true; |
---|
46 | } |
---|
47 | |
---|
48 | SearchClause.prototype.GetIndexInput = function(){ |
---|
49 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index-input'); |
---|
50 | }; |
---|
51 | |
---|
52 | SearchClause.prototype.GetRelInput = function(){ |
---|
53 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.rel_input'); |
---|
54 | }; |
---|
55 | SearchClause.prototype.GetValueInput = function(){ |
---|
56 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.value-input'); |
---|
57 | }; |
---|
58 | |
---|
59 | SearchClause.prototype.GetIndexSelect = function(){ |
---|
60 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index_select'); |
---|
61 | }; |
---|
62 | SearchClause.prototype.GetIndexInputTermset = function(){ |
---|
63 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index-input-termset'); |
---|
64 | }; |
---|
65 | SearchClause.prototype.GetIndexInput = function(){ |
---|
66 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index-input'); |
---|
67 | }; |
---|
68 | |
---|
69 | |
---|
70 | SearchClause.prototype.GetValueSelect = function(){ |
---|
71 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.value_select'); |
---|
72 | }; |
---|
73 | |
---|
74 | SearchClause.prototype.render = function (rel) { |
---|
75 | |
---|
76 | //TODO defaults |
---|
77 | //this.relation = '='; |
---|
78 | //var index_detail = ""; |
---|
79 | //if ((this.i == 0) && (this.j == 0)) { |
---|
80 | // index_detail = "<span name='detail_index' class='cmd cmd_detail'></span>"; |
---|
81 | //} |
---|
82 | var x = "<div id='" + this.j + "' class='sc-j or_level' ><div id='" + this.listid + "' class='sc-wrapper focused' > " + |
---|
83 | "<div class='search'><span class='index-search'><select class='index_select'/><input type='text' class='index-input-termset autocomplete-input' /><input type='text' class='index-input autocomplete-input' /></span>" + |
---|
84 | //index_detail + |
---|
85 | //"<select type='text' class='rel_input' />" + |
---|
86 | "<select class='rel_input'><option value='='>=</option><option value='>'>></option><option value='<'><</option><option value='any'>any</option><option value='contains'>contains</option><option value='all'>all</option></select>" + |
---|
87 | "<select class='value_select'/><input type='text' class='value-input' /><span name='detail_value' class='cmd cmd_detail'></span>" + |
---|
88 | "<span class='sc_cmds'><span class='cmd cmd_sc_delete'> </span><span class='sc_id'>" + this.listid + "</span>" + |
---|
89 | "<span class='cmd cmd_add_and'> </span><span class='cmd cmd_add_or'></span>"+ |
---|
90 | " </span></div><div class='index-context'><table></table></div></div></div>"; |
---|
91 | |
---|
92 | addToSClist(x, this.i, this.j, rel); |
---|
93 | |
---|
94 | |
---|
95 | var e_index = this.GetIndexInput(); |
---|
96 | //new $.GrowingInput(e_index, {max: 80}); |
---|
97 | var e_relation = this.GetRelInput(); |
---|
98 | var e_value = this.GetValueInput(); |
---|
99 | var index_select = this.GetIndexSelect(); |
---|
100 | //var index_input_termset = this.GetIndexInputTermset(); |
---|
101 | var value_select = this.GetValueSelect(); |
---|
102 | |
---|
103 | $(index_select).hide(); |
---|
104 | //$(index_input_term).hide(); |
---|
105 | this.GetIndexInput().hide(); |
---|
106 | value_select.hide(); |
---|
107 | //$(e_index).closest('.sc-wrapper').find('.index-context').hide(); |
---|
108 | |
---|
109 | //alert("focused: " + $('.focused','#searchclauselist').size()); |
---|
110 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
111 | $(this).removeClass("focused"); |
---|
112 | }); |
---|
113 | $(e_index).closest('.sc-wrapper').addClass("focused"); |
---|
114 | //alert("focused: " + $('.focused','#searchclauselist').size()); |
---|
115 | |
---|
116 | // set focus |
---|
117 | e_index.focusin(function(){ |
---|
118 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
119 | $(this).removeClass("focused"); |
---|
120 | }); |
---|
121 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
122 | }); |
---|
123 | index_select.focusin(function(){ |
---|
124 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
125 | $(this).removeClass("focused"); |
---|
126 | }); |
---|
127 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
128 | }); |
---|
129 | e_relation.focusin(function(){ |
---|
130 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
131 | $(this).removeClass("focused"); |
---|
132 | }); |
---|
133 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
134 | }); |
---|
135 | e_value.focusin(function(){ |
---|
136 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
137 | $(this).removeClass("focused"); |
---|
138 | }); |
---|
139 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
140 | }); |
---|
141 | $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.cmd_detail').click(function(){ |
---|
142 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
143 | $(this).removeClass("focused"); |
---|
144 | }); |
---|
145 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
146 | }); |
---|
147 | |
---|
148 | //TODO handle keydown |
---|
149 | /* e_index.keydown(function(ev){ |
---|
150 | var evStop = function(){ ev.stopPropagation(); ev.preventDefault(); }; |
---|
151 | if (ev.which === 13) evStop(); |
---|
152 | var evFocusNext = function(){ |
---|
153 | ev.preventDefault(); |
---|
154 | e_relation.focus(); |
---|
155 | }; |
---|
156 | //notifyUser($(this).attr("value").length); |
---|
157 | if ($(this).attr("value").length > 0 && ev.which === 32) evFocusNext(); // focus next element |
---|
158 | |
---|
159 | }); |
---|
160 | |
---|
161 | e_relation.keydown(function(ev){ |
---|
162 | var evStop = function(){ ev.stopPropagation(); ev.preventDefault(); }; |
---|
163 | if (ev.which === 13) evStop(); |
---|
164 | var evFocusNext = function(){ |
---|
165 | e_value.focus(); |
---|
166 | }; |
---|
167 | if (ev.which === 32) evFocusNext(); // focus next element |
---|
168 | notifyUser(ev.which); |
---|
169 | }); |
---|
170 | */ |
---|
171 | |
---|
172 | //selects for the first use |
---|
173 | index_select.change(function(){ |
---|
174 | $(this).next().val($(this).find('option:selected').text()); |
---|
175 | $(this).hide(); |
---|
176 | $(this).next().show(); |
---|
177 | }); |
---|
178 | value_select.change(function(){ |
---|
179 | $(this).next().val($(this).find('option:selected').text()); |
---|
180 | $(this).hide(); |
---|
181 | $(this).next().show(); |
---|
182 | }); |
---|
183 | |
---|
184 | e_index.val(this.index); |
---|
185 | e_relation.val(this.relation); |
---|
186 | e_value.val(this.value); |
---|
187 | //update after text change |
---|
188 | e_index.bind('change', function(){ |
---|
189 | |
---|
190 | var i = $(this).closest('.sc-i').attr("id"); |
---|
191 | var j = $(this).closest('.sc-j').attr("id"); |
---|
192 | //alert("e-index-chabge;" + i + j + $(this).val()); |
---|
193 | searchclauseset.searchclauses[i][j].index = $(this).val(); |
---|
194 | notifyUser("index_sc" + i + "-" + j + " changed to:" + searchclauseset.searchclauses[i][j].index, "debug"); |
---|
195 | searchclauseset.searchclauses[i][j].is_category = false; |
---|
196 | }); |
---|
197 | e_relation.change(function(){ |
---|
198 | var i = $(this).closest('.sc-i').attr("id"); |
---|
199 | var j = $(this).closest('.sc-j').attr("id"); |
---|
200 | //notifyUser("rel change:" + $(this).val(), 'debug'); |
---|
201 | searchclauseset.searchclauses[i][j].relation = $(this).val(); |
---|
202 | |
---|
203 | searchclauseset.searchclauses[i][j].is_category = false; |
---|
204 | }); |
---|
205 | e_value.change(function(){ |
---|
206 | var i = $(this).closest('.sc-i').attr("id"); |
---|
207 | var j = $(this).closest('.sc-j').attr("id"); |
---|
208 | searchclauseset.searchclauses[i][j].value = $(this).val(); |
---|
209 | |
---|
210 | searchclauseset.searchclauses[i][j].is_category = false; |
---|
211 | }); |
---|
212 | |
---|
213 | try{ |
---|
214 | this.initAutocomplete(); |
---|
215 | } catch (e){ |
---|
216 | notifyUser("autocomplete failed: " + e.message); |
---|
217 | } |
---|
218 | |
---|
219 | }; |
---|
220 | |
---|
221 | SearchClause.prototype.initAutocomplete = function(){ |
---|
222 | |
---|
223 | if (element_autocomplete.length == 0) return; |
---|
224 | |
---|
225 | $(this.GetIndexInputTermset()).autocomplete({ |
---|
226 | source: element_autocomplete, |
---|
227 | autoFill:true, |
---|
228 | width:150, |
---|
229 | //onFindValue:findValueTermset, |
---|
230 | //onItemSelect:selectItemTermset, |
---|
231 | minLength: 0, |
---|
232 | matchContains:true, |
---|
233 | delay: 0, |
---|
234 | select: function( event, ui ) { |
---|
235 | $(this).data("item", ui.item); |
---|
236 | selectItemTermset(ui.item); |
---|
237 | } |
---|
238 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
239 | var t, re; |
---|
240 | if (this.term == ""){ |
---|
241 | t = item.value; |
---|
242 | } else { |
---|
243 | re = new RegExp(this.term + "+") ; |
---|
244 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
245 | this.term + |
---|
246 | "</span>"); |
---|
247 | } |
---|
248 | |
---|
249 | return $( "<li></li>" ) |
---|
250 | .data( "item.autocomplete", item ) |
---|
251 | .append( "<a>" + t + "</a>" ) |
---|
252 | .appendTo( ul ); |
---|
253 | }; |
---|
254 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
255 | |
---|
256 | }; |
---|
257 | |
---|
258 | |
---|
259 | SearchClause.prototype.CreateSelect = function(str, element){ |
---|
260 | var index_select = GetIndexSelect(); |
---|
261 | var index_input = GetIndexInput(); |
---|
262 | index_select.show(); |
---|
263 | var x = "<option value='" + str + "'>" + str + "</option>"; |
---|
264 | $(element).each(function(){ |
---|
265 | x = x+"<option value='" + $(this).text() + "'>" + $(this).text() + "</option>"; |
---|
266 | }); |
---|
267 | index_select.html(x); |
---|
268 | |
---|
269 | index_input.hide(); |
---|
270 | |
---|
271 | }; |
---|
272 | |
---|
273 | SearchClause.prototype.PlainText = function(){ |
---|
274 | if (this.index.trim().length == 0 || this.value.trim().length == 0){ |
---|
275 | return ""; |
---|
276 | } |
---|
277 | if (this.is_category){ |
---|
278 | return "ISOCAT( " + this.category + ") " + this.relation + " " + this.value; |
---|
279 | } |
---|
280 | return this.index.trim().replace(" ","_") + " " + this.relation + " " + this.value; |
---|
281 | }; |
---|
282 | |
---|
283 | /** special handling for special characters: double escaping (escape the %-sign) |
---|
284 | * to survive the %-encoding through the request (and parsing) down to the transformation in XCQL2XPath.xsl |
---|
285 | * it's: whitespace, and single and double-quotes (unified to double quotes %22) |
---|
286 | */ |
---|
287 | SearchClause.prototype.escape = function(){ |
---|
288 | var escape_string = ""; |
---|
289 | var escape_value_string = ""; |
---|
290 | |
---|
291 | escape_value_string =escape(this.value).replace(/%20/g,"%2520").replace(/\%2[27]/g,"%2522").replace(/%7C/g,"%257C").replace(/\+/g,"%2B"); |
---|
292 | |
---|
293 | if (this.is_complex) { |
---|
294 | escape_string = escape_string + escape(this.index.trim().replace(" ","_") + " " + this.relation + " ") + escape_value_string; |
---|
295 | } else { |
---|
296 | // case more simple words in search |
---|
297 | escape_string = escape_value_string; |
---|
298 | } |
---|
299 | return escape_string; |
---|
300 | |
---|
301 | }; |
---|
302 | |
---|
303 | SearchClause.createFromData = function(scstr){ |
---|
304 | var n; |
---|
305 | var scarr; |
---|
306 | var rel = ""; |
---|
307 | n = scstr.indexOf("="); |
---|
308 | if (n > 0){ |
---|
309 | scarr = scstr.split("="); |
---|
310 | rel = "="; |
---|
311 | } |
---|
312 | n = scstr.indexOf(" any "); |
---|
313 | if (n > 0){ |
---|
314 | scarr = scstr.split(" any "); |
---|
315 | rel = "any"; |
---|
316 | } |
---|
317 | n = scstr.indexOf(" contains "); |
---|
318 | if (n > 0){ |
---|
319 | scarr = scstr.split(" contains "); |
---|
320 | rel = "contains"; |
---|
321 | } |
---|
322 | n = scstr.indexOf("<"); |
---|
323 | if (n > 0){ |
---|
324 | scarr = scstr.split("<"); |
---|
325 | rel = "<"; |
---|
326 | } |
---|
327 | n = scstr.indexOf(">"); |
---|
328 | if (n > 0){ |
---|
329 | scarr = scstr.split(">"); |
---|
330 | rel = ">"; |
---|
331 | } |
---|
332 | n = scstr.indexOf(" all "); |
---|
333 | if (n > 0){ |
---|
334 | scarr = scstr.split(" all "); |
---|
335 | rel = "all"; |
---|
336 | } |
---|
337 | //notifyUser("scarr:" + scarr[0] + scarr[1],'debug'); |
---|
338 | |
---|
339 | if (scarr == undefined) { |
---|
340 | //this.issimpletext = true; |
---|
341 | sc = new SearchClause('*','any',scstr); |
---|
342 | sc.is_complex = false; |
---|
343 | } else { |
---|
344 | //this.issimpletext = false; |
---|
345 | sc = new SearchClause(scarr[0],rel,scarr[1]); |
---|
346 | sc.is_complex = true; |
---|
347 | } |
---|
348 | |
---|
349 | return sc; |
---|
350 | }; |
---|
351 | /* |
---|
352 | Searchclause.prototype.submit = function () { |
---|
353 | |
---|
354 | var uri = link('recordset','htmltable', this.query_uri()); |
---|
355 | notifyUser("submitting query:" + uri); |
---|
356 | |
---|
357 | this.container.find('.result').load( uri, function() { |
---|
358 | notifyUser("result-loaded"); |
---|
359 | var get = $(this).parent().find('.cmd_get'); |
---|
360 | |
---|
361 | get.removeClass('cmd_get'); |
---|
362 | get.addClass('cmd_up'); |
---|
363 | // get.show(); |
---|
364 | }); |
---|
365 | |
---|
366 | } |
---|
367 | */ |
---|
368 | |
---|
369 | $('.index-context td').live('click', function(event) { |
---|
370 | |
---|
371 | searchclauseset.updatedata(this.textContent, false, ""); |
---|
372 | //$('.focused','#searchclauselist').find('.index-input').val( this.textContent); |
---|
373 | $('.focused','#searchclauselist').find('.index-context').hide(); |
---|
374 | |
---|
375 | $('.focused','#searchclauselist').find('.value-input').focus(); |
---|
376 | |
---|
377 | }); |
---|
378 | |
---|
379 | |
---|
380 | var searchclauseset_container = $("#searchclauselist"); |
---|
381 | |
---|
382 | /** |
---|
383 | * container of actually used Searchclauses in the query-input |
---|
384 | * with basic functionality for building container - add, remove, clear |
---|
385 | * and conversion functions - conversions from-to querystring |
---|
386 | * @constructor |
---|
387 | */ |
---|
388 | |
---|
389 | var searchclauseset = { |
---|
390 | /** @field */ |
---|
391 | searchclauses: [], |
---|
392 | container: '#searchclauselist', |
---|
393 | sctext: '', |
---|
394 | |
---|
395 | addsearchclause: function (searchclause, rel, _i, _j){ |
---|
396 | var i,j; |
---|
397 | |
---|
398 | if (this.searchclauses.length == 0){ |
---|
399 | i = 0; |
---|
400 | this.searchclauses[i] = new Array(); |
---|
401 | j = 0; |
---|
402 | } else { |
---|
403 | if (rel == "or") { |
---|
404 | i = _i;//this.searchclauses.length - 1; |
---|
405 | j = this.searchclauses[i].length;//this.searchclauses[this.searchclauses.length - 1].length; |
---|
406 | } else { |
---|
407 | i = this.searchclauses.length; |
---|
408 | this.searchclauses[i] = new Array(); |
---|
409 | j = 0; |
---|
410 | } |
---|
411 | } |
---|
412 | searchclause.i = i; |
---|
413 | searchclause.j = j; |
---|
414 | searchclause.listid = "sc" + i + "-" + j; |
---|
415 | this.searchclauses[i][j] = searchclause; |
---|
416 | |
---|
417 | searchclause.render(rel); |
---|
418 | //$('#querylist').html(this.render()); |
---|
419 | }, |
---|
420 | |
---|
421 | fillFromURL: function(url){ |
---|
422 | }, |
---|
423 | |
---|
424 | clear: function() { |
---|
425 | notifyUser("clear query",'debug'); |
---|
426 | |
---|
427 | for (var i = this.searchclauses.length - 1; i > -1; i--){ |
---|
428 | for (var j = this.searchclauses[i].length - 1; j > -1; j--){ |
---|
429 | |
---|
430 | |
---|
431 | this.searchclauses[i].splice(j, 1); |
---|
432 | if (j == 0){ |
---|
433 | this.searchclauses.splice(i, 1); |
---|
434 | $('#' + 'sc' + i + '-' + j).parent().parent().remove(); |
---|
435 | $('#' + 'sc' + i + '-' + j).parent().remove(); |
---|
436 | } else { |
---|
437 | $('#' + 'sc' + i + '-' + j).parent().remove(); |
---|
438 | } |
---|
439 | |
---|
440 | |
---|
441 | } |
---|
442 | } |
---|
443 | |
---|
444 | notifyUser(this.searchclauses.length,'debug'); |
---|
445 | |
---|
446 | // reset focused |
---|
447 | //$('.sc-wrapper','#searchclauselist').each(function(){ |
---|
448 | // $(this).removeClass("focused"); |
---|
449 | //}); |
---|
450 | //$('#sc0-0').addClass("focused"); |
---|
451 | }, |
---|
452 | |
---|
453 | //TODO remove only last items |
---|
454 | removesearchclause: function (i, j) { |
---|
455 | notifyUser("removing sc:" + i + "," + j,'debug'); |
---|
456 | |
---|
457 | if ((j == 0) && (i == 0)){ |
---|
458 | searchclauseset.searchclauses[i][j].index = ""; |
---|
459 | searchclauseset.searchclauses[i][j].is_category = false; |
---|
460 | searchclauseset.searchclauses[i][j].relation = "="; |
---|
461 | searchclauseset.searchclauses[i][j].value = ""; |
---|
462 | $('#sc0-0').find('.index-input').val(""); |
---|
463 | $('#sc0-0').find('.index-input-termset').val(""); |
---|
464 | $('#sc0-0').find('.rel_input').val("="); |
---|
465 | $('#sc0-0').find('.value-input').val(""); |
---|
466 | notifyUser("cannot remove", 'debug'); |
---|
467 | return; |
---|
468 | } |
---|
469 | if ((j == 0) && (i < this.searchclauses.length - 1)){ |
---|
470 | notifyUser("cannot remove",'debug'); |
---|
471 | return; |
---|
472 | } |
---|
473 | if (j < this.searchclauses[i].length - 1){ |
---|
474 | notifyUser("cannot remove",'debug'); |
---|
475 | return; |
---|
476 | } |
---|
477 | this.searchclauses[i].splice(j, 1); |
---|
478 | |
---|
479 | if (j == 0){ |
---|
480 | this.searchclauses.splice(i, 1); |
---|
481 | $('#' + 'sc' + i + '-' + j).parent().parent().remove(); |
---|
482 | } else { |
---|
483 | $('#' + 'sc' + i + '-' + j).parent().remove(); |
---|
484 | } |
---|
485 | |
---|
486 | notifyUser("sc removed, new sc.length:" + this.searchclauses.length,'debug'); |
---|
487 | for (var j = 0; j < this.searchclauses.length; j++) { |
---|
488 | notifyUser(" new sc.or_length:" + this.searchclauses[j].length,'debug'); |
---|
489 | } |
---|
490 | // reset focused |
---|
491 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
492 | $(this).removeClass("focused"); |
---|
493 | }); |
---|
494 | $('#sc0-0').addClass("focused"); |
---|
495 | |
---|
496 | }, |
---|
497 | /* |
---|
498 | // just test |
---|
499 | load: function(i,j,rel,data) { |
---|
500 | if (data["triple"] == null ) { |
---|
501 | this.searchclauses[i][j].index = data["searchClause"]["index"]; |
---|
502 | this.searchclauses[i][j].relation = data["searchClause"]["relation"]["value"]; |
---|
503 | this.searchclauses[i][j].value = data["searchClause"]["term"]; |
---|
504 | |
---|
505 | $('#sc0-0','#searchclauselist').find('.index-input').val(data["searchClause"]["index"]); |
---|
506 | $('#sc0-0','#searchclauselist').find('.relation_input').val(data["searchClause"]["relation"]["value"]); |
---|
507 | $('#sc0-0','#searchclauselist').find('.value-input').val(data["searchClause"]["term"]); |
---|
508 | } else { |
---|
509 | if (data["triple"]["boolean"]["value"] == "and") { |
---|
510 | //var sc = new SearchClause("","",""); |
---|
511 | //this.addsearchclause(sc, "and", _i, _j) |
---|
512 | // update(leftO) |
---|
513 | // update(rightO) |
---|
514 | load(i,j,"",data["triple"]["leftOperand"]); |
---|
515 | i = this.searchclauses.length; |
---|
516 | load(i+1,j,"and",data["triple"]["rightOperand"]); |
---|
517 | } else { |
---|
518 | load(i,j,"",data["triple"]["leftOperand"]); |
---|
519 | j = this.searchclauses[i].length; |
---|
520 | load(i,j,"or",data["triple"]["rightOperand"]); |
---|
521 | } |
---|
522 | |
---|
523 | } |
---|
524 | |
---|
525 | }, |
---|
526 | */ |
---|
527 | // from querystring to searchclauses |
---|
528 | buildfromquerystring: function(){ |
---|
529 | var arr = Query.simplequerystring(this.sctext); |
---|
530 | var sc, screl; |
---|
531 | |
---|
532 | this.clear(); |
---|
533 | |
---|
534 | //notifyUser(arr,'debug'); |
---|
535 | var arr_and = arr.split(" and "); |
---|
536 | screl = ""; |
---|
537 | for( var i=0;i<arr_and.length;i++){ |
---|
538 | var scstring = $.trim(arr_and[i]); |
---|
539 | |
---|
540 | if (scstring.substring(0,1) == "(" && scstring.substring(scstring.length-1) == ")") { |
---|
541 | scstring = scstring.substring(1,scstring.length-1); |
---|
542 | scstring = $.trim(scstring); |
---|
543 | } |
---|
544 | |
---|
545 | //notifyUser("i:" + scstring,'debug'); |
---|
546 | var arr_or = scstring.split(" or "); |
---|
547 | if (i > 0) {screl = "and";} |
---|
548 | for( var j=0;j<arr_or.length;j++){ |
---|
549 | if (j > 0) {screl = "or";} |
---|
550 | |
---|
551 | sc = SearchClause.createFromData($.trim(arr_or[j])); |
---|
552 | this.addsearchclause(sc,screl,i,j); |
---|
553 | } |
---|
554 | } |
---|
555 | }, |
---|
556 | |
---|
557 | |
---|
558 | buildsctext: function(){ |
---|
559 | var uncompletequery = false; |
---|
560 | var ptext = ""; |
---|
561 | |
---|
562 | if ($('.searchtype_text','#search').size() > 0) { |
---|
563 | this.sctext = $('#query_area').val(); |
---|
564 | } else { |
---|
565 | |
---|
566 | this.sctext = ""; |
---|
567 | for (var i = 0; i < this.searchclauses.length; i++) { |
---|
568 | if ( i>0) this.sctext = this.sctext + " and "; |
---|
569 | if (this.searchclauses.length> 1) this.sctext = this.sctext + " ( "; |
---|
570 | for (var j = 0; j < this.searchclauses[i].length; j++) { |
---|
571 | if ( j>0) this.sctext = this.sctext + " or "; |
---|
572 | if (this.searchclauses[i].length > 1) this.sctext = this.sctext + " ( "; |
---|
573 | ptext = this.searchclauses[i][j].PlainText(); |
---|
574 | if (ptext.length == 0){ |
---|
575 | uncompletequery = true; |
---|
576 | } |
---|
577 | this.sctext = this.sctext + ptext; |
---|
578 | if (this.searchclauses[i].length > 1) this.sctext = this.sctext + " ) "; |
---|
579 | } |
---|
580 | if (this.searchclauses.length> 1) this.sctext = this.sctext + " ) "; |
---|
581 | } |
---|
582 | |
---|
583 | } |
---|
584 | if ((i == 1 && j == 1) && (this.sctext.substring(0,6) == '* any ')) { |
---|
585 | this.sctext = this.sctext.replace('* any ',''); |
---|
586 | } |
---|
587 | if (uncompletequery){ |
---|
588 | this.sctext = ""; |
---|
589 | } |
---|
590 | notifyUser(this.sctext); |
---|
591 | return this.sctext; |
---|
592 | |
---|
593 | }, |
---|
594 | |
---|
595 | updatedata: function(term, is_category, category, value) { |
---|
596 | |
---|
597 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
598 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
599 | |
---|
600 | if (term != undefined){ |
---|
601 | $('.focused','#searchclauselist').find('.index-input').val(term); |
---|
602 | searchclauseset.searchclauses[i][j].index = term.replace(" ","_"); |
---|
603 | } |
---|
604 | |
---|
605 | if (value == undefined){ |
---|
606 | $('.focused','#searchclauselist').find('.value-input').focus(); |
---|
607 | } else { |
---|
608 | $('.focused','#searchclauselist').find('.value-input').val(value); |
---|
609 | searchclauseset.searchclauses[i][j].value = value; |
---|
610 | } |
---|
611 | |
---|
612 | if (is_category) { |
---|
613 | searchclauseset.searchclauses[i][j].is_category = true; |
---|
614 | searchclauseset.searchclauses[i][j].category = category; |
---|
615 | } else { |
---|
616 | searchclauseset.searchclauses[i][j].is_category = false; |
---|
617 | } |
---|
618 | |
---|
619 | }, |
---|
620 | |
---|
621 | initAutocomplete: function() { |
---|
622 | notifyUser("init autocomplete",'debug'); |
---|
623 | |
---|
624 | for (var i = this.searchclauses.length - 1; i > -1; i--){ |
---|
625 | for (var j = this.searchclauses[i].length - 1; j > -1; j--){ |
---|
626 | this.searchclauses[i][j].initAutocomplete(); |
---|
627 | } |
---|
628 | } |
---|
629 | } |
---|
630 | }; |
---|
631 | |
---|
632 | function escapequerystring(querystring){ |
---|
633 | var arr = Query.simplequerystring(querystring); |
---|
634 | var sc, screl; |
---|
635 | var escape_string = ""; |
---|
636 | var add_bracket = false; |
---|
637 | |
---|
638 | //notifyUser(arr,'debug'); |
---|
639 | var arr_and = arr.split(" and "); |
---|
640 | screl = ""; |
---|
641 | for( var i=0;i<arr_and.length;i++){ |
---|
642 | var scstring = $.trim(arr_and[i]); |
---|
643 | |
---|
644 | add_bracket = false; |
---|
645 | if (scstring.substring(0,1) == "(" && scstring.substring(scstring.length-1) == ")") { |
---|
646 | scstring = scstring.substring(1,scstring.length-1); |
---|
647 | scstring = $.trim(scstring); |
---|
648 | escape_string = escape_string + "("; |
---|
649 | add_bracket = true; |
---|
650 | } |
---|
651 | |
---|
652 | //notifyUser("i:" + scstring,'debug'); |
---|
653 | var arr_or = scstring.split(" or "); |
---|
654 | if (i > 0) {screl = "and";} |
---|
655 | |
---|
656 | for( var j=0;j<arr_or.length;j++){ |
---|
657 | var scstr = $.trim(arr_or[j]); |
---|
658 | if (j > 0) {screl = "or";} |
---|
659 | |
---|
660 | sc = SearchClause.createFromData(scstr); |
---|
661 | if (screl != ""){ |
---|
662 | escape_string = escape_string + "%20" + screl + "%20"; |
---|
663 | } |
---|
664 | escape_string = escape_string + sc.escape(); |
---|
665 | } |
---|
666 | if (add_bracket){ |
---|
667 | escape_string = escape_string + ")"; |
---|
668 | } |
---|
669 | } |
---|
670 | return escape_string; |
---|
671 | } |
---|
672 | |
---|
673 | |
---|
674 | |
---|
675 | //autocomplete |
---|
676 | // not used |
---|
677 | function handleTermsSelection(i,j,elem){ |
---|
678 | /* |
---|
679 | var context = $('#' + 'sc' + i + '-' + j).find('.index-context'); |
---|
680 | // fill context |
---|
681 | //$(context).remove(); |
---|
682 | $(context).html(elements_hashtable[elem]); |
---|
683 | $(context).show(); |
---|
684 | //notifyUser($('#' + 'sc' + i + '-' + j).find('.index-input').val(), 'debug'); |
---|
685 | //$('#' + 'sc' + i + '-' + j).find('.index-input').focus(); |
---|
686 | |
---|
687 | $('#' + 'sc' + i + '-' + j).find('.index-input').blur(function(){ |
---|
688 | $(context).hide(); |
---|
689 | }); |
---|
690 | $('#' + 'sc' + i + '-' + j).find('.index-input').focusin(function(){ |
---|
691 | $(context).hide(); |
---|
692 | }); |
---|
693 | */ |
---|
694 | //$('#' + 'sc' + i + '-' + j).find('.index-input').hide(); |
---|
695 | //$('#' + 'sc' + i + '-' + j).find('.index-input-termset').show(); |
---|
696 | |
---|
697 | }; |
---|
698 | |
---|
699 | function findValueValue(e) { |
---|
700 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
701 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
702 | //alert(i+ ',' + j + sValue); |
---|
703 | var termsetitem = $('#' + 'sc' + i + '-' + j).find('.value-input').data('item'); |
---|
704 | var termset = ""; |
---|
705 | if (termsetitem != null) termset = termsetitem.key; |
---|
706 | searchclauseset.searchclauses[i][j].value = e.value; |
---|
707 | |
---|
708 | } |
---|
709 | |
---|
710 | function selectItemValue(li) { |
---|
711 | findValueValue(li); |
---|
712 | } |
---|
713 | |
---|
714 | function initValueAutocomplete(i,j,index, term_index){ |
---|
715 | |
---|
716 | $('#' + 'sc' + i + '-' + j).find('.value-input').autocomplete({ |
---|
717 | source: element_autocomplete[index].data[term_index].values, |
---|
718 | autoFill:true, |
---|
719 | width:150, |
---|
720 | minLength: 0, |
---|
721 | matchContains:true, |
---|
722 | delay: 0, |
---|
723 | select: function( event, ui ) { |
---|
724 | $(this).data("item", ui.item); |
---|
725 | selectItemValue(ui.item); |
---|
726 | } |
---|
727 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
728 | var t, re; |
---|
729 | if (this.term == ""){ |
---|
730 | t = item.value; |
---|
731 | } else { |
---|
732 | re = new RegExp(this.term + "+") ; |
---|
733 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
734 | this.term + |
---|
735 | "</span>"); |
---|
736 | } |
---|
737 | |
---|
738 | return $( "<li></li>" ) |
---|
739 | .data( "item.autocomplete", item ) |
---|
740 | .append( "<a>" + t + "</a>" ) |
---|
741 | .appendTo( ul ); |
---|
742 | }; |
---|
743 | |
---|
744 | |
---|
745 | // reset the index value |
---|
746 | $('#' + 'sc' + i + '-' + j).find('.value-input').val(""); |
---|
747 | searchclauseset.searchclauses[i][j].value = ""; |
---|
748 | $('#' + 'sc' + i + '-' + j).find('.value-input').show(); |
---|
749 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
750 | |
---|
751 | |
---|
752 | $('.focused','#searchclauselist').find('.value-input').focus(); |
---|
753 | |
---|
754 | |
---|
755 | }; |
---|
756 | |
---|
757 | function findValueTerm(e) { |
---|
758 | |
---|
759 | //var sValue = e.selectValue; |
---|
760 | |
---|
761 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
762 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
763 | //alert(i+ ',' + j + sValue); |
---|
764 | var termsetitem = $('#' + 'sc' + i + '-' + j).find('.index-input-termset').data('item'); |
---|
765 | var termset = ""; |
---|
766 | if (termsetitem != null) termset = termsetitem.key; |
---|
767 | searchclauseset.searchclauses[i][j].index = termset + ":" + e.value; |
---|
768 | |
---|
769 | //handleTermsSelection(i,j,sValue); |
---|
770 | //find element value |
---|
771 | var index; |
---|
772 | $.each(element_autocomplete,function(i, item){ |
---|
773 | if (this.key == elem.key){ |
---|
774 | index = i; |
---|
775 | return; |
---|
776 | } |
---|
777 | }); |
---|
778 | var term_index; |
---|
779 | $.each(element_autocomplete[index],function(i, item){ |
---|
780 | if (this.key == e.key){ |
---|
781 | term_index = i; |
---|
782 | return; |
---|
783 | } |
---|
784 | }); |
---|
785 | if (element_autocomplete[index].data[term_index].values.length == 0){ |
---|
786 | jQuery.get(link('fcs','?operation=scan&scanClause=' + e.value),function(data){ |
---|
787 | $(data).find('sru:term').each(function(i){ |
---|
788 | element_autocomplete[index].data[term_index].values[i] = {label:$(this).find('sru:value').text()}; |
---|
789 | }); |
---|
790 | initValueAutocomplete(i,j, index, term_index); |
---|
791 | }); |
---|
792 | } else { |
---|
793 | initValueAutocomplete(i,j, index, term_index); |
---|
794 | } |
---|
795 | |
---|
796 | |
---|
797 | } |
---|
798 | |
---|
799 | function selectItemTerm(li) { |
---|
800 | findValueTerm(li); |
---|
801 | } |
---|
802 | |
---|
803 | function initTermsetAutocomplete(i,j,index){ |
---|
804 | //$('#' + 'sc' + i + '-' + j).find('.index-input').hide(); |
---|
805 | |
---|
806 | // not working |
---|
807 | //searchclauseset.searchclauses[i][j].initAutocompleteTerms(elem); |
---|
808 | |
---|
809 | $('#' + 'sc' + i + '-' + j).find('.index-input').autocomplete({ |
---|
810 | source: element_autocomplete[index].data, |
---|
811 | autoFill:true, |
---|
812 | width:150, |
---|
813 | //onFindValue:findValueTerm, |
---|
814 | //onItemSelect:selectItemTerm, |
---|
815 | minLength: 0, |
---|
816 | matchContains:true, |
---|
817 | delay: 0, |
---|
818 | select: function( event, ui ) { |
---|
819 | $(this).data("item", ui.item); |
---|
820 | selectItemTerm(ui.item); |
---|
821 | } |
---|
822 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
823 | var t, re; |
---|
824 | if (this.term == ""){ |
---|
825 | t = item.value; |
---|
826 | } else { |
---|
827 | re = new RegExp(this.term + "+") ; |
---|
828 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
829 | this.term + |
---|
830 | "</span>"); |
---|
831 | } |
---|
832 | |
---|
833 | return $( "<li></li>" ) |
---|
834 | .data( "item.autocomplete", item ) |
---|
835 | .append( "<a>" + t + "</a>" ) |
---|
836 | .appendTo( ul ); |
---|
837 | }; |
---|
838 | |
---|
839 | |
---|
840 | // reset the index value |
---|
841 | $('#' + 'sc' + i + '-' + j).find('.index-input').val(""); |
---|
842 | searchclauseset.searchclauses[i][j].index = ""; |
---|
843 | $('#' + 'sc' + i + '-' + j).find('.index-input').show(); |
---|
844 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
845 | |
---|
846 | |
---|
847 | $('.focused','#searchclauselist').find('.index-input').focus(); |
---|
848 | |
---|
849 | |
---|
850 | }; |
---|
851 | /* |
---|
852 | function handleTermsetSelection(i,j,elem){ |
---|
853 | |
---|
854 | // create apropriate array, than initialize autocomplete |
---|
855 | if ($('#elements_hashtable_'+elem).children().length == 0) { |
---|
856 | $('#elements_hashtable_'+elem).load(link('smc','list/?context='+elem),function(){ |
---|
857 | //var e = $(this).attr("id"); |
---|
858 | $(this).find('Term').each(function(index){ |
---|
859 | elements_hashtable[elem][index] = $(this).text(); |
---|
860 | }); |
---|
861 | initTermsetAutocomplete(i,j,elem); |
---|
862 | }); |
---|
863 | } else { |
---|
864 | initTermsetAutocomplete(i,j,elem); |
---|
865 | } |
---|
866 | }; |
---|
867 | */ |
---|
868 | |
---|
869 | function findValueTermset(elem) { |
---|
870 | //var sValue = e.selectValue; |
---|
871 | |
---|
872 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
873 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
874 | |
---|
875 | //searchclauseset.searchclauses[i][j].index = sValue; |
---|
876 | //handleTermsetSelection(i,j,sValue); |
---|
877 | |
---|
878 | //find element |
---|
879 | var index; |
---|
880 | $.each(element_autocomplete,function(i, item){ |
---|
881 | if (this.key == elem.key){ |
---|
882 | index = i; |
---|
883 | return; |
---|
884 | } |
---|
885 | }); |
---|
886 | |
---|
887 | if (element_autocomplete[index].data.length == 0){ |
---|
888 | jQuery.get(link('smc','list/?context=' + element_autocomplete[index].key),function(data){ |
---|
889 | $(data).find('Term').each(function(i){ |
---|
890 | element_autocomplete[index].data[i] = {label:$(this).text(), value:$(this).text(), id:$(this).attr("concept-id"),values:[] }; |
---|
891 | }); |
---|
892 | initTermsetAutocomplete(i,j, index); |
---|
893 | }); |
---|
894 | } else { |
---|
895 | initTermsetAutocomplete(i,j, index); |
---|
896 | } |
---|
897 | |
---|
898 | } |
---|
899 | |
---|
900 | function selectItemTermset(li) { |
---|
901 | findValueTermset(li); |
---|
902 | } |
---|
903 | |
---|