[1219] | 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 | |
---|
[615] | 14 | // client-side modelling of "business-objects": |
---|
| 15 | // SearchClause, SearchClauseset, |
---|
| 16 | |
---|
[782] | 17 | |
---|
[615] | 18 | //TODO use select-options or autocomplete ??? |
---|
| 19 | //var relation_autocomplete = new Array('any','all','=','>','<'); |
---|
| 20 | //var value_autocomplete = new Array(); |
---|
[1234] | 21 | |
---|
| 22 | /** |
---|
| 23 | * SearchClause model [index,relation, value], with basic functionality - |
---|
| 24 | * creation, render, autocomplete. |
---|
| 25 | * @constructor |
---|
| 26 | */ |
---|
[1177] | 27 | function SearchClause(index, relation, value ) { |
---|
[615] | 28 | this.index = index; |
---|
[1177] | 29 | this.relation = relation; |
---|
| 30 | this.value = value; |
---|
[615] | 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 | |
---|
[676] | 41 | if (this.relation == "") { |
---|
| 42 | this.relation = "="; |
---|
| 43 | } |
---|
[1594] | 44 | |
---|
| 45 | this.is_complex = true; |
---|
[615] | 46 | } |
---|
| 47 | |
---|
| 48 | SearchClause.prototype.GetIndexInput = function(){ |
---|
[782] | 49 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index-input'); |
---|
[615] | 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(){ |
---|
[1177] | 56 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.value-input'); |
---|
[615] | 57 | }; |
---|
| 58 | |
---|
| 59 | SearchClause.prototype.GetIndexSelect = function(){ |
---|
| 60 | return $($($('.sc-i','#searchclauselist')[this.i]).find('.sc-j')[this.j]).find('.index_select'); |
---|
| 61 | }; |
---|
[1664] | 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 | }; |
---|
[615] | 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 |
---|
[676] | 77 | //this.relation = '='; |
---|
[1177] | 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 | //} |
---|
[782] | 82 | var x = "<div id='" + this.j + "' class='sc-j or_level' ><div id='" + this.listid + "' class='sc-wrapper focused' > " + |
---|
[1918] | 83 | "<div class='search'><span class='cmd cmd_sc_autocomplete cmd_sca_explain'></span><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>" + |
---|
[1177] | 84 | //index_detail + |
---|
[615] | 85 | //"<select type='text' class='rel_input' />" + |
---|
[862] | 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>" + |
---|
[1177] | 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>" + |
---|
[648] | 89 | "<span class='cmd cmd_add_and'> </span><span class='cmd cmd_add_or'></span>"+ |
---|
[782] | 90 | " </span></div><div class='index-context'><table></table></div></div></div>"; |
---|
[615] | 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(); |
---|
[1664] | 100 | //var index_input_termset = this.GetIndexInputTermset(); |
---|
[615] | 101 | var value_select = this.GetValueSelect(); |
---|
| 102 | |
---|
| 103 | $(index_select).hide(); |
---|
[1664] | 104 | //$(index_input_term).hide(); |
---|
| 105 | this.GetIndexInput().hide(); |
---|
[615] | 106 | value_select.hide(); |
---|
[782] | 107 | //$(e_index).closest('.sc-wrapper').find('.index-context').hide(); |
---|
[615] | 108 | |
---|
| 109 | //alert("focused: " + $('.focused','#searchclauselist').size()); |
---|
[782] | 110 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
[615] | 111 | $(this).removeClass("focused"); |
---|
| 112 | }); |
---|
[782] | 113 | $(e_index).closest('.sc-wrapper').addClass("focused"); |
---|
[615] | 114 | //alert("focused: " + $('.focused','#searchclauselist').size()); |
---|
| 115 | |
---|
| 116 | // set focus |
---|
| 117 | e_index.focusin(function(){ |
---|
[782] | 118 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
[615] | 119 | $(this).removeClass("focused"); |
---|
| 120 | }); |
---|
[782] | 121 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
[615] | 122 | }); |
---|
| 123 | index_select.focusin(function(){ |
---|
[782] | 124 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
[615] | 125 | $(this).removeClass("focused"); |
---|
| 126 | }); |
---|
[782] | 127 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
[615] | 128 | }); |
---|
| 129 | e_relation.focusin(function(){ |
---|
[782] | 130 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
[615] | 131 | $(this).removeClass("focused"); |
---|
| 132 | }); |
---|
[782] | 133 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
[615] | 134 | }); |
---|
| 135 | e_value.focusin(function(){ |
---|
[782] | 136 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
[615] | 137 | $(this).removeClass("focused"); |
---|
| 138 | }); |
---|
[782] | 139 | $(this).closest('.sc-wrapper').addClass("focused"); |
---|
[615] | 140 | }); |
---|
[1177] | 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 | }); |
---|
[615] | 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 | }; |
---|
[647] | 156 | //notifyUser($(this).attr("value").length); |
---|
[615] | 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 |
---|
[647] | 168 | notifyUser(ev.which); |
---|
[615] | 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 | |
---|
[676] | 184 | e_index.val(this.index); |
---|
| 185 | e_relation.val(this.relation); |
---|
| 186 | e_value.val(this.value); |
---|
[615] | 187 | //update after text change |
---|
| 188 | e_index.bind('change', function(){ |
---|
[1029] | 189 | |
---|
[615] | 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(); |
---|
[1029] | 194 | notifyUser("index_sc" + i + "-" + j + " changed to:" + searchclauseset.searchclauses[i][j].index, "debug"); |
---|
[615] | 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"); |
---|
[676] | 200 | //notifyUser("rel change:" + $(this).val(), 'debug'); |
---|
[615] | 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 | |
---|
[1266] | 213 | try{ |
---|
[1918] | 214 | this.initAutocomplete(false); |
---|
[1919] | 215 | //this.initAutocomplete(true); |
---|
[1266] | 216 | } catch (e){ |
---|
[1267] | 217 | notifyUser("autocomplete failed: " + e.message); |
---|
[1266] | 218 | } |
---|
[615] | 219 | |
---|
| 220 | }; |
---|
[832] | 221 | |
---|
[1918] | 222 | |
---|
| 223 | SearchClause.prototype.initAutocomplete = function(is_explain){ |
---|
[832] | 224 | |
---|
[1918] | 225 | if (is_explain){ |
---|
| 226 | if (element_autocomplete_explain.length == 0) return; |
---|
| 227 | |
---|
| 228 | $(this.GetIndexInputTermset()).autocomplete({ |
---|
| 229 | source: element_autocomplete_explain, |
---|
| 230 | autoFill:true, |
---|
| 231 | width:150, |
---|
| 232 | //onFindValue:findValueTermset, |
---|
| 233 | //onItemSelect:selectItemTermset, |
---|
| 234 | minLength: 0, |
---|
| 235 | matchContains:true, |
---|
| 236 | delay: 0, |
---|
| 237 | select: function( event, ui ) { |
---|
| 238 | $(this).data("item", ui.item); |
---|
| 239 | selectItemTermsetExplain(ui.item); |
---|
| 240 | } |
---|
| 241 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
| 242 | var t, re; |
---|
| 243 | if (this.term == ""){ |
---|
| 244 | t = item.value; |
---|
| 245 | } else { |
---|
| 246 | re = new RegExp(this.term + "+") ; |
---|
| 247 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
| 248 | this.term + |
---|
| 249 | "</span>"); |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | return $( "<li></li>" ) |
---|
| 253 | .data( "item.autocomplete", item ) |
---|
| 254 | .append( "<a>" + t + "</a>" ) |
---|
| 255 | .appendTo( ul ); |
---|
| 256 | }; |
---|
| 257 | |
---|
| 258 | } else { |
---|
| 259 | if (element_autocomplete.length == 0) return; |
---|
| 260 | |
---|
| 261 | $(this.GetIndexInputTermset()).autocomplete({ |
---|
| 262 | source: element_autocomplete, |
---|
| 263 | autoFill:true, |
---|
| 264 | width:150, |
---|
| 265 | //onFindValue:findValueTermset, |
---|
| 266 | //onItemSelect:selectItemTermset, |
---|
| 267 | minLength: 0, |
---|
| 268 | matchContains:true, |
---|
| 269 | delay: 0, |
---|
| 270 | select: function( event, ui ) { |
---|
| 271 | $(this).data("item", ui.item); |
---|
| 272 | selectItemTermset(ui.item); |
---|
| 273 | } |
---|
| 274 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
| 275 | var t, re; |
---|
| 276 | if (this.term == ""){ |
---|
| 277 | t = item.value; |
---|
| 278 | } else { |
---|
| 279 | re = new RegExp(this.term + "+") ; |
---|
| 280 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
| 281 | this.term + |
---|
| 282 | "</span>"); |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | return $( "<li></li>" ) |
---|
| 286 | .data( "item.autocomplete", item ) |
---|
| 287 | .append( "<a>" + t + "</a>" ) |
---|
| 288 | .appendTo( ul ); |
---|
| 289 | }; |
---|
| 290 | |
---|
| 291 | } |
---|
[1681] | 292 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
[832] | 293 | |
---|
| 294 | }; |
---|
| 295 | |
---|
[1664] | 296 | |
---|
[615] | 297 | SearchClause.prototype.CreateSelect = function(str, element){ |
---|
| 298 | var index_select = GetIndexSelect(); |
---|
| 299 | var index_input = GetIndexInput(); |
---|
| 300 | index_select.show(); |
---|
| 301 | var x = "<option value='" + str + "'>" + str + "</option>"; |
---|
| 302 | $(element).each(function(){ |
---|
| 303 | x = x+"<option value='" + $(this).text() + "'>" + $(this).text() + "</option>"; |
---|
| 304 | }); |
---|
| 305 | index_select.html(x); |
---|
| 306 | |
---|
| 307 | index_input.hide(); |
---|
| 308 | |
---|
| 309 | }; |
---|
| 310 | |
---|
| 311 | SearchClause.prototype.PlainText = function(){ |
---|
[745] | 312 | if (this.index.trim().length == 0 || this.value.trim().length == 0){ |
---|
| 313 | return ""; |
---|
| 314 | } |
---|
| 315 | if (this.is_category){ |
---|
[615] | 316 | return "ISOCAT( " + this.category + ") " + this.relation + " " + this.value; |
---|
[745] | 317 | } |
---|
[1594] | 318 | return this.index.trim().replace(" ","_") + " " + this.relation + " " + this.value; |
---|
[745] | 319 | }; |
---|
[1594] | 320 | |
---|
| 321 | /** special handling for special characters: double escaping (escape the %-sign) |
---|
| 322 | * to survive the %-encoding through the request (and parsing) down to the transformation in XCQL2XPath.xsl |
---|
| 323 | * it's: whitespace, and single and double-quotes (unified to double quotes %22) |
---|
| 324 | */ |
---|
| 325 | SearchClause.prototype.escape = function(){ |
---|
| 326 | var escape_string = ""; |
---|
| 327 | var escape_value_string = ""; |
---|
| 328 | |
---|
| 329 | escape_value_string =escape(this.value).replace(/%20/g,"%2520").replace(/\%2[27]/g,"%2522").replace(/%7C/g,"%257C").replace(/\+/g,"%2B"); |
---|
| 330 | |
---|
| 331 | if (this.is_complex) { |
---|
| 332 | escape_string = escape_string + escape(this.index.trim().replace(" ","_") + " " + this.relation + " ") + escape_value_string; |
---|
| 333 | } else { |
---|
| 334 | // case more simple words in search |
---|
| 335 | escape_string = escape_value_string; |
---|
| 336 | } |
---|
| 337 | return escape_string; |
---|
| 338 | |
---|
| 339 | }; |
---|
| 340 | |
---|
| 341 | SearchClause.createFromData = function(scstr){ |
---|
| 342 | var n; |
---|
| 343 | var scarr; |
---|
| 344 | var rel = ""; |
---|
| 345 | n = scstr.indexOf("="); |
---|
| 346 | if (n > 0){ |
---|
| 347 | scarr = scstr.split("="); |
---|
| 348 | rel = "="; |
---|
| 349 | } |
---|
| 350 | n = scstr.indexOf(" any "); |
---|
| 351 | if (n > 0){ |
---|
| 352 | scarr = scstr.split(" any "); |
---|
| 353 | rel = "any"; |
---|
| 354 | } |
---|
| 355 | n = scstr.indexOf(" contains "); |
---|
| 356 | if (n > 0){ |
---|
| 357 | scarr = scstr.split(" contains "); |
---|
| 358 | rel = "contains"; |
---|
| 359 | } |
---|
| 360 | n = scstr.indexOf("<"); |
---|
| 361 | if (n > 0){ |
---|
| 362 | scarr = scstr.split("<"); |
---|
| 363 | rel = "<"; |
---|
| 364 | } |
---|
| 365 | n = scstr.indexOf(">"); |
---|
| 366 | if (n > 0){ |
---|
| 367 | scarr = scstr.split(">"); |
---|
| 368 | rel = ">"; |
---|
| 369 | } |
---|
| 370 | n = scstr.indexOf(" all "); |
---|
| 371 | if (n > 0){ |
---|
| 372 | scarr = scstr.split(" all "); |
---|
| 373 | rel = "all"; |
---|
| 374 | } |
---|
| 375 | //notifyUser("scarr:" + scarr[0] + scarr[1],'debug'); |
---|
| 376 | |
---|
| 377 | if (scarr == undefined) { |
---|
| 378 | //this.issimpletext = true; |
---|
| 379 | sc = new SearchClause('*','any',scstr); |
---|
| 380 | sc.is_complex = false; |
---|
| 381 | } else { |
---|
| 382 | //this.issimpletext = false; |
---|
| 383 | sc = new SearchClause(scarr[0],rel,scarr[1]); |
---|
| 384 | sc.is_complex = true; |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | return sc; |
---|
| 388 | }; |
---|
[615] | 389 | /* |
---|
| 390 | Searchclause.prototype.submit = function () { |
---|
| 391 | |
---|
| 392 | var uri = link('recordset','htmltable', this.query_uri()); |
---|
| 393 | notifyUser("submitting query:" + uri); |
---|
| 394 | |
---|
| 395 | this.container.find('.result').load( uri, function() { |
---|
[647] | 396 | notifyUser("result-loaded"); |
---|
[615] | 397 | var get = $(this).parent().find('.cmd_get'); |
---|
| 398 | |
---|
| 399 | get.removeClass('cmd_get'); |
---|
| 400 | get.addClass('cmd_up'); |
---|
| 401 | // get.show(); |
---|
| 402 | }); |
---|
| 403 | |
---|
| 404 | } |
---|
| 405 | */ |
---|
| 406 | |
---|
[782] | 407 | $('.index-context td').live('click', function(event) { |
---|
| 408 | |
---|
[783] | 409 | searchclauseset.updatedata(this.textContent, false, ""); |
---|
| 410 | //$('.focused','#searchclauselist').find('.index-input').val( this.textContent); |
---|
[782] | 411 | $('.focused','#searchclauselist').find('.index-context').hide(); |
---|
| 412 | |
---|
[1177] | 413 | $('.focused','#searchclauselist').find('.value-input').focus(); |
---|
[782] | 414 | |
---|
| 415 | }); |
---|
| 416 | |
---|
| 417 | |
---|
[615] | 418 | var searchclauseset_container = $("#searchclauselist"); |
---|
| 419 | |
---|
[1234] | 420 | /** |
---|
| 421 | * container of actually used Searchclauses in the query-input |
---|
| 422 | * with basic functionality for building container - add, remove, clear |
---|
| 423 | * and conversion functions - conversions from-to querystring |
---|
| 424 | * @constructor |
---|
| 425 | */ |
---|
| 426 | |
---|
| 427 | var searchclauseset = { |
---|
| 428 | /** @field */ |
---|
[615] | 429 | searchclauses: [], |
---|
| 430 | container: '#searchclauselist', |
---|
| 431 | sctext: '', |
---|
| 432 | |
---|
| 433 | addsearchclause: function (searchclause, rel, _i, _j){ |
---|
| 434 | var i,j; |
---|
| 435 | |
---|
| 436 | if (this.searchclauses.length == 0){ |
---|
| 437 | i = 0; |
---|
| 438 | this.searchclauses[i] = new Array(); |
---|
| 439 | j = 0; |
---|
| 440 | } else { |
---|
| 441 | if (rel == "or") { |
---|
| 442 | i = _i;//this.searchclauses.length - 1; |
---|
| 443 | j = this.searchclauses[i].length;//this.searchclauses[this.searchclauses.length - 1].length; |
---|
| 444 | } else { |
---|
| 445 | i = this.searchclauses.length; |
---|
| 446 | this.searchclauses[i] = new Array(); |
---|
| 447 | j = 0; |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | searchclause.i = i; |
---|
| 451 | searchclause.j = j; |
---|
| 452 | searchclause.listid = "sc" + i + "-" + j; |
---|
| 453 | this.searchclauses[i][j] = searchclause; |
---|
| 454 | |
---|
| 455 | searchclause.render(rel); |
---|
| 456 | //$('#querylist').html(this.render()); |
---|
| 457 | }, |
---|
[656] | 458 | |
---|
| 459 | fillFromURL: function(url){ |
---|
| 460 | }, |
---|
| 461 | |
---|
| 462 | clear: function() { |
---|
| 463 | notifyUser("clear query",'debug'); |
---|
| 464 | |
---|
| 465 | for (var i = this.searchclauses.length - 1; i > -1; i--){ |
---|
[676] | 466 | for (var j = this.searchclauses[i].length - 1; j > -1; j--){ |
---|
| 467 | |
---|
[615] | 468 | |
---|
[656] | 469 | this.searchclauses[i].splice(j, 1); |
---|
| 470 | if (j == 0){ |
---|
| 471 | this.searchclauses.splice(i, 1); |
---|
| 472 | $('#' + 'sc' + i + '-' + j).parent().parent().remove(); |
---|
[676] | 473 | $('#' + 'sc' + i + '-' + j).parent().remove(); |
---|
[656] | 474 | } else { |
---|
| 475 | $('#' + 'sc' + i + '-' + j).parent().remove(); |
---|
| 476 | } |
---|
| 477 | |
---|
[676] | 478 | |
---|
[656] | 479 | } |
---|
| 480 | } |
---|
| 481 | |
---|
[676] | 482 | notifyUser(this.searchclauses.length,'debug'); |
---|
[656] | 483 | |
---|
| 484 | // reset focused |
---|
[782] | 485 | //$('.sc-wrapper','#searchclauselist').each(function(){ |
---|
[676] | 486 | // $(this).removeClass("focused"); |
---|
| 487 | //}); |
---|
| 488 | //$('#sc0-0').addClass("focused"); |
---|
[656] | 489 | }, |
---|
| 490 | |
---|
[615] | 491 | //TODO remove only last items |
---|
| 492 | removesearchclause: function (i, j) { |
---|
| 493 | notifyUser("removing sc:" + i + "," + j,'debug'); |
---|
| 494 | |
---|
| 495 | if ((j == 0) && (i == 0)){ |
---|
[762] | 496 | searchclauseset.searchclauses[i][j].index = ""; |
---|
| 497 | searchclauseset.searchclauses[i][j].is_category = false; |
---|
| 498 | searchclauseset.searchclauses[i][j].relation = "="; |
---|
| 499 | searchclauseset.searchclauses[i][j].value = ""; |
---|
[782] | 500 | $('#sc0-0').find('.index-input').val(""); |
---|
[1664] | 501 | $('#sc0-0').find('.index-input-termset').val(""); |
---|
[762] | 502 | $('#sc0-0').find('.rel_input').val("="); |
---|
[1177] | 503 | $('#sc0-0').find('.value-input').val(""); |
---|
[615] | 504 | notifyUser("cannot remove", 'debug'); |
---|
| 505 | return; |
---|
| 506 | } |
---|
| 507 | if ((j == 0) && (i < this.searchclauses.length - 1)){ |
---|
| 508 | notifyUser("cannot remove",'debug'); |
---|
| 509 | return; |
---|
| 510 | } |
---|
| 511 | if (j < this.searchclauses[i].length - 1){ |
---|
| 512 | notifyUser("cannot remove",'debug'); |
---|
| 513 | return; |
---|
| 514 | } |
---|
| 515 | this.searchclauses[i].splice(j, 1); |
---|
| 516 | |
---|
| 517 | if (j == 0){ |
---|
| 518 | this.searchclauses.splice(i, 1); |
---|
| 519 | $('#' + 'sc' + i + '-' + j).parent().parent().remove(); |
---|
| 520 | } else { |
---|
| 521 | $('#' + 'sc' + i + '-' + j).parent().remove(); |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | notifyUser("sc removed, new sc.length:" + this.searchclauses.length,'debug'); |
---|
| 525 | for (var j = 0; j < this.searchclauses.length; j++) { |
---|
| 526 | notifyUser(" new sc.or_length:" + this.searchclauses[j].length,'debug'); |
---|
| 527 | } |
---|
| 528 | // reset focused |
---|
[782] | 529 | $('.sc-wrapper','#searchclauselist').each(function(){ |
---|
[615] | 530 | $(this).removeClass("focused"); |
---|
| 531 | }); |
---|
| 532 | $('#sc0-0').addClass("focused"); |
---|
| 533 | |
---|
| 534 | }, |
---|
[692] | 535 | /* |
---|
[656] | 536 | // just test |
---|
| 537 | load: function(i,j,rel,data) { |
---|
| 538 | if (data["triple"] == null ) { |
---|
| 539 | this.searchclauses[i][j].index = data["searchClause"]["index"]; |
---|
| 540 | this.searchclauses[i][j].relation = data["searchClause"]["relation"]["value"]; |
---|
| 541 | this.searchclauses[i][j].value = data["searchClause"]["term"]; |
---|
| 542 | |
---|
[782] | 543 | $('#sc0-0','#searchclauselist').find('.index-input').val(data["searchClause"]["index"]); |
---|
[656] | 544 | $('#sc0-0','#searchclauselist').find('.relation_input').val(data["searchClause"]["relation"]["value"]); |
---|
[1177] | 545 | $('#sc0-0','#searchclauselist').find('.value-input').val(data["searchClause"]["term"]); |
---|
[656] | 546 | } else { |
---|
[692] | 547 | if (data["triple"]["boolean"]["value"] == "and") { |
---|
[656] | 548 | //var sc = new SearchClause("","",""); |
---|
| 549 | //this.addsearchclause(sc, "and", _i, _j) |
---|
| 550 | // update(leftO) |
---|
| 551 | // update(rightO) |
---|
| 552 | load(i,j,"",data["triple"]["leftOperand"]); |
---|
| 553 | i = this.searchclauses.length; |
---|
| 554 | load(i+1,j,"and",data["triple"]["rightOperand"]); |
---|
| 555 | } else { |
---|
| 556 | load(i,j,"",data["triple"]["leftOperand"]); |
---|
| 557 | j = this.searchclauses[i].length; |
---|
| 558 | load(i,j,"or",data["triple"]["rightOperand"]); |
---|
| 559 | } |
---|
[692] | 560 | |
---|
[656] | 561 | } |
---|
| 562 | |
---|
| 563 | }, |
---|
[692] | 564 | */ |
---|
[676] | 565 | // from querystring to searchclauses |
---|
| 566 | buildfromquerystring: function(){ |
---|
[692] | 567 | var arr = Query.simplequerystring(this.sctext); |
---|
[676] | 568 | var sc, screl; |
---|
| 569 | |
---|
| 570 | this.clear(); |
---|
| 571 | |
---|
[692] | 572 | //notifyUser(arr,'debug'); |
---|
[676] | 573 | var arr_and = arr.split(" and "); |
---|
| 574 | screl = ""; |
---|
| 575 | for( var i=0;i<arr_and.length;i++){ |
---|
[742] | 576 | var scstring = $.trim(arr_and[i]); |
---|
[676] | 577 | |
---|
| 578 | if (scstring.substring(0,1) == "(" && scstring.substring(scstring.length-1) == ")") { |
---|
| 579 | scstring = scstring.substring(1,scstring.length-1); |
---|
[742] | 580 | scstring = $.trim(scstring); |
---|
[676] | 581 | } |
---|
[745] | 582 | |
---|
[692] | 583 | //notifyUser("i:" + scstring,'debug'); |
---|
[676] | 584 | var arr_or = scstring.split(" or "); |
---|
| 585 | if (i > 0) {screl = "and";} |
---|
| 586 | for( var j=0;j<arr_or.length;j++){ |
---|
| 587 | if (j > 0) {screl = "or";} |
---|
[1561] | 588 | |
---|
[1594] | 589 | sc = SearchClause.createFromData($.trim(arr_or[j])); |
---|
| 590 | this.addsearchclause(sc,screl,i,j); |
---|
[676] | 591 | } |
---|
| 592 | } |
---|
| 593 | }, |
---|
| 594 | |
---|
[1594] | 595 | |
---|
[615] | 596 | buildsctext: function(){ |
---|
[745] | 597 | var uncompletequery = false; |
---|
| 598 | var ptext = ""; |
---|
[615] | 599 | |
---|
| 600 | if ($('.searchtype_text','#search').size() > 0) { |
---|
| 601 | this.sctext = $('#query_area').val(); |
---|
| 602 | } else { |
---|
| 603 | |
---|
| 604 | this.sctext = ""; |
---|
| 605 | for (var i = 0; i < this.searchclauses.length; i++) { |
---|
| 606 | if ( i>0) this.sctext = this.sctext + " and "; |
---|
[1561] | 607 | if (this.searchclauses.length> 1) this.sctext = this.sctext + " ( "; |
---|
[615] | 608 | for (var j = 0; j < this.searchclauses[i].length; j++) { |
---|
| 609 | if ( j>0) this.sctext = this.sctext + " or "; |
---|
[1561] | 610 | if (this.searchclauses[i].length > 1) this.sctext = this.sctext + " ( "; |
---|
[745] | 611 | ptext = this.searchclauses[i][j].PlainText(); |
---|
| 612 | if (ptext.length == 0){ |
---|
| 613 | uncompletequery = true; |
---|
| 614 | } |
---|
| 615 | this.sctext = this.sctext + ptext; |
---|
[1561] | 616 | if (this.searchclauses[i].length > 1) this.sctext = this.sctext + " ) "; |
---|
[615] | 617 | } |
---|
[1561] | 618 | if (this.searchclauses.length> 1) this.sctext = this.sctext + " ) "; |
---|
[615] | 619 | } |
---|
| 620 | |
---|
| 621 | } |
---|
[1584] | 622 | if ((i == 1 && j == 1) && (this.sctext.substring(0,6) == '* any ')) { |
---|
[1594] | 623 | this.sctext = this.sctext.replace('* any ',''); |
---|
[1584] | 624 | } |
---|
[745] | 625 | if (uncompletequery){ |
---|
| 626 | this.sctext = ""; |
---|
| 627 | } |
---|
[647] | 628 | notifyUser(this.sctext); |
---|
[1584] | 629 | return this.sctext; |
---|
| 630 | |
---|
[615] | 631 | }, |
---|
| 632 | |
---|
[1177] | 633 | updatedata: function(term, is_category, category, value) { |
---|
[615] | 634 | |
---|
| 635 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
| 636 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
| 637 | |
---|
[1177] | 638 | if (term != undefined){ |
---|
| 639 | $('.focused','#searchclauselist').find('.index-input').val(term); |
---|
| 640 | searchclauseset.searchclauses[i][j].index = term.replace(" ","_"); |
---|
| 641 | } |
---|
[615] | 642 | |
---|
[1177] | 643 | if (value == undefined){ |
---|
| 644 | $('.focused','#searchclauselist').find('.value-input').focus(); |
---|
| 645 | } else { |
---|
| 646 | $('.focused','#searchclauselist').find('.value-input').val(value); |
---|
| 647 | searchclauseset.searchclauses[i][j].value = value; |
---|
| 648 | } |
---|
| 649 | |
---|
[615] | 650 | if (is_category) { |
---|
| 651 | searchclauseset.searchclauses[i][j].is_category = true; |
---|
| 652 | searchclauseset.searchclauses[i][j].category = category; |
---|
| 653 | } else { |
---|
| 654 | searchclauseset.searchclauses[i][j].is_category = false; |
---|
| 655 | } |
---|
| 656 | |
---|
[832] | 657 | }, |
---|
| 658 | |
---|
[1918] | 659 | initAutocomplete: function(is_explain) { |
---|
[832] | 660 | notifyUser("init autocomplete",'debug'); |
---|
| 661 | |
---|
| 662 | for (var i = this.searchclauses.length - 1; i > -1; i--){ |
---|
| 663 | for (var j = this.searchclauses[i].length - 1; j > -1; j--){ |
---|
[1918] | 664 | this.searchclauses[i][j].initAutocomplete(is_explain); |
---|
[832] | 665 | } |
---|
| 666 | } |
---|
[615] | 667 | } |
---|
| 668 | }; |
---|
[923] | 669 | |
---|
[1594] | 670 | function escapequerystring(querystring){ |
---|
| 671 | var arr = Query.simplequerystring(querystring); |
---|
| 672 | var sc, screl; |
---|
| 673 | var escape_string = ""; |
---|
| 674 | var add_bracket = false; |
---|
| 675 | |
---|
| 676 | //notifyUser(arr,'debug'); |
---|
| 677 | var arr_and = arr.split(" and "); |
---|
| 678 | screl = ""; |
---|
| 679 | for( var i=0;i<arr_and.length;i++){ |
---|
| 680 | var scstring = $.trim(arr_and[i]); |
---|
| 681 | |
---|
| 682 | add_bracket = false; |
---|
| 683 | if (scstring.substring(0,1) == "(" && scstring.substring(scstring.length-1) == ")") { |
---|
| 684 | scstring = scstring.substring(1,scstring.length-1); |
---|
| 685 | scstring = $.trim(scstring); |
---|
| 686 | escape_string = escape_string + "("; |
---|
| 687 | add_bracket = true; |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | //notifyUser("i:" + scstring,'debug'); |
---|
| 691 | var arr_or = scstring.split(" or "); |
---|
| 692 | if (i > 0) {screl = "and";} |
---|
| 693 | |
---|
| 694 | for( var j=0;j<arr_or.length;j++){ |
---|
| 695 | var scstr = $.trim(arr_or[j]); |
---|
| 696 | if (j > 0) {screl = "or";} |
---|
| 697 | |
---|
| 698 | sc = SearchClause.createFromData(scstr); |
---|
| 699 | if (screl != ""){ |
---|
| 700 | escape_string = escape_string + "%20" + screl + "%20"; |
---|
| 701 | } |
---|
| 702 | escape_string = escape_string + sc.escape(); |
---|
| 703 | } |
---|
| 704 | if (add_bracket){ |
---|
| 705 | escape_string = escape_string + ")"; |
---|
| 706 | } |
---|
| 707 | } |
---|
| 708 | return escape_string; |
---|
| 709 | } |
---|
| 710 | |
---|
[1664] | 711 | |
---|
| 712 | |
---|
| 713 | //autocomplete |
---|
[1866] | 714 | |
---|
| 715 | function findValueValue(e) { |
---|
| 716 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
| 717 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
| 718 | //alert(i+ ',' + j + sValue); |
---|
| 719 | var termsetitem = $('#' + 'sc' + i + '-' + j).find('.value-input').data('item'); |
---|
| 720 | var termset = ""; |
---|
| 721 | if (termsetitem != null) termset = termsetitem.key; |
---|
| 722 | searchclauseset.searchclauses[i][j].value = e.value; |
---|
| 723 | |
---|
| 724 | } |
---|
| 725 | function selectItemValue(li) { |
---|
| 726 | findValueValue(li); |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | function initValueAutocomplete(i,j,index, term_index){ |
---|
| 730 | |
---|
| 731 | $('#' + 'sc' + i + '-' + j).find('.value-input').autocomplete({ |
---|
| 732 | source: element_autocomplete[index].data[term_index].values, |
---|
| 733 | autoFill:true, |
---|
| 734 | width:150, |
---|
| 735 | minLength: 0, |
---|
| 736 | matchContains:true, |
---|
| 737 | delay: 0, |
---|
| 738 | select: function( event, ui ) { |
---|
| 739 | $(this).data("item", ui.item); |
---|
| 740 | selectItemValue(ui.item); |
---|
| 741 | } |
---|
| 742 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
| 743 | var t, re; |
---|
| 744 | if (this.term == ""){ |
---|
| 745 | t = item.value; |
---|
| 746 | } else { |
---|
| 747 | re = new RegExp(this.term + "+") ; |
---|
| 748 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
| 749 | this.term + |
---|
| 750 | "</span>"); |
---|
| 751 | } |
---|
[1664] | 752 | |
---|
[1866] | 753 | return $( "<li></li>" ) |
---|
| 754 | .data( "item.autocomplete", item ) |
---|
| 755 | .append( "<a>" + t + "</a>" ) |
---|
| 756 | .appendTo( ul ); |
---|
| 757 | }; |
---|
| 758 | |
---|
| 759 | |
---|
| 760 | // reset the index value |
---|
| 761 | $('#' + 'sc' + i + '-' + j).find('.value-input').val(""); |
---|
| 762 | searchclauseset.searchclauses[i][j].value = ""; |
---|
| 763 | $('#' + 'sc' + i + '-' + j).find('.value-input').show(); |
---|
| 764 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
| 765 | |
---|
| 766 | |
---|
| 767 | $('.focused','#searchclauselist').find('.value-input').focus(); |
---|
| 768 | |
---|
| 769 | |
---|
| 770 | }; |
---|
[1918] | 771 | function initValueAutocompleteExplain(i,j,index, term_index){ |
---|
| 772 | |
---|
| 773 | // reset the index value |
---|
| 774 | $('#' + 'sc' + i + '-' + j).find('.value-input').val(""); |
---|
| 775 | searchclauseset.searchclauses[i][j].value = ""; |
---|
| 776 | $('#' + 'sc' + i + '-' + j).find('.value-input').show(); |
---|
| 777 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
| 778 | |
---|
| 779 | |
---|
| 780 | $('.focused','#searchclauselist').find('.value-input').focus(); |
---|
[1866] | 781 | |
---|
[1918] | 782 | |
---|
| 783 | }; |
---|
| 784 | |
---|
[1664] | 785 | function findValueTerm(e) { |
---|
[1918] | 786 | |
---|
| 787 | //var sValue = e.selectValue; |
---|
| 788 | |
---|
| 789 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
| 790 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
| 791 | //alert(i+ ',' + j + sValue); |
---|
| 792 | var sClause = $('#' + 'sc' + i + '-' + j); |
---|
| 793 | var context = ""; |
---|
| 794 | var termsetitem = $(sClause).find('.index-input-termset').data('item'); |
---|
| 795 | var termset = ""; |
---|
| 796 | if (termsetitem != null) termset = termsetitem.key; |
---|
| 797 | var str = e.id; |
---|
| 798 | str = str.substring(str.lastIndexOf('/')+1, str.length); |
---|
| 799 | var termsetindex = termset + ":" + str; |
---|
| 800 | searchclauseset.searchclauses[i][j].index = termsetindex; |
---|
| 801 | |
---|
| 802 | //handleTermsSelection(i,j,sValue); |
---|
| 803 | //find element value |
---|
| 804 | |
---|
| 805 | var index; |
---|
| 806 | $.each(element_autocomplete,function(i, item){ |
---|
| 807 | if (this.key == termset){ |
---|
| 808 | index = i; |
---|
| 809 | return; |
---|
| 810 | } |
---|
| 811 | }); |
---|
| 812 | var term_index; |
---|
| 813 | |
---|
| 814 | $.each(element_autocomplete[index].data,function(i, item){ |
---|
| 815 | if (this.id == e.id){ |
---|
| 816 | term_index = i; |
---|
| 817 | return; |
---|
| 818 | } |
---|
| 819 | }); |
---|
| 820 | if (element_autocomplete[index].data[term_index].values.length == 0){ |
---|
| 821 | jQuery.get(link('fcs','?operation=scan&scanClause' + termsetindex + '&x-context=' + getSelectedRepository()),function(data){ |
---|
| 822 | $(data).find("sru\\:term").each(function(i){ |
---|
| 823 | element_autocomplete[index].data[term_index].values[i] = {label:$(this).find('sru\\:value').text()}; |
---|
| 824 | }); |
---|
| 825 | initValueAutocomplete(i,j, index, term_index); |
---|
| 826 | }); |
---|
| 827 | } else { |
---|
| 828 | initValueAutocomplete(i,j, index, term_index); |
---|
| 829 | } |
---|
[1664] | 830 | } |
---|
[1918] | 831 | function findValueTermExplain(e) { |
---|
| 832 | |
---|
| 833 | //var sValue = e.selectValue; |
---|
| 834 | |
---|
| 835 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
| 836 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
| 837 | //alert(i+ ',' + j + sValue); |
---|
| 838 | var sClause = $('#' + 'sc' + i + '-' + j); |
---|
| 839 | var context = ""; |
---|
| 840 | var termsetitem = $(sClause).find('.index-input-termset').data('item'); |
---|
| 841 | var termset = ""; |
---|
| 842 | if (termsetitem != null) termset = termsetitem.key; |
---|
| 843 | var str = e.id; |
---|
| 844 | str = str.substring(str.lastIndexOf('/')+1, str.length); |
---|
| 845 | var termsetindex = termset + ":" + str; |
---|
| 846 | searchclauseset.searchclauses[i][j].index = termsetindex; |
---|
| 847 | |
---|
| 848 | //find element value |
---|
| 849 | |
---|
| 850 | var index; |
---|
| 851 | $.each(element_autocomplete_explain,function(i, item){ |
---|
| 852 | if (this.key == termset){ |
---|
| 853 | index = i; |
---|
| 854 | return; |
---|
| 855 | } |
---|
| 856 | }); |
---|
| 857 | var term_index; |
---|
| 858 | |
---|
| 859 | $.each(element_autocomplete_explain[index].data,function(i, item){ |
---|
| 860 | if (this.id == e.id){ |
---|
| 861 | term_index = i; |
---|
| 862 | return; |
---|
| 863 | } |
---|
| 864 | }); |
---|
| 865 | if (element_autocomplete_explain[index].data[term_index].values.length == 0){ |
---|
| 866 | jQuery.get(link('fcs','?operation=scan&scanClause' + termsetindex + '&x-context=' + getSelectedRepository()),function(data){ |
---|
| 867 | $(data).find("sru\\:term").each(function(i){ |
---|
| 868 | element_autocomplete[index].data[term_index].values[i] = {label:$(this).find('sru\\:value').text()}; |
---|
| 869 | }); |
---|
| 870 | initValueAutocompleteExplain(i,j, index, term_index); |
---|
| 871 | }); |
---|
| 872 | } else { |
---|
| 873 | initValueAutocompleteExplain(i,j, index, term_index); |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | |
---|
[1664] | 877 | function selectItemTerm(li) { |
---|
[1918] | 878 | findValueTerm(li); |
---|
| 879 | } |
---|
| 880 | function selectItemTermExplain(li) { |
---|
| 881 | findValueTermExplain(li); |
---|
| 882 | } |
---|
[1664] | 883 | |
---|
[1681] | 884 | function initTermsetAutocomplete(i,j,index){ |
---|
[1664] | 885 | |
---|
[1681] | 886 | $('#' + 'sc' + i + '-' + j).find('.index-input').autocomplete({ |
---|
| 887 | source: element_autocomplete[index].data, |
---|
[1664] | 888 | autoFill:true, |
---|
[1681] | 889 | width:150, |
---|
| 890 | minLength: 0, |
---|
| 891 | matchContains:true, |
---|
| 892 | delay: 0, |
---|
| 893 | select: function( event, ui ) { |
---|
| 894 | $(this).data("item", ui.item); |
---|
| 895 | selectItemTerm(ui.item); |
---|
[1918] | 896 | } |
---|
[1681] | 897 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
| 898 | var t, re; |
---|
| 899 | if (this.term == ""){ |
---|
| 900 | t = item.value; |
---|
| 901 | } else { |
---|
| 902 | re = new RegExp(this.term + "+") ; |
---|
| 903 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
| 904 | this.term + |
---|
| 905 | "</span>"); |
---|
| 906 | } |
---|
[1918] | 907 | |
---|
| 908 | return $( "<li></li>" ) |
---|
| 909 | .data( "item.autocomplete", item ) |
---|
| 910 | .append( "<a>" + t + "</a>" ) |
---|
| 911 | .appendTo( ul ); |
---|
[1866] | 912 | }; |
---|
[1681] | 913 | |
---|
[1918] | 914 | |
---|
| 915 | // reset the index value |
---|
[1664] | 916 | $('#' + 'sc' + i + '-' + j).find('.index-input').val(""); |
---|
| 917 | searchclauseset.searchclauses[i][j].index = ""; |
---|
[1918] | 918 | $('#' + 'sc' + i + '-' + j).find('.value-input').val(""); |
---|
| 919 | searchclauseset.searchclauses[i][j].value = ""; |
---|
[1664] | 920 | $('#' + 'sc' + i + '-' + j).find('.index-input').show(); |
---|
| 921 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
| 922 | |
---|
[1681] | 923 | |
---|
| 924 | $('.focused','#searchclauselist').find('.index-input').focus(); |
---|
[1918] | 925 | }; |
---|
| 926 | function initTermsetAutocompleteExplain(i,j,index){ |
---|
[1681] | 927 | |
---|
[1918] | 928 | $('#' + 'sc' + i + '-' + j).find('.index-input').autocomplete({ |
---|
| 929 | source: element_autocomplete_explain[index].data, |
---|
| 930 | autoFill:true, |
---|
| 931 | width:150, |
---|
| 932 | minLength: 0, |
---|
| 933 | matchContains:true, |
---|
| 934 | delay: 0, |
---|
| 935 | select: function( event, ui ) { |
---|
| 936 | $(this).data("item", ui.item); |
---|
| 937 | selectItemTermExplain(ui.item); |
---|
| 938 | } |
---|
| 939 | }).data( "autocomplete" )._renderItem = function( ul, item ) { |
---|
| 940 | var t, re; |
---|
| 941 | if (this.term == ""){ |
---|
| 942 | t = item.value; |
---|
| 943 | } else { |
---|
| 944 | re = new RegExp(this.term + "+") ; |
---|
| 945 | t = item.value.replace(re,"<span style='font-weight:bold;color:Blue;'>" + |
---|
| 946 | this.term + |
---|
| 947 | "</span>"); |
---|
| 948 | } |
---|
[1681] | 949 | |
---|
[1918] | 950 | return $( "<li></li>" ) |
---|
| 951 | .data( "item.autocomplete", item ) |
---|
| 952 | .append( "<a>" + t + "</a>" ) |
---|
| 953 | .appendTo( ul ); |
---|
| 954 | }; |
---|
[1664] | 955 | |
---|
[1918] | 956 | |
---|
| 957 | // reset the index value |
---|
| 958 | $('#' + 'sc' + i + '-' + j).find('.index-input').val(""); |
---|
| 959 | searchclauseset.searchclauses[i][j].index = ""; |
---|
| 960 | $('#' + 'sc' + i + '-' + j).find('.index-input').show(); |
---|
| 961 | $('body').find('.ac_results').css({'z-index' : '1000'}); |
---|
| 962 | |
---|
| 963 | |
---|
| 964 | $('.focused','#searchclauselist').find('.index-input').focus(); |
---|
[1664] | 965 | }; |
---|
| 966 | |
---|
[1918] | 967 | |
---|
[1681] | 968 | function findValueTermset(elem) { |
---|
| 969 | //var sValue = e.selectValue; |
---|
[1918] | 970 | |
---|
[1664] | 971 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
| 972 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
[1918] | 973 | |
---|
[1664] | 974 | //searchclauseset.searchclauses[i][j].index = sValue; |
---|
[1681] | 975 | //handleTermsetSelection(i,j,sValue); |
---|
[1918] | 976 | |
---|
[1681] | 977 | //find element |
---|
| 978 | var index; |
---|
| 979 | $.each(element_autocomplete,function(i, item){ |
---|
| 980 | if (this.key == elem.key){ |
---|
| 981 | index = i; |
---|
| 982 | return; |
---|
| 983 | } |
---|
| 984 | }); |
---|
[1918] | 985 | |
---|
[1681] | 986 | if (element_autocomplete[index].data.length == 0){ |
---|
| 987 | jQuery.get(link('smc','list/?context=' + element_autocomplete[index].key),function(data){ |
---|
| 988 | $(data).find('Term').each(function(i){ |
---|
[1866] | 989 | element_autocomplete[index].data[i] = {label:$(this).text(), value:$(this).text(), id:$(this).attr("concept-id"),values:[] }; |
---|
[1681] | 990 | }); |
---|
| 991 | initTermsetAutocomplete(i,j, index); |
---|
| 992 | }); |
---|
| 993 | } else { |
---|
| 994 | initTermsetAutocomplete(i,j, index); |
---|
| 995 | } |
---|
[1918] | 996 | } |
---|
| 997 | function findValueTermsetExplain(elem) { |
---|
[1681] | 998 | |
---|
[1918] | 999 | var i = $('.focused','#searchclauselist').closest('.sc-i').attr("id"); |
---|
| 1000 | var j = $('.focused','#searchclauselist').closest('.sc-j').attr("id"); |
---|
| 1001 | |
---|
| 1002 | //find element |
---|
| 1003 | var index; |
---|
| 1004 | $.each(element_autocomplete_explain,function(i, item){ |
---|
| 1005 | if (this.key == elem.key){ |
---|
| 1006 | index = i; |
---|
| 1007 | return; |
---|
| 1008 | } |
---|
| 1009 | }); |
---|
| 1010 | |
---|
| 1011 | if (element_autocomplete_explain[index].data.length == 0){ |
---|
| 1012 | jQuery.get(link('fcs','?operation=explain&x-context=' + getSelectedRepository()),function(data){ |
---|
| 1013 | $(data).find('indexInfo').children('index').children('map').children('name[set='+ element_autocomplete_explain[index].key +']').each(function(i){ |
---|
| 1014 | element_autocomplete_explain[index].data[i] = {label:$(this).text(), value:$(this).text(), id:$(this).text(),values:[] }; |
---|
| 1015 | }); |
---|
| 1016 | initTermsetAutocompleteExplain(i,j, index); |
---|
| 1017 | }); |
---|
| 1018 | } else { |
---|
| 1019 | initTermsetAutocompleteExplain(i,j, index); |
---|
| 1020 | } |
---|
| 1021 | |
---|
[1664] | 1022 | } |
---|
[1918] | 1023 | |
---|
| 1024 | |
---|
[1664] | 1025 | function selectItemTermset(li) { |
---|
| 1026 | findValueTermset(li); |
---|
[1918] | 1027 | } |
---|
| 1028 | function selectItemTermsetExplain(li) { |
---|
| 1029 | findValueTermsetExplain(li); |
---|
| 1030 | } |
---|
[1681] | 1031 | |
---|