1 | // main js-code |
---|
2 | |
---|
3 | var jsonw; |
---|
4 | var params; |
---|
5 | |
---|
6 | var actions = { |
---|
7 | base: { |
---|
8 | base_uri: "/MDService2/" |
---|
9 | }, |
---|
10 | collections: { |
---|
11 | base_uri: "/MDService2/collections/", |
---|
12 | current:'olac'}, |
---|
13 | elements: { |
---|
14 | base_uri: "/MDService2/element/", |
---|
15 | current:''}, |
---|
16 | terms: { |
---|
17 | base_uri: "/MDService2/terms/", |
---|
18 | current:'all', |
---|
19 | maxdepth: 8}, |
---|
20 | terms_autocomplete: { |
---|
21 | base_uri: "/MDService2/terms/", |
---|
22 | current:''}, |
---|
23 | components: { |
---|
24 | base_uri: "/MDService2/comp/", |
---|
25 | current:''}, |
---|
26 | /* current:'cmdi-corpus-aac2'}, */ |
---|
27 | compprofiles: { |
---|
28 | base_uri: "/MDService2/compprofile/", |
---|
29 | current:''}, |
---|
30 | /* current:'cmdi-corpus-aac2'}, */ |
---|
31 | |
---|
32 | recordset: { |
---|
33 | base_uri: "/MDService2/recordset/" |
---|
34 | }, |
---|
35 | |
---|
36 | isocat: { |
---|
37 | base_uri: "/MDService2/datcats/", |
---|
38 | current:5 |
---|
39 | } |
---|
40 | |
---|
41 | }; |
---|
42 | |
---|
43 | |
---|
44 | $(function(){ |
---|
45 | |
---|
46 | init(); |
---|
47 | loadWelcomeMessage(); |
---|
48 | // Collections and terms loaded after WorkspaceProfile is loaded |
---|
49 | loadWorkspaceProfiles(); |
---|
50 | //loadCollections(); |
---|
51 | //loadTerms(); |
---|
52 | //handleQueryInput(); |
---|
53 | |
---|
54 | loadComponentsRegistry(); |
---|
55 | loadDCR(); |
---|
56 | |
---|
57 | handleBubble(); |
---|
58 | |
---|
59 | addFunctionality(); |
---|
60 | addVisuals(); |
---|
61 | |
---|
62 | //queryuriparams loaded after collections and workspaceprofile are loaded |
---|
63 | //loadQueryFromUriParams(); |
---|
64 | |
---|
65 | }); |
---|
66 | |
---|
67 | |
---|
68 | function init () { |
---|
69 | |
---|
70 | // turn on debugging (see jquery.xslTransform.js) |
---|
71 | var DEBUG = false; |
---|
72 | |
---|
73 | // check for jQuery and Sarissa |
---|
74 | try{ |
---|
75 | jQuery; |
---|
76 | }catch(e){ |
---|
77 | alert('You need to include jQuery!'); |
---|
78 | } |
---|
79 | |
---|
80 | ////////////// |
---|
81 | params = getUrlVars(); |
---|
82 | createSearchClauses(); |
---|
83 | |
---|
84 | createInfos(); |
---|
85 | } |
---|
86 | |
---|
87 | function createInfos(){ |
---|
88 | var info = "<span class='cmd cmd-info'></span>"; |
---|
89 | $('.cmds-ui-block').children('.header').append(info); |
---|
90 | |
---|
91 | $('.cmds-ui-block').children('.header').children('.cmd-info').click(function(){ |
---|
92 | var a = $(this).parent().next().attr('id'); |
---|
93 | var uri = window.location.pathname + "static/info.xml"; |
---|
94 | $.get(uri,{"id":a}, showDetail,'html'); |
---|
95 | return false; |
---|
96 | }); |
---|
97 | } |
---|
98 | |
---|
99 | function update (uri, src_container, target_container,handler) { |
---|
100 | notifyUser("update-uri:" + uri,'debug'); |
---|
101 | $(target_container).load(uri, handler ); |
---|
102 | } |
---|
103 | // TODO multiple collections |
---|
104 | function submit_query (columns, query, squery, ws) { |
---|
105 | notifyUser("processing query"); |
---|
106 | |
---|
107 | if (jQuery.trim(query).length == 0){ |
---|
108 | query = null; |
---|
109 | } |
---|
110 | if (jQuery.trim(squery).length == 0){ |
---|
111 | squery = null; |
---|
112 | } |
---|
113 | |
---|
114 | var q = new Query(collections, columns, query, squery); //actions.collections.current, query ); |
---|
115 | q.repository = getSelectedRepository(); |
---|
116 | if (ws) { |
---|
117 | q.options = "withSummary"; |
---|
118 | } |
---|
119 | notifyUser("submit_query:" + q.query_uri(),'debug'); |
---|
120 | queryset.addquery(q); |
---|
121 | //notifyUser("container" + q.container.attr('id')); |
---|
122 | //$("#querylist").append("sdfdsf"); |
---|
123 | } |
---|
124 | |
---|
125 | /* OBSOLETE? */ |
---|
126 | function handle_result (data, textStatus) { |
---|
127 | try { |
---|
128 | $(this).text("done"); |
---|
129 | //$(this).html(data); |
---|
130 | notifyUser("query processed:" + textStatus); |
---|
131 | } catch (e) { |
---|
132 | notifyUser(e,'debug'); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | function showNotifyMessages(){ |
---|
138 | try { |
---|
139 | $('#notify-float').html($('#notify').html()); |
---|
140 | var title = "Notify - Messages"; |
---|
141 | $('#notify-float').dialog( "option", "title", title ); |
---|
142 | |
---|
143 | //ui-state-default |
---|
144 | $('#notify-float').dialog('open'); |
---|
145 | $('#notify-float').siblings('div.ui-dialog-titlebar').addClass('ui-state-default'); |
---|
146 | $('#notify-float').siblings('div.ui-dialog-titlebar').children().remove(); |
---|
147 | var x = '<span class="cmd cmd_del ui-dialog-titlebar-del "/><span class="cmd cmd_up ui-dialog-titlebar-up"/><span>' + title +'</span>'; |
---|
148 | $('#notify-float').siblings('div.ui-dialog-titlebar').prepend(x); |
---|
149 | |
---|
150 | } catch (e) { |
---|
151 | notifyUser(e,'debug'); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | function showDetail(_data, textStatus, xmlhttpreq) { |
---|
156 | try { |
---|
157 | var data = _data; |
---|
158 | var blankdata = "<html><\html>"; |
---|
159 | |
---|
160 | if (xmlhttpreq.responseXML != null){ |
---|
161 | var isinfo = xmlhttpreq.responseXML.baseURI.split("/static/info.xml?id="); |
---|
162 | if (isinfo != "undefined"){ |
---|
163 | if ( isinfo.length = 2){ |
---|
164 | var infoid = new RegExp('[\\?]id=([^&#]*)').exec(xmlhttpreq.responseXML.baseURI); |
---|
165 | infoid = infoid[1] || 0; |
---|
166 | infoid = infoid + "-info"; |
---|
167 | data = $(_data).find('#' + infoid); |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | if (data == null){ |
---|
173 | var title = ""; |
---|
174 | $('#detail-float').html(blankdata); |
---|
175 | |
---|
176 | if ( $('#detail-float').dialog("isOpen")) { |
---|
177 | var up = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-titlebar-up'); |
---|
178 | up.removeClass('.cmd_up .ui-dialog-titlebar-up'); |
---|
179 | up.addClass('.cmd_get .ui-dialog-titlebar-get'); |
---|
180 | var down = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-titlebar-down'); |
---|
181 | down.removeClass('.cmd_down .ui-dialog-titlebar-down'); |
---|
182 | down.addClass('.cmd_get .ui-dialog-titlebar-get'); |
---|
183 | |
---|
184 | $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-title').text(title); |
---|
185 | } else { |
---|
186 | $('#detail-float').dialog('open'); |
---|
187 | $('#detail-float').siblings('div.ui-dialog-titlebar').addClass('ui-state-default'); |
---|
188 | $('#detail-float').siblings('div.ui-dialog-titlebar').children().remove(); |
---|
189 | var x = '<span class="cmd cmd_del ui-dialog-titlebar-del "/><span class="cmd cmd_get ui-dialog-titlebar-get"/><span class="ui-dialog-title">' + "" +'</span>'; |
---|
190 | $('#detail-float').siblings('div.ui-dialog-titlebar').prepend(x); |
---|
191 | |
---|
192 | } |
---|
193 | |
---|
194 | } else |
---|
195 | { |
---|
196 | $('#detail-float').html(data); |
---|
197 | var title = $('#detail-float').find('.inner_title').attr("value"); |
---|
198 | $('#detail-float').dialog( "option", "title", title ); |
---|
199 | |
---|
200 | if ( $('#detail-float').dialog("isOpen")) { |
---|
201 | var get = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.cmd_get'); |
---|
202 | get.removeClass('cmd_get'); |
---|
203 | get.removeClass('ui-dialog-titlebar-get'); |
---|
204 | get.addClass('cmd_up'); |
---|
205 | get.addClass('ui-dialog-titlebar-up'); |
---|
206 | |
---|
207 | $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-title').text(title); |
---|
208 | } else { |
---|
209 | //ui-state-default |
---|
210 | $('#detail-float').dialog('open'); |
---|
211 | $('#detail-float').siblings('div.ui-dialog-titlebar').addClass('ui-state-default'); |
---|
212 | $('#detail-float').siblings('div.ui-dialog-titlebar').children().remove(); |
---|
213 | var x = '<span class="cmd cmd_del ui-dialog-titlebar-del "/><span class="cmd cmd_up ui-dialog-titlebar-up"/><span class="ui-dialog-title">' + title +'</span>'; |
---|
214 | $('#detail-float').siblings('div.ui-dialog-titlebar').prepend(x); |
---|
215 | |
---|
216 | notifyUser("query processed:" + textStatus); |
---|
217 | } |
---|
218 | } |
---|
219 | } catch (e) { |
---|
220 | notifyUser(e,'debug'); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | function showDetail2(data, textStatus) { |
---|
225 | try { |
---|
226 | //notifyUser("receiving data:",'debug'); |
---|
227 | //notifyUser(data,'debug'); |
---|
228 | $('#detail').html(data); |
---|
229 | //$(this).html(data); |
---|
230 | |
---|
231 | notifyUser("query processed:" + textStatus); |
---|
232 | $("#detail .treeview").treeview({ |
---|
233 | animated: "fast", |
---|
234 | collapsed: true |
---|
235 | }); |
---|
236 | |
---|
237 | } catch (e) { |
---|
238 | notifyUser(e,'debug'); |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | function getNotifyMessagesText(){ |
---|
243 | var text = ""; |
---|
244 | for(var i=0;i<notify_messages.length;i++){ |
---|
245 | text = text + "/n" + notify_messages[i].getText(); |
---|
246 | } |
---|
247 | return text; |
---|
248 | } |
---|
249 | function notifyUser (msg) { |
---|
250 | var notifymessage = new NotifyMessage(new Date(),msg); |
---|
251 | notifyset.add(notifymessage); |
---|
252 | //notify_messages[notify_messages.length] = new NotifyMessage( new Date(),msg); |
---|
253 | //$('#notify').text(msg); |
---|
254 | //$('#notify').text(getNotifyMessagesText()); |
---|
255 | //$('#notify-all').find('textarea').attr("value",$('#notify-all').find('textarea').attr("value") + '\n' + msg); |
---|
256 | } |
---|
257 | |
---|
258 | function notifyUser (msg, type) { |
---|
259 | |
---|
260 | if (type=='debug' & !(typeof console == "undefined")) { |
---|
261 | console.log(msg); |
---|
262 | } else { |
---|
263 | var notifymessage = new NotifyMessage(new Date(),msg); |
---|
264 | notifyset.add(notifymessage); |
---|
265 | //notify_messages[notify_messages.length] = new NotifyMessage(new Date(),msg); |
---|
266 | //$('#notify').text(msg); |
---|
267 | //$('#notify').text(getNotifyMessagesText()); |
---|
268 | //$('#notify-all').find('textarea').attr("value",$('#notify-all').find('textarea').attr("value") + '\n' + msg); |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | |
---|
273 | |
---|
274 | function addToQuerylist (x) { |
---|
275 | $("#querylist").prepend(x); |
---|
276 | } |
---|
277 | |
---|
278 | function addToNotifylist (x) { |
---|
279 | $("#notifylist").prepend(x); |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | function addToSClist (div, i, j, rel) { |
---|
284 | |
---|
285 | var x; |
---|
286 | |
---|
287 | //notifyUser(i + "," + j + "," + rel); |
---|
288 | if (rel == ""){ |
---|
289 | x = $('<div />').addClass("sc-i").addClass("and_level"); |
---|
290 | $(div).appendTo($(x).appendTo($('#searchclauselist'))); |
---|
291 | $(x).attr("id",i); |
---|
292 | } else { |
---|
293 | if (rel == "and") { |
---|
294 | x = $('<div />').addClass("sc-i").addClass("and_level"); |
---|
295 | $(x).attr("id",i); |
---|
296 | $(div).appendTo($(x).appendTo($('#searchclauselist'))); |
---|
297 | } else { |
---|
298 | $(div).appendTo($('#searchclauselist').children()[i]); |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | //$('#searchclauselist').append($(li)); |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | var last_bubble_uri; |
---|
307 | |
---|
308 | |
---|
309 | function showBubble (elem) { |
---|
310 | //get the position of the placeholder element |
---|
311 | notifyUser($(elem),'debug'); |
---|
312 | var pos = $(elem).offset(); |
---|
313 | var width = $(elem).width(); |
---|
314 | //show the menu directly over the placeholder |
---|
315 | //notifyUser(pos + width,'debug'); |
---|
316 | $("#bubble").css( { "left": (pos.left + width) + "px", "top":pos.top + "px" } ); |
---|
317 | $("#bubble").show(); |
---|
318 | } |
---|
319 | |
---|
320 | function link(action,format,params) { |
---|
321 | var l = actions[action].base_uri + format; |
---|
322 | |
---|
323 | // default param is q |
---|
324 | if (params){ |
---|
325 | if ( ! $.isArray(params)) { |
---|
326 | l += '/' + params; |
---|
327 | } else { |
---|
328 | l += '?' + $.param(params); |
---|
329 | } |
---|
330 | } |
---|
331 | notifyUser("l:"+ l,'debug'); |
---|
332 | return l; |
---|
333 | } |
---|
334 | |
---|
335 | function preprocessJSON(json){ |
---|
336 | |
---|
337 | if (json["WorkspaceProfile"].Querysets[0] == undefined){ |
---|
338 | var jj = json["WorkspaceProfile"]["Querysets"]["item"]; |
---|
339 | delete json["WorkspaceProfile"]["Querysets"]["item"]; |
---|
340 | json["WorkspaceProfile"]["Querysets"] = [{}]; |
---|
341 | json["WorkspaceProfile"]["Querysets"][0] = jj; |
---|
342 | } |
---|
343 | if (String(json["WorkspaceProfile"]["Querysets"]) != "null") { |
---|
344 | |
---|
345 | $.each(json["WorkspaceProfile"]["Querysets"], function(i,item) { |
---|
346 | if (this.Queries[0] == undefined){ |
---|
347 | var jj = this["Queries"]["item"]; |
---|
348 | delete this["Queries"]["item"]; |
---|
349 | this.Queries = [{}]; |
---|
350 | this.Queries[0] = jj; |
---|
351 | } |
---|
352 | }); |
---|
353 | |
---|
354 | $.each(json["WorkspaceProfile"]["Querysets"], function(i,item){ |
---|
355 | if (String(this.Queries) != "null") { |
---|
356 | $.each(this.Queries, function(i,item){ |
---|
357 | if (this.collections != "null") { |
---|
358 | if (this.collections[0] == undefined){ |
---|
359 | var jj = this["collections"]["item"]; |
---|
360 | delete this["collections"]["item"]; |
---|
361 | this.collections = [{}]; |
---|
362 | this.collections[0] = jj; |
---|
363 | } |
---|
364 | } |
---|
365 | if (this.columns != "null") { |
---|
366 | if (this.columns[0] == undefined){ |
---|
367 | var jj = this["columns"]["item"]; |
---|
368 | delete this["columns"]["item"]; |
---|
369 | this.columns = [{}]; |
---|
370 | this.columns[0] = jj; |
---|
371 | } |
---|
372 | } |
---|
373 | }); |
---|
374 | } |
---|
375 | }); |
---|
376 | } |
---|
377 | |
---|
378 | return json; |
---|
379 | |
---|
380 | } |
---|
381 | function appendQueryUI(json,i, qs){ |
---|
382 | var del = ''; |
---|
383 | var name = ''; |
---|
384 | //var ul; |
---|
385 | var id = $(qs).parent().attr('id'); |
---|
386 | |
---|
387 | /* |
---|
388 | if ($(qs).find('ul').size() == 0) { |
---|
389 | ul = $('<ul></ul>'); |
---|
390 | $(ul).appendTo($(qs)); |
---|
391 | } else { |
---|
392 | ul = $(qs).children('ul'); |
---|
393 | } |
---|
394 | |
---|
395 | var x = '<li><span class="query_detail_caller" ><a href="'+id + '_'+ i+'" >' + |
---|
396 | Query.fullformatstring(json) + '</a></span><span class="cmd cmd_load"></span>' + |
---|
397 | del + |
---|
398 | '<div class="term_detail" >' + |
---|
399 | '<ul><li><div class="elem text"><span class="elem_name">query:<span><span class="elem_value">' + Query.simplequerystring(json.querystring)+ |
---|
400 | '</span></div></li><li><div class="elem text"><span class="elem_name">collections:</span><span class="elem_value">' + Query.collectiontext(json) + '</span></div></li></ul></div></li>'; |
---|
401 | */ |
---|
402 | |
---|
403 | if (id == 'userqs') { |
---|
404 | del = '<span class="cmd cmd_del" ><xsl:text> </xsl:text></span>'; |
---|
405 | name = '<div class="cmds-elem-prop"><span class="label">name:</span><input type="text" class="input-name" value="' + json.name + '"></div>'; |
---|
406 | } else { |
---|
407 | name = '<div class="cmds-elem-prop"><span class="label">name:</span><span class="value">' + json.name + |
---|
408 | '</span></div>'; |
---|
409 | } |
---|
410 | var x = '<div class="cmds-elem-plus" ><span class="cmd cmd_load"></span><span class="detail-caller" ><a href="'+id + '_'+ i+'" >' + |
---|
411 | json.name + '</a></span>' + |
---|
412 | del + |
---|
413 | '<div class="detail" >' + |
---|
414 | name + |
---|
415 | '<div class="cmds-elem-prop"><span class="label">squery:</span><span class="value">' + json.squerystring + |
---|
416 | '</span></div>' + |
---|
417 | '<div class="cmds-elem-prop"><span class="label">query:</span><span class="value">' + Query.simplequerystring(json.querystring) + |
---|
418 | '</span></div><div class="cmds-elem-prop"><span class="label">collections:</span><span class="value">' + Query.collectiontext(json) + '</span></div>' + |
---|
419 | '</div>'; |
---|
420 | |
---|
421 | $(qs).append(x); |
---|
422 | |
---|
423 | |
---|
424 | $(qs).find('.input-name').keydown(function(ev){ |
---|
425 | var evStop = function(){ |
---|
426 | ev.stopPropagation(); |
---|
427 | ev.preventDefault(); |
---|
428 | }; |
---|
429 | if (ev.which === 13) { |
---|
430 | var id = parseInt( $("#qts_select option:selected").val()); |
---|
431 | $(this).parent().parent().parent().find('a').text($(this).val()); |
---|
432 | var str = $(this).parent().parent().parent().find('a').attr("href"); |
---|
433 | var iq = parseInt(str.substring(7)); |
---|
434 | |
---|
435 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq].name = $(this).val(); |
---|
436 | saveWorkspace("USER"); |
---|
437 | evStop(); |
---|
438 | } |
---|
439 | }); |
---|
440 | } |
---|
441 | |
---|
442 | function createQueriesUI(json, qs){ |
---|
443 | $(qs).children().remove(); |
---|
444 | if (json.Queries != "null") { |
---|
445 | $.each(json.Queries, function(i,item) { |
---|
446 | if (this != "null"){ |
---|
447 | appendQueryUI(this,i, qs); |
---|
448 | } |
---|
449 | }); |
---|
450 | } |
---|
451 | |
---|
452 | } |
---|
453 | |
---|
454 | function loadRepositories(json) { |
---|
455 | |
---|
456 | var $select; |
---|
457 | $select = $('#repositories_select'); |
---|
458 | |
---|
459 | |
---|
460 | $select.find("option").remove(); |
---|
461 | |
---|
462 | if (String(json) != "null") { |
---|
463 | |
---|
464 | $.each(json, function(i,item) { |
---|
465 | $select.append(new Option(this.name, this.id)); |
---|
466 | }); |
---|
467 | |
---|
468 | } |
---|
469 | // select first |
---|
470 | if (params["repository"] != undefined){ |
---|
471 | var r = parseInt(params["repository"])-1; |
---|
472 | $($select.find("option")[r]).attr("selected","true"); |
---|
473 | } else { |
---|
474 | $select.find("option").first().attr("selected","true"); |
---|
475 | } |
---|
476 | |
---|
477 | |
---|
478 | $select.change(function(data){ |
---|
479 | loadCollections(false); |
---|
480 | //loadTerms(); |
---|
481 | handleQueryInput(); |
---|
482 | $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository()); |
---|
483 | }); |
---|
484 | |
---|
485 | } |
---|
486 | |
---|
487 | function getSelectedRepository(){ |
---|
488 | //var id = parseInt($('#repositories_select').find("option:selected").val()); |
---|
489 | return $('#repositories_select').find("option:selected").val(); |
---|
490 | |
---|
491 | } |
---|
492 | |
---|
493 | function loadQuerysets(json, type) { |
---|
494 | |
---|
495 | var $select; |
---|
496 | if (type == "user") { |
---|
497 | $select = $('#qts_select'); |
---|
498 | } else { |
---|
499 | $select = $('#serverqts_select'); |
---|
500 | } |
---|
501 | |
---|
502 | $select.find("option").remove(); |
---|
503 | |
---|
504 | if (String(json) != "null") { |
---|
505 | |
---|
506 | $.each(json, function(i,item) { |
---|
507 | //notifyUser(i + ',' + this.name + ',' + this.created,'debug'); |
---|
508 | $select.append(new Option(this.name, i)); |
---|
509 | }); |
---|
510 | |
---|
511 | |
---|
512 | // find id of selected |
---|
513 | if ($select.find("option").size() > 0) { |
---|
514 | $select.find("option").first().attr("selected","true"); |
---|
515 | var id = parseInt($select.find("option:selected").val()); |
---|
516 | var jsonq = json[id]; |
---|
517 | |
---|
518 | if (type == "user") { |
---|
519 | $('#qts_input').val(jsonq["name"]); |
---|
520 | qs = $("#userqueries"); |
---|
521 | } else { |
---|
522 | qs = $("#serverqueries"); |
---|
523 | } |
---|
524 | createQueriesUI(jsonq, qs); |
---|
525 | } |
---|
526 | |
---|
527 | $select.change(function(data){ |
---|
528 | if ($select.find("option").size() > 0) { |
---|
529 | // find id of selected |
---|
530 | var id = parseInt($select.find("option:selected").val()); |
---|
531 | var jsonq = json[id]; |
---|
532 | |
---|
533 | if (type == "user") { |
---|
534 | $('#qts_input').val(jsonq["name"]); |
---|
535 | qs = $("#userqueries"); |
---|
536 | } else { |
---|
537 | qs = $("#serverqueries"); |
---|
538 | } |
---|
539 | createQueriesUI(jsonq, qs); |
---|
540 | |
---|
541 | /* $('#qs_select').find("option").remove(); |
---|
542 | |
---|
543 | if (String(jsonw["WorkspaceProfile"].Querysets[id].Queries) != "null") { |
---|
544 | $.each(jsonw["WorkspaceProfile"].Querysets[id].Queries, function(i,item) { |
---|
545 | |
---|
546 | notifyUser(i + ',' + this.querystring + ',' + this.collections[0],'debug'); |
---|
547 | $('#qs_select').append(new Option(Query.simplequerystring(this.querystring) , i)); |
---|
548 | }); |
---|
549 | } |
---|
550 | */ |
---|
551 | } |
---|
552 | }); |
---|
553 | } |
---|
554 | |
---|
555 | |
---|
556 | } |
---|
557 | |
---|
558 | function saveWorkspace(type){ |
---|
559 | var JSONText = JSON.stringify(jsonw["WorkspaceProfile"]); |
---|
560 | //var JSONText = JSON.stringify({"aa.a":"r"}); |
---|
561 | //notifyUser(JSONText,'debug'); |
---|
562 | $.post("/MDService2/workspaceprofilesave/" + type,{"data":JSONText}); |
---|
563 | |
---|
564 | } |
---|
565 | //////////////////////////////////////////////// |
---|
566 | function loadWelcomeMessage(){ |
---|
567 | $('#detail').load("/MDService2/static/welcome.xml", function() { //profile.collections.base_uri, |
---|
568 | $('#welcome').addClass("ui-helper-reset ui-corner-all ui-widget-content"); |
---|
569 | if ($("#querylist").children().size() > 0) { |
---|
570 | hideWelcomeMessage(); |
---|
571 | } |
---|
572 | }); |
---|
573 | } |
---|
574 | |
---|
575 | function hideWelcomeMessage(){ |
---|
576 | // kick the welcome message on first submit |
---|
577 | notifyUser("hiding welcome"); |
---|
578 | if( $('#welcome').is(':visible') ) { |
---|
579 | $('#welcome').hide(); |
---|
580 | } |
---|
581 | } |
---|
582 | |
---|
583 | function loadWorkspaceProfiles(){ |
---|
584 | //empty json |
---|
585 | jsonw = {'WorkspaceProfile':{'Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}}; |
---|
586 | $('#qts_input').val(""); |
---|
587 | |
---|
588 | |
---|
589 | jQuery.getJSON("/MDService2/workspaceprofile/server",function(data){ |
---|
590 | notifyUser(data['WorkspaceProfile'],'debug'); |
---|
591 | var json = preprocessJSON(data); |
---|
592 | $("#serverqs").attr("data",JSON.stringify(json)); |
---|
593 | loadQuerysets(json["WorkspaceProfile"]["Querysets"],"server"); |
---|
594 | loadRepositories(json["WorkspaceProfile"]["Repositories"]); |
---|
595 | |
---|
596 | loadCollections(true); |
---|
597 | loadTerms(); |
---|
598 | handleQueryInput(); |
---|
599 | }); |
---|
600 | |
---|
601 | // USER WORKSPACEPROFILE |
---|
602 | jQuery.getJSON("/MDService2/workspaceprofile/user",function(data){ |
---|
603 | notifyUser(data['WorkspaceProfile'],'debug'); |
---|
604 | jsonw = preprocessJSON(data); |
---|
605 | loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); |
---|
606 | }); |
---|
607 | |
---|
608 | } |
---|
609 | function loadCollections(ini){ |
---|
610 | |
---|
611 | $('#collections').load(link('collections','htmllist?repository=' + getSelectedRepository()), //profile.collections.base_uri, |
---|
612 | function() { |
---|
613 | |
---|
614 | if (ini) { |
---|
615 | loadQueryFromUriParams(); |
---|
616 | } |
---|
617 | |
---|
618 | |
---|
619 | $("#collections .treeview").treeview({ |
---|
620 | animated: "fast", |
---|
621 | collapsed: true |
---|
622 | }); |
---|
623 | |
---|
624 | $(".treeview","#collections").find(".showselection").css("color","white"); |
---|
625 | |
---|
626 | // handle treeview click |
---|
627 | $(".treeview","#collections").find(".selection").click(function() { |
---|
628 | var checked_status = this.checked; |
---|
629 | |
---|
630 | // select or deselect all children according to parent |
---|
631 | $(this).next().next().next().find(".selection").attr("checked",checked_status); |
---|
632 | $(this).next().next().next().find(".selection").attr("child","undefined"); |
---|
633 | |
---|
634 | // deselect parents |
---|
635 | if (checked_status===false){ |
---|
636 | $(this).parent().parents("li").each(function(){ |
---|
637 | $(this).children(".selection").attr("checked",false); |
---|
638 | }); |
---|
639 | } |
---|
640 | |
---|
641 | |
---|
642 | // refresh sign of existent selection |
---|
643 | // first reset childrens settings |
---|
644 | $(this).next().next().next().find(".showselection").css("color","white"); |
---|
645 | $(this).next().next().next().find(".showselection").attr("some_selection","0"); |
---|
646 | |
---|
647 | // then refresh selections |
---|
648 | $(this).parents("li").each(function(){ |
---|
649 | var count_selected = $(this).find("ul li .selection:checked").size(); |
---|
650 | if (count_selected > 0){ |
---|
651 | $(this).children(".showselection").attr("some_selection","1");//css("color","red"); |
---|
652 | } else { |
---|
653 | $(this).children(".showselection").attr("some_selection","0");//css("color","white"); |
---|
654 | } |
---|
655 | //TODO move into .css |
---|
656 | if (count_selected > 0){ |
---|
657 | $(this).children(".showselection").css("color","red"); |
---|
658 | } else { |
---|
659 | $(this).children(".showselection").css("color","white"); |
---|
660 | } |
---|
661 | $(this).children(".showselection").attr("count",count_selected); |
---|
662 | }); |
---|
663 | |
---|
664 | // uncheck parents node + param settings |
---|
665 | $(this).parent().parents("li").each(function(){ |
---|
666 | $(this).find(".selection").attr("child","undefined"); |
---|
667 | $(this).children(".selection").attr("checked",false); |
---|
668 | }); |
---|
669 | |
---|
670 | // sett the parent_selection attr |
---|
671 | $(this).parents("li").each(function(){ |
---|
672 | $(this).find(".selection").each(function(){ |
---|
673 | if (($(this).attr("checked")===true) && |
---|
674 | (($(this).parent().parent().parent().children(".selection").attr("checked")===false) || |
---|
675 | ($(this).parent().parent().parent().children(".treeview").size() == 1)) |
---|
676 | ){ |
---|
677 | $(this).attr("child","parent_selection"); |
---|
678 | } |
---|
679 | }); |
---|
680 | }); |
---|
681 | |
---|
682 | // update collection_selection |
---|
683 | var $treeview = $(".treeview","#collections"); |
---|
684 | //var collection = $("li",$treeview).find("input:checked[child='parent_selection']").next().text(); |
---|
685 | //notifyUser("collection:" + collection,'debug'); |
---|
686 | |
---|
687 | |
---|
688 | var collection_text = ""; |
---|
689 | var coll; |
---|
690 | collections.splice(0, collections.length); |
---|
691 | $("li",$treeview).find("input:checked[child='parent_selection']").next().each(function(index){ |
---|
692 | notifyUser("selection...:" + index + ":" + this.textContent + $(this).attr("handle"),'debug'); |
---|
693 | coll = new Collection($(this).attr("handle"), this.textContent); |
---|
694 | collections[collections.length] = coll; |
---|
695 | /* |
---|
696 | if (index == 0) { |
---|
697 | collection_text = this.textContent; |
---|
698 | } else { |
---|
699 | collection_text = collection_text + ", " + this.textContent; |
---|
700 | } |
---|
701 | */ |
---|
702 | |
---|
703 | }); |
---|
704 | //$('#collection_list').attr("value",collection_text); |
---|
705 | collections_widget.load(collections); |
---|
706 | |
---|
707 | });// end of treeview click |
---|
708 | });// end of collection callback |
---|
709 | } |
---|
710 | function loadTerms(){ |
---|
711 | |
---|
712 | //$('#model_profiles').load(link('terms','htmlselect',actions.terms.current));// + '?repository=' + getSelectedRepository()); |
---|
713 | $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository()); |
---|
714 | |
---|
715 | $('#terms-select').live('change', function(event) { |
---|
716 | //notifyUser(this.value,'debug'); |
---|
717 | update(link('terms', 'htmllist', this.value)+ '?maxdepth=' + actions.terms.maxdepth + '&repository=' + getSelectedRepository(), |
---|
718 | '#terms-select', '#model_terms', |
---|
719 | function() { |
---|
720 | $("#model_terms .treeview").treeview({ |
---|
721 | animated: "fast", |
---|
722 | collapsed: false |
---|
723 | }); |
---|
724 | //notifyUser($("#model_terms .treeview"),'debug'); |
---|
725 | notifyUser("loaded: #model_terms .treeview",'debug'); |
---|
726 | } |
---|
727 | ); |
---|
728 | } |
---|
729 | ); |
---|
730 | |
---|
731 | $('#terms .cmd_filter').live('click', function(event) { |
---|
732 | //var term = $(this).parent().find('span.term_detail_caller a').text(); |
---|
733 | var term = $(this).parent().children('span.data').text(); |
---|
734 | if ($('.searchtype_text','#search').size()> 0 ) { |
---|
735 | var t = $('#query_area').text(); |
---|
736 | $('#query_area').val(t + " " + term); |
---|
737 | } else { |
---|
738 | searchclauseset.updatedata(term); |
---|
739 | |
---|
740 | } |
---|
741 | //$('#srquery').val(term); |
---|
742 | }); |
---|
743 | |
---|
744 | $('#terms .cmd_columns').live('click', function(event) { |
---|
745 | //var term = $(this).parent().find('span.term_detail_caller a').text(); |
---|
746 | var term = $(this).parent().children('span.data').text(); |
---|
747 | // old method |
---|
748 | /* |
---|
749 | var columns_text = $('#columns_list').attr("value"); |
---|
750 | if (columns_text.length > 0){ |
---|
751 | columns_text = columns_text + ","; |
---|
752 | } |
---|
753 | columns_text = columns_text + term; |
---|
754 | $('#columns_list').attr("value",columns_text); |
---|
755 | */ |
---|
756 | // |
---|
757 | columns_widget.add(new ListItem(term)); |
---|
758 | // columnset.addcolumn(new Column(term)); |
---|
759 | |
---|
760 | }); |
---|
761 | |
---|
762 | /* |
---|
763 | * deactivated -> obsolete? |
---|
764 | * |
---|
765 | $('#terms .cmd_detail').live('click', function(event) { |
---|
766 | //showTermDetail($(this).parent().text()); |
---|
767 | // notifyUser($(this).parent().find('span.term_detail_caller a').text(),'debug'); |
---|
768 | var term = $(this).parent().find('span.term_detail_caller a').text(); |
---|
769 | var uri = link('terms', 'htmltable', term); // + " body"; |
---|
770 | |
---|
771 | // $.ajax({ |
---|
772 | // url: uri, |
---|
773 | // success: showDetail |
---|
774 | // }); |
---|
775 | $.get(uri, showDetail,'html'); |
---|
776 | |
---|
777 | }); |
---|
778 | */ |
---|
779 | } |
---|
780 | function loadComponentsRegistry(){ |
---|
781 | $('#profiles').load(link('compprofiles','htmlselect')); |
---|
782 | |
---|
783 | $('#components a').live('click', function (event) { |
---|
784 | event.preventDefault(); |
---|
785 | update($(this).attr('href'), '#components', '#components'); |
---|
786 | }); |
---|
787 | |
---|
788 | $('#profile-select').live('change', function(event) { |
---|
789 | //notifyUser(this.value,'debug'); |
---|
790 | update(link('compprofiles', 'htmllist', this.value), |
---|
791 | '#profile-select', '#components', |
---|
792 | function() { |
---|
793 | $("#components .treeview").treeview({ |
---|
794 | animated: "fast", |
---|
795 | collapsed: false |
---|
796 | }); |
---|
797 | notifyUser($("#components .treeview"),'debug'); |
---|
798 | } |
---|
799 | ); |
---|
800 | } |
---|
801 | ); |
---|
802 | |
---|
803 | $('#components .cmd_filter').live('click', function(event) { |
---|
804 | var term = $(this).prev().text(); |
---|
805 | if ($('.searchtype_text','#search').size()> 0 ) { |
---|
806 | var t = $('#query_area').text(); |
---|
807 | $('#query_area').val(t + " " + term); |
---|
808 | } else { |
---|
809 | searchclauseset.updatedata(term); |
---|
810 | //$('.focused','#searchclauselist').find('.index_input').val(term); |
---|
811 | } |
---|
812 | //$('#srquery').val($(this).parent().children('a').attr('href')); |
---|
813 | }); |
---|
814 | |
---|
815 | $('#compreg .cmd_detail').live('click', function(event) { |
---|
816 | //showTermDetail($(this).parent().text()); |
---|
817 | |
---|
818 | var uri = $(this).parent().children('a').attr('href'); // + " body"; |
---|
819 | // $.ajax({ |
---|
820 | // url: uri, |
---|
821 | // success: showDetail2 |
---|
822 | // }); |
---|
823 | |
---|
824 | $.get(uri, showDetail2,'html'); |
---|
825 | |
---|
826 | }); |
---|
827 | |
---|
828 | } |
---|
829 | function loadDCR(){ |
---|
830 | |
---|
831 | // ISOCAT DCR |
---|
832 | $('#dcr').load(link('isocat', 'htmllist', actions.isocat.current) ); |
---|
833 | |
---|
834 | // display minimal info in a bubble next to the calling anchor |
---|
835 | $("#dcr a, .comp_detail a").live('click', |
---|
836 | function (event) { |
---|
837 | event.preventDefault(); |
---|
838 | |
---|
839 | var uri = $(this).attr('href'); |
---|
840 | $('#bubble').empty(); |
---|
841 | // weirdly not functioning |
---|
842 | var isVisible = $('#bubble').is(':visible'); |
---|
843 | if (uri==last_bubble_uri) { |
---|
844 | $('#bubble').hide(); |
---|
845 | last_bubble_uri = ''; |
---|
846 | } else { |
---|
847 | notifyUser("conceptlink_uri: " + uri,'debug'); |
---|
848 | $('#bubble').load(uri); |
---|
849 | last_bubble_uri = uri; |
---|
850 | showBubble($(this)); |
---|
851 | } |
---|
852 | notifyUser('last_bubble_uri:' + last_bubble_uri,'debug'); |
---|
853 | |
---|
854 | //TODO filter, read isocat:nr |
---|
855 | // use in query clause |
---|
856 | var term = $(this).val(); |
---|
857 | var x = uri.split("/"); |
---|
858 | var category = x[x.length-1]; |
---|
859 | notifyUser(term); |
---|
860 | searchclauseset.updatedata(term, true, category); |
---|
861 | }); |
---|
862 | } |
---|
863 | |
---|
864 | function handleQueryInput(){ |
---|
865 | |
---|
866 | var elem; |
---|
867 | $('#terms_autocomplete').children().remove(); |
---|
868 | $('#terms_autocomplete').css('display','none'); |
---|
869 | $('#terms_autocomplete').load(link('terms_autocomplete','autocomplete/?q=all&repository='+ getSelectedRepository()),function(){ |
---|
870 | $(this).find('term').each(function(index){ |
---|
871 | elem = $(this).attr("name"); |
---|
872 | element_autocomplete[index] = elem; |
---|
873 | elements_hashtable[elem] = $(this).html(); |
---|
874 | }); |
---|
875 | // add autocomplete 's |
---|
876 | searchclauseset.initAutocomplete(); |
---|
877 | columns_widget.initAutocomplete(element_autocomplete); |
---|
878 | /* |
---|
879 | createSearchClauses(); |
---|
880 | $('#query_list').css('display', 'none'); |
---|
881 | $('<div id="searchclauselist"/>').insertAfter($('#query_list')); |
---|
882 | |
---|
883 | var sc = new SearchClause("","",""); |
---|
884 | searchclauseset.addsearchclause(sc,"",0,0); |
---|
885 | |
---|
886 | // $('#query_area').hide(); |
---|
887 | $('#searchclauselist').show(); |
---|
888 | $('#toggle_inputmode_cmd').addClass("searchtype_clauses"); |
---|
889 | |
---|
890 | $('#toggle_inputmode_cmd').live('click',function(){ |
---|
891 | if ($(this).text() == "TEXT") { |
---|
892 | searchclauseset.buildsctext(); |
---|
893 | $('#query_area').val(searchclauseset.sctext); |
---|
894 | $('#query_area').show(); |
---|
895 | $('#searchclauselist').hide(); |
---|
896 | $(this).toggleClass('searchtype_text searchtype_clauses'); |
---|
897 | $(this).text("FORM"); |
---|
898 | } else { |
---|
899 | $('#query_area').hide(); |
---|
900 | $('#searchclauselist').show(); |
---|
901 | $(this).text("TEXT"); |
---|
902 | $(this).toggleClass('searchtype_text searchtype_clauses'); |
---|
903 | } |
---|
904 | }); |
---|
905 | |
---|
906 | // load query if exists params |
---|
907 | loadQueryFromUriParams(); |
---|
908 | */ |
---|
909 | }); |
---|
910 | |
---|
911 | |
---|
912 | |
---|
913 | }; |
---|
914 | //create searchclauses, columns and collections |
---|
915 | function createSearchClauses() { |
---|
916 | $('#query_list').css('display', 'none'); |
---|
917 | $('<div id="searchclauselist"/>').insertAfter($('#query_list')); |
---|
918 | |
---|
919 | var sc = new SearchClause("","",""); |
---|
920 | searchclauseset.addsearchclause(sc,"",0,0); |
---|
921 | |
---|
922 | // $('#query_area').hide(); |
---|
923 | $('#searchclauselist').show(); |
---|
924 | $('#toggle_inputmode_cmd').addClass("searchtype_clauses"); |
---|
925 | |
---|
926 | $('#toggle_inputmode_cmd').live('click',function(){ |
---|
927 | if ($(this).text() == "TEXT") { |
---|
928 | searchclauseset.buildsctext(); |
---|
929 | $('#query_area').val(searchclauseset.sctext); |
---|
930 | $('#query_area').show(); |
---|
931 | $('#searchclauselist').hide(); |
---|
932 | $(this).toggleClass('searchtype_text searchtype_clauses'); |
---|
933 | $(this).text("FORM"); |
---|
934 | } else { |
---|
935 | $('#query_area').hide(); |
---|
936 | $('#searchclauselist').show(); |
---|
937 | $(this).text("TEXT"); |
---|
938 | $(this).toggleClass('searchtype_text searchtype_clauses'); |
---|
939 | } |
---|
940 | }); |
---|
941 | |
---|
942 | // load query if exists params |
---|
943 | //loadQueryFromUriParams(); |
---|
944 | |
---|
945 | // create columnswidget |
---|
946 | columns_widget = new ListWidget($('#columns-widget')); |
---|
947 | |
---|
948 | // create collectionswidget |
---|
949 | collections_widget = new ListWidget($('#collections-widget')); |
---|
950 | }; |
---|
951 | |
---|
952 | function loadQueryFromUriParams(){ |
---|
953 | |
---|
954 | var q = params["q"]; |
---|
955 | var squery = params["squery"]; |
---|
956 | var collection = params["collection"]; |
---|
957 | var startRecord = params["startRecords"]; |
---|
958 | var numRecords = params["numRecords"]; |
---|
959 | var repository = params["repository"]; |
---|
960 | var columns = params["columns"]; |
---|
961 | if ((q != undefined) || (squery != undefined) || (collection != undefined)) { |
---|
962 | if (q == undefined) { |
---|
963 | q = ""; |
---|
964 | } else { |
---|
965 | q = Url.decode(q); |
---|
966 | } |
---|
967 | if (squery == undefined) { |
---|
968 | squery = ""; |
---|
969 | } |
---|
970 | if (columns == undefined) { |
---|
971 | columns = ""; |
---|
972 | } |
---|
973 | if (startRecord == undefined) { |
---|
974 | startRecord = 1; |
---|
975 | } |
---|
976 | if (numRecords == undefined) { |
---|
977 | numRecords = 10; |
---|
978 | } |
---|
979 | if (repository == undefined) { |
---|
980 | repository = 1; |
---|
981 | } |
---|
982 | if (collection == undefined){ |
---|
983 | collection = ""; |
---|
984 | } |
---|
985 | var collections = []; |
---|
986 | if (collection.length > 0 ){ |
---|
987 | var coll = collection.split(","); |
---|
988 | $.each(coll,function(i,item){ |
---|
989 | var n; |
---|
990 | n = $('#collections').find(".folder:[handle='"+item+"']").text(); |
---|
991 | var simple_collection = new Collection(item, n); |
---|
992 | collections[i] = simple_collection; |
---|
993 | }); |
---|
994 | } |
---|
995 | |
---|
996 | var query = new Query(collections, columns, q, squery); |
---|
997 | query.startRecord = startRecord; |
---|
998 | query.numRecords = numRecords; |
---|
999 | query.repository = repository; |
---|
1000 | |
---|
1001 | |
---|
1002 | queryset.addquery(query); |
---|
1003 | |
---|
1004 | searchclauseset.sctext = query.query; |
---|
1005 | notifyUser(searchclauseset.sctext,'debug'); |
---|
1006 | |
---|
1007 | searchclauseset.buildfromquerystring(); |
---|
1008 | |
---|
1009 | $('#collection_list').attr("value",query.getcollectiontext("name")); |
---|
1010 | columns_widget.load(query.columns); |
---|
1011 | //$('#columns_list').attr("value",query.columns); |
---|
1012 | $('#input-simplequery').attr("value",query.squery); |
---|
1013 | |
---|
1014 | $('#query-input').show(); |
---|
1015 | |
---|
1016 | hideWelcomeMessage(); |
---|
1017 | } |
---|
1018 | |
---|
1019 | } |
---|
1020 | |
---|
1021 | function handleBubble(){ |
---|
1022 | // this is dangerous workaround |
---|
1023 | // actually I want it only for context-paths in #terms, |
---|
1024 | // but they are moved out of the '.term_detail' context into the #bubble |
---|
1025 | // so I have to use the generic.. |
---|
1026 | // well, dangerous - you might wonder, why the links don't work.. |
---|
1027 | $('#bubble a').live('click', function(event) { |
---|
1028 | //showTermDetail($(this).parent().text()); |
---|
1029 | event.preventDefault(); |
---|
1030 | } ); |
---|
1031 | |
---|
1032 | |
---|
1033 | $('#bubble .cmd_filter').live('click', function(event) { |
---|
1034 | var term = $(this).next().next().attr("href"); |
---|
1035 | if ($('.searchtype_text','#search').size()> 0 ) { |
---|
1036 | var t = $('#query_area').text(); |
---|
1037 | $('#query_area').val(t + " " + term); |
---|
1038 | } else { |
---|
1039 | $('.focused','#searchclauselist').find('.index-input').val(term); |
---|
1040 | } |
---|
1041 | //$('#srquery').val(term); |
---|
1042 | }); |
---|
1043 | |
---|
1044 | /* obsolete: ? */ |
---|
1045 | /* $(".term_detail_caller a, .query-detail-caller a").live('click', |
---|
1046 | // function(event) { |
---|
1047 | // //notifyUser("term_detail_caller_live_click",'debug'); |
---|
1048 | // event.preventDefault(); |
---|
1049 | // $(this).parents('li').find('div.term_detail').toggle(); |
---|
1050 | //}); |
---|
1051 | function (event) { |
---|
1052 | event.preventDefault(); |
---|
1053 | var uri = $(this).attr('href'); |
---|
1054 | $('#bubble').empty(); |
---|
1055 | // weirdly not functioning |
---|
1056 | // var isVisible = $('#bubble').is(':visible'); |
---|
1057 | if (uri==last_bubble_uri) { |
---|
1058 | $('#bubble').hide(); |
---|
1059 | last_bubble_uri = ''; |
---|
1060 | } else { |
---|
1061 | |
---|
1062 | notifyUser("term_uri: " + uri,'debug'); |
---|
1063 | var detail_info = $(this).parents('li').find('div.term_detail').html(); |
---|
1064 | $('#bubble').html(detail_info); |
---|
1065 | last_bubble_uri = uri; |
---|
1066 | showBubble($(this)); |
---|
1067 | } |
---|
1068 | notifyUser('last_bubble_uri:' + last_bubble_uri,'debug'); |
---|
1069 | }); |
---|
1070 | */ |
---|
1071 | |
---|
1072 | } |
---|
1073 | |
---|
1074 | function addFunctionality(){ |
---|
1075 | |
---|
1076 | /* $('.cmds-elem-plus').live('click', function(event) { |
---|
1077 | $(this).children('.detail').toggle(); |
---|
1078 | }); |
---|
1079 | */ |
---|
1080 | $('.autocomplete-select-caller').live('click', function(event) { |
---|
1081 | |
---|
1082 | $(this).closest(".index-context").prev().parent().find(".autocomplete-input").val($(this).text()).change(); |
---|
1083 | $(this).closest(".index-context").hide(); |
---|
1084 | }); |
---|
1085 | $('.autocomplete-select-caller a').live('click', function(event) { |
---|
1086 | event.preventDefault(); |
---|
1087 | }); |
---|
1088 | $('.detail-caller, .cmd_detail').live('click', function(event) { |
---|
1089 | $(this).parent().children('.detail').toggle(); |
---|
1090 | $(this).children('.cmd_down, .cmd_up').toggleClass('cmd_down cmd_up'); |
---|
1091 | }); |
---|
1092 | |
---|
1093 | $('.detail-caller a').live('click', function(event) { |
---|
1094 | event.preventDefault(); |
---|
1095 | }); |
---|
1096 | |
---|
1097 | $('.comp_detail input').live('keyup', function(event) { |
---|
1098 | $('#srquery').val( |
---|
1099 | $(this).parent().children('span.cmdelem_name').text() |
---|
1100 | + "=" + $(this).val() ); |
---|
1101 | }); |
---|
1102 | |
---|
1103 | // open detail (from result-set, but also already within detail-view (ResourceRef, IsPartOf) |
---|
1104 | $('.result a.internal, .mdrecord-detail a.internal').live('click', function(event) { |
---|
1105 | event.preventDefault(); |
---|
1106 | |
---|
1107 | var uri = $(this).attr('href'); // + " body"; |
---|
1108 | notifyUser('internal-link: ' + uri,'debug' ); |
---|
1109 | $.get(uri, showDetail,'html'); |
---|
1110 | }); |
---|
1111 | |
---|
1112 | $('.result a.external, .mdrecord-detail a.external').live('click', function(event) { |
---|
1113 | |
---|
1114 | //event.preventDefault(); |
---|
1115 | var uri = $(this).attr('href'); // + " body"; |
---|
1116 | notifyUser('resource-link: ' + uri,'debug' ); |
---|
1117 | // $.get(uri, showDetail,'html'); */ |
---|
1118 | }); |
---|
1119 | |
---|
1120 | $('.result .cmd_detail').live('click', function(event) { |
---|
1121 | |
---|
1122 | var uri = $(this).parent().find("a").attr('href'); // + " body"; |
---|
1123 | $.get(uri, showDetail,'html'); |
---|
1124 | }); |
---|
1125 | |
---|
1126 | // RECORDSET searchRetrieve |
---|
1127 | $('#searchretrieve').submit( function(event) { |
---|
1128 | event.preventDefault(); |
---|
1129 | hideWelcomeMessage(); |
---|
1130 | searchclauseset.buildsctext(); |
---|
1131 | notifyUser(searchclauseset.sctext,'debug'); |
---|
1132 | //submit_query ($('#columns_list').attr("value"),searchclauseset.sctext, $('#input-simplequery').attr("value")); |
---|
1133 | submit_query (columns_widget.getColumnsListText(),searchclauseset.sctext, $('#input-simplequery').attr("value"), $('#input-withsummary').attr("checked")); |
---|
1134 | }); |
---|
1135 | |
---|
1136 | /* |
---|
1137 | $('#querylist .query_header').find('.cmd_del').live('click', function(event) { |
---|
1138 | //showTermDetail($(this).parent().text()); |
---|
1139 | |
---|
1140 | queryset.removequery($(this).closest('.query_wrapper').attr('id')); |
---|
1141 | |
---|
1142 | }); |
---|
1143 | */ |
---|
1144 | |
---|
1145 | $('#querylist .cmd_up').live('click', function(event) { |
---|
1146 | $(this).closest('.query_wrapper').find('.result').hide(); |
---|
1147 | $(this).toggleClass('cmd_down cmd_up'); |
---|
1148 | }); |
---|
1149 | |
---|
1150 | |
---|
1151 | $('#querylist .cmd_save').live('click', function(event) { |
---|
1152 | |
---|
1153 | var qid = ""; |
---|
1154 | var qstring = ""; |
---|
1155 | var json_coll = "null"; |
---|
1156 | var json_cols = "null"; |
---|
1157 | var squery = ""; |
---|
1158 | var bookmark = "0"; |
---|
1159 | var json_options = "null"; |
---|
1160 | |
---|
1161 | if ($(this).parents('.result').length > 0){ |
---|
1162 | qstring = $(this).parent().find("a").attr('href'); |
---|
1163 | qstring = qstring.substring(18,qstring.length); |
---|
1164 | bookmark = "1"; |
---|
1165 | } else { |
---|
1166 | qid = $(this).closest('.query_wrapper').attr("id"); |
---|
1167 | qstring = queryset.getquerystring(qid); |
---|
1168 | json_coll = queryset.getcollections(qid); |
---|
1169 | json_cols = queryset.getcolumns(qid); |
---|
1170 | squery = queryset.getsquery(qid); |
---|
1171 | json_options = queryset.getoptions(qid); |
---|
1172 | } |
---|
1173 | |
---|
1174 | // JSON conversion |
---|
1175 | if (qstring.length == 0){ |
---|
1176 | qstring = "[NULL]"; |
---|
1177 | } |
---|
1178 | if (squery.length == 0){ |
---|
1179 | squery = "[NULL]"; |
---|
1180 | } |
---|
1181 | |
---|
1182 | var id = parseInt($("#qts_select option:selected").val()); |
---|
1183 | var iq = $('#userqueries').children().size(); |
---|
1184 | |
---|
1185 | if (iq == 0){ |
---|
1186 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = [{}]; |
---|
1187 | } |
---|
1188 | var jsonq = {"name":"", "squerystring":squery, "querystring":qstring,"searchclauses":"null" , "collections" : json_coll, "columns" : json_cols, "options" : json_options, "bookmark" : bookmark}; |
---|
1189 | |
---|
1190 | var name; |
---|
1191 | if (bookmark == "1") { |
---|
1192 | qstring = Url.decode(qstring); |
---|
1193 | var s = qstring.split(':'); |
---|
1194 | name = s[s.length - 2] + ":" + s[s.length - 1]; |
---|
1195 | } else { |
---|
1196 | name = Query.fullformatstring(jsonq); |
---|
1197 | } |
---|
1198 | jsonq.name = name; |
---|
1199 | |
---|
1200 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq] = jsonq; |
---|
1201 | saveWorkspace("USER"); |
---|
1202 | appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries')); |
---|
1203 | |
---|
1204 | //$("#qs_select").append(new Option(Query.simplequerystring(qstring),iq)); |
---|
1205 | }); |
---|
1206 | |
---|
1207 | $('#querylist .cmd-xml').live('click', function(event) { |
---|
1208 | var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
1209 | |
---|
1210 | queryset.getQuery(qid).open('xml'); |
---|
1211 | }); |
---|
1212 | $('#querylist .cmd-page').live('click', function(event) { |
---|
1213 | var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
1214 | |
---|
1215 | queryset.getQuery(qid).open('htmlpage'); |
---|
1216 | }); |
---|
1217 | /* |
---|
1218 | $('#querylist .cmd-link').live('click', function(event) { |
---|
1219 | /* var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
1220 | var qstring = queryset.getquerystring(qid); |
---|
1221 | var json_coll = queryset.getcollections(qid); |
---|
1222 | var json_cols = queryset.getcolumns(qid); |
---|
1223 | var squery = queryset.getsquery(qid); |
---|
1224 | // JSON conversion |
---|
1225 | if (qstring.length == 0){ |
---|
1226 | qstring = "[NULL]"; |
---|
1227 | } |
---|
1228 | if (squery.length == 0){ |
---|
1229 | squery = "[NULL]"; |
---|
1230 | } |
---|
1231 | var jsonq = {"squerystring":squery, "querystring":qstring,"searchclauses":"null" , "collections" : json_coll, "columns" : json_cols}; |
---|
1232 | /// |
---|
1233 | |
---|
1234 | queryset.getQuery(qid).open(); |
---|
1235 | }); |
---|
1236 | */ |
---|
1237 | /* |
---|
1238 | $('.cmd_select').live('click', function(event) { |
---|
1239 | var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
1240 | |
---|
1241 | searchclauseset.sctext = queryset.getquerystring(qid); |
---|
1242 | searchclauseset.buildfromquerystring(); |
---|
1243 | }); |
---|
1244 | */ |
---|
1245 | $('#queryslist .cmd_reload').live('click', function(event) { |
---|
1246 | var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
1247 | |
---|
1248 | queryset.resubmit(qid); |
---|
1249 | |
---|
1250 | }); |
---|
1251 | |
---|
1252 | |
---|
1253 | $('.cmd_down').live('click', function(event) { |
---|
1254 | $(this).closest('.query_wrapper').find('.result').show(); |
---|
1255 | $(this).toggleClass('cmd_down cmd_up'); |
---|
1256 | }); |
---|
1257 | $('.cmd_sc_delete').live('click', function(event) { |
---|
1258 | var i = $(this).closest('.sc-i').attr('id'); |
---|
1259 | var j = $(this).closest('.sc-j').attr('id'); |
---|
1260 | //notifyUser(i + j,'debug'); |
---|
1261 | searchclauseset.removesearchclause(i,j); |
---|
1262 | |
---|
1263 | }); |
---|
1264 | $('.cmd_add_and').live('click', function(event) { |
---|
1265 | //showTermDetail($(this).parent().text()); |
---|
1266 | //$(this).next().hide(); |
---|
1267 | $(this).attr("value","AND"); |
---|
1268 | var searchclause = new SearchClause("","",""); |
---|
1269 | var i = $(this).closest('.sc-i').attr('id'); |
---|
1270 | var j = $(this).closest('.sc-j').attr('id'); |
---|
1271 | //notifyUser(i + j,'debug'); |
---|
1272 | searchclauseset.addsearchclause(searchclause,"and",i,j); |
---|
1273 | |
---|
1274 | }); |
---|
1275 | $('.cmd_add_or').live('click', function(event) { |
---|
1276 | //showTermDetail($(this).parent().text()); |
---|
1277 | //$(this).next().hide(); |
---|
1278 | var i,j; |
---|
1279 | $(this).attr("value","OR"); |
---|
1280 | var searchclause = new SearchClause("","",""); |
---|
1281 | searchclauseset.addsearchclause(searchclause,"or",$(this).closest('.sc-i').attr('id'),$(this).closest('.sc-j').attr('id')); |
---|
1282 | |
---|
1283 | }); |
---|
1284 | |
---|
1285 | ///// datasets/queries |
---|
1286 | $('#qts_save').click(function(){ |
---|
1287 | var id = $("#qts_select option:selected").val(); |
---|
1288 | //notifyUser($('#qts_input').val() + $('#qts_input').text(),'debug'); |
---|
1289 | jsonw["WorkspaceProfile"]["Querysets"][id]["name"] = $('#qts_input').val(); |
---|
1290 | |
---|
1291 | $("#qts_select option:selected").text( $('#qts_input').val()); |
---|
1292 | saveWorkspace("USER"); |
---|
1293 | }); |
---|
1294 | $('#qts_add').click(function(){ |
---|
1295 | var new_name = "new_queryset"; |
---|
1296 | |
---|
1297 | var id = $('#qts_select option').size(); |
---|
1298 | var dt = new Date(); |
---|
1299 | var str_time = dt.toString("yyyy-MM-dd HH:mm:ss"); |
---|
1300 | |
---|
1301 | if (id == 0){ |
---|
1302 | jsonw["WorkspaceProfile"]["Querysets"] = [{}]; |
---|
1303 | } |
---|
1304 | |
---|
1305 | jsonw["WorkspaceProfile"]["Querysets"][id] = {"name":new_name,"created":str_time , "Queries" : "null"}; |
---|
1306 | |
---|
1307 | saveWorkspace("USER"); |
---|
1308 | //todo |
---|
1309 | |
---|
1310 | //loadWorkspace(jsonw["WorkspaceProfile"]["Querysets"]); |
---|
1311 | $("#qts_select").append(new Option(new_name, id)); |
---|
1312 | $("#qts_select").find('option').attr("selected","false"); |
---|
1313 | $("#qts_select").find('option').last().attr("selected","true"); |
---|
1314 | $('#qts_input').val(new_name); |
---|
1315 | }); |
---|
1316 | $('#qts_delete').click(function(){ |
---|
1317 | var count = $("#qts_select option").size(); |
---|
1318 | |
---|
1319 | //if (count > 1){ |
---|
1320 | var id = parseInt($("#qts_select option:selected").val()); |
---|
1321 | var size = jsonw["WorkspaceProfile"].Querysets.length; |
---|
1322 | |
---|
1323 | for (var i=id;i<size-1;i++){ |
---|
1324 | jsonw["WorkspaceProfile"].Querysets[i] = jsonw["WorkspaceProfile"].Querysets[i+1]; |
---|
1325 | } |
---|
1326 | |
---|
1327 | delete jsonw["WorkspaceProfile"].Querysets[size-1]; |
---|
1328 | jsonw["WorkspaceProfile"]["Querysets"].length = size-1; |
---|
1329 | // set null string , if 0 querysets |
---|
1330 | if (count == 1) { |
---|
1331 | jsonw["WorkspaceProfile"]["Querysets"] = "null"; |
---|
1332 | } |
---|
1333 | saveWorkspace("USER"); |
---|
1334 | //$("#qts_select option").remove(); |
---|
1335 | loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); |
---|
1336 | |
---|
1337 | //} |
---|
1338 | }); |
---|
1339 | |
---|
1340 | $('#collections .cmd_load').live('click',function(event){ |
---|
1341 | hideWelcomeMessage(); |
---|
1342 | var collection_text = ""; |
---|
1343 | var coll = $(this).next().next().next(); |
---|
1344 | collections.splice(0, collections.length); |
---|
1345 | collections[0] = new Collection($(coll).attr("handle"), $(coll).html()); |
---|
1346 | var columns = columns_widget.getColumnsListText();//$('#columns_list').attr("value"); |
---|
1347 | var query = new Query(collections,columns,"",""); |
---|
1348 | query.repository = getSelectedRepository(); |
---|
1349 | |
---|
1350 | //searchclauseset.clear(); |
---|
1351 | queryset.addquery(query); |
---|
1352 | //$('#collection_list').attr("value",query.getcollectiontext("name")); |
---|
1353 | collections_widget.load(query.collection); |
---|
1354 | |
---|
1355 | }); |
---|
1356 | $('#serverqueries .cmd_load').live('click',function(event){ |
---|
1357 | |
---|
1358 | var id = parseInt( $("#serverqts_select option:selected").val()); |
---|
1359 | var str = $(this).parent().find('a').attr("href"); |
---|
1360 | var iq = parseInt(str.substring(9)); |
---|
1361 | var json = jQuery.parseJSON($("#serverqs").attr("data")); |
---|
1362 | var q = json["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]; |
---|
1363 | |
---|
1364 | loadQuery(q); |
---|
1365 | }); |
---|
1366 | $('#userqueries .cmd_load').live('click',function(event){ |
---|
1367 | |
---|
1368 | var id = parseInt( $("#qts_select option:selected").val()); |
---|
1369 | var str = $(this).parent().find('a').attr("href"); |
---|
1370 | var iq = parseInt(str.substring(7)); |
---|
1371 | var q = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]; |
---|
1372 | |
---|
1373 | loadQuery(q); |
---|
1374 | }); |
---|
1375 | $('#userqueries .cmd_del').live('click', function(event){ |
---|
1376 | //var count = $("#userqueries li").size(); |
---|
1377 | var id = parseInt($("#qts_select option:selected").val()); |
---|
1378 | var str = $(this).parent().find('a').attr("href"); |
---|
1379 | var iq = parseInt(str.substring(7)); |
---|
1380 | var size = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length; |
---|
1381 | |
---|
1382 | for (var i=iq;i<size-1;i++){ |
---|
1383 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i] = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i+1]; |
---|
1384 | } |
---|
1385 | |
---|
1386 | delete jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][size-1]; |
---|
1387 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length = size-1; |
---|
1388 | |
---|
1389 | if (size == 1){ |
---|
1390 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = "null"; |
---|
1391 | } |
---|
1392 | |
---|
1393 | saveWorkspace("USER"); |
---|
1394 | loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); |
---|
1395 | //$("#qs_select option").remove(); |
---|
1396 | //$("#qs_select option").first().attr("selected","true"); |
---|
1397 | }); |
---|
1398 | |
---|
1399 | |
---|
1400 | $('.ui-dialog-titlebar-del').live('click', function(event){ |
---|
1401 | //$('#detail-float').dialog('close'); |
---|
1402 | var t = $(this).parents('.ui-widget').children('.ui-dialog-content'); |
---|
1403 | $(t).dialog('close'); |
---|
1404 | }); |
---|
1405 | |
---|
1406 | $('.ui-dialog-titlebar-up').live('click', function(event){ |
---|
1407 | var t = $(this).parents('.ui-widget').children('.ui-dialog-content'); |
---|
1408 | |
---|
1409 | $(this).parents('.ui-widget').attr("tempheight",$(this).parents('.ui-widget').height()); |
---|
1410 | //notifyUser("up(height):" + $(this).parents('.ui-widget').height(),'debug'); |
---|
1411 | $(this).parents('.ui-widget').height(30); |
---|
1412 | //notifyUser("up(tempheight):" + $(this).parents('.ui-widget').attr("tempheight"),'debug'); |
---|
1413 | |
---|
1414 | |
---|
1415 | //$(t).find(".ui-dialog-buttonpane:first, .ui-dialog-content").stop({clearQueue:true}).fadeOut(300); |
---|
1416 | //$(t).stop({clearQueue:true}).animate({height:'0px'},300); |
---|
1417 | |
---|
1418 | $(this).removeClass('cmd_up ui-dialog-titlebar-up'); |
---|
1419 | $(this).addClass('cmd_down ui-dialog-titlebar-down'); |
---|
1420 | }); |
---|
1421 | $('.ui-dialog-titlebar-down').live('click', function(event){ |
---|
1422 | var t = $(this).parents('.ui-widget').children('.ui-dialog-content'); |
---|
1423 | |
---|
1424 | var h = $(this).parents('.ui-widget').attr("tempheight"); |
---|
1425 | //notifyUser("down(tempheight):" + h,'debug'); |
---|
1426 | $(this).parents('.ui-widget').height(parseInt(h)); |
---|
1427 | //notifyUser("down(height):" + $(this).parents('.ui-widget').height(),'debug'); |
---|
1428 | |
---|
1429 | |
---|
1430 | //$(this).parents('.ui-widget').attr("tempheight",$(this).parents('.ui-widget').height()); |
---|
1431 | //$(t).find(".ui-dialog-content, .ui-dialog-buttonpane:first").stop({clearQueue:true}).fadeIn(800) |
---|
1432 | //.end().stop({clearQueue:true}).animate({height:'100%'},300); |
---|
1433 | |
---|
1434 | $(this).removeClass('cmd_down ui-dialog-titlebar-down'); |
---|
1435 | $(this).addClass('cmd_up ui-dialog-titlebar-up'); |
---|
1436 | }); |
---|
1437 | |
---|
1438 | |
---|
1439 | |
---|
1440 | } |
---|
1441 | function loadQuery(q){ |
---|
1442 | if (q["bookmark"] == "1") { |
---|
1443 | var uri = "http://localhost:8080/MDService2/record/htmldetail/" + q["querystring"]; |
---|
1444 | showDetail(null,'html'); |
---|
1445 | $.get(uri, showDetail,'html'); |
---|
1446 | } else { |
---|
1447 | hideWelcomeMessage(); |
---|
1448 | var query = new Query([],"","",""); |
---|
1449 | query.load(q); |
---|
1450 | query.repository = getSelectedRepository(); |
---|
1451 | queryset.addquery(query); |
---|
1452 | |
---|
1453 | searchclauseset.sctext = query.query; |
---|
1454 | notifyUser(searchclauseset.sctext,'debug'); |
---|
1455 | searchclauseset.buildfromquerystring(); |
---|
1456 | |
---|
1457 | collections = query.collection; |
---|
1458 | collections_widget.load(query.collection); |
---|
1459 | columns_widget.load(query.columns.split(',')); |
---|
1460 | $('#input-simplequery').attr("value",query.squery); |
---|
1461 | $('#input-withsummary').attr("checked",(query.options != null)); |
---|
1462 | } |
---|
1463 | |
---|
1464 | } |
---|
1465 | function addVisuals(){ |
---|
1466 | ////////////VISUALS |
---|
1467 | |
---|
1468 | // $('#left-menu').addClass('ui-accordion ui-widget ui-helper-reset ui-accordion-icons'); |
---|
1469 | $('.cmds-ui-block').addClass('ui-helper-reset ui-corner-all'); |
---|
1470 | $('.cmds-ui-block .header').addClass('ui-widget-header ui-state-default ui-corner-top'); |
---|
1471 | $('.cmds-ui-block .content').addClass('ui-widget-content ui-corner-bottom'); |
---|
1472 | $('.cmds-ui-block .header').click(function() { |
---|
1473 | $(this).next().toggle('fast'); |
---|
1474 | return false; |
---|
1475 | }).next().hide(); |
---|
1476 | |
---|
1477 | $('.cmds-ui-block.init-show .header').next().show(); |
---|
1478 | |
---|
1479 | /* |
---|
1480 | // Accordion |
---|
1481 | $("#left-menu").accordion({ header: "h2",event: 'click' }); |
---|
1482 | $("#left-menu").accordion('option', 'autoHeight', false); |
---|
1483 | // hack to open the accordion without scroll-bars on init |
---|
1484 | $("#left-menu").accordion('option', 'active', 1); |
---|
1485 | */ |
---|
1486 | |
---|
1487 | //$("#main-menu").treeview(); |
---|
1488 | |
---|
1489 | // Detail |
---|
1490 | // $("#detail").tabs("add", "#components","Tab1"); |
---|
1491 | $("#detail-float").dialog({ autoOpen: false, |
---|
1492 | position: ['right','70px'], |
---|
1493 | height: 450, |
---|
1494 | width: 300, |
---|
1495 | minHeigh: 100}); |
---|
1496 | |
---|
1497 | //$('#detail-float').dialog( "option", "minHeight", '0px' ); |
---|
1498 | |
---|
1499 | $("#detail-float").dialog(); |
---|
1500 | $("#detail-float").tabs(); |
---|
1501 | |
---|
1502 | /// notify-messages |
---|
1503 | $("#notify-float").dialog({ autoOpen: false, |
---|
1504 | position: ['right','10px'], |
---|
1505 | height: 200, |
---|
1506 | width: 400, |
---|
1507 | minHeigh: 100}); |
---|
1508 | $("#notify-float").dialog(); |
---|
1509 | $("#notify-float").tabs(); |
---|
1510 | |
---|
1511 | } |
---|
1512 | |
---|
1513 | function getUrlVars() |
---|
1514 | { |
---|
1515 | var vars = [], hash; |
---|
1516 | var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); |
---|
1517 | for(var i = 0; i < hashes.length; i++) |
---|
1518 | { |
---|
1519 | hash = hashes[i].split('='); |
---|
1520 | vars.push(hash[0]); |
---|
1521 | vars[hash[0]] = hash[1]; |
---|
1522 | } |
---|
1523 | return vars; |
---|
1524 | } |
---|
1525 | |
---|
1526 | String.prototype.beginsWith = function(t, i) { if (i==false) { return |
---|
1527 | (t == this.substring(0, t.length)); } else { return (t.toLowerCase() |
---|
1528 | == this.substring(0, t.length).toLowerCase()); } } ; |
---|
1529 | |
---|
1530 | |
---|
1531 | String.prototype.endsWith = function(t, i) { if (i==false) { return (t |
---|
1532 | == this.substring(this.length - t.length)); } else { return |
---|
1533 | (t.toLowerCase() == this.substring(this.length - |
---|
1534 | t.length).toLowerCase()); } } ; |
---|
1535 | |
---|
1536 | |
---|
1537 | var Url = { |
---|
1538 | |
---|
1539 | // public method for url encoding |
---|
1540 | encode : function (string) { |
---|
1541 | return escape(this._utf8_encode(string)); |
---|
1542 | }, |
---|
1543 | |
---|
1544 | // public method for url decoding |
---|
1545 | decode : function (string) { |
---|
1546 | return this._utf8_decode(unescape(string)); |
---|
1547 | }, |
---|
1548 | |
---|
1549 | // private method for UTF-8 encoding |
---|
1550 | _utf8_encode : function (string) { |
---|
1551 | string = string.replace(/\r\n/g,"\n"); |
---|
1552 | var utftext = ""; |
---|
1553 | |
---|
1554 | for (var n = 0; n < string.length; n++) { |
---|
1555 | |
---|
1556 | var c = string.charCodeAt(n); |
---|
1557 | |
---|
1558 | if (c < 128) { |
---|
1559 | utftext += String.fromCharCode(c); |
---|
1560 | } |
---|
1561 | else if((c > 127) && (c < 2048)) { |
---|
1562 | utftext += String.fromCharCode((c >> 6) | 192); |
---|
1563 | utftext += String.fromCharCode((c & 63) | 128); |
---|
1564 | } |
---|
1565 | else { |
---|
1566 | utftext += String.fromCharCode((c >> 12) | 224); |
---|
1567 | utftext += String.fromCharCode(((c >> 6) & 63) | 128); |
---|
1568 | utftext += String.fromCharCode((c & 63) | 128); |
---|
1569 | } |
---|
1570 | |
---|
1571 | } |
---|
1572 | |
---|
1573 | return utftext; |
---|
1574 | }, |
---|
1575 | |
---|
1576 | // private method for UTF-8 decoding |
---|
1577 | _utf8_decode : function (utftext) { |
---|
1578 | var string = ""; |
---|
1579 | var i = 0; |
---|
1580 | var c = c1 = c2 = 0; |
---|
1581 | |
---|
1582 | while ( i < utftext.length ) { |
---|
1583 | |
---|
1584 | c = utftext.charCodeAt(i); |
---|
1585 | |
---|
1586 | if (c < 128) { |
---|
1587 | string += String.fromCharCode(c); |
---|
1588 | i++; |
---|
1589 | } |
---|
1590 | else if((c > 191) && (c < 224)) { |
---|
1591 | c2 = utftext.charCodeAt(i+1); |
---|
1592 | string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); |
---|
1593 | i += 2; |
---|
1594 | } |
---|
1595 | else { |
---|
1596 | c2 = utftext.charCodeAt(i+1); |
---|
1597 | c3 = utftext.charCodeAt(i+2); |
---|
1598 | string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); |
---|
1599 | i += 3; |
---|
1600 | } |
---|
1601 | |
---|
1602 | } |
---|
1603 | |
---|
1604 | return string; |
---|
1605 | } |
---|
1606 | |
---|
1607 | }; |
---|