Page MenuHomec4science

websearch_search.html
No OneTemporary

File Metadata

Created
Thu, Nov 7, 09:21

websearch_search.html

{#
## This file is part of Invenio.
## Copyright (C) 2012 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#}
{% from "_formhelpers.html" import render_filter_form with context %}
{% from "websearch_helpers.html" import collection_tree, portalbox_sidebar, search_also, search_form, record_brief_links with context %}
{% from "websearch_results.html" import render_search_results with context %}
{% extends "page.html" %}
{% set title = collection.name_ln if collection.id > 1 else None %}
{%- set portalboxes = dict() -%}
{%- for k,l in collection.portalboxes_ln|groupby('position') -%}
{%- do portalboxes.update({k:l}) -%}
{%- endfor -%}
{% block breadcrumb %}
{% endblock %}
{% block title %}
{{ portalboxes.tp }}
{{ super() }}
{{ portalboxes.te }}
{% endblock %}
{% block header %}
{{ super() }}
{% js "js/websearch_typeahead.js" %}
{% js "js/websearch_facet.js" %}
{% js "js/bootstrap-select.js" %}
{%- set args = request.args.copy().to_dict() -%}
{%- set jrec = (pagination.page-2)*pagination.per_page+1 if pagination.has_prev else 1 -%}
{%- do args.update({'jrec': jrec}) -%}
{%- if pagination.has_prev -%}
<link rel="prev" href="{{ url_for(request.endpoint, **args) }}"/>
{%- endif -%}
{%- if pagination.has_next -%}
{%- set jrec = (pagination.page)*pagination.per_page+1 if pagination.has_next else (pagination.pages-1)*pagination.per_page+1 -%}
{%- do args.update({'jrec': jrec}) -%}
<link rel="next" href="{{ url_for(request.endpoint, **args) }}"/>
{%- endif -%}
{% endblock %}
{% block body %}
<style>
.modal-backdrop {
/* Show lighter modal window for search. */
background-color: rgba(255,255,255,0.5);
}
#facet_list .accordion-heading {
background-color: whiteSmoke;
}
#facet_list .accordion-heading a:after {
content: ' ';
float: right;
display: inline-block;
width: 14px;
height: 14px;
line-height: 14px;
vertical-align: text-top;
background-image: url("../img/glyphicons-halflings.png");
background-position: 14px 14px;
background-repeat: no-repeat;
/* list alt */
background-position: -264px -24px;
}
#facet_list ul.unstyled ul.unstyled {
padding-left: 10px;
font-size: 90%;
}
#facet_list {
}
#facet_list.affix {
top: 60px;
}
body {
position: relative;
}
#facet_list.affix-bottom {
position: absolute;
top: auto;
bottom: 170px;
}
</style>
{{ search_form(collection) }}
{% if not recids|length %}
<div class="row">
<div class="span12">
<p>
<strong>{{ _('Your search did not match any records. Please try again.') }}</strong>
</p>
{{ create_nearest_terms_box()|safe }}
</div>
</div>
{% else %}
<div class="row">
<div class="span2 visible-desktop">
<div class="row">
<div
class="accordion span2 facet"
id="facet_list">
</div>
</div>
</div>
<div class="span10">
<div class="row visible-desktop">
<div class="span10">
<div class="well" id="facet_filter" style="clear:both; display: none;">
<input type="hidden" value="{{ request.args.get('p', '') }}" name="p" />
</div>
</div>
</div>
<div class="row">
<div id="search_results" class="span10">
{{ render_search_results(recids, collection, pagination, format_record) }}
</div>
</div>
</div>
</div>
<div class="modal hide" id="overlay">
<div class="modal-body">
<center>
<img alt="" src="/img/loading.gif" id="img-load" />
<strong>{{ _('Filtering') }} ...</strong>
</center>
</div>
</div>
<script>
(function($) {
var popupTimer // global popup timer
// side facet list
$('#facet_list').affix({
offset: {
top: function () {
var $s = $('#search-box-main'),
h = $s.height(),
y = $s.offset()['top']
return $(window).width() <= 980 ? 165 : h }
, bottom: 170
}
})
$('#overlay').modal({
keyboard: false,
backdrop: 'static'
}).modal('hide');
$('#facet_list').facet({
button_builder: function(title) {
return '<a style="cursor:pointer" class="muted"><small>'+title+' ...</small></a> ';
},
row_builder: function(data, name) {
var title = data[(data.length==3)?2:0],
counter = data[1]
return '<li class="controls" style="display:none">'+
'<a class="expandable" style="cursor:pointer" ' +
'data-target="#facet_list" ' +
'data-facet="toggle" ' +
'data-facet-action="+" '+
'data-facet-key="' + name + '" '+
'data-facet-value="' + data[0] + '">' +
title +
'</a> <small class="muted">('+counter+')</small>' +
'</li>'
},
box_builder: function(name, title) {
return '<div class="'+name+'">' +
'<a style="cursor:pointer" ' +
'data-facet="reset-key" '+
'data-target="#facet_list" ' +
'data-facet-key="'+ name +'"><strong>'+
title + '</strong></a>' +
'<ul class="context unstyled"><ul></div>'
},
facets: {{ facets|tojson|safe }}
}).on('updated', function(event) {
var p = $('#facet_filter input[name=p]').val()
, facet = $('#facet_list').data('facet')
$('#search-box-main input[name=p]')
.val(p+' '+facet.queryString());
var filter = JSON.stringify(facet.filter)
, hash = decodeURIComponent(document.location.hash)
if (filter != hash.substr(1)) {
if (filter != '[]') {
document.location.hash = encodeURIComponent(filter);
} else {
document.location.hash = '';
}
}
var showModal = true;
var modalShow= function() {
if (showModal) {
$("#overlay").modal('show');
}
};
setTimeout(modalShow, 100);
$.ajax('{{ url_for('.results', qid=qid) }}', {
type: 'POST',
data: $.extend( {},
{{ request.args.to_dict()|tojson|safe }}
,{
'filter': filter
})
}).done(function(data) {
$('#search_results').html(data);
showModal = false;
$("#overlay").modal('hide');
});
}).on('loaded', function(event) {
var typeahead = $('form[name=search] input[name=p]').data('typeahead')
, facet = $('#facet_list').data('facet')
// Move out from library
var expand = jQuery.grep(facet.filter, function (a) {
return a[0] == '!'
})
$.each(expand, function(i,v) {
facet.$element.trigger($.Event('added', {op: v[0], key: v[1], value: v[2]}));
});
if ($.inArray(event.name+':', typeahead.options.source)<0) {
typeahead.options.source.push(event.name+':');
}
if (! typeahead.options.sources ) {
typeahead.options.sources = {}
}
typeahead.options.sources[event.name] = $.map(event.facet, function(i) {
return i[0];
});
$('[data-facet="toggle"]')
.filter('[data-facet-key="'+event.name+'"]')
.addClass('muted').each(function(i) {
var $e = $(this),
filterContent = function() {
return '{{ _('Default action is <em class="text-info">limit</em>, however you can also <abbr title="you can use shift+left click"><em class="text-error">exclude</em></abbr> selected term from results.')|safe }}<br/><a class="btn btn-small btn-error" style="cursor:pointer" ' +
'data-target="#facet_list" ' +
'data-facet="toggle" ' +
'data-facet-action="-" '+
'data-facet-key="' + $e.attr('data-facet-key') + '" '+
'data-facet-value="' + $e.attr('data-facet-value') + '">' +
'{{ _('Exclude') }}' + '</a>'
}
$e.popover({
html: true
, placement: 'right'
, trigger: 'manual'
, content: filterContent
, title: '{{ _('Did you know?') }}'
}).on('mouseenter', function() {
var popupFunc = function() {$e.popover('show')}
if (popupTimer)
clearTimeout(popupTimer)
popupTimer = setTimeout(popupFunc, 2000)
}).on('click', function() {
if (popupTimer)
clearTimeout(popupTimer)
$e.popover('hide')
}).parent().on('mouseleave', function() {
if (popupTimer)
clearTimeout(popupTimer)
$e.popover('hide')
})
}).on('click', function(event) {
var $el_clicked = $(this),
options = $('#facet_list').data('facet').options
if (!$el_clicked.hasClass('expandable') && $el_clicked.attr('data-facet-key') === 'collection') {
if ($el_clicked.parent().has('ul')) {
var $ul = $el_clicked.parent().find('ul')
$ul.each(function(i, ul) {
$(this).find('[data-facet="toggle"]').each(function() {
$('#facet_list').data('facet').delete('+', $(this).attr('data-facet-key'), $(this).attr('data-facet-value'))
$('#facet_list').data('facet').delete('-', $(this).attr('data-facet-key'), $(this).attr('data-facet-value'))
})
})
if ($el_clicked.hasClass('text-info') ||
$el_clicked.hasClass('text-error')) {
$ul.remove()
$el_clicked.addClass('expandable')
$('#facet_list').data('facet').filter = $('#facet_list').data('facet').exclude('!', $(this).attr('data-facet-key'), $(this).attr('data-facet-value'))
}
}
}
})
// on hover add button in popover
//$('[data-facet="reset-key"]').addClass('text-info')
$('[data-facet="reset-key"]').each(function(e) {
$(this).on('click', function() {
$('[data-facet-key="'+ $(this).attr('data-facet-key') +'"]')
.attr('data-facet-action', '+')
.removeClass('text-error')
.removeClass('text-info')
.css('font-weight', 'normal')
$(this).removeClass('muted').addClass('text-info')
})
})
$('#search_results').css('min-height', $('#facet_list').height())
$('#facet_list').affix('checkPosition');
if (document.location.hash.length > 2) {
$(window).trigger('hashchange');
}
}).on('deleted', function(event) {
$('[data-facet-key="'+event.key+'"]')
.filter('[data-facet-value="'+event.value+'"]')
.each(function(e) {
$(this)
.removeClass('text-error')
.removeClass('text-info')
.css('font-weight', 'normal')
.attr('data-facet-action', '+')
})
var resetKey = false
try {
if ($(this).data('facet').findByKey(event.key).length == 0) {
resetKey = true
}
} catch(err) {
resetKey = true
}
if (resetKey) {
$('[data-facet="reset-key"]')
.filter('[data-facet-key="'+event.key+'"]')
.addClass('text-info')
}
}).on('added', function(event) {
var type = (event.op == '+')?'info':'error'
$('[data-facet-key="'+event.key+'"]')
.filter('[data-facet-value="'+event.value+'"]')
.each(function(e) {
if (event.op != '!') {
$(this)
.addClass('text-'+type)
.css('font-weight', 'bold')
}
})
.filter('.expandable')
.each(function() {
var $el_clicked = $(this),
options = $('#facet_list').data('facet').options
$el_clicked.removeClass('expandable')
if (event.key === 'collection') {
//if ($el_clicked.parent().has('ul').length > 0) {
// $el_clicked.parent().find('ul').each(function(i, ul) {
// $(this).find('[data-facet="toggle"]').each(function() {
// $('#facet_list').data('facet').delete('+', $(this).attr('data-facet-key'), $(this).attr('data-facet-value'))
// $('#facet_list').data('facet').delete('-', $(this).attr('data-facet-key'), $(this).attr('data-facet-value'))
// })
// }).remove()
//} else {
// do cleaning first
$(this).parent().find('ul').remove()
var facet = {url: options.url_map[event.key]
, facet: event.key}
, data = {parent: event.value}
, $ul = $('<ul class="context unstyled"><ul>').clone().appendTo($el_clicked.parent())
$('#facet_list').data('facet').filter.push(['!', event.key, event.value])
$('#facet_list').data('facet').createFacetBox(facet, $ul, data)
//}
}
})
$('[data-facet="reset-key"]')
.filter('[data-facet-key="'+event.key+'"]')
.removeClass('text-info')
.addClass('muted')
}).on('exists', function(event) {
alert('{{ _('An item is already in the facet filter.') }}');
});
// Enable tooltips.
$('[rel=tooltip]').tooltip();
// Rebuild facet filter on hash change.
$(window).bind('hashchange', function() {
var hash = decodeURIComponent(document.location.hash)
, hash_filter = hash.substr(1)
, filter = jQuery.parseJSON(hash_filter);
if (JSON.stringify($('#facet_list').data('facet').filter) != hash_filter) {
$('#facet_list').data('facet').rebuildFilter(filter || []);
}
});
// Trigger history change.
if (document.location.hash.length > 2) {
$(window).trigger('hashchange');
}
})(jQuery);
</script>
{% endif %}
{% endblock %}

Event Timeline