- m_filters = []
- triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery);
- switchView('records'); // In case it's configured to start off as hidden
- m_submitted = true;
- }
- that.newSearch = newSearch;
-
-
- function triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery) {
- resetPage();
- queue("navi").publish();
-
- var pp2filter = "";
- var pp2limit = limit || "";
-
- // Continue to use previous query/sort-order unless new ones are specified
- if (query) {
- m_query = query;
- }
- if (sortOrder) {
- m_sortOrder = sortOrder;
- }
- if (perpage) {
- m_perpage = perpage;
- }
- if (targets) {
- m_filters.push({ id: targets, name: targets });
- }
-
- for (var i in m_filters) {
- var filter = m_filters[i];
- if (filter.id) {
- if (pp2filter)
- pp2filter += ",";
- if (filter.id.match(/^[a-z:]+[=~]/)) {
- log("filter '" + filter.id + "' already begins with SETTING OP");
- } else {
- filter.id = 'pz:id=' + filter.id;
- }
- pp2filter += filter.id;
- } else {
- if (pp2limit)
- pp2limit += ",";
- pp2limit += filter.field + "=" + filter.value.replace(/[\\|,]/g, '\\$&');
- }
- }
-
- var params = {};
- if (pp2limit) {
- params.limit = pp2limit;
- }
- if (maxrecs) {
- params.maxrecs = maxrecs;
- }
- if (torusquery) {
- if (!mkws.config.use_service_proxy)
- alert("can't narrow search by torusquery when Service Proxy is not in use");
- params.torusquery = torusquery;
- }
-
- log("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", " +
- "pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
-
- // We can use: params.torusquery = "udb=NAME"
- // Note: that won't work when running against raw pazpar2
- m_paz.search(m_query, m_perpage, m_sortOrder, pp2filter, undefined, params);
- }
-
-
- // switching view between targets and records
- function switchView(view) {
- var targets = widgetNode('Targets');
- var results = widgetNode('Results') || widgetNode('Records');
- var blanket = widgetNode('Blanket');
- var motd = widgetNode('MOTD');
-
- switch(view) {
- case 'targets':
- if (targets) targets.css('display', 'block');
- if (results) results.css('display', 'none');
- if (blanket) blanket.css('display', 'none');
- if (motd) motd.css('display', 'none');
- break;
- case 'records':
- if (targets) targets.css('display', 'none');
- if (results) results.css('display', 'block');
- if (blanket) blanket.css('display', 'block');
- if (motd) motd.css('display', 'none');
- break;
- case 'none':
- alert("mkws.switchView(" + m_teamName + ", 'none') shouldn't happen");
- if (targets) targets.css('display', 'none');
- if (results) results.css('display', 'none');
- if (blanket) blanket.css('display', 'none');
- if (motd) motd.css('display', 'none');
- break;
- default:
- alert("Unknown view '" + view + "'");
- }
- }
- that.switchView = switchView;
-
-
- // detailed record drawing
- that.showDetails = function(recId) {
- var oldRecordId = m_currentRecordId;
- m_currentRecordId = recId;
-
- // remove current detailed view if any
- findnode('#' + recordDetailsId(oldRecordId)).remove();
-
- // if the same clicked, just hide
- if (recId == oldRecordId) {
- m_currentRecordId = '';
- m_currentRecordData = null;
- return;
- }
- // request the record
- log("showDetails() requesting record '" + recId + "'");
- m_paz.record(recId);
- };
-
-
- /*
- * All the HTML stuff to render the search forms and
- * result pages.
- */
- function mkwsHtmlAll() {
- mkwsSetLang();
- if (m_config.show_lang)
- mkwsHtmlLang();
-
- log("HTML search form");
- findnode('.mkwsSearch').html('\
-<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + m_teamName + '" action="" >\
- <input class="mkwsQuery mkwsTeam_' + m_teamName + '" type="text" size="' + m_config.query_width + '" />\
- <input class="mkwsButton mkwsTeam_' + m_teamName + '" type="submit" value="' + M('Search') + '" />\
-</form>');
-
- log("HTML records");
- // If the team has a .mkwsResults, populate it in the usual
- // way. If not, assume that it's a smarter application that
- // defines its own subcomponents, some or all of the
- // following:
- // .mkwsTermlists
- // .mkwsRanking
- // .mkwsPager
- // .mkwsNavi
- // .mkwsRecords
- findnode(".mkwsResults").html('\
-<table width="100%" border="0" cellpadding="6" cellspacing="0">\
- <tr>\
- <td class="mkwsTermlistContainer1 mkwsTeam_' + m_teamName + '" width="250" valign="top">\
- <div class="mkwsTermlists mkwsTeam_' + m_teamName + '"></div>\
- </td>\
- <td class="mkwsMOTDContainer mkwsTeam_' + m_teamName + '" valign="top">\
- <div class="mkwsRanking mkwsTeam_' + m_teamName + '"></div>\
- <div class="mkwsPager mkwsTeam_' + m_teamName + '"></div>\
- <div class="mkwsNavi mkwsTeam_' + m_teamName + '"></div>\
- <div class="mkwsRecords mkwsTeam_' + m_teamName + '"></div>\
- </td>\
- </tr>\
- <tr>\
- <td colspan="2">\
- <div class="mkwsTermlistContainer2 mkwsTeam_' + m_teamName + '"></div>\
- </td>\
- </tr>\
-</table>');
-
- var acc = [];
- var facets = m_config.facets;
- acc.push('<div class="title">' + M('Termlists') + '</div>');
- for (var i = 0; i < facets.length; i++) {
- acc.push('<div class="mkwsFacet mkwsTeam_' + m_teamName + '" data-mkws-facet="' + facets[i] + '">');
- acc.push('</div>');
- }
- findnode(".mkwsTermlists").html(acc.join(''));
-
- var ranking_data = '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + m_teamName + '" action="" >';
- if (m_config.show_sort) {
- ranking_data += M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
- }
- if (m_config.show_perpage) {
- ranking_data += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
- }
- ranking_data += '</form>';
- findnode(".mkwsRanking").html(ranking_data);
-
- mkwsHtmlSwitch();
-
- findnode('.mkwsSearchForm').submit(function() {
- var val = widgetNode('Query').val();
- newSearch(val);
- return false;
- });
-
- // on first page, hide the termlist
- $(document).ready(function() { widgetNode("Termlists").hide(); });
- var container = findnode(".mkwsMOTDContainer");
- if (container.length) {
- // Move the MOTD from the provided element down into the container
- findnode(".mkwsMOTD").appendTo(container);
- }