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