Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104569137
websearch_helpers.html
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Mar 10, 13:30
Size
23 KB
Mime Type
text/html
Expires
Wed, Mar 12, 13:30 (2 d)
Engine
blob
Format
Raw Data
Handle
24814050
Attached To
R3600 invenio-infoscience
websearch_helpers.html
View Options
{#
## 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.
#}
{% macro record_brief_links(recID) %}
{%- set rinfo = RecordInfo(recID) -%}
<p>
{%- set similar = "recid:%d" % recID -%}
{%- if config.CFG_WEBSEARCH_USE_ALEPH_SYSNOS -%}
{%- set alephsysnos = rinfo.get_fieldvalues("970__a") -%}
{%- if len(alephsysnos) > 0 -%}
{%- set recID = alephsysnos[0] -%}
{%- set similar = "sysno:%d" % recID -%}
{%- endif -%}
{%- endif -%}
<a class="text-success"
href="{{ url_for('record.metadata', recid=recID) }}">
{{ _("Detailed record") }}
</a>
-
<a class="text-success"
href="{{ url_for('.search', p=similar, rm='wrd') }}">
{{ _("Similar records") }}
</a>
{# Citations link #}
{%- if config.CFG_BIBRANK_SHOW_CITATION_LINKS -%}
{%- set num_citations = rinfo.get_cited_by_count() -%}
{%- if num_citations -%}
-
<a href="{{ url_for('.search', p="refersto:recid:%d" % recID) }}">
{{ _("Cited by %i records") % num_citations if num_citations > 1 else _("Cited by 1 record") }}
</a>
{%- endif -%}
{%- endif -%}
{# Comments link #}
{%- if config.CFG_WEBCOMMENT_ALLOW_COMMENTS and config.CFG_WEBSEARCH_SHOW_COMMENT_COUNT -%}
{%- set num_comments = rinfo.get_nb_comments() -%}
{%- if num_comments -%}
-
<a href="{{ url_for('webcomment.comments', recid=recID) }}">
<i class="icon-comment"></i>
{{ _("%i comments") % num_comments if num_comments > 1 else _("1 comment") }}
</a>
{%- endif -%}
{%- endif -%}
{# Reviews link #}
{%- if config.CFG_WEBCOMMENT_ALLOW_REVIEWS and config.CFG_WEBSEARCH_SHOW_REVIEW_COUNT -%}
{%- set num_reviews = rinfo.get_nb_reviews() -%}
{%- if num_reviews -%}
-
<a href="{{ url_for('webcomment.reviews', recid=recID) }}">
<i class="icon-eye-open"></i>
{{ _("%i reviews") % num_reviews if num_reviews > 1 else _("1 review") }}
</a>
{%- endif -%}
{%- endif -%}
</p>
{% endmacro %}
{% macro collection_tree(collections, limit=None) %}
{%- set idxs = [0] -%}
<ul {{ kwargs|xmlattr }}>
{% for collection in collections recursive %}
<li>
{# Do not show checkboxes in new UI
{% if idxs|length == 1 %}
<input type="checkbox" name="c" value="{{ collection.name }}" checked/>
{% endif %}
#}
<a href="{{ url_for(".collection", name=collection.name) }}">
{{ collection.name_ln }} <span class="badge">{{ collection.nbrecs }}</span>
</a>
{% if collection.collection_children and idxs|length < limit %}
{%- do idxs.append(loop.index) -%}
<ul {{ kwargs|xmlattr }}>
{{ loop(collection.collection_children) }}
</ul>
{%- do idxs.pop() -%}
{% endif %}
</li>
{% endfor %}
</ul>
{% endmacro %}
{% macro portalbox_sidebar(portalboxes, width=2) %}
{% if portalboxes %}
<div {{ kwargs|xmlattr }}>
<ul class="thumbnails">
{% for cp in portalboxes %}
<li class="span{{ width }}">
<div class="thumbnail">
<h5>{{ cp.portalbox.title }}</h5>
<p>{{ cp.portalbox.body|safe }}</p>
</div>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endmacro %}
{% macro search_also(externalcollections) %}
{% if externalcollections %}
<h4>{{ _("Search also") }}</h4>
<ul>
{% for ex in externalcollections %}
<li>{{ ex.name }} <a href="{{ ex.engine.base_url}}">
<img src="{{ url_for("static", filename="img/external-icon-light-8x8.gif")}}" alt="{{ ex.engine.base_url }}"/>
</a></li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
{% macro _search_hidden_options() %}
{%- for name in ['rg', 'of', 'so', 'sf', 'rm'] -%}
{%- if request.args.get(name) -%}
<input type="hidden" name="{{ name }}" value="{{ request.args.get(name, '') }}" />
{%- endif -%}
{%- endfor -%}
{% endmacro %}
{% macro _search_simple_box(collection) %}
{% for f in easy_search_form if not f.name=='csrf_token' %}
<div class="control-group">
<label class="control-label">
{{ f.label.text }}
</label>
<div class="controls controls-row">
{{ f|safe }}
</div>
</div>
{% endfor %}
{% endmacro %}
{% macro _search_advanced_box(collection) %}
<div class="control-group">
<label class="control-label">
<strong>{{ _('what') }}:</strong>
</label>
<div class="controls">
<input type="text" name="p1" value="" class="span3"/>
</div>
</div>
<div class="control-group">
<label class="control-label">
<strong>{{ _('where') }}:</strong>
</label>
<div class="controls">
<select class="span2" name="f">
{% for code, name in collection.search_within.iteritems() %}
<option value="{{ code }}">
{{ name }}
</option>
{% endfor %}
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">
<strong>{{ _('how') }}:</strong>
</label>
<div class="controls">
<select class="span2" name="m1">
{%- for k,v in config.CFG_WEBSEACH_MATCHING_TYPES.iteritems() -%}
<option value="{{ k }}">{{ _(v.title)|safe }}</option>
{%- endfor -%}
</select>
<span id="addtosearch" class="btn">
<i class="icon-ok"></i>
</span>
</div>
</div>
{% for id, soo in collection.search_options|groupby('id_field') %}
<hr/>
<div class="control-group">
<label class="control-label">{{ soo[0].field.name_ln }}</label>
<div class="controls">
<select class="span2" name="{{ soo[0].field.code }}">
<option value="">*** {{ _('select') }} ***</option>
{% for so in soo %}
<option value="{{ so.fieldvalue.value }}">
{{ so.fieldvalue.name }}
</option>
{% endfor %}
</select>
<span data-target="p" data-source="{{ soo[0].field.code }}" class="btn appender">
<i class="icon-ok"></i>
</span>
</div>
</div>
{% endfor %}
{% endmacro %}
{% macro search_box(collection) %}
<div style="padding: 0px;" class="dropdown-menu donothide">
<div class="row">
<div class="span6" style="min-width: 400px;">
<div class="modal-header">
<button type="button" style="z-index:9999; position: relative;" class="close" onclick="$('.dropdown.open').removeClass('open')">×</button>
<div class="control" style="margin-bottom: 0px;">
<label class="control-label">
<strong>{{ _('Add to search') }}</strong>
</label>
<div class="controls">
<div style="padding-top:4px;" class="btn-group" data-toggle="buttons-radio">
<label class="btn btn-mini active">
<input style="display:none;" type="radio" name="op1" value="a" checked/>{{ _('AND') }}
</label>
<label class="btn btn-mini">
<input style="display:none;" type="radio" name="op1" value="o"/>{{ _('OR') }}
</label>
<label class="btn btn-mini">
<input style="display:none;" type="radio" name="op1" value="n"/>{{ _('AND NOT') }}
</label>
</div>
</div>
</div>
</div><!-- end modal-header-->
<div style="max-height: 800px;" class="modal-body">
<div class="tab-content">
<div class="tab-pane active" id="simple-search">
{{ _search_simple_box(collection) }}
</div>
<div class="tab-pane" id="advanced-search">
{{ _search_advanced_box(collection) }}
</div>
</div>
</div><!-- end modal-body -->
<div class="modal-footer">
<small><ul class="nav nav-pills nav-pill-gray pull-left" style="margin-bottom: 0px; text-align: left;">
<li class="active">
<a href="#simple-search" data-toggle="tab">simple</a>
</li>
<li>
<a href="#advanced-search" data-toggle="tab">advanced</a>
</li>
</ul></small>
<button name="action_browse" class="btn">
<i class="icon-list"></i> {{ _("Browse") }}
</button>
<button name="action_search" type="submit" class="btn btn-primary">
<i class="icon-search icon-white"></i> {{ _("Search") }}
</button>
</div><!-- end modal-footer -->
</div><!-- end span5 -->
</div><!-- end row -->
</div><!-- end dropdown-menu -->
<style>
.nav.nav-pill-gray > .active > a,
.nav.nav-pill-gray > li > a:hover {
background: none;
text-decoration: underline;
color: inherit;
}
</style>
{% endmacro %}
{% macro search_form(collection) %}
<div id="search-box-main" class="row">
<div class="span12">
<div class="control-group well">
<form action="{{ url_for('.search') }}" name="search" method="get" class="pull-left form-horizontal" style="margin: 0px;">
<label for="p" class="control-label">
{%- set nbrecs = collection.nbrecs -%}
{%- if not collection.nbrecs -%}
{%- set nbrecs = 0 -%}
{%- endif -%}
{{ _("Search %d records for:")|format(nbrecs) }}
</label>
<div class="controls">
<div id="searchdropdown" style="float: left;" class="dropdown">
{% set search_placeholder = _('Input query') %}
{% if collection.examples %}
{% set search_placeholder = (collection.examples|random).example.body %}
{% endif %}
<div class="input-append">
<input autocomplete="off"
data-provide="typeahead"
data-items="4"
name="p"
class="span5"
type="text"
placeholder="{{ _('Example') }}: {{ search_placeholder }}"
value="{{ request.args.get('p', '') }}" autofocus/><!--
No space!
--><span data-toggle="dropdown" data-target="#searchdropdown" class="add-on btn">
<i class="caret"></i>
</span>
</div>
{#
# This is a dirty hack for browser without Javascript support.
#}
<script>
var box = {{ search_box(collection)|tojson|safe }};
//var box = {{ _search_simple_box(collection)|tojson|safe }};
//var box = {{ _search_advanced_box(collection)|tojson|safe }};
document.write(box);
</script>
<!-- Hidden configuration fields -->
{% if collection.id != 1 %}
<input type="hidden" name="cc" value="{{ collection.name }}" />
{% endif %}
{{ _search_hidden_options() }}
<!-- end of configuration fields -->
<button name="action_search" type="submit" class="btn btn-primary">
<i class="icon-search icon-white"></i> {{ _("Search") }}
</button>
<span class="help-inline">
<a href="/help/search-tips">{{ _("Search Tips") }}</a>
</span>
</div>
</div><!-- end controls -->
</form>
<form action="{{ url_for('.search') }}" name="settings" method="get"
style="margin: 0px;" class="pull-right form-inline">
<input name="p" value="{{ request.args.get('p','') }}" type="hidden" />
<div id="settingsdropdown" class="pull-right btn-group dropdown">
<button class="btn dropdown-toggle" data-target="#settingsdropdown" data-toggle="dropdown">
<i class="icon-cog"></i>
<span class="caret"></span>
</button>
<ul class="dropdown-menu donothide clearfix"
style="min-width: 300px; padding-bottom: 0px;">
<li class="nav-header">{{ _('Search settings') }}</li>
<li class="divider"></li>
<li class="clearfix nav-list">
<div class="control-group clearfix">
<label class="control-label pull-left">{{ _('Display on page') }}</label>
<div class="controls pull-right">
<select
name="rg"
style="height: inherit; line-height: inherit;"
class="btn-small span2">
{%- for i in [10, 25, 50, 100, 250, 500] -%}
{%- if i <= config.CFG_WEBSEARCH_MAX_RECORDS_IN_GROUPS -%}
<option value="{{ i }}"{{ ' selected' if request.args.get('rg',10)==i.__str__() }}>{{ i }} {{ _('results') }}</option>
{%- endif -%}
{%- endfor -%}
</select>
</div>
</div>
<div class="control-group clearfix">
<label class="control-label pull-left">{{ _('Output format') }}</label>
<div class="controls pull-right">
<select
name="of"
style="height: inherit; line-height: inherit;"
class="btn-small span2">
{%- for i in collection.formatoptions -%}
<option value="{{ i.code }}"{{ ' selected' if request.args.get('of','hb')==i.code }}>{{ i.name }}</option>
{%- endfor -%}
</select>
</div>
</div>
<div class="clearfix">
<label class="control-label pull-left">{{ _('Sort by most') }}</label>
<div class="controls pull-right">
<div class="btn-group" data-toggle="buttons-radio">
{%- for (k,v,vv) in [('recent', 'rm', ''), ('cited', 'rm', 'citation'), ('relevant', 'rm', 'wrd')] -%}
<label class="btn btn-mini {{ 'active' if request.args.get(v,'') == vv}}">
<input style="display:none;"
type="radio"
name="{{ v }}"
value="{{ vv }}"
{{ 'checked="checked"'|safe if request.args.get(v,'') == vv}}>
{{ _(k) }}
</label>
{%- endfor -%}
</div>
</div>
</div>
</li>
<li class="divider"></li>
<li class="clearfix nav-list">
<div class="control-group clearfix">
<label class="control-label pull-left">{{ _('Search form') }}</label>
<div class="controls pull-right">
<div class="btn-group" data-toggle="buttons-radio">
{%- for (k,v) in [(_('Simple'), 'simple'), (_('Advanced'), 'advanced')] -%}
{%- set active = v=='simple' -%}
<label class="btn btn-mini">
<input style="display:none;"
type="radio"
name="box"
value="{{ v }}"
{{ 'checked="checked"'|safe if active}}>
{{ k }}
</label>
{%- endfor -%}
</div>
</div>
</div>
</li>
<li class="modal-footer nav-list clearfix">
{%- if not current_user.is_guest() -%}
<button name="action_save"
rel="tooltip"
title="{{ _('store permanently in user settings') }}"
data-placement="bottom"
class="btn btn-primary btn-small pull-left">
<i class="icon-hdd icon-white"></i> {{ _('Save') }}
</button>
{%- endif -%}
<button name="action_search"
rel="tooltip"
title="{{ _('use settings in current search') }}"
data-placement="bottom"
class="btn btn-small pull-right">
<i class="icon-ok"></i> {{ _('Apply') }}
</button>
</li>
</ul>
</div>
</form>
<div style="clear: both;"></div>
</div><!-- end controll-group well -->
</div><!-- end span12 -->
</div><!-- end row -->
<script>
$(function () {
$("form[name=search]").submit(function() {
$('.donothide').remove();
return true; // ensure form still submits
});
$('#settingsdropdown select[name="of"]').buttonSelect({
button: '<div class="btn btn-mini" />'
, span: '<span class="btn btn-mini" style="width: 80px;" />'
, next: '<i class="icon icon-chevron-right"></i>'
, prev: '<i class="icon icon-chevron-left"></i>'
})
$('#settingsdropdown select[name="rg"]').buttonSelect({
button: '<div class="btn btn-mini" />'
, span: '<span class="btn btn-mini" style="width: 80px;" />'
, next: '<i class="icon icon-plus"></i>'
, prev: '<i class="icon icon-minus"></i>'
})
if (!("autofocus" in $("form[name=search] input[name=q]"))) {
// ensure we get the focus always in search input
$("form[name=search] input[name=q]").focus();
}
var op1_fn = {'a': 'AND ', 'o': 'OR ', 'n': 'AND NOT '},
m1_fn = {
{%- for k,v in config.CFG_WEBSEACH_MATCHING_TYPES.iteritems() -%}
'{{ k }}': function(val, f) {
{{ v.tokenize|safe }}
}{{ ',' if not loop.last }}
{%- endfor -%}
};
var addtosearch_callback = function(e) {
var op1 = $('[name=op1]:checked').val(),
m1 = $('[name=m1]').val(),
p1 = $('[name=p1]').val(),
f = $('[name=f]').val(),
p = $('[name=p]'),
val = p.val(),
op = (op1=='a' && val=="")?'':op1_fn[op1];
if (val !== "") {
val += ' ';
}
if (p1 === "") { return false; }
if (f !== "") {
f +=':';
}
p.val(val+op+m1_fn[m1](p1,f));
$('[name=p1]').val('');
e.stopPropagation();
return false;
};
function perform_easy_search() {
// get values
var p = $('[name=p]'),
val = p.val(),
op1 = $('[name=op1]:checked').val(),
op = (op1=='a' && val=="")?'':op1_fn[op1],
author = $('#author').val(),
title = $('#title').val(),
rn = $('#rn').val(),
aff = $('#aff').val()
cn = $('#cn').val(),
k = $('#k').val(),
//eprinttype = $('#eprint-type').val(),
//eprintnumber = $('#eprint-number').val(),
j = $('#journal-name').val(),
jvol = $('#journal-vol').val(),
jpage = $('#journal-page').val();
if (val !== "") {
val += ' ';
}
// filter and build
var query = [];
if (author !== '') { query.push('author:' + author); }
if (title !== '') { query.push('title:' + title); }
if (rn !== '') { query.push('reportnumber:' + rn); }
if (aff !== '') { query.push('affiliation:' + aff); }
if (cn !== '') { query.push('collaboration:' + cn); }
if (k !== '') { query.push('keyword:' + k); }
if (j !== '') { query.push('journal:' + j); }
if (jvol !== '') { query.push('909C4v:' + jvol); }
if (jpage !== '') { query.push('909C4c:' + jpage); }
//query = query.replace(/topcite (\d+)?\+/, 'topcite $1->99999');
//query = query.replace(' and ', ' ');
//query = query.replace(/ /g, '+');
//window.location = search_url;
if (query.length > 0) {
p.val(val+op+query.join(' '+op1_fn[op1]));
}
};
$('.donothide .btn-primary').on('click', function(e) {
if ($('.modal-footer li.active a').attr('href') === '#simple-search') {
perform_easy_search();
} else {
addtosearch_callback(e);
$('#searchdropdown .appender').trigger('click');
}
});
$('form[name=search] button[name=action_browse]').on('click', function(e) {
$('form[name=search] button[name=action_search]')
.attr('name', 'action_browse');
$('.donothide .btn-primary').trigger('click');
});
$('#advanced-search #addtosearch').on('click', addtosearch_callback);
$('#advanced-search [name=p1]').keypress(function(event) {
if ( event.which == 13 ) {
if ($(this).val() !== '') {
event.preventDefault();
addtosearch_callback(event);
}
}
});
$('#searchdropdown #advanced-search .appender').on('click', function(e) {
var op1 = $('[name=op1]:checked').val(),
btn = $(this),
source = $('[name='+btn.attr('data-source')+']'),
target = $('[name='+btn.attr('data-target')+']'),
val = target.val(),
op = (op1=='a' && val=="")?'':op1_fn[op1];
if (val !== "") {
val += ' ';
}
if (source.val() === "") { return false }
if (source.val().length > 0) {
target.val(val+op+source.attr('name')+':"'+source.val()+'"');
source.val('');
}
e.stopPropagation();
return false;
});
$('html').on('click.dropdown', '.dropdown .donothide', function (e) {
if (!$(e.target).hasClass('close')) {
e.stopPropagation();
}
});
$('html').on('click.dropdown.donothide.data-api', function (e) {
$('#searchdropdown').removeClass('open');
});
var source = $.map({{ collection.search_within.keys()[1:]|tojson|safe }},
function(val, i) { return val+':';}); //['author:', 'title:', 'isbn:'];
source.push('AND ');
source.push('OR ');
source.push('AND NOT ');
var sources = {
{% for id, soo in collection.search_options|groupby('id_field') %}
'{{ soo[0].field.code }}': [{% for so in soo %}
'{{ so.fieldvalue.name }}' {{ ',' if not loop.last }}
{% endfor %}
]{{ ',' if not loop.last }}
{% endfor %}
};
{% for id, soo in collection.search_options|groupby('id_field') %}
source.push('{{ soo[0].field.code }}:');
{% endfor %}
sources['author'] = function(query) {
var typeahead = this
$.ajax({
type: 'GET',
url: '{{ url_for('search.list', field='exactauthor') }}',
data: $.param({
q: query.substr(query.lastIndexOf(':')+1)
}),
success: function(data) {
typeahead.process(data.results)
}
})
};
$('form[name=search] input[name=p]').searchTypeahead({
source: source,
sources: sources,
type: 'search'
});
$('body').on(
'focus.typeahead.data-api',
'[data-provide="typeahead-url"]',
function (e) {
var $this = $(this)
if ($this.data('typeahead')) return
e.preventDefault()
var data_url = $this.data('source')
var options = {
source: function(query) {
var typeahead = this
$.ajax({
type: 'GET',
url: data_url,
data: $.param({
q: query
}),
success: function(data) {
typeahead.process(data.results)
}
})
}
}
var data = $.extend({}, $this.data(), options)
$this.typeahead(data)
}
);
});
</script>
{% endmacro %}
Event Timeline
Log In to Comment