X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=aeb0d129f8dca8717da6753b54f8a7b4896c45a4;hb=3ef390ce1f70178ffc78957ccb74216ce169fd59;hp=8fc2d897589137a4d38484f90a8085026b889894;hpb=788954be61eb460e03e9c409a42a22c7198b84a5;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 8fc2d89..aeb0d12 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. // 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) { @@ -184,11 +228,13 @@ function team($, teamName) { 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_/)) { @@ -228,6 +274,13 @@ function team($, teamName) { } + // Finds the node of the specified class within the current team + function findnode(selector, teamName) { + teamName ||= m_teamName; + return $(selector + '.mkwsTeam_' + m_teamName); + } + + // // pz2.js event handlers: // @@ -242,18 +295,19 @@ function team($, teamName) { debug("show"); m_totalRec = data.merged; - var pager = $(".mkwsPager.mkwsTeam_" + m_teamName); + var pager = findnode(".mkwsPager"); if (pager.length) { pager.html(drawPager(data)) } - // navi - var results = $(".mkwsRecords.mkwsTeam_" + m_teamName); + var results = findnode(".mkwsRecords"); + if (!results.length) + return; var html = []; for (var i = 0; i < data.hits.length; i++) { var hit = data.hits[i]; - html.push('
\ - \ + \ | \\ - \ - \ - \ - \ + \ + \ + \ + \ | \