- return sort_html;
- }
-
-
- function mkwsHtmlPerpage() {
- log("HTML perpage, m_perpage = " + m_perpage);
- var perpage_html = '<select class="mkwsPerpage mkwsTeam_' + m_teamName + '">';
-
- for(var i = 0; i < mkws_config.perpage_options.length; i++) {
- var key = mkws_config.perpage_options[i];
-
- perpage_html += '<option value="' + key + '"';
- if (key == m_perpage) {
- perpage_html += ' selected="selected"';
- }
- perpage_html += '>' + key + '</option>';
- }
- perpage_html += '</select>';
-
- return perpage_html;
- }
-
-
- function mkwsHtmlSwitch() {
- log("HTML switch for team " + m_teamName);
-
- var node = findnode(".mkwsSwitch");
- node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'records\')">' + M('Records') + '</a>'));
- node.append($("<span/>", { text: " | " }));
- node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'targets\')">' + M('Targets') + '</a>'));
-
- log("HTML targets");
- var node = findnode(".mkwsTargets");
- node.html('\
-<div class="mkwsBytarget mkwsTeam_' + m_teamName + '">\
- No information available yet.\
-</div>');
- node.css("display", "none");
- }
-
-
- that.runAutoSearch = function() {
- var node = findnode('.mkwsRecords,.mkwsTermlists');
- var query = node.attr('autosearch');
- if (!query)
- return;
-
- if (query.match(/^!param!/)) {
- var param = query.replace(/^!param!/, '');
- query = getParameterByName(param);
- log("obtained query '" + query + "' from param '" + param + "'");
- if (!query) {
- alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter");
- }
- } else if (query.match(/^!path!/)) {
- var index = query.replace(/^!path!/, '');
- var path = window.location.pathname.split('/');
- query = path[path.length - index];
- log("obtained query '" + query + "' from path-component '" + index + "'");
- if (!query) {
- alert("This page has a MasterKey widget that needs a query specified by the path-component " + index);
- }
- }
-
- log("node=" + node + ", class='" + node.className + "', query=" + query);
-
- var sortOrder = node.attr('sort');
- var targets = node.attr('targets');
- var s = "running auto search: '" + query + "'";
- if (sortOrder) s += " sorted by '" + sortOrder + "'";
- if (targets) s += " in targets '" + targets + "'";
- log(s);
-
- newSearch(query, sortOrder, targets);
- }
-
-
- // This function is taken from a StackOverflow answer
- // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
- function getParameterByName(name) {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
- results = regex.exec(location.search);
- return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
- }
-
-
- // Translation function. At present, this is properly a
- // global-level function (hence the assignment to mkws.M) but we
- // want to make it per-team so different teams can operate in
- // different languages.
- //
- function M(word) {
- var lang = mkws_config.lang;
-
- if (!lang || !mkws.locale_lang[lang])
- return word;
-
- return mkws.locale_lang[lang][word] || word;
- }
- mkws.M = M; // so the Handlebars helper can use it
-
-
- // Finds the node of the specified class within the current team
- // Multiple OR-clauses separated by commas are handled
- // More complex cases may not work
- //
- function findnode(selector, teamName) {
- teamName = teamName || m_teamName;
-
- selector = $.map(selector.split(','), function(s, i) {
- return s + '.mkwsTeam_' + teamName;
- }).join(',');
-
- return $(selector);
- }
-
-
- function renderDetails(data, marker)
- {
- var template = loadTemplate("Record");
- var details = template(data);
- return '<div class="details mkwsTeam_' + m_teamName + '" id="' + recordDetailsId(data.recid[0]) + '">' + details + '</div>';
- }
- that.renderDetails = renderDetails;
-
-
- 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 = findnode(".mkwsTemplate_" + name, "ALL");
- }
-
- var source = node.html();
- if (!source) {
- source = defaultTemplate(name);
- }
-
- template = Handlebars.compile(source);
- log("compiled template '" + name + "'");
- m_template[name] = template;
- }
-
- return template;
- }
- that.loadTemplate = loadTemplate;
-
-
- function defaultTemplate(name)
- {
- if (name === 'Record') {
- return '\
-<table>\
- <tr>\
- <th>{{translate "Title"}}</th>\
- <td>\
- {{md-title}}\
- {{#if md-title-remainder}}\
- ({{md-title-remainder}})\
- {{/if}}\
- {{#if md-title-responsibility}}\
- <i>{{md-title-responsibility}}</i>\
- {{/if}}\
- </td>\
- </tr>\
- {{#if md-date}}\
- <tr>\
- <th>{{translate "Date"}}</th>\
- <td>{{md-date}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-author}}\
- <tr>\
- <th>{{translate "Author"}}</th>\
- <td>{{md-author}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-electronic-url}}\
- <tr>\
- <th>{{translate "Links"}}</th>\
- <td>\
- {{#each md-electronic-url}}\
- <a href="{{this}}">Link{{index1}}</a>\
- {{/each}}\
- </td>\
- </tr>\
- {{/if}}\
- {{#if-any location having="md-subject"}}\
- <tr>\
- <th>{{translate "Subject"}}</th>\
- <td>\
- {{#first location having="md-subject"}}\
- {{#if md-subject}}\
- {{#commaList md-subject}}\
- {{this}}{{/commaList}}\
- {{/if}}\
- {{/first}}\
- </td>\
- </tr>\
- {{/if-any}}\
- <tr>\
- <th>{{translate "Locations"}}</th>\
- <td>\
- {{#commaList location}}\
- {{attr "@name"}}{{/commaList}}\
- </td>\
- </tr>\
-</table>\
-';
- } else if (name === "Summary") {
- return '\
-<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
- <b>{{md-title}}</b>\
-</a>\
-{{#if md-title-remainder}}\
- <span>{{md-title-remainder}}</span>\
-{{/if}}\
-{{#if md-title-responsibility}}\
- <span><i>{{md-title-responsibility}}</i></span>\
-{{/if}}\
-';
- }
-
- var s = "There is no default '" + name +"' template!";
- alert(s);
- return s;
- }
-
-
- // The following PubSub code is modified from the jQuery manual:
- // https://api.jquery.com/jQuery.Callbacks/
- //
- // Use as:
- // team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
- // team.queue("eventName").publish(arg1, arg2, ...);
-
- var queues = {};
- var queue = function(id) {
- if (!queues[id]) {
- var callbacks = $.Callbacks();
- queues[id] = {
- publish: callbacks.fire,
- subscribe: callbacks.add,
- unsubscribe: callbacks.remove
- };
- }
- return queues[id];
- }
- that.queue = queue;