X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=tools%2Fhtdocs%2Fmkws.js;h=fe29a5eff399d0e1925208279e4c1a215f1b6968;hb=a69a66b88e3317022c375792df0b1c3689431496;hp=8fc2d897589137a4d38484f90a8085026b889894;hpb=788954be61eb460e03e9c409a42a22c7198b84a5;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 8fc2d89..fe29a5e 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -65,13 +65,19 @@ Handlebars.registerHelper('commaList', function(items, options) {
});
+Handlebars.registerHelper('index1', function(obj) {
+ return obj.data.index + 1;
+});
+
+
// Set up global mkws object. Contains truly global state such as SP
-// authentication, and a hash of team objects, indexed by windowid.
+// authentication, and a hash of team objects, indexed by team-name.
//
var mkws = {
authenticated: false,
- debug_level: undefined, // will be initialised from mkws_config
+ debug_level: 1, // Will be overridden from mkws_config, but
+ // initial value allows jQuery popup to use logging.
paz: undefined, // will be set up during initialisation
teams: {},
locale_lang: {
@@ -136,20 +142,57 @@ var mkws = {
};
+// The following PubSub code is modified from the jQuery manual:
+// https://api.jquery.com/jQuery.Callbacks/
+//
+// Use as:
+// mkws.queue("eventName").subscribe(function(param1, param2 ...) { ... });
+// mkws.queue("eventName").publish(arg1, arg2, ...);
+
+(function() {
+ var queues = {};
+ mkws.queue = function(id) {
+ if (!queues[id]) {
+ var callbacks = $.Callbacks();
+ queues[id] = {
+ publish: callbacks.fire,
+ subscribe: callbacks.add,
+ unsubscribe: callbacks.remove
+ };
+ }
+ return queues[id];
+ }
+}());
+
+
// Define empty mkws_config for simple applications that don't define it.
if (mkws_config == null || typeof mkws_config != 'object') {
var mkws_config = {};
}
+// Factory function for widget objects.
+function widget($, team, type, node) {
+ var that = {
+ team: team,
+ type: type,
+ node: node
+ };
+
+ // ### More to do here, surely: e.g. wiring into the team
+ mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
+
+ return that;
+}
+
+
// Factory function for team objects. As much as possible, this uses
// only member variables (prefixed "m_") and inner functions with
// private scope. Some functions are visibl as member-functions to be
// called from outside code -- specifically, from generated
// HTML. These functions are that.switchView(), showDetails(),
// limitTarget(), limitQuery(), delimitTarget(), delimitQuery(),
-// pagerPrev(), pagerNext(), showPage(). Also mkws.M() is made
-// available for the Handlebars helper 'translate'
+// pagerPrev(), pagerNext(), showPage().
//
function team($, teamName) {
var that = {};
@@ -169,6 +212,7 @@ function team($, teamName) {
"last": $.now()
};
var m_paz; // will be initialised below
+ var m_template = {};
var debug = function (s) {
@@ -182,105 +226,68 @@ function team($, teamName) {
debug("start running MKWS");
m_sort = mkws_config.sort_default;
- debug("copied mkws_config.sort_default '" + mkws_config.sort_default + "' to m_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;
- }
-
- for (var key in mkws_config) {
- if (mkws_config.hasOwnProperty(key)) {
- if (key.match(/^language_/)) {
- var lang = key.replace(/^language_/, "");
- // Copy custom languages into list
- mkws.locale_lang[lang] = mkws_config[key];
- debug("Added locally configured language '" + lang + "'");
- }
- }
- }
-
- // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp"
- if (mkws_config.pazpar2_url.match(/^\/\//)) {
- mkws_config.pazpar2_url = document.location.protocol + mkws_config.pazpar2_url;
- debug("adjust protocol independent links: " + mkws_config.pazpar2_url);
- }
+ m_perpage = mkws_config.perpage_default;
debug("Create main pz2 object");
// create a parameters array and pass it to the pz2's constructor
// then register the form submit event with the pz2.search function
// autoInit is set to true on default
- m_paz = new pz2({ "onshow": my_onshow,
- "windowid": teamName,
- "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
+ m_paz = new pz2({ "windowid": teamName,
"pazpar2path": mkws_config.pazpar2_url,
- "oninit": my_oninit,
- "onstat": my_onstat,
- "onterm": (mkws_config.facets.length ? my_onterm : undefined),
- "termlist": mkws_config.facets.join(','),
- "onbytarget": my_onbytarget,
"usesessions" : mkws_config.use_service_proxy ? false : true,
- "showResponseType": '', // or "json" (for debugging?)
- "onrecord": my_onrecord });
-
- if (!isNaN(parseInt(mkws_config.perpage_default))) {
- m_perpage = parseInt(mkws_config.perpage_default);
- }
+ "oninit": onInit,
+ "onbytarget": onBytarget,
+ "onstat": onStat,
+ "onterm": (mkws_config.facets.length ? onTerm : undefined),
+ "onshow": onShow,
+ "onrecord": onRecord,
+ "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
+ "termlist": mkws_config.facets.join(',')
+ });
//
// pz2.js event handlers:
//
- function my_oninit(teamName) {
+ function onInit(teamName) {
debug("init");
m_paz.stat();
m_paz.bytarget();
}
- function my_onshow(data, teamName) {
- debug("show");
- m_totalRec = data.merged;
-
- var pager = $(".mkwsPager.mkwsTeam_" + m_teamName);
- if (pager.length) {
- pager.html(drawPager(data))
- }
+ function onBytarget(data, teamName) {
+ debug("target");
+ var node = findnode('.mkwsBytarget');
+ if (node.length === 0) return;
- // navi
- var results = $(".mkwsRecords.mkwsTeam_" + m_teamName);
+ var table ='
' +
+ '
' + M('Target ID') + '
' +
+ '
' + M('Hits') + '
' +
+ '
' + M('Diags') + '
' +
+ '
' + M('Records') + '
' +
+ '
' + M('State') + '
' +
+ '
';
- var html = [];
- for (var i = 0; i < data.hits.length; i++) {
- var hit = data.hits[i];
- html.push('
',
- renderSummary(hit),
- '
');
- if (hit.recid == m_curDetRecId) {
- if (m_curDetRecData)
- html.push(renderDetails(m_curDetRecData));
- }
+ for (var i = 0; i < data.length; i++) {
+ table += "
\
-';
- } else if (name === "Summary") {
- return '\
-\
- {{md-title}}\
-\
-{{#if md-title-remainder}}\
- {{md-title-remainder}}\
-{{/if}}\
-{{#if md-title-responsibility}}\
- {{md-title-responsibility}}\
-{{/if}}\
-';
- }
-
- var s = "There is no default '" + name +"' template!";
- alert(s);
- return s;
- }
-
-
/*
* All the HTML stuff to render the search forms and
* result pages.
*/
- function mkws_html_all() {
- mkws_set_lang();
+ function mkwsHtmlAll() {
+ mkwsSetLang();
if (mkws_config.show_lang)
- mkws_html_lang();
+ mkwsHtmlLang();
- // For some reason, doing this programmatically results in
- // document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
debug("HTML search form");
- // ### There is only one match here by design: fix not to bother looping
- $('.mkwsSearch.mkwsTeam_' + m_teamName).each(function (i, obj) {
- var node = this;
- mkws.handle_node_with_team(node, function(tname) {
- $(node).html('\
+ mkws.handleNodeWithTeam(findnode('.mkwsSearch'), function(tname) {
+ this.html('\
');
- });
});
debug("HTML records");
@@ -895,18 +781,18 @@ function team($, teamName) {
// .mkwsPager
// .mkwsNavi
// .mkwsRecords
- if ($(".mkwsResults.mkwsTeam_" + m_teamName).length) {
- $(".mkwsResults.mkwsTeam_" + m_teamName).html('\
+ if (findnode(".mkwsResults").length) {
+ findnode(".mkwsResults").html('\
\
\
\
- \
+ \
\
\
- \
- \
- \
- \
+ \
+ \
+ \
+ \
\
\
\
@@ -917,37 +803,38 @@ function team($, teamName) {
');
}
- var node = $(".mkwsRanking.mkwsTeam_" + m_teamName);
+ var node = findnode(".mkwsRanking");
if (node.length) {
var ranking_data = '';
ranking_data += '';
node.html(ranking_data);
}
- mkws_html_switch();
-
- if (mkws_config.responsive_design_width) {
- // Responsive web design - change layout on the fly based on
- // current screen width. Required for mobile devices.
- $(window).resize(function(e) { mkws.resize_page() });
- // initial check after page load
- $(document).ready(function() { mkws.resize_page() });
- }
+ mkwsHtmlSwitch();
- domReady();
+ var node;
+ node = findnode('.mkwsSearchForm');
+ if (node.length)
+ node.submit(onFormSubmitEventHandler);
+ node = findnode('.mkwsSort');
+ if (node.length)
+ node.change(onSelectDdChange);
+ node = findnode('.mkwsPerpage');
+ if (node.length)
+ node.change(onSelectDdChange);
// on first page, hide the termlist
- $(document).ready(function() { $(".mkwsTermlists.mkwsTeam_" + m_teamName).hide(); });
- var motd = $(".mkwsMOTD.mkwsTeam_" + m_teamName);
- var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName);
+ $(document).ready(function() { findnode(".mkwsTermlists").hide(); });
+ var motd = findnode(".mkwsMOTD");
+ var container = findnode(".mkwsMOTDContainer");
if (motd.length && container.length) {
// Move the MOTD from the provided element down into the container
motd.appendTo(container);
@@ -955,20 +842,7 @@ function team($, teamName) {
}
- // implement $.parseQuerystring() for parsing URL parameters
- function parseQuerystring() {
- var nvpair = {};
- var qs = window.location.search.replace('?', '');
- var pairs = qs.split('&');
- $.each(pairs, function(i, v){
- var pair = v.split('=');
- nvpair[pair[0]] = pair[1];
- });
- return nvpair;
- }
-
-
- function mkws_set_lang() {
+ function mkwsSetLang() {
var lang = parseQuerystring().lang || mkws_config.lang;
if (!lang || !mkws.locale_lang[lang]) {
mkws_config.lang = ""
@@ -981,16 +855,16 @@ function team($, teamName) {
}
- function mkws_html_switch() {
+ function mkwsHtmlSwitch() {
debug("HTML switch for team " + m_teamName);
- var node = $(".mkwsSwitch.mkwsTeam_" + m_teamName);
+ var node = findnode(".mkwsSwitch");
node.append($('' + M('Records') + ''));
node.append($("", { text: " | " }));
node.append($('' + M('Targets') + ''));
debug("HTML targets");
- var node = $(".mkwsTargets.mkwsTeam_" + m_teamName);
+ var node = findnode(".mkwsTargets");
node.html('\
\
No information available yet.\
@@ -999,7 +873,7 @@ function team($, teamName) {
}
- function mkws_html_sort() {
+ function mkwsHtmlSort() {
debug("HTML sort, m_sort = '" + m_sort + "'");
var sort_html = '