// Set up namespace and some state.
var mkws = {
+ sort: 'relevance',
+ authenticated: false,
filters: [],
};
}
}
+mkws.sort = mkws_config.sort_default;
+debug("copied mkws_config.sort_default '" + mkws_config.sort_default + "' to mkws.sort");
+
if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
debug("Reset query width: " + mkws_config.query_width);
mkws_config.query_width = 50;
var totalRec = 0;
var curDetRecId = '';
var curDetRecData = null;
-var curSort = 'relevance';
var submitted = false;
var SourceMax = 16;
var SubjectMax = 10;
// navi
var results = document.getElementById("mkwsRecords");
- debug("my_onshow(" + JSON.stringify(data) + ")");
var html = [];
for (var i = 0; i < data.hits.length; i++) {
return false;
}
-function newSearch(query)
+function newSearch(query, sort)
{
+ if (!mkws.authenticated) {
+ alert("searching before authentication");
+ return;
+ }
+
mkws.filters = []
redraw_navi();
resetPage();
loadSelect();
- triggerSearch(query);
+ triggerSearch(query, sort);
mkws.switchView('records'); // In case it's configured to start off as hidden
submitted = true;
}
if (!submitted) return false;
resetPage();
loadSelect();
- my_paz.show(0, recPerPage, curSort);
+ my_paz.show(0, recPerPage, mkws.sort);
return false;
}
totalRec = 0;
}
-function triggerSearch (query)
+function triggerSearch (query, sort)
{
var pp2filter = "";
var pp2limit = "";
- // Re-use previous query if a new one is not specified
+ // Re-use previous query/sort if new ones are not specified
if (query) {
mkws.query = query;
}
+ if (sort) {
+ mkws.sort = sort;
+ }
for (var i in mkws.filters) {
var filter = mkws.filters[i];
}
debug("triggerSearch(" + mkws.query + "): filters = " + JSON.stringify(mkws.filters) + ", pp2filter = " + pp2filter + ", pp2limit = " + pp2limit);
- my_paz.search(mkws.query, recPerPage, curSort, pp2filter, undefined, { limit: pp2limit });
+ my_paz.search(mkws.query, recPerPage, mkws.sort, pp2filter, undefined, { limit: pp2limit });
}
function loadSelect ()
{
if (document.mkwsSelect) {
if (document.mkwsSelect.mkwsSort)
- curSort = document.mkwsSelect.mkwsSort.value;
+ mkws.sort = document.mkwsSelect.mkwsSort.value;
if (document.mkwsSelect.mkwsPerpage)
recPerPage = document.mkwsSelect.mkwsPerpage.value;
}
function run_auto_searches() {
var node = $('#mkwsRecords');
if (node.attr('autosearch')) {
- var query = node.attr('query');
+ var query = node.attr('autosearch');
var sort = node.attr('sort');
- debug("running auto search: '" + query + "' sorted by '" + sort + "'");
- // ### currently ignoring sort
- newSearch(query);
+ var targets = node.attr('targets');
+ var s = "running auto search: '" + query + "'";
+ if (sort) s += " sorted by '" + sort + "'";
+ if (targets) s += " in targets '" + targets + "'";
+ debug(s);
+ newSearch(query, sort, targets);
}
}
}
function mkws_html_sort() {
- debug("HTML sort");
+ debug("HTML sort, mkws.sort = '" + mkws.sort + "'");
var sort_html = '<select name="mkwsSort" id="mkwsSort">';
for(var i = 0; i < mkws_config.sort_options.length; i++) {
var val = opt.length == 1 ? opt[0] : opt[1];
sort_html += '<option value="' + key + '"';
- if (key == mkws_config.sort_default) {
+ if (mkws.sort == key || mkws.sort == val) {
sort_html += ' selected="selected"';
}
sort_html += '>' + M(val) + '</option>';
}
debug("Service proxy auth successfully done");
- mkws.service_proxy_auth = true;
+ mkws.authenticated = true;
+ run_auto_searches();
});
}
mkws_config.error = e.message;
// alert(e.message);
}
-
- run_auto_searches();
});
})(jQuery);