forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from crhallberg/ebsco
EDS advanced search in Bootstrap.
- Loading branch information
Showing
4 changed files
with
236 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/*global addSearchString, searchFields, searchFieldLabel, searchLabel, searchMatch */ | ||
|
||
var nextGroup = 0; | ||
var groupSearches = []; | ||
var booleanSearchOperators = ["AND", "OR", "NOT"]; | ||
|
||
function addSearch(group, term, field, op) | ||
{ | ||
// Does anyone use this??? | ||
if (typeof term == "undefined") {term = '';} | ||
if (typeof field == "undefined") {field = '';} | ||
if (typeof op == "undefined") {op = 'AND';} | ||
|
||
// Build the new search | ||
var inputIndex = $('#group'+group+' input').length; | ||
var inputID = group+'_'+$('#group'+group+' input').length; | ||
var newSearch ='<div class="search" id="search'+inputID+'"><div class="span3 text-right">'; | ||
if (typeof groupSearches[group] == "undefined") { | ||
newSearch += '<label for="search_lookfor' + group + '_' + groupSearches[group] + '"><span class="help-inline">' + searchLabel + ':</span></label>'; | ||
groupSearches[group] = 0; | ||
} else { | ||
newSearch += '<select id="search_op' + group + '_' + groupSearches[group] + '" name="op' + group + '[]" class="span9">'; | ||
for(var i=0, len= booleanSearchOperators.length; i < len; i++) { | ||
var searchOp = booleanSearchOperators[i]; | ||
var sel = ''; | ||
if(op == searchOp) { | ||
sel = ' selected=selected '; | ||
} | ||
newSearch += '<option value="' + searchOp + '" ' + sel + ">" + searchOp +"</option>"; | ||
} | ||
newSearch += '</select>'; | ||
} | ||
newSearch += '</div><div class="span9"><input class="span7" id="search_lookfor'+inputID+'" type="text" name="lookfor'+group+'[]" value="'+term+'">' | ||
+ '<span class="help-inline">'+searchFieldLabel+'</span> ' | ||
+ '<select class="span4" id="search_type'+inputID+'" name="type'+group+'[]">'; | ||
for (var key in searchFields) { | ||
newSearch += '<option value="' + key + '"'; | ||
if (key == field) { | ||
newSearch += ' selected="selected"'; | ||
} | ||
newSearch += ">" + searchFields[key] + "</option>"; | ||
} | ||
newSearch += '</select> <a href="#" onClick="deleteSearch('+group+','+inputIndex+')" class="help-inline delete" title="Remove this term">×</a></div>'; | ||
|
||
// Insert it | ||
$("#group" + group + "Holder").before(newSearch); | ||
// Show x | ||
$('#group'+group+' .search .delete').show(); | ||
groupSearches[group]++; | ||
} | ||
|
||
function deleteSearch(group, eq) | ||
{ | ||
var searches = $('#group'+group+' .search'); | ||
for(var i=eq;i<searches.length-1;i++) { | ||
$(searches[i]).find('input').val($(searches[i+1]).find('input').val()); | ||
var select0 = $(searches[i]).find('select')[0]; | ||
var select1 = $(searches[i+1]).find('select')[0]; | ||
select0.selectedIndex = select1.selectedIndex; | ||
} | ||
if(groupSearches[group] > 1) { | ||
$('#group'+group+' .search:last').remove(); | ||
groupSearches[group]--; | ||
} | ||
// Hide x | ||
if(groupSearches[group] == 1) { | ||
$('#group'+group+' .search .delete').hide(); | ||
} | ||
} | ||
|
||
function addGroup(firstTerm, firstField, join) | ||
{ | ||
if (firstTerm == undefined) {firstTerm = '';} | ||
if (firstField == undefined) {firstField = '';} | ||
if (join == undefined) {join = '';} | ||
|
||
var newGroup = '<div id="group'+nextGroup+'" class="group well clearfix">' | ||
+ '<input type="hidden" name="bool'+nextGroup+'[]" value="AND"/>' | ||
+ '<div class="span11"><div id="group'+nextGroup+'Holder" class="span9 offset3"><i class="icon-plus-sign"></i> <a href="#" onClick="addSearch('+nextGroup+')">'+addSearchString+'</a></div></div>' | ||
+ '<div class="span1"><a href="#" onClick="deleteGroup('+nextGroup+')" class="close hide" title="Remove Group">×</a></div></div>'; | ||
|
||
$('#groupPlaceHolder').before(newGroup); | ||
addSearch(nextGroup, firstTerm, firstField); | ||
// Show join menu | ||
if($('.group').length > 1) { | ||
$('#groupJoin').removeClass('hidden'); | ||
// Show x | ||
$('.group .close').show(); | ||
} | ||
return nextGroup++; | ||
} | ||
|
||
function deleteGroup(group) | ||
{ | ||
// Find the group and remove it | ||
$("#group" + group).remove(); | ||
// If the last group was removed, add an empty group | ||
if($('.group').length == 0) { | ||
addGroup(); | ||
} else if($('.group').length == 1) { // Hide join menu | ||
$('#groupJoin').addClass('hidden'); | ||
// Hide x | ||
$('.group .close').hide(); | ||
} | ||
} | ||
|
||
// Fired by onclick event | ||
function deleteGroupJS(group) | ||
{ | ||
var groupNum = group.id.replace("delete_link_", ""); | ||
deleteGroup(groupNum); | ||
return false; | ||
} | ||
|
||
// Fired by onclick event | ||
function addSearchJS(group) | ||
{ | ||
var groupNum = group.id.replace("add_search_link_", ""); | ||
addSearch(groupNum); | ||
return false; | ||
} |
26 changes: 26 additions & 0 deletions
26
themes/bootstrap/templates/search/advanced/build_page_eds.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
$(document).ready(function() { | ||
<? if (isset($this->searchDetails) && is_object($this->searchDetails)): ?> | ||
<? foreach ($this->searchDetails->getQueries() as $searchGroup): ?> | ||
<? $i = 0; foreach ($searchGroup->getQueries() as $search): ?> | ||
<? if (++$i == 1): ?> | ||
var new_group = addGroup( | ||
'<?=addslashes($search->getString())?>', | ||
'<?=addslashes($search->getHandler())?>', | ||
'<?=$searchGroup->isNegated() ? 'NOT' : $searchGroup->getOperator()?>' | ||
); | ||
<? else: ?> | ||
addSearch(new_group, | ||
'<?=addslashes($search->getString())?>', | ||
'<?=addslashes($search->getHandler())?>', | ||
'<?=addslashes($search->getOperator())?>' | ||
); | ||
<? endif; ?> | ||
<? endforeach; ?> | ||
<? endforeach; ?> | ||
<? else: ?> | ||
var new_group = addGroup(); | ||
addSearch(new_group); | ||
addSearch(new_group); | ||
<? endif; ?> | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<? if (!empty($this->expanderList)): ?> | ||
<fieldset class="span4"> | ||
<legend><?=$this->transEsc('eds_modes_and_expanders')?></legend> | ||
<? foreach ($this->expanderList as $field => $expander): | ||
$value = $expander['Value'] ?> | ||
<label class="displayBlock" for="expand_<?=$this->escapeHtml(str_replace(' ', '+', $field))?>"><?=$this->transEsc('eds_expander_' . $value, array(), $expander['Label'])?></label> | ||
<input id="expand_<?=$this->escapeHtml(str_replace(' ', '+', $field))?>" type="checkbox" <?=(isset($expander['selected']) && $expander['selected'])?'checked="checked"':''?> name="filter[]" value="EXPAND:<?=$this->escapeHtml($value)?>"> | ||
<? endforeach; ?> | ||
|
||
<label class="displayBlock" for="searchModes"><?=$this->transEsc('Search Mode')?></label> | ||
<select id="searchMode_<?=$this->escapeHtml($field)?>" name="filter[]"> | ||
<? foreach ($this->searchModes as $field => $searchMode): | ||
$value = $searchMode['Value'] ?> | ||
<option <?=(isset($searchMode['selected']) && $searchMode['selected'])?'selected="selected"':''?> value="SEARCHMODE:<?=$this->escapeHtml($value)?>"> | ||
<?= /* 'Label' comes from API and is always in English; try to translate structured value before using it: */ $this->transEsc('eds_mode_' . $value, array(), $searchMode['Label']) ?> | ||
</option> | ||
<? endforeach; ?> | ||
</select> | ||
</fieldset> | ||
<? endif; ?> | ||
|
||
<? if (!empty($this->limiterList)): ?> | ||
<fieldset class="span4"> | ||
<legend><?=$this->transEsc('Limit To')?></legend> | ||
<? foreach ($this->limiterList as $field => $facet): ?> | ||
<? switch($facet['Type']){ | ||
case 'multiselectvalue': ?> | ||
<label class="displayBlock" for="limit_<?=$this->escapeHtml(str_replace(' ', '+', $field))?>"><?=$this->transEsc($facet['Label'])?></label> | ||
<select id="limit_<?=$this->escapeHtml($field)?>" name="filter[]" multiple="multiple" size="10"> | ||
<? foreach ($facet['LimiterValues'] as $id => $facetValue): ?> | ||
<? $value = $facetValue['Value']; ?> | ||
<option value="<?='LIMIT|'.$this->escapeHtml($field . ':' . $facetValue['Value'])?>"<?=(isset($facetValue['selected']) && $facetValue['selected'])?' selected="selected"':''?>><?=$this->escapeHtml($facetValue['Value'])?></option> | ||
<? endforeach; ?> | ||
</select> | ||
<!-- <br/> --> | ||
<? break; | ||
case 'select': | ||
$value = $facet['LimiterValues'][0]['Value'] ?> | ||
<label class="displayBlock" for="limit_<?=$this->escapeHtml(str_replace(' ', '+', $field))?>"> | ||
<?=$this->transEsc('eds_limiter_' . $field, array(), $facet['Label'])?> | ||
</label> | ||
<input id="limit_<?=$this->escapeHtml(str_replace(' ', '+', $field))?>" type="checkbox" <?=(isset($facet['LimiterValues'][0]['selected']) && $facet['LimiterValues'][0]['selected'])?'checked="checked"':''?> name="filter[]" value="<?=$this->escapeHtml('LIMIT|'.$field . ':' . $value)?>"> | ||
<!-- <br/> --> | ||
<? break; | ||
case 'text': ?> | ||
<!-- not implemented --> | ||
<? break; | ||
case 'numeric':?> | ||
<!-- not implemented --> | ||
<? break; | ||
case 'numericrange':?> | ||
<!-- not implemented --> | ||
<? break; | ||
case 'ymrange': ?> | ||
<!-- not implemented --> | ||
<? break; | ||
case 'yrange:' ?> | ||
<!-- not implemented --> | ||
<? break; | ||
case 'historicalrange':?> | ||
<!-- not implemented --> | ||
<? break; | ||
case 'singleselectvalue':?> | ||
<!-- not implemented --> | ||
<? break; | ||
}; ?> | ||
<? endforeach; ?> | ||
</fieldset> | ||
<? endif; ?> | ||
<? if (isset($this->dateRangeLimit)): ?> | ||
<? /* Load the publication date slider UI widget */ $this->headScript()->appendFile('pubdate_slider.js'); ?> | ||
<input type="hidden" name="daterange[]" value="PublicationDate"/> | ||
<fieldset class="publishDateLimit span4" id="PublicationDate"> | ||
<legend><?=$this->transEsc('adv_search_year')?></legend> | ||
<label for="PublicationDatefrom"><?=$this->transEsc('date_from')?>:</label> | ||
<input type="text" size="4" maxlength="4" class="yearbox" name="PublicationDatefrom" id="PublicationDatefrom" value="<?=$this->escapeHtml($this->dateRangeLimit[0])?>" /> | ||
<label for="PublicationDateto"><?=$this->transEsc('date_to')?>:</label> | ||
<input type="text" size="4" maxlength="4" class="yearbox" name="PublicationDateto" id="PublicationDateto" value="<?=$this->escapeHtml($this->dateRangeLimit[1])?>" /> | ||
<div id="PublicationDateSlider" class="dateSlider"></div> | ||
</fieldset> | ||
<? endif; ?> |