source: MDService2/branches/MDService_simple3/WebContent/scripts/mdservice_searchclause.js @ 1664

Last change on this file since 1664 was 1664, checked in by gaba, 12 years ago

index autocomplete

File size: 22.6 KB
Line 
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*/ 
27function 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
48SearchClause.prototype.GetIndexInput = function(){
49        return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index-input');
50};
51
52SearchClause.prototype.GetRelInput = function(){
53        return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.rel_input');
54};
55SearchClause.prototype.GetValueInput = function(){
56        return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.value-input');
57};
58
59SearchClause.prototype.GetIndexSelect = function(){
60        return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index_select');
61};
62SearchClause.prototype.GetIndexInputTermset = function(){
63        return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index-input-termset');
64};
65SearchClause.prototype.GetIndexInput = function(){
66        return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index-input');
67};
68
69
70SearchClause.prototype.GetValueSelect = function(){
71        return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.value_select');
72};
73
74SearchClause.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()).autocompleteArray(element_autocomplete,{
226                        autoFill:true,
227                        //width:150,
228                        onFindValue:findValueTermset,
229                        onItemSelect:selectItemTermset
230                });
231
232                $('body').find('.ac_results').css({'z-index' : '1000'});
233         
234 };
235
236
237SearchClause.prototype.CreateSelect = function(str, element){
238        var index_select = GetIndexSelect();
239        var index_input  = GetIndexInput();
240        index_select.show();
241        var x = "<option value='" + str + "'>" + str + "</option>";
242        $(element).each(function(){
243                x = x+"<option value='" + $(this).text() + "'>" + $(this).text() + "</option>";
244        });
245        index_select.html(x);
246       
247        index_input.hide();
248       
249};
250
251SearchClause.prototype.PlainText = function(){ 
252        if (this.index.trim().length == 0 || this.value.trim().length == 0){
253                return "";
254        }
255        if (this.is_category){
256                        return "ISOCAT( " + this.category + ") " + this.relation + " " + this.value;
257        }
258        return this.index.trim().replace(" ","_") + " " + this.relation + " " + this.value;
259};
260
261/** special handling for special characters: double escaping (escape the %-sign)
262 * to survive the %-encoding through the request (and parsing) down to the transformation in XCQL2XPath.xsl
263 * it's: whitespace, and single and double-quotes (unified to double quotes %22)
264*/ 
265SearchClause.prototype.escape = function(){
266        var escape_string = "";
267        var escape_value_string = "";
268       
269        escape_value_string =escape(this.value).replace(/%20/g,"%2520").replace(/\%2[27]/g,"%2522").replace(/%7C/g,"%257C").replace(/\+/g,"%2B"); 
270
271        if (this.is_complex) {
272                escape_string = escape_string + escape(this.index.trim().replace(" ","_") + " " + this.relation + " ") + escape_value_string;
273        } else {
274                // case more simple words in search
275                escape_string = escape_value_string;
276        }       
277        return escape_string;
278       
279};
280
281SearchClause.createFromData = function(scstr){
282        var n;
283        var scarr;
284        var rel = "";
285        n = scstr.indexOf("=");
286        if (n > 0){
287                scarr = scstr.split("=");
288                rel = "=";
289        }
290        n = scstr.indexOf(" any ");
291        if (n > 0){
292                scarr = scstr.split(" any ");
293                rel = "any";
294        }
295        n = scstr.indexOf(" contains ");
296        if (n > 0){
297                scarr = scstr.split(" contains ");
298                rel = "contains";
299        }
300        n = scstr.indexOf("<");
301        if (n > 0){
302                scarr = scstr.split("<");
303                rel = "<";
304        }
305        n = scstr.indexOf(">");
306        if (n > 0){
307                scarr = scstr.split(">");
308                rel = ">";
309        }
310        n = scstr.indexOf(" all ");
311        if (n > 0){
312                scarr = scstr.split(" all ");
313                rel = "all";
314        }
315        //notifyUser("scarr:" + scarr[0] + scarr[1],'debug');
316       
317        if (scarr == undefined) {
318                //this.issimpletext = true;
319                sc = new SearchClause('*','any',scstr);
320                sc.is_complex = false;
321        } else {
322                //this.issimpletext = false;
323                sc = new SearchClause(scarr[0],rel,scarr[1]);
324                sc.is_complex = true;
325        }
326
327        return sc;
328};
329/*
330Searchclause.prototype.submit = function () {
331       
332        var uri = link('recordset','htmltable', this.query_uri());
333        notifyUser("submitting query:" +  uri);
334       
335        this.container.find('.result').load( uri, function() {
336                                notifyUser("result-loaded");
337                                var get = $(this).parent().find('.cmd_get');                           
338
339                                get.removeClass('cmd_get');
340                                get.addClass('cmd_up');
341                                // get.show();
342                        });
343
344}
345*/
346   
347$('.index-context td').live('click',  function(event) {
348       
349        searchclauseset.updatedata(this.textContent, false, "");
350        //$('.focused','#searchclauselist').find('.index-input').val(   this.textContent);
351        $('.focused','#searchclauselist').find('.index-context').hide();
352       
353        $('.focused','#searchclauselist').find('.value-input').focus();
354
355});
356
357
358var searchclauseset_container = $("#searchclauselist"); 
359
360/**
361 * container of actually used Searchclauses in the query-input
362 * with basic functionality for building container - add, remove, clear
363 * and conversion functions - conversions from-to querystring
364 * @constructor
365 */
366
367var searchclauseset = {
368                /**  @field */
369        searchclauses: [],
370        container: '#searchclauselist',
371        sctext: '',
372               
373        addsearchclause: function (searchclause, rel, _i, _j){
374                var i,j;
375                       
376                if (this.searchclauses.length == 0){
377                        i = 0;
378                        this.searchclauses[i] = new Array();
379                        j = 0;
380                } else {
381                        if (rel == "or") {
382                                i = _i;//this.searchclauses.length - 1;
383                                j = this.searchclauses[i].length;//this.searchclauses[this.searchclauses.length - 1].length;
384                        } else {
385                                i = this.searchclauses.length;
386                                this.searchclauses[i] = new Array();
387                                j = 0;
388                        }
389                }
390                searchclause.i = i;
391                searchclause.j = j;
392                searchclause.listid = "sc" + i + "-" + j;
393                this.searchclauses[i][j] = searchclause;
394               
395                searchclause.render(rel);                                               
396                //$('#querylist').html(this.render());
397        },
398       
399        fillFromURL: function(url){
400        },
401       
402        clear: function() {
403                notifyUser("clear query",'debug');
404               
405                for (var i = this.searchclauses.length - 1; i > -1; i--){
406                        for (var j = this.searchclauses[i].length - 1; j > -1; j--){
407                       
408
409                                        this.searchclauses[i].splice(j, 1);
410                                        if  (j == 0){
411                                                this.searchclauses.splice(i, 1);
412                                                $('#' + 'sc' +  i + '-' + j).parent().parent().remove();
413                                                $('#' + 'sc' +  i + '-' + j).parent().remove();
414                                        } else {
415                                                $('#' + 'sc' +  i + '-' + j).parent().remove();
416                                        }               
417               
418                       
419                        }
420                }
421               
422                notifyUser(this.searchclauses.length,'debug');
423               
424                // reset focused
425                //$('.sc-wrapper','#searchclauselist').each(function(){
426                //      $(this).removeClass("focused");
427                //});
428                //$('#sc0-0').addClass("focused");
429        },
430       
431        //TODO remove only last items
432        removesearchclause: function (i, j) {
433                notifyUser("removing sc:"  + i + "," + j,'debug');
434               
435                if ((j == 0) && (i == 0)){
436                        searchclauseset.searchclauses[i][j].index = "";
437                        searchclauseset.searchclauses[i][j].is_category = false;
438                        searchclauseset.searchclauses[i][j].relation = "=";
439                        searchclauseset.searchclauses[i][j].value = "";
440                        $('#sc0-0').find('.index-input').val("");
441                        $('#sc0-0').find('.index-input-termset').val("");
442                        $('#sc0-0').find('.rel_input').val("=");
443                        $('#sc0-0').find('.value-input').val("");                       
444                        notifyUser("cannot remove", 'debug');
445                        return;
446                }
447                if ((j == 0) && (i < this.searchclauses.length - 1)){
448                        notifyUser("cannot remove",'debug');
449                        return;
450                }
451                if (j < this.searchclauses[i].length - 1){
452                        notifyUser("cannot remove",'debug');
453                        return;
454                }
455                this.searchclauses[i].splice(j, 1);
456                 
457                if  (j == 0){
458                        this.searchclauses.splice(i, 1);
459                        $('#' + 'sc' +  i + '-' + j).parent().parent().remove();
460                } else {
461                        $('#' + 'sc' +  i + '-' + j).parent().remove();
462                }               
463
464                notifyUser("sc removed, new sc.length:"  + this.searchclauses.length,'debug');
465                for (var j = 0; j < this.searchclauses.length; j++) {
466                        notifyUser("  new sc.or_length:"  + this.searchclauses[j].length,'debug');
467                }       
468                // reset focused
469                $('.sc-wrapper','#searchclauselist').each(function(){
470                        $(this).removeClass("focused");
471                });
472                $('#sc0-0').addClass("focused");
473               
474        },
475        /*
476        // just test
477        load: function(i,j,rel,data) {
478                if (data["triple"] == null ) {
479                         this.searchclauses[i][j].index =  data["searchClause"]["index"];
480                         this.searchclauses[i][j].relation =  data["searchClause"]["relation"]["value"];
481                         this.searchclauses[i][j].value =  data["searchClause"]["term"];
482                         
483                         $('#sc0-0','#searchclauselist').find('.index-input').val(data["searchClause"]["index"]);
484                         $('#sc0-0','#searchclauselist').find('.relation_input').val(data["searchClause"]["relation"]["value"]);
485                         $('#sc0-0','#searchclauselist').find('.value-input').val(data["searchClause"]["term"]);
486                 } else {
487                         if (data["triple"]["boolean"]["value"] == "and") {
488                                 //var sc = new SearchClause("","","");
489                                 //this.addsearchclause(sc, "and", _i, _j)
490                                 // update(leftO)
491                                 // update(rightO)
492                                 load(i,j,"",data["triple"]["leftOperand"]);
493                                 i = this.searchclauses.length;
494                                 load(i+1,j,"and",data["triple"]["rightOperand"]);
495                         } else {
496                                 load(i,j,"",data["triple"]["leftOperand"]);
497                                 j = this.searchclauses[i].length;
498                                 load(i,j,"or",data["triple"]["rightOperand"]);
499                         }
500                         
501                 }
502                 
503        },
504        */
505        // from querystring to searchclauses
506        buildfromquerystring: function(){
507                var arr = Query.simplequerystring(this.sctext);
508                var sc, screl;
509               
510                this.clear();
511               
512                //notifyUser(arr,'debug');
513                var arr_and = arr.split(" and ");
514                screl = "";
515                for( var i=0;i<arr_and.length;i++){
516                        var scstring = $.trim(arr_and[i]);
517                       
518                        if (scstring.substring(0,1) == "(" && scstring.substring(scstring.length-1) == ")") {
519                                scstring = scstring.substring(1,scstring.length-1);
520                                scstring = $.trim(scstring);
521                        }
522                       
523                        //notifyUser("i:" + scstring,'debug');
524                        var arr_or = scstring.split(" or ");
525                        if (i > 0) {screl = "and";}
526                        for( var j=0;j<arr_or.length;j++){
527                                if (j > 0) {screl = "or";}
528                               
529                                sc = SearchClause.createFromData($.trim(arr_or[j]));
530                                this.addsearchclause(sc,screl,i,j);                             
531                        }
532                }
533        },
534       
535       
536        buildsctext: function(){
537           var uncompletequery = false;
538           var ptext = "";
539           
540                if ($('.searchtype_text','#search').size() > 0) {
541                        this.sctext = $('#query_area').val();
542                } else {
543               
544                        this.sctext = "";
545                        for (var i = 0; i < this.searchclauses.length; i++) {
546                                if ( i>0) this.sctext = this.sctext + " and ";
547                                if (this.searchclauses.length> 1) this.sctext = this.sctext + " ( ";
548                                for (var j = 0; j < this.searchclauses[i].length; j++) {
549                                        if ( j>0) this.sctext = this.sctext + " or ";
550                                        if (this.searchclauses[i].length > 1) this.sctext = this.sctext + " ( ";
551                                        ptext = this.searchclauses[i][j].PlainText();
552                                        if (ptext.length == 0){
553                                                uncompletequery = true;
554                                        }
555                                        this.sctext = this.sctext + ptext;
556                                        if (this.searchclauses[i].length > 1) this.sctext = this.sctext + " ) ";
557                                }
558                                if (this.searchclauses.length> 1) this.sctext = this.sctext + " ) ";
559                        }
560                       
561                }       
562                if ((i == 1 && j == 1) && (this.sctext.substring(0,6) == '* any ')) {
563                        this.sctext  = this.sctext.replace('* any ','');
564                }
565                if (uncompletequery){
566                        this.sctext = "";
567                }
568                notifyUser(this.sctext);
569                return this.sctext;
570               
571        },
572       
573        updatedata: function(term, is_category, category, value) {       
574               
575                var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id");
576                var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id");
577               
578                if (term != undefined){
579                        $('.focused','#searchclauselist').find('.index-input').val(term);
580                        searchclauseset.searchclauses[i][j].index = term.replace(" ","_");
581                }
582               
583                if (value == undefined){
584                        $('.focused','#searchclauselist').find('.value-input').focus();
585                } else {
586                        $('.focused','#searchclauselist').find('.value-input').val(value);
587                        searchclauseset.searchclauses[i][j].value = value;
588                }
589               
590                if (is_category) {
591                        searchclauseset.searchclauses[i][j].is_category = true;
592                        searchclauseset.searchclauses[i][j].category = category;
593                } else {
594                        searchclauseset.searchclauses[i][j].is_category = false;
595                }
596               
597        },
598       
599        initAutocomplete: function() {
600                notifyUser("init autocomplete",'debug');
601               
602                for (var i = this.searchclauses.length - 1; i > -1; i--){
603                        for (var j = this.searchclauses[i].length - 1; j > -1; j--){
604                                        this.searchclauses[i][j].initAutocomplete();           
605                        }
606                }       
607        }
608};
609
610function escapequerystring(querystring){
611        var arr = Query.simplequerystring(querystring);
612        var sc, screl;
613        var escape_string = "";
614        var add_bracket = false;
615       
616        //notifyUser(arr,'debug');
617        var arr_and = arr.split(" and ");
618        screl = "";
619        for( var i=0;i<arr_and.length;i++){
620                var scstring = $.trim(arr_and[i]);
621               
622                add_bracket = false;
623                if (scstring.substring(0,1) == "(" && scstring.substring(scstring.length-1) == ")") {
624                        scstring = scstring.substring(1,scstring.length-1);
625                        scstring = $.trim(scstring);
626                        escape_string = escape_string + "(";
627                        add_bracket = true;
628                }
629               
630                //notifyUser("i:" + scstring,'debug');
631                var arr_or = scstring.split(" or ");
632                if (i > 0) {screl = "and";}
633               
634                for( var j=0;j<arr_or.length;j++){
635                        var scstr = $.trim(arr_or[j]);         
636                        if (j > 0) {screl = "or";}
637                       
638                        sc = SearchClause.createFromData(scstr);
639                        if (screl != ""){
640                                escape_string  = escape_string + "%20" + screl + "%20";
641                        }
642                        escape_string = escape_string + sc.escape();
643                }
644                if (add_bracket){
645                        escape_string = escape_string + ")";
646                }
647        }
648        return escape_string;
649}
650
651
652
653//autocomplete
654// not used
655function handleTermsSelection(i,j,elem){
656                        /*
657                        var context = $('#' + 'sc' +  i + '-' + j).find('.index-context');
658                        // fill context
659                        //$(context).remove();
660                        $(context).html(elements_hashtable[elem]);
661                        $(context).show();
662                        //notifyUser($('#' + 'sc' +  i + '-' + j).find('.index-input').val(), 'debug');
663                        //$('#' + 'sc' +  i + '-' + j).find('.index-input').focus();
664                       
665                        $('#' + 'sc' +  i + '-' + j).find('.index-input').blur(function(){
666                                $(context).hide();
667                        });
668                        $('#' + 'sc' +  i + '-' + j).find('.index-input').focusin(function(){
669                                $(context).hide();
670                        });
671                        */
672                        //$('#' + 'sc' +  i + '-' + j).find('.index-input').hide();
673                        //$('#' + 'sc' +  i + '-' + j).find('.index-input-termset').show();
674                       
675};
676               
677function findValueTerm(e) {
678                       
679                        var sValue = e.selectValue;
680                       
681                        var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id");
682                        var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id");
683                        //alert(i+ ',' + j + sValue);
684                        searchclauseset.searchclauses[i][j].index = sValue;
685                       
686                        //handleTermsSelection(i,j,sValue);             
687                       
688}
689                 
690function selectItemTerm(li) {
691                        findValueTerm(li);
692                }
693
694
695function initTermsetAutocomplete(i,j,elem){
696        //$('#' + 'sc' +  i + '-' + j).find('.index-input').hide();
697       
698        // not working
699        //searchclauseset.searchclauses[i][j].initAutocompleteTerms(elem);
700
701        $('#' + 'sc' +  i + '-' + j).find('.index-input').autocompleteArray(elements_hashtable[elem],{
702                autoFill:true,
703                //width:150,
704                onFindValue:findValueTerm,
705                onItemSelect:selectItemTerm
706        });
707        // reset the index value
708        $('#' + 'sc' +  i + '-' + j).find('.index-input').val("");
709        searchclauseset.searchclauses[i][j].index = "";
710        $('#' + 'sc' +  i + '-' + j).find('.index-input').show();
711        $('body').find('.ac_results').css({'z-index' : '1000'});
712       
713};
714
715function handleTermsetSelection(i,j,elem){
716       
717        // create apropriate array, than initialize autocomplete
718        if ($('#elements_hashtable_'+elem).children().length == 0) {
719                $('#elements_hashtable_'+elem).load(link('smc','list/?context='+elem),function(){
720                        //var e = $(this).attr("id");
721                        $(this).find('Term').each(function(index){
722                                elements_hashtable[elem][index] = $(this).text();
723                        });
724                        initTermsetAutocomplete(i,j,elem);
725                });
726        } else {
727                initTermsetAutocomplete(i,j,elem);
728        }       
729};
730
731function findValueTermset(e) {
732        var sValue = e.selectValue;
733       
734        var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id");
735        var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id");
736       
737        //searchclauseset.searchclauses[i][j].index = sValue;   
738        handleTermsetSelection(i,j,sValue);             
739       
740        $('.focused','#searchclauselist').find('.index-input').focus();
741       
742}
743 
744function selectItemTermset(li) {
745        findValueTermset(li);
746}
Note: See TracBrowser for help on using the repository browser.