X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-core.js;h=4d389747b7ceb9e213076a536a95049a544928dc;hb=4d14df7f445cfbe077dbd93cdeac23f9e1455892;hp=b30b38007c43814a1e51a2f2184732441b0896bc;hpb=857d9397ed4c8bee8e96747e4619297bcaff9c87;p=mkws-moved-to-github.git diff --git a/src/mkws-core.js b/src/mkws-core.js index b30b380..4d38974 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -14,6 +14,8 @@ var mkws = { log_level: 1, // Will be overridden from mkws_config, but // initial value allows jQuery popup to use logging. teams: {}, + widgetType2function: {}, + locale_lang: { "de": { "Authors": "Autoren", @@ -82,28 +84,39 @@ if (mkws_config == null || typeof mkws_config != 'object') { } -// wrapper to call team() after page load -(function (j) { - mkws.log = function (string) { - if (!mkws.log_level) - return; +mkws.log = function(string) { + if (!mkws.log_level) + return; - if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */ - return; - } + if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */ + return; + } - // you need to disable use strict at the top of the file!!! - if (mkws.log_level >= 3) { - console.log(arguments.callee.caller); - } else if (mkws.log_level >= 2) { - console.log(">>> called from function " + arguments.callee.caller.name + ' <<<'); - } - console.log(string); + // you need to disable use strict at the top of the file!!! + if (mkws.log_level >= 3) { + console.log(arguments.callee.caller); + } else if (mkws.log_level >= 2) { + console.log(">>> called from function " + arguments.callee.caller.name + ' <<<'); } - var log = mkws.log; + console.log(string); +}; - mkws.handleNodeWithTeam = function(node, callback) { +mkws.registerWidgetType = function(name, fn) { + mkws.widgetType2function[name] = fn; + mkws.log("registered widget-type '" + name + "'"); +}; + +mkws.promotionFunction = function(name) { + return mkws.widgetType2function[name]; +}; + + +// wrapper to call team() after page load +(function(j) { + var log = mkws.log; + + function handleNodeWithTeam(node, callback) { // First branch for DOM objects; second branch for jQuery objects var classes = node.className || node.attr('class'); if (!classes) { @@ -161,41 +174,45 @@ if (mkws_config == null || typeof mkws_config != 'object') { }; + // The following functions are dispatchers for team methods that + // are called from the UI using a team-name rather than implicit + // context. Apart from mkws.log, they are the ONLY public UI to + // this module. mkws.switchView = function(tname, view) { mkws.teams[tname].switchView(view); - } + }; - mkws.showDetails = function (tname, prefixRecId) { + mkws.showDetails = function(tname, prefixRecId) { mkws.teams[tname].showDetails(prefixRecId); - } + }; - mkws.limitTarget = function (tname, id, name) { + mkws.limitTarget = function(tname, id, name) { mkws.teams[tname].limitTarget(id, name); - } + }; - mkws.limitQuery = function (tname, field, value) { + mkws.limitQuery = function(tname, field, value) { mkws.teams[tname].limitQuery(field, value); - } + }; - mkws.delimitTarget = function (tname, id) { + mkws.delimitTarget = function(tname, id) { mkws.teams[tname].delimitTarget(id); - } + }; - mkws.delimitQuery = function (tname, field, value) { + mkws.delimitQuery = function(tname, field, value) { mkws.teams[tname].delimitQuery(field, value); - } + }; - mkws.showPage = function (tname, pageNum) { + mkws.showPage = function(tname, pageNum) { mkws.teams[tname].showPage(pageNum); - } + }; - mkws.pagerPrev = function (tname) { + mkws.pagerPrev = function(tname) { mkws.teams[tname].pagerPrev(); - } + }; - mkws.pagerNext = function (tname) { + mkws.pagerNext = function(tname) { mkws.teams[tname].pagerNext(); - } + }; function defaultMkwsConfig() { @@ -272,12 +289,17 @@ if (mkws_config == null || typeof mkws_config != 'object') { } var status = $(data).find("status"); if (status.text() != "OK") { - alert("service proxy auth repsonse status: " + status.text() + ", give up!"); + alert("service proxy auth response status: " + status.text() + ", give up!"); return; } log("Service proxy auth successfully done"); mkws.authenticated = true; + var authName = $(data).find("displayName").text(); + for (var teamName in mkws.teams) { + mkws.teams[teamName].queue("authenticated").publish(authName); + } + runAutoSearches(); }); } @@ -293,7 +315,6 @@ if (mkws_config == null || typeof mkws_config != 'object') { $(document).ready(function() { - log("on load ready"); defaultMkwsConfig(); if (mkws_config.query_width < 5 || mkws_config.query_width > 150) { @@ -342,7 +363,7 @@ if (mkws_config == null || typeof mkws_config != 'object') { // For all MKWS-classed nodes that don't have a team // specified, set the team to AUTO. - $('[class^="mkws"],[class*=" mkws"]').each(function () { + $('[class^="mkws"],[class*=" mkws"]').each(function() { if (!this.className.match(/mkwsTeam_/)) { log("adding AUTO team to node with class '" + this.className + "'"); $(this).addClass('mkwsTeam_AUTO'); @@ -352,8 +373,8 @@ if (mkws_config == null || typeof mkws_config != 'object') { // Find all nodes with an MKWS class, and determine their team from // the mkwsTeam_* class. Make all team objects. var then = $.now(); - $('[class^="mkws"],[class*=" mkws"]').each(function () { - mkws.handleNodeWithTeam(this, function(tname, type) { + $('[class^="mkws"],[class*=" mkws"]').each(function() { + handleNodeWithTeam(this, function(tname, type) { if (!mkws.teams[tname]) { mkws.teams[tname] = team(j, tname); log("Made MKWS team '" + tname + "'"); @@ -364,8 +385,8 @@ if (mkws_config == null || typeof mkws_config != 'object') { // to be done separately, and after the team-creation, since // that sometimes makes new widget nodes (e.g. creating // mkwsTermlists inside mkwsResults. - $('[class^="mkws"],[class*=" mkws"]').each(function () { - mkws.handleNodeWithTeam(this, function(tname, type) { + $('[class^="mkws"],[class*=" mkws"]').each(function() { + handleNodeWithTeam(this, function(tname, type) { var myTeam = mkws.teams[tname]; var myWidget = widget(j, myTeam, type, this); });