X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=03cd18ef6735fc889cdae2c7cec1bedd4cd1e905;hb=8455cc39538aeafe0191a15ec3b670d3fbbdd912;hp=0a62b9be7cb05694786d7718a505bcd91ff126ae;hpb=94ed8c801e4ce9cdc13d541827775c47d74f62d6;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 0a62b9b..03cd18e 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -141,7 +141,7 @@ if (mkws_config == null || typeof mkws_config != 'object') { // wrapper for jQuery lib -function _make_mkws_team($, teamName) { +function team($, teamName) { var that = {}; var m_teamName = teamName; var m_submitted = false; @@ -162,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; @@ -281,7 +282,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); } @@ -355,7 +356,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); @@ -404,7 +405,14 @@ function _make_mkws_team($, teamName) { // wait until the DOM is ready function domReady () { - document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler; + $('.mkwsSearchForm').each(function (i, obj) { + var node = this; + debug("adding class 'foo' to node " + node); + mkws.handle_node_with_team(node, function(tname) { + $(node).submit(onFormSubmitEventHandler); + }); + }); + document.mkwsSearchForm.mkwsQuery.value = ''; if (document.mkwsSelect) { if (document.mkwsSelect.mkwsSort) @@ -418,7 +426,11 @@ function _make_mkws_team($, teamName) { // when search button pressed function onFormSubmitEventHandler() { - that.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; } @@ -722,7 +734,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; @@ -863,11 +875,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('\ -
\ - \ - \ + $('.mkwsSearch').each(function (i, obj) { + var node = this; + mkws.handle_node_with_team(node, function(tname) { + $(node).html('\ +\ + \ + \
'); + }); + }); debug("HTML records"); // If the application has an #mkwsResults, populate it in the @@ -1264,7 +1281,7 @@ 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 (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */ @@ -1294,36 +1311,19 @@ function _mkws_jquery_plugin ($) { } } - // Backwards compatibility: the special-case undefined team - // ### Will not be necessary when non-default teams are working - mkws.teams['AUTO'] = _make_mkws_team(j, "AUTO"); - 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) { @@ -1337,6 +1337,27 @@ function _mkws_jquery_plugin ($) { }); + 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 = {