Commit 78e85e94 authored by Romain Loth's avatar Romain Loth

php topbar: show current filters (exposed whoswho.popfilter and used it in js...

php topbar: show current filters (exposed whoswho.popfilter and used it in js elements for print_directory)
parent 29ff6612
...@@ -5,6 +5,20 @@ ...@@ -5,6 +5,20 @@
* TODO use more eg for charts * TODO use more eg for charts
*/ */
// to autoselect current whoswho filters
// NB: uses global value $data
$auto_popfilters_snippet = '<script type="text/javascript">' ;
foreach ($data as $filter => $array_vals) {
foreach ($array_vals as $val) {
$auto_popfilters_snippet .= '
whoswho.popfilter("'.$filter.'", {"prefill":"'.$val.'"});
';
}
}
$auto_popfilters_snippet .= '</script>';
// exemple snippet this one is to use in html context // exemple snippet this one is to use in html context
$rm_ads_snippet = <<< ENDHTML $rm_ads_snippet = <<< ENDHTML
<script type="text/javascript"> <script type="text/javascript">
......
<?php <?php
include ("php_library/comex_library.php"); include ("php_library/comex_library.php");
include ("php_library/js_elements.php");
include ("php_library/parametres.php"); include ("php_library/parametres.php");
include ("php_library/normalize.php"); include ("php_library/normalize.php");
include ("php_library/baselayout_head_template.php"); include ("php_library/baselayout_head_template.php");
...@@ -8,10 +7,18 @@ include ("php_library/baselayout_topbar_template.php"); ...@@ -8,10 +7,18 @@ include ("php_library/baselayout_topbar_template.php");
include ("php_library/baselayout_tail_template.php"); include ("php_library/baselayout_tail_template.php");
$meta = $html_head_inner; $meta = $html_head_inner;
$meta .= $rm_ads_snippet;
$data = json_decode($_GET['query']); $data = json_decode($_GET['query']);
print_r('query here<br>');
print_r($data);
print_r('/query here<br>');
// this one after we got query data
include ("php_library/js_elements.php");
function objectToArray($d) { function objectToArray($d) {
if (is_object($d)) { if (is_object($d)) {
// Gets the properties of the given object // Gets the properties of the given object
...@@ -473,6 +480,8 @@ echo $footer; ...@@ -473,6 +480,8 @@ echo $footer;
// echo '</div>'; // echo '</div>';
echo '</div>'; echo '</div>';
echo $html_tail_imports; echo $html_tail_imports;
echo $rm_ads_snippet;
echo $auto_popfilters_snippet;
echo '</body> echo '</body>
</html>'; </html>';
exit(0); exit(0);
......
...@@ -8,7 +8,6 @@ include ("php_library/baselayout_topbar_template.php"); ...@@ -8,7 +8,6 @@ include ("php_library/baselayout_topbar_template.php");
include ("php_library/baselayout_tail_template.php"); include ("php_library/baselayout_tail_template.php");
$meta = $html_head_inner; $meta = $html_head_inner;
$meta .= $rm_ads_snippet;
//phpinfo(); //phpinfo();
//echo $_GET['query']."<br/>"; //echo $_GET['query']."<br/>";
...@@ -284,6 +283,7 @@ echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot pr ...@@ -284,6 +283,7 @@ echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot pr
// echo '</div>'; // echo '</div>';
echo '</div>'; echo '</div>';
echo $html_tail_imports; echo $html_tail_imports;
echo $rm_ads_snippet;
echo '</body> echo '</body>
</html>'; </html>';
exit(0); exit(0);
......
...@@ -383,7 +383,7 @@ div.ccsection-footer { ...@@ -383,7 +383,7 @@ div.ccsection-footer {
/*in directory view*/ /*in directory view*/
.full-directory { .full-directory {
margin: 0 25; margin: 70 25 0 25;
} }
.container.inner { .container.inner {
width: 100%; width: 100%;
......
...@@ -18,14 +18,110 @@ jQuery.fn.disableTextSelect = function() { ...@@ -18,14 +18,110 @@ jQuery.fn.disableTextSelect = function() {
}); });
}; };
ids = 0; ids = 0;
completion = {}; completion = {};
gexf = ""; gexf = "";
// module fragment to expose selected functions
var whoswho = {};
whoswho = (function(ww) {
// filter type => label
ww.filters = {
'countries': "in",
'institutions': "from",
'laboratories': "working at",
'keywords': "working on",
'tags': "tagged"
}
// autocomplete
ww.popfilter = function(type, options) {
var label, footer, header, id, id1, id2, input, closebox, labelization;
if (!options) {
options = {}
}
if (! options.prefill) {
options['prefill']=''
}
label = ww.filters[type];
id = ids++;
id1 = "filter" + id;
id2 = "combo" + id;
id3 = "close" + id;
header = "<li id=\"" + id1 + "\" class=\"comex-nav-item filter\" style=\"padding-top: 5px;\">";
labelization = "<span style=\"color: #fff;\">&nbsp; " + label + " </span>";
input = "<input type=\"text\" id=\"" + id2 + "\" class=\"medium filter" + type + "\" placeholder=\"" + type + "\" / value=\""+options['prefill']+"\">";
closebox = "<div id=\""+id3+"\" for=\""+id1+"\" class=\"filter-close operation-light\">x</div>"
footer = "</li>;";
$(header + labelization + input + closebox + footer).insertBefore("#refine");
$('#' + id3).click(whoswho.closeThisBox)
// debug
console.log("whoswho.popfilter: adding autocomplete menu", $("#" + id1))
$("#" + id2).autocomplete({
source: function (req, resp) {
$.ajax({
dataType: "json",
type: "GET",
// url: "/search_filter.php",
url: "/services/api/aggs",
data: {
"field": type,
"like": req.term,
},
success: function(data){
resp(data.map(function(info) {
return {
'label': info.x,
'score': info.n
}
}))
},
error: function(response) {
console.log("ERROR from search_filter AJAX", response)
}
}) ;
},
minLength: 2
})
$("" + id1).hide();
show("#" + id1);
$("#" + id2).focus();
return false;
};
// small filter closing function
ww.closeThisBox = function() {
var targetId = this.getAttribute("for")
if (targetId) {
var tgtBox = document.getElementById(targetId)
// start transition
tgtBox.style.opacity = 0
// remove box
setTimeout(function(){tgtBox.remove()}, 500)
return true
}
else {
console.warn('closeThisBox: no @for attribute!')
return false
}
}
return ww;
})(whoswho);
$(document).ready(function() { $(document).ready(function() {
var cache, closeBox, collectFilters, loadGraph, popfilter, xhrs; var cache, closeBox, collectFilters, loadGraph;
log("document ready.. installing whoswho"); log("document ready.. installing whoswho");
loadGraph = function(g) { loadGraph = function(g) {
gexf = g; gexf = g;
...@@ -38,74 +134,6 @@ $(document).ready(function() { ...@@ -38,74 +134,6 @@ $(document).ready(function() {
} }
}; };
// small filter closing function
closeThisBox = function() {
var targetId = this.getAttribute("for")
if (targetId) {
var tgtBox = document.getElementById(targetId)
// start transition
tgtBox.style.opacity = 0
// remove box
setTimeout(function(){tgtBox.remove()}, 500)
return true
}
else {
console.warn('closeThisBox: no @for attribute!')
return false
}
}
// autocomplete
popfilter = function(label, type, options) {
var footer, header, id, id1, id2, input, closebox, labelization;
id = ids++;
id1 = "filter" + id;
id2 = "combo" + id;
id3 = "close" + id;
header = "<li id=\"" + id1 + "\" class=\"comex-nav-item filter\" style=\"padding-top: 5px;\">";
labelization = "<span style=\"color: #fff;\">&nbsp; " + label + " </span>";
input = "<input type=\"text\" id=\"" + id2 + "\" class=\"medium filter" + type + "\" placeholder=\"" + type + "\" />";
closebox = "<div id=\""+id3+"\" for=\""+id1+"\" class=\"filter-close operation-light\">x</div>"
footer = "</li>;";
$(header + labelization + input + closebox + footer).insertBefore("#refine");
$('#' + id3).click(closeThisBox)
// debug
console.log("whoswho.popfilter: adding autocomplete menu", $("#" + id1))
$("#" + id2).autocomplete({
source: function (req, resp) {
$.ajax({
dataType: "json",
type: "GET",
// url: "/search_filter.php",
url: "/services/api/aggs",
data: {
"field": type,
"like": req.term,
},
success: function(data){
resp(data.map(function(info) {
return {
'label': info.x,
'score': info.n
}
}))
},
error: function(response) {
console.log("ERROR from search_filter AJAX", response)
}
}) ;
},
minLength: 2
})
$("" + id1).hide();
show("#" + id1);
$("#" + id2).focus();
return false;
};
// jQuery(".unselectable").disableTextSelect(); // jQuery(".unselectable").disableTextSelect();
jQuery(".unselectable").disableSelection(); jQuery(".unselectable").disableSelection();
$(".unselectable").hover((function() { $(".unselectable").hover((function() {
...@@ -125,26 +153,22 @@ $(document).ready(function() { ...@@ -125,26 +153,22 @@ $(document).ready(function() {
}); });
$("#addfiltercountry").click(function() { $("#addfiltercountry").click(function() {
return popfilter("in", "countries", []); return whoswho.popfilter("countries");
}); });
// $("#addfilterorganization").click(function() { // $("#addfilterorganization").click(function() {
// return popfilter("from", "organizations", []); // return whoswho.popfilter("organizations");
// }); // });
$("#addfilterinstitution").click(function() { $("#addfilterinstitution").click(function() {
return popfilter("from", "institutions", []); return whoswho.popfilter("institutions");
}); });
$("#addfilterlaboratory").click(function() { $("#addfilterlaboratory").click(function() {
var prefix; return whoswho.popfilter("laboratories");
prefix = "working";
return popfilter("" + prefix + " at", "laboratories", []);
}); });
$("#addfilterkeyword").click(function() { $("#addfilterkeyword").click(function() {
var prefix; return whoswho.popfilter("keywords");
prefix = "working";
return popfilter("" + prefix + " on", "keywords", []);
}); });
$("#addfiltertag").click(function() { $("#addfiltertag").click(function() {
return popfilter("tagged", "tags", []); return whoswho.popfilter("tags");
}); });
$("#register").click(function() { $("#register").click(function() {
return window.open("/services/user/register/"); return window.open("/services/user/register/");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment