source: main/trunk/model-sites-dev/von-sparql/js/von-sparql-setup.js@ 28914

Last change on this file since 28914 was 28914, checked in by ak19, 10 years ago

Supporting javascript libraries and bespoke code written by Steffan to support the von-sparql user interface

File size: 3.5 KB
Line 
1var sparqlEndpoint= location.protocol + '//' + location.hostname + ":3030/greenstone/query" ;
2var collectionName = gs.cgiParams.c;
3function getAutocompleteQuery()
4{
5var sparqlQuery = "PREFIX gsdl: <http://localhost:3030/greenstone/data/>" +
6 "SELECT ?o ?identifier where{ "+
7 " GRAPH gsdl:" + collectionName + " {" +
8 " ?s <http://purl.org/dc/elements/1.1/Title> ?o" +
9 ' FILTER regex(?o, "' + $('#autocomplete').val() + '", "i")'+
10 '}}LIMIT 50 ';
11
12 return sparqlEndpoint + "?query=" + encodeURIComponent(sparqlQuery);
13
14}
15function setupPage()
16{
17
18 $("#btn_ShowChart").click(function(){
19 newQuery("sgvzl_container", $('#sel_ChartType').val(),2000);
20 });
21
22 $("#cb_RefineSearch").click(function(){
23 if(document.getElementById("cb_RefineSearch").checked==false)
24 toggle_RefineSearch(0);
25 else
26 toggle_RefineSearch(1);
27 generateQuery();
28 });
29
30
31
32 $("#sel_Limit").change(function(){
33 generateQuery();
34 });
35
36 $('#div_Selects select').combobox({
37 select: function(event, ui){
38 var id = event.target.id;
39 if(id=="sel_Predicate"){
40 updateRefineObjectSelector($("#sel_Predicate").val());
41 //Empty predicate selector and put empty option in it
42 /* $('#sel_RefinePredicate').empty();
43 $('#sel_RefinePredicate')
44 .append("<option value=\"\">Select ?o above</option>");
45 $('#sel_RefinePredicate').next().find('.custom-combobox-input').val("Select ?o above");*/
46
47 generateQuery();
48 }
49 else if(id=="sel_RefineObject"){
50 //updateRefinePredicateSelector($("#sel_RefineObject").val());
51 generateQuery();
52 }
53 else if(id=="sel_RefinePredicate"){
54 generateQuery();
55 }
56 }});
57 $('#table_refineControls tr td:first').addClass("alignRight");
58
59 $('#autocomplete').autocomplete({
60 source: function(request, response) {
61 $.ajax({
62 url: getAutocompleteQuery(),
63 type:"GET",
64 data:"output=json",
65 success: function( json ) {
66 console.log($('#autocomplete').val());
67 var parsedJSON = ((typeof json) == "string") ? $.parseJSON(json) : json;
68 response( $.map(json.results.bindings, function(item){
69 return{
70 label: /*item.identifier.value + " " + */item.o.value,
71 value: item.o.value
72 }
73 }))
74 },
75 open: function(){
76 $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
77 },
78 close: function(){
79 $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
80 }
81 });
82 },
83 appendTo: "div_autocomplete",
84 minLength: 0,
85 delay: 500,
86 })
87
88 setupCharts();
89
90}
91
92function setupCharts()
93{
94 $('#div_PredicateOverview .google-visualization-table-tr-even td:first-child, #div_PredicateOverview .google-visualization-table-tr-odd td:first-child').live("click", function(){
95 var clickedText = tidyPredicate($(this).text());
96 $('#sel_Predicate option[text="' + clickedText + '"]').attr("selected","selected");
97 $('#sel_Predicate option').filter(function(){
98 return $(this).text() == clickedText;
99 }).attr('selected', true);
100
101 //Update refine object selector with new value for predicate
102 updateRefineObjectSelector($("#sel_Predicate").val());
103
104 //Clear refine predicate selector
105 /*$('#sel_RefinePredicate').empty();
106 $('#sel_RefinePredicate')
107 .append("<option value=\"\">Select ?o above</option>");
108 $('#sel_RefinePredicate').next().find('.custom-combobox-input').val("Select ?o above");*/
109 generateQuery();
110
111 $('#sel_Predicate').siblings('.custom-combobox').find('.custom-combobox-input').val(clickedText);
112
113 newQuery("sgvzl_container", $('#sel_ChartType').val(),500);
114 });
115
116 sgvizler.defaultChartWidth(675);
117}
Note: See TracBrowser for help on using the repository browser.