X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=b735cf6609951b6d58f3953cab3e57176bd6553d;hb=e1e6241171d921bdf2dddb603ef40422fe1b5519;hp=597e55b96ca5ab88c96d41c337001bec5a12d90c;hpb=e14aea2ca68c5b8975d53bab9877dac6370796f7;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 597e55b..b735cf6 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -10,7 +10,6 @@ Handlebars.registerHelper('json', function(obj) {
Handlebars.registerHelper('translate', function(s) {
- debug("translating '" + s + "'");
return mkws.M(s);
});
@@ -142,9 +141,9 @@ if (mkws_config == null || typeof mkws_config != 'object') {
// wrapper for jQuery lib
-function _make_mkws_team($, teamName) {
+function team($, teamName) {
var that = {};
- var m_termName = teamName;
+ var m_teamName = teamName;
var m_submitted = false;
var m_query; // initially undefined
var m_sort = 'relevance';
@@ -163,10 +162,11 @@ function _make_mkws_team($, teamName) {
// if (console && console.log) // disabled, will fail in IE8
- // console.log("run _make_mkws_team(" + (teamName ? teamName : "") + ")");
+ // console.log("run team(" + (teamName ? teamName : "") + ")");
- // Needs to be defined inside _make_mkws_team() so it can see m_debug_time
+ // Needs to be defined inside team() so it can see m_debug_time
+ // ### member access won't work: there is only one instance of this function
mkws.debug_function = function (string) {
if (!mkws.debug_level)
return;
@@ -262,7 +262,7 @@ function _make_mkws_team($, teamName) {
}
// navi
- var results = document.getElementById("mkwsRecords");
+ var results = $(".mkwsRecords.mkwsTeam_" + m_teamName);
var html = [];
for (var i = 0; i < data.hits.length; i++) {
@@ -271,10 +271,11 @@ function _make_mkws_team($, teamName) {
renderSummary(hit),
'');
if (hit.recid == m_curDetRecId) {
- html.push(renderDetails(m_curDetRecData));
+ if (m_curDetRecData)
+ html.push(renderDetails(m_curDetRecData));
}
}
- replaceHtml(results, html.join(''));
+ results.html(html.join(''));
}
@@ -282,7 +283,7 @@ function _make_mkws_team($, teamName) {
{
var template = loadTemplate("Summary");
hit._id = "mkwsRec_" + hit.recid;
- hit._onclick = "mkws.showDetails(this.id);return false;"
+ hit._onclick = "mkws.showDetails(this.id, '" + m_teamName + "');return false;"
return template(hit);
}
@@ -328,9 +329,9 @@ function _make_mkws_team($, teamName) {
}
}
- var termlist = document.getElementById("mkwsTermlists");
+ var termlist = $("#mkwsTermlists");
if (termlist)
- replaceHtml(termlist, acc.join(''));
+ termlist.html(acc.join(''));
}
@@ -356,7 +357,7 @@ function _make_mkws_team($, teamName) {
}
- function my_onrecord(data, teamName) {
+ function my_onrecord(data, args, teamName) {
debug("record for " + teamName);
// FIXME: record is async!!
clearTimeout(m_paz.recordTimer);
@@ -405,7 +406,15 @@ function _make_mkws_team($, teamName) {
// wait until the DOM is ready
function domReady ()
{
- document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler;
+ $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) {
+ debug("adding search-forms for team '" + m_teamName + "'");
+ var node = this;
+ mkws.handle_node_with_team(node, function(tname) {
+ debug("adding search-form '" + tname + "' for team '" + m_teamName + "'");
+ $(node).submit(onFormSubmitEventHandler);
+ });
+ });
+
document.mkwsSearchForm.mkwsQuery.value = '';
if (document.mkwsSelect) {
if (document.mkwsSelect.mkwsSort)
@@ -419,12 +428,16 @@ function _make_mkws_team($, teamName) {
// when search button pressed
function onFormSubmitEventHandler()
{
- newSearch(document.mkwsSearchForm.mkwsQuery.value);
+ mkws.handle_node_with_team(this, function (tname) {
+ var val = $('.mkwsQuery.mkwsTeam_' + tname).val();
+ mkws.teams[tname].newSearch(val);
+ });
+
return false;
}
- function newSearch(query, sort, targets, windowid)
+ that.newSearch = function(query, sort, targets, windowid)
{
debug("newSearch: " + query);
@@ -723,7 +736,7 @@ function _make_mkws_team($, teamName) {
// detailed record drawing
- mkws.showDetails = function (prefixRecId) {
+ that.showDetails = function (prefixRecId) {
var recId = prefixRecId.replace('mkwsRec_', '');
var oldRecId = m_curDetRecId;
m_curDetRecId = recId;
@@ -745,21 +758,6 @@ function _make_mkws_team($, teamName) {
}
- function replaceHtml(el, html) {
- var oldEl = typeof el === "string" ? document.getElementById(el) : el;
- /*@cc_on // Pure innerHTML is slightly faster in IE
- oldEl.innerHTML = html;
- return oldEl;
- @*/
- var newEl = oldEl.cloneNode(false);
- newEl.innerHTML = html;
- oldEl.parentNode.replaceChild(newEl, oldEl);
- /* Since we just removed the old element from the DOM, return a reference
- to the new element, which can be used to restore variable references. */
- return newEl;
- };
-
-
function renderDetails(data, marker)
{
var template = loadTemplate("Record");
@@ -879,11 +877,16 @@ function _make_mkws_team($, teamName) {
// For some reason, doing this programmatically results in
// document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
debug("HTML search form");
- $("#mkwsSearch").html('\
-
');
+ });
+ });
debug("HTML records");
// If the application has an #mkwsResults, populate it in the
@@ -898,19 +901,19 @@ function _make_mkws_team($, teamName) {
$("#mkwsResults").html('\
\
\
- \
- \
+ | \
+ \
| \
\
- \
- \
- \
- \
+ \
+ \
+ \
+ \
| \
\
\
\
- \
+ \
| \
\
');
@@ -989,7 +992,7 @@ function _make_mkws_team($, teamName) {
debug("HTML targets");
$("#mkwsTargets").html('\
-\
+
\
No information available yet.\
');
$("#mkwsTargets").css("display", "none");
@@ -1280,11 +1283,15 @@ function _mkws_jquery_plugin ($) {
};
-// wrapper to call _make_mkws_team() after page load
+// wrapper to call team() after page load
(function (j) {
function log(s) {
- if (console && console.log) console.log(s);
+ if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
+ return;
+ }
+ console.log(s);
}
+
// enable before page load, so we could call it before mkws() runs
_mkws_jquery_plugin(j);
@@ -1306,55 +1313,59 @@ function _mkws_jquery_plugin ($) {
}
}
- // Backwards compatibility: the special-case undefined team
- // ### Will not be necessary when non-default teams are working
- mkws.teams[''] = _make_mkws_team(j, undefined);
- log("Made the unnamed MKWS team");
-
// Find all nodes with class (NOT id) mkwsRecords, and
// determine their team from the mkwsTeam_* class. So:
//
- $('.mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () {
+ $('.mkwsSearch, .mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () {
var node = this;
- var classes = this.className;
- var list = classes.split(/\s+/)
- var tname;
- for (var i = 0; i < list.length; i++) {
- var cname = list[i];
- if (cname.match(/^mkwsTeam_/)) {
- tname = cname.replace(/^mkwsTeam_/, '');
+ mkws.handle_node_with_team(node, function(tname) {
+ if (mkws.teams[tname]) {
+ log("MKWS team '" + tname + "' already exists, skipping");
+ } else {
+ mkws.teams[tname] = team(j, tname);
+ log("Made MKWS team '" + tname + "'");
}
- }
- if (!tname) {
- alert("No MKWS team specified for mkwsRecords element with classes '" + classes + "'");
- } else if (mkws.teams[tname]) {
- log("MKWS team '" + tname + "' already exists, skipping");
- } else if (tname === "AUTO") {
- // ### For now: later, this will be how the backwards-compatibility is done
- log("Skipping MKWS team '" + tname + "'");
- } else {
- mkws.teams[tname] = _make_mkws_team(j, tname);
- log("Made MKWS team '" + tname + "'");
- }
+ });
});
if (mkws_config.use_service_proxy) {
- mkws.authenticate_session(mkws_config.service_proxy_auth,
- mkws_config.service_proxy_auth_domain,
- mkws_config.pazpar2_url);
+ authenticate_session(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain,
+ mkws_config.pazpar2_url);
} else {
// raw pp2
- mkws.run_auto_searches();
+ run_auto_searches();
}
});
+ mkws.handle_node_with_team = function(node, callback) {
+ var classes = node.className;
+ var list = classes.split(/\s+/)
+ var tname;
+ for (var i = 0; i < list.length; i++) {
+ var cname = list[i];
+ if (cname.match(/^mkwsTeam_/)) {
+ tname = cname.replace(/^mkwsTeam_/, '');
+ }
+ }
+ if (!tname)
+ tname = "AUTO";
+ callback(tname);
+ }
+
+
+ mkws.showDetails = function (prefixRecId, tname) {
+ mkws.teams[tname].showDetails(prefixRecId);
+ }
+
+
function default_mkws_config() {
/* default mkws config */
var config_default = {
use_service_proxy: true,
- pazpar2_url: "http://mkws.indexdata.com/service-proxy/",
- service_proxy_auth: "http://mkws.indexdata.com/service-proxy-auth",
+ pazpar2_url: "//mkws.indexdata.com/service-proxy/",
+ service_proxy_auth: "//mkws.indexdata.com/service-proxy-auth",
lang: "",
sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
perpage_options: [10, 20, 30, 50],
@@ -1399,12 +1410,12 @@ function _mkws_jquery_plugin ($) {
* The username/password is configured in the apache config file
* for the site.
*/
- mkws.authenticate_session = function(auth_url, auth_domain, pp2_url) {
- debug("Run service proxy auth URL: " + auth_url);
+ function authenticate_session(auth_url, auth_domain, pp2_url) {
+ console.log("Run service proxy auth URL: " + auth_url);
if (!auth_domain) {
auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2');
- debug("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
+ console.log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
}
var request = new pzHttpRequest(auth_url, function(err) {
@@ -1423,36 +1434,34 @@ function _mkws_jquery_plugin ($) {
return;
}
- debug("Service proxy auth successfully done");
+ console.log("Service proxy auth successfully done");
mkws.authenticated = true;
- mkws.run_auto_searches();
+ run_auto_searches();
});
}
- mkws.run_auto_searches = function() {
- debug("running auto searches");
+ function run_auto_searches() {
+ console.log("running auto searches");
- $('[id^="mkwsRecords"]').each(function () {
- var node = $(this);
+ for (var teamName in mkws.teams) {
+ // ### should check mkwsTermlist as well, for facet-only teams
+ var node = $('.mkwsRecords.mkwsTeam_' + teamName);
var query = node.attr('autosearch');
+ console.log("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query);
if (query) {
- var windowid = undefined;
- var id = node.attr('id');
- if (id.match(/^mkwsRecords_/, '')) {
- windowid = id.replace(/^mkwsRecords_/, '');
- }
-
var sort = node.attr('sort');
var targets = node.attr('targets');
var s = "running auto search: '" + query + "'";
- if (windowid) s += " [windowid '" + windowid + "']";
+ if (teamName) s += " [teamName '" + teamName + "']";
if (sort) s += " sorted by '" + sort + "'";
if (targets) s += " in targets '" + targets + "'";
- debug(s);
- newSearch(query, sort, targets, windowid);
+ console.log(s);
+ var team = mkws.teams[teamName];
+ console.log($.toJSON(team));
+ team.newSearch(query, sort, targets, teamName);
}
- });
+ }
}
})(jQuery);