X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=bb96eac035787d5896331e3025a253d70f154130;hb=6a49d9b12dead08c0cc734afedb5975a6c58faaf;hp=cd0a18e32c7d4925a2346cac050505ff8d070dcb;hpb=d47fe777bdfaed4b12dfe7050e9da71502d36e0e;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index cd0a18e..bb96eac 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -72,7 +72,7 @@ Handlebars.registerHelper('index1', function(obj) {
// 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,
@@ -226,114 +226,71 @@ 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");
-
- // ### should be in global code
- if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
- debug("Reset query width: " + mkws_config.query_width);
- mkws_config.query_width = 50;
- }
-
- // ### should be in global code
- 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);
- }
-
-
- // Finds the node of the specified class within the current team
- function findnode(s) {
- return $(s + '.mkwsTeam_' + m_teamName);
- }
+ "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 = findnode(".mkwsPager");
- if (pager.length) {
- pager.html(drawPager(data))
+ function onBytarget(data, teamName) {
+ debug("target");
+ var targetDiv = findnode('.mkwsBytarget');
+ if (targetDiv.length === 0) {
+ return;
}
- var results = findnode(".mkwsRecords");
- if (!results.length)
- return;
+ var table ='
');
acc.push('
' + M(caption) + '
');
for (var i = 0; i < data.length && i < max; i++) {
@@ -386,7 +385,7 @@ function team($, teamName) {
if (!pzIndex) {
// Special case: target selection
acc.push('target_id='+data[i].id+' ');
- if (!target_filtered(data[i].id)) {
+ if (!targetFiltered(data[i].id)) {
action = 'mkws.limitTarget(\'' + m_teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
}
} else {
@@ -400,7 +399,7 @@ function team($, teamName) {
}
- function target_filtered(id) {
+ function targetFiltered(id) {
for (var i = 0; i < m_filters.length; i++) {
if (m_filters[i].id === id ||
m_filters[i].id === 'pz:id=' + id) {
@@ -411,67 +410,20 @@ function team($, teamName) {
}
- function my_onrecord(data, args, teamName) {
- debug("record: teamName=" + teamName + ", m_teamName=" + m_teamName);
- // FIXME: record is async!!
- clearTimeout(m_paz.recordTimer);
- // in case on_show was faster to redraw element
- var detRecordDiv = document.getElementById('mkwsDet_' + teamName + '_' + data.recid);
- if (detRecordDiv) return;
- m_curDetRecData = data;
- var recordDiv = document.getElementById('mkwsRecdiv_' + teamName + '_' + m_curDetRecData.recid);
- var html = renderDetails(m_curDetRecData);
- recordDiv.innerHTML += html;
- }
-
-
- function my_onbytarget(data, teamName) {
- debug("target");
- var targetDiv = findnode('.mkwsBytarget');
- if (!targetDiv) {
- return;
- }
-
- var table ='
' +
- '' + M('Target ID') + ' | ' +
- '' + M('Hits') + ' | ' +
- '' + M('Diags') + ' | ' +
- '' + M('Records') + ' | ' +
- '' + M('State') + ' | ' +
- '
';
-
- for (var i = 0; i < data.length; i++) {
- table += "" + data[i].id +
- " | " + data[i].hits +
- " | " + data[i].diagnostic +
- " | " + data[i].records +
- " | " + data[i].state + " |
";
- }
-
- table += '
';
- targetDiv.html(table);
- }
-
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// when search button pressed
- // ### This is closure, so can always just operate on its own team
function onFormSubmitEventHandler()
{
- mkws.handle_node_with_team(this, function (tname) {
- var val = findnode('.mkwsQuery').val();
- mkws.teams[tname].newSearch(val);
- });
-
+ var val = findnode('.mkwsQuery').val();
+ newSearch(val);
return false;
}
- // ### won't need to be externally visible once onFormSubmitEventHandler() is fixed.
- // ### doesn't need windowid
- that.newSearch = function(query, sort, targets, windowid)
+ function newSearch(query, sort, targets)
{
debug("newSearch: " + query);
@@ -481,11 +433,11 @@ function team($, teamName) {
}
m_filters = []
- redraw_navi();
+ redrawNavi();
resetPage();
loadSelect();
- triggerSearch(query, sort, targets, windowid);
- that.switchView('records'); // In case it's configured to start off as hidden
+ triggerSearch(query, sort, targets);
+ switchView('records'); // In case it's configured to start off as hidden
m_submitted = true;
}
@@ -507,8 +459,7 @@ function team($, teamName) {
}
- // ### doesn't need windowid
- function triggerSearch (query, sort, targets, windowid)
+ function triggerSearch (query, sort, targets)
{
var pp2filter = "";
var pp2limit = "";
@@ -521,7 +472,6 @@ function team($, teamName) {
m_sort = sort;
}
if (targets) {
- // ### should support multiple |-separated targets
m_filters.push({ id: targets, name: targets });
}
@@ -547,9 +497,7 @@ function team($, teamName) {
if (pp2limit) {
params.limit = pp2limit;
}
- if (windowid) {
- params.windowid = windowid;
- }
+
debug("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
// We can use: params.torusquery = "udb=NAME"
@@ -578,7 +526,7 @@ function team($, teamName) {
{
debug("limitTarget(id=" + id + ", name=" + name + ")");
m_filters.push({ id: id, name: name });
- redraw_navi();
+ redrawNavi();
resetPage();
loadSelect();
triggerSearch();
@@ -591,7 +539,7 @@ function team($, teamName) {
{
debug("limitQuery(field=" + field + ", value=" + value + ")");
m_filters.push({ field: field, value: value });
- redraw_navi();
+ redrawNavi();
resetPage();
loadSelect();
triggerSearch();
@@ -614,7 +562,7 @@ function team($, teamName) {
}
m_filters = newFilters;
- redraw_navi();
+ redrawNavi();
resetPage();
loadSelect();
triggerSearch();
@@ -639,7 +587,7 @@ function team($, teamName) {
}
m_filters = newFilters;
- redraw_navi();
+ redrawNavi();
resetPage();
loadSelect();
triggerSearch();
@@ -647,7 +595,7 @@ function team($, teamName) {
}
- function redraw_navi ()
+ function redrawNavi ()
{
var navi = findnode('.mkwsNavi');
if (!navi) return;
@@ -749,10 +697,9 @@ function team($, teamName) {
// switching view between targets and records
- that.switchView = function(view) {
+ function switchView(view) {
var targets = findnode('.mkwsTargets');
- // ### Fix next line to use findnode()
- var results = $('.mkwsResults.mkwsTeam_' + m_teamName + ',.mkwsRecords.mkwsTeam_' + m_teamName);
+ var results = findnode('.mkwsResults,.mkwsRecords');
var blanket = findnode('.mkwsBlanket');
var motd = findnode('.mkwsMOTD');
@@ -782,6 +729,9 @@ function team($, teamName) {
}
+ that.switchView = switchView;
+
+
// detailed record drawing
that.showDetails = function (prefixRecId) {
var recId = prefixRecId.replace('mkwsRec_', '');
@@ -806,132 +756,17 @@ function team($, teamName) {
}
- function renderDetails(data, marker)
- {
- var template = loadTemplate("Record");
- var details = template(data);
- return '
' + details + '
';
- }
-
-
- function loadTemplate(name)
- {
- var template = m_template[name];
-
- if (template === undefined) {
- // Fall back to generic template if there is no team-specific one
- var node = findnode(".mkwsTemplate_" + name);
- if (!node.length) {
- node = $(".mkwsTemplate_" + name + ".mkwsTeam_ALL");
- }
-
- var source = node.html();
- if (!source) {
- source = defaultTemplate(name);
- }
-
- template = Handlebars.compile(source);
- debug("compiled template '" + name + "'");
- m_template[name] = template;
- }
-
- return template;
- }
-
-
- function defaultTemplate(name)
- {
- if (name === 'Record') {
- return '\
-
\
- \
- {{translate "Title"}} | \
- \
- {{md-title}}\
- {{#if md-title-remainder}}\
- ({{md-title-remainder}})\
- {{/if}}\
- {{#if md-title-responsibility}}\
- {{md-title-responsibility}}\
- {{/if}}\
- | \
-
\
- {{#if md-date}}\
- \
- {{translate "Date"}} | \
- {{md-date}} | \
-
\
- {{/if}}\
- {{#if md-author}}\
- \
- {{translate "Author"}} | \
- {{md-author}} | \
-
\
- {{/if}}\
- {{#if md-electronic-url}}\
- \
- {{translate "Links"}} | \
- \
- {{#each md-electronic-url}}\
- Link{{index1}}\
- {{/each}}\
- | \
-
\
- {{/if}}\
- {{#if-any location having="md-subject"}}\
- \
- {{translate "Subject"}} | \
- \
- {{#first location having="md-subject"}}\
- {{#if md-subject}}\
- {{#commaList md-subject}}\
- {{this}}{{/commaList}}\
- {{/if}}\
- {{/first}}\
- | \
-
\
- {{/if-any}}\
- \
- {{translate "Locations"}} | \
- \
- {{#commaList location}}\
- {{attr "@name"}}{{/commaList}}\
- | \
-
\
-
\
-';
- } 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.
*/
- // ### This and other multi-word identifiers should be camelCase
- function mkws_html_all() {
- mkws_set_lang();
+ function mkwsHtmlAll() {
+ mkwsSetLang();
if (mkws_config.show_lang)
- mkws_html_lang();
+ mkwsHtmlLang();
debug("HTML search form");
- mkws.handle_node_with_team(findnode('.mkwsSearch'), function(tname) {
+ mkws.handleNodeWithTeam(findnode('.mkwsSearch'), function(tname) {
this.html('\