Commit 82663596 authored by Romain Loth's avatar Romain Loth

Search in abstract with a better code structure (separate from the lib)

parent b63ed41b
...@@ -26,6 +26,10 @@ th a { ...@@ -26,6 +26,10 @@ th a {
min-width: 20em; min-width: 20em;
} }
#doubleSearch {
min-width: 25em;
}
.dynatable-search { .dynatable-search {
margin-left: 2em; margin-left: 2em;
font-size: 16px; font-size: 16px;
......
...@@ -435,11 +435,14 @@ function Main_test( Data , SearchFilter ) { ...@@ -435,11 +435,14 @@ function Main_test( Data , SearchFilter ) {
}, },
features: { features: {
pushState: false, pushState: false,
// prevent default title search which can't do title vs abstract
search: false,
// sort: false //i need to fix the sorting function... the current one just sucks // sort: false //i need to fix the sorting function... the current one just sucks
}, },
// inputs: { inputs: {
// queries: $('#searchAB') // our own search which differentiates title vs abstract queries
// }, queries: $('#doubleSearch')
},
writers: { writers: {
_rowWriter: ulWriter _rowWriter: ulWriter
// _cellWriter: customCellWriter // _cellWriter: customCellWriter
...@@ -454,26 +457,53 @@ function Main_test( Data , SearchFilter ) { ...@@ -454,26 +457,53 @@ function Main_test( Data , SearchFilter ) {
$(".dynatable-record-count").insertAfter(".imadiv") $(".dynatable-record-count").insertAfter(".imadiv")
$(".dynatable-pagination-links").insertAfter(".imadiv") $(".dynatable-pagination-links").insertAfter(".imadiv")
// make filter checkboxes appear in the right place (ie after search box)
$("#filter_search").html( $("#filter_search").html().replace('selected="selected"') ); $("#filter_search").html( $("#filter_search").html().replace('selected="selected"') );
$("#"+SearchFilter).attr( "selected" , "selected" ) $("#"+SearchFilter).attr( "selected" , "selected" )
var the_content = $("#filter_search").html(); var the_content = $("#filter_search").html();
$(""+the_content).insertAfter("#dynatable-query-search-my-ajax-table") $(""+the_content).insertAfter("#doubleSearch")
// binds a custom filter to our 'doubleSearch' via dynatable.queries.functions
// $('#searchAB').click( function() { MyTable.data('dynatable').queries
// if($(this).is(':checked')) { .functions['doubleSearch'] = function(record,searchString) {
// console.log( "Do stuff") // NB searchString == $("#doubleSearch").val()
// $("#dynatable-query-search-my-ajax-table").keyup(function (e) {
// if (e.keyCode == 13) { // by default we always decide to search in the title
// console.log("Do stuff: Just pressed ENTER") matchInTexts = [record.title]
// }
// }) // if box is checked we'll also search in the abstracts
// } if ($("#searchAB").is(':checked')) {
// }); matchInTexts.push(record.hyperdata.abstract)
// MyTable.data('dynatable').settings.inputs.queries = { $('#searchAB') } }
// .insertAfter("#dynatable-query-search-my-ajax-table") // inspired from the default cf. dynatable.queries.functions['search']
var contains = false;
for (i in matchInTexts) {
matchInText = matchInTexts[i]
contains = (
matchInText.toLowerCase().indexOf(
searchString.toLowerCase()
) !== -1
)
if (contains) { break; } else { continue; }
}
return contains;
}
MyTable.data('dynatable').process
// re-apply search function on click
$('#searchAB').click( function() {
MyTable.data('dynatable').process();
});
// re-apply search function on ENTER
$("#doubleSearch").keyup(function (e) {
if (e.keyCode == 13) {
MyTable.data('dynatable').process();
}
})
return "OK" return "OK"
} }
......
...@@ -61,6 +61,14 @@ ...@@ -61,6 +61,14 @@
<p id="corpusdisplayer" onclick='Final_UpdateTable("click")' class="btn btn-primary btn-lg" style="width:200px; margin:0 auto; display:block;">Titles</h2></p> <p id="corpusdisplayer" onclick='Final_UpdateTable("click")' class="btn btn-primary btn-lg" style="width:200px; margin:0 auto; display:block;">Titles</h2></p>
</a> </a>
</h4> </h4>
<!-- search box with custom function in Docs_dyna_chart_and_tables.js -->
<div class="pull-left" style="margin-top:1.85em; font-size: 16px;">
Search:
<input type="search" id="doubleSearch"/>
</div>
</div> </div>
<div id="collapseOne" class="panel-collapse collapse no-transition" role="tabpanel"> <div id="collapseOne" class="panel-collapse collapse no-transition" role="tabpanel">
<div class="panel-body"> <div class="panel-body">
...@@ -78,6 +86,7 @@ ...@@ -78,6 +86,7 @@
<div id="filter_search" style="visibility:hidden"> <div id="filter_search" style="visibility:hidden">
<span style="font-size:70%;"> <span style="font-size:70%;">
<!-- Used by the #doubleSearch associated function -->
<input title="Search in Titles" id="searchTI" name="searchTI" type="checkbox" checked onclick="return false">TI&nbsp; <input title="Search in Titles" id="searchTI" name="searchTI" type="checkbox" checked onclick="return false">TI&nbsp;
<input title="Search in Abstracts" id="searchAB" name="searchAB" type="checkbox">AB <input title="Search in Abstracts" id="searchAB" name="searchAB" type="checkbox">AB
</span>&nbsp;&nbsp; </span>&nbsp;&nbsp;
...@@ -90,7 +99,10 @@ ...@@ -90,7 +99,10 @@
<!-- </optgroup> --> <!-- </optgroup> -->
<!-- <optgroup label="Duplicates"> --> <!-- <optgroup label="Duplicates"> -->
<!-- <option value="filter_doi">By DOI</option> --> <!-- <option value="filter_doi">By DOI</option> -->
<option id="filter_dupl-titles" value="filter_dupl-titles">Duplicates by Title</option>
<!-- TODO
<option id="filter_dupl-titles" value="filter_dupl-titles">Duplicates by Title</option> -->
<!-- </optgroup> --> <!-- </optgroup> -->
</select> </select>
......
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