mkwsHtmlSwitch no longer sets up the .mkwsSwitch element, because now
[mkws-moved-to-github.git] / src / mkws-team.js
1 // Factory function for team objects. As much as possible, this uses
2 // only member variables (prefixed "m_") and inner functions with
3 // private scope.
4 //
5 // Some functions are visible as member-functions to be called from
6 // outside code -- specifically, from generated HTML. These functions
7 // are that.switchView(), showDetails(), limitTarget(), limitQuery(),
8 // limitCategory(), delimitTarget(), delimitQuery(), showPage(),
9 // pagerPrev(), pagerNext().
10 //
11 function team($, teamName) {
12     var that = {};
13     var m_teamName = teamName;
14     var m_submitted = false;
15     var m_query; // initially undefined
16     var m_sortOrder; // will be set below
17     var m_perpage; // will be set below
18     var m_filterSet = filterSet(that);
19     var m_totalRecordCount = 0;
20     var m_currentPage = 1;
21     var m_currentRecordId = '';
22     var m_currentRecordData = null;
23     var m_logTime = {
24         // Timestamps for logging
25         "start": $.now(),
26         "last": $.now()
27     };
28     var m_paz; // will be initialised below
29     var m_tempateText = {}; // widgets can register tempates to be compiled
30     var m_template = {}; // compiled templates, from any source
31     var m_config = mkws.objectInheritingFrom(mkws.config);
32     var m_widgets = {}; // Maps widget-type to object
33
34     that.toString = function() { return '[Team ' + teamName + ']'; };
35
36     // Accessor methods for individual widgets: readers
37     that.name = function() { return m_teamName; };
38     that.submitted = function() { return m_submitted; };
39     that.perpage = function() { return m_perpage; };
40     that.totalRecordCount = function() { return m_totalRecordCount; };
41     that.currentPage = function() { return m_currentPage; };
42     that.currentRecordId = function() { return m_currentRecordId; };
43     that.currentRecordData = function() { return m_currentRecordData; };
44     that.filters = function() { return m_filterSet; };
45     that.config = function() { return m_config; };
46
47     // Accessor methods for individual widgets: writers
48     that.set_sortOrder = function(val) { m_sortOrder = val };
49     that.set_perpage = function(val) { m_perpage = val };
50
51
52     // The following PubSub code is modified from the jQuery manual:
53     // http://api.jquery.com/jQuery.Callbacks/
54     //
55     // Use as:
56     //  team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
57     //  team.queue("eventName").publish(arg1, arg2, ...);
58     //
59     var queues = {};
60     function queue(id) {
61         if (!queues[id]) {
62             var callbacks = $.Callbacks();
63             queues[id] = {
64                 publish: callbacks.fire,
65                 subscribe: callbacks.add,
66                 unsubscribe: callbacks.remove
67             };
68         }
69         return queues[id];
70     };
71     that.queue = queue;
72
73
74     function log(s) {
75         var now = $.now();
76         var timestamp = (((now - m_logTime.start)/1000).toFixed(3) + " (+" +
77                          ((now - m_logTime.last)/1000).toFixed(3) + ") ");
78         m_logTime.last = now;
79         mkws.log(m_teamName + ": " + timestamp + s);
80         that.queue("log").publish(m_teamName, timestamp, s);
81     }
82     that.log = log;
83
84
85     log("start running MKWS");
86
87     m_sortOrder = m_config.sort_default;
88     m_perpage = m_config.perpage_default;
89
90     log("Create main pz2 object");
91     // create a parameters array and pass it to the pz2's constructor
92     // then register the form submit event with the pz2.search function
93     // autoInit is set to true on default
94     m_paz = new pz2({ "windowid": teamName,
95                       "pazpar2path": m_config.pazpar2_url,
96                       "usesessions" : m_config.use_service_proxy ? false : true,
97                       "oninit": onInit,
98                       "onbytarget": onBytarget,
99                       "onstat": onStat,
100                       "onterm": (m_config.facets.length ? onTerm : undefined),
101                       "onshow": onShow,
102                       "onrecord": onRecord,
103                       "showtime": 500,            //each timer (show, stat, term, bytarget) can be specified this way
104                       "termlist": m_config.facets.join(',')
105                     });
106
107     // pz2.js event handlers:
108     function onInit() {
109         log("init");
110         m_paz.stat();
111         m_paz.bytarget();
112     }
113
114     function onBytarget(data) {
115         log("target");
116         queue("targets").publish(data);
117     }
118
119     function onStat(data) {
120         queue("stat").publish(data);
121         if (parseInt(data.activeclients[0], 10) === 0)
122             queue("complete").publish(parseInt(data.hits[0], 10));
123     }
124
125     function onTerm(data) {
126         log("term");
127         queue("termlists").publish(data);
128     }
129
130     function onShow(data, teamName) {
131         log("show");
132         m_totalRecordCount = data.merged;
133         log("found " + m_totalRecordCount + " records");
134         queue("pager").publish(data);
135         queue("records").publish(data);
136     }
137
138     function onRecord(data, args, teamName) {
139         log("record");
140         // FIXME: record is async!!
141         clearTimeout(m_paz.recordTimer);
142         var detRecordDiv = findnode(recordDetailsId(data.recid[0]));
143         if (detRecordDiv.length) {
144             // in case on_show was faster to redraw element
145             return;
146         }
147         m_currentRecordData = data;
148         var recordDiv = findnode('.' + recordElementId(m_currentRecordData.recid[0]));
149         var html = renderDetails(m_currentRecordData);
150         $(recordDiv).append(html);
151     }
152
153
154     // Used by the Records widget and onRecord()
155     function recordElementId(s) {
156         return 'mkwsRec_' + s.replace(/[^a-z0-9]/ig, '_');
157     }
158     that.recordElementId = recordElementId;
159
160     // Used by onRecord(), showDetails() and renderDetails()
161     function recordDetailsId(s) {
162         return 'mkwsDet_' + s.replace(/[^a-z0-9]/ig, '_');
163     }
164
165
166     that.targetFiltered = function(id) {
167         return m_filterSet.targetFiltered(id);
168     };
169
170
171     that.limitTarget = function(id, name) {
172         log("limitTarget(id=" + id + ", name=" + name + ")");
173         m_filterSet.add(targetFilter(id, name));
174         if (m_query) triggerSearch();
175         return false;
176     };
177
178
179     that.limitQuery = function(field, value) {
180         log("limitQuery(field=" + field + ", value=" + value + ")");
181         m_filterSet.add(fieldFilter(field, value));
182         if (m_query) triggerSearch();
183         return false;
184     };
185
186
187     that.limitCategory = function(id) {
188         log("limitCategory(id=" + id + ")");
189         // Only one category filter at a time
190         m_filterSet.removeMatching(function(f) { return f.type === 'category' });
191         if (id !== '') m_filterSet.add(categoryFilter(id));
192         if (m_query) triggerSearch();
193         return false;
194     };
195
196
197     that.delimitTarget = function(id) {
198         log("delimitTarget(id=" + id + ")");
199         m_filterSet.removeMatching(function(f) { return f.type === 'target' });
200         if (m_query) triggerSearch();
201         return false;
202     };
203
204
205     that.delimitQuery = function(field, value) {
206         log("delimitQuery(field=" + field + ", value=" + value + ")");
207         m_filterSet.removeMatching(function(f) { return f.type == 'field' &&
208                                                  field == f.field && value == f.value });
209         if (m_query) triggerSearch();
210         return false;
211     };
212
213
214     that.showPage = function(pageNum) {
215         m_currentPage = pageNum;
216         m_paz.showPage(m_currentPage - 1);
217     };
218
219
220     that.pagerNext = function() {
221         if (m_totalRecordCount - m_perpage*m_currentPage > 0) {
222             m_paz.showNext();
223             m_currentPage++;
224         }
225     };
226
227
228     that.pagerPrev = function() {
229         if (m_paz.showPrev() != false)
230             m_currentPage--;
231     };
232
233
234     that.reShow = function() {
235         resetPage();
236         m_paz.show(0, m_perpage, m_sortOrder);
237     };
238
239
240     function resetPage() {
241         m_currentPage = 1;
242         m_totalRecordCount = 0;
243     }
244     that.resetPage = resetPage;
245
246
247     function newSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery) {
248         log("newSearch: " + query);
249
250         if (m_config.use_service_proxy && !mkws.authenticated) {
251             alert("searching before authentication");
252             return;
253         }
254
255         m_filterSet.removeMatching(function(f) { return f.type !== 'category' });
256         triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery);
257         switchView('records'); // In case it's configured to start off as hidden
258         m_submitted = true;
259     }
260     that.newSearch = newSearch;
261
262
263     function triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery) {
264         resetPage();
265         queue("navi").publish();
266
267         // Continue to use previous query/sort-order unless new ones are specified
268         if (query) m_query = query;
269         if (sortOrder) m_sortOrder = sortOrder;
270         if (perpage) m_perpage = perpage;
271         if (targets) m_filterSet.add(targetFilter(targets, targets));
272
273         var pp2filter = m_filterSet.pp2filter();
274         var pp2limit = m_filterSet.pp2limit(limit);
275         var pp2catLimit = m_filterSet.pp2catLimit();
276         if (pp2catLimit) {
277             pp2filter = pp2filter ? pp2filter + "," + pp2catLimit : pp2catLimit;
278         }
279
280         var params = {};
281         if (pp2limit) params.limit = pp2limit;
282         if (maxrecs) params.maxrecs = maxrecs;
283         if (torusquery) {
284             if (!mkws.config.use_service_proxy)
285                 alert("can't narrow search by torusquery when Service Proxy is not in use");
286             params.torusquery = torusquery;
287         }
288
289         log("triggerSearch(" + m_query + "): filters = " + m_filterSet.toJSON() + ", " +
290             "pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
291
292         m_paz.search(m_query, m_perpage, m_sortOrder, pp2filter, undefined, params);
293     }
294
295
296     // switching view between targets and records
297     function switchView(view) {
298         var targets = widgetNode('Targets');
299         var results = widgetNode('Results') || widgetNode('Records');
300         var blanket = widgetNode('Blanket');
301         var motd    = widgetNode('MOTD');
302
303         switch(view) {
304         case 'targets':
305             if (targets) targets.css('display', 'block');
306             if (results) results.css('display', 'none');
307             if (blanket) blanket.css('display', 'none');
308             if (motd) motd.css('display', 'none');
309             break;
310         case 'records':
311             if (targets) targets.css('display', 'none');
312             if (results) results.css('display', 'block');
313             if (blanket) blanket.css('display', 'block');
314             if (motd) motd.css('display', 'none');
315             break;
316         case 'none':
317             alert("mkws.switchView(" + m_teamName + ", 'none') shouldn't happen");
318             if (targets) targets.css('display', 'none');
319             if (results) results.css('display', 'none');
320             if (blanket) blanket.css('display', 'none');
321             if (motd) motd.css('display', 'none');
322             break;
323         default:
324             alert("Unknown view '" + view + "'");
325         }
326     }
327     that.switchView = switchView;
328
329
330     // detailed record drawing
331     that.showDetails = function(recId) {
332         var oldRecordId = m_currentRecordId;
333         m_currentRecordId = recId;
334
335         // remove current detailed view if any
336         findnode('#' + recordDetailsId(oldRecordId)).remove();
337
338         // if the same clicked, just hide
339         if (recId == oldRecordId) {
340             m_currentRecordId = '';
341             m_currentRecordData = null;
342             return;
343         }
344         // request the record
345         log("showDetails() requesting record '" + recId + "'");
346         m_paz.record(recId);
347     };
348
349
350     /*
351      * All the HTML stuff to render the search forms and
352      * result pages.
353      */
354     function mkwsHtmlAll() {
355         mkwsSetLang();
356         if (m_config.show_lang)
357             mkwsHtmlLang();
358
359         log("HTML search form");
360         findnode('.mkwsSearch').html('\
361 <form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + m_teamName + '" action="" >\
362   <input class="mkwsQuery mkwsTeam_' + m_teamName + '" type="text" size="' + m_config.query_width + '" />\
363   <input class="mkwsButton mkwsTeam_' + m_teamName + '" type="submit" value="' + M('Search') + '" />\
364 </form>');
365
366         log("HTML records");
367         // If the team has a .mkwsResults, populate it in the usual
368         // way. If not, assume that it's a smarter application that
369         // defines its own subcomponents, some or all of the
370         // following:
371         //      .mkwsTermlists
372         //      .mkwsRanking
373         //      .mkwsPager
374         //      .mkwsNavi
375         //      .mkwsRecords
376         findnode(".mkwsResults").html('\
377 <table width="100%" border="0" cellpadding="6" cellspacing="0">\
378   <tr>\
379     <td class="mkwsTermlistContainer1 mkwsTeam_' + m_teamName + '" width="250" valign="top">\
380       <div class="mkwsTermlists mkwsTeam_' + m_teamName + '"></div>\
381     </td>\
382     <td class="mkwsMOTDContainer mkwsTeam_' + m_teamName + '" valign="top">\
383       <div class="mkwsRanking mkwsTeam_' + m_teamName + '"></div>\
384       <div class="mkwsPager mkwsTeam_' + m_teamName + '"></div>\
385       <div class="mkwsNavi mkwsTeam_' + m_teamName + '"></div>\
386       <div class="mkwsRecords mkwsTeam_' + m_teamName + '"></div>\
387     </td>\
388   </tr>\
389   <tr>\
390     <td colspan="2">\
391       <div class="mkwsTermlistContainer2 mkwsTeam_' + m_teamName + '"></div>\
392     </td>\
393   </tr>\
394 </table>');
395
396         var acc = [];
397         var facets = m_config.facets;
398         acc.push('<div class="title">' + M('Termlists') + '</div>');
399         for (var i = 0; i < facets.length; i++) {
400             acc.push('<div class="mkwsFacet mkwsTeam_' + m_teamName + '" data-mkws-facet="' + facets[i] + '">');
401             acc.push('</div>');
402         }
403         findnode(".mkwsTermlists").html(acc.join(''));
404
405         var ranking_data = '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + m_teamName + '" action="" >';
406         if (m_config.show_sort) {
407             ranking_data +=  M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
408         }
409         if (m_config.show_perpage) {
410             ranking_data += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
411         }
412         ranking_data += '</form>';
413         findnode(".mkwsRanking").html(ranking_data);
414
415         mkwsHtmlSwitch();
416
417         findnode('.mkwsSearchForm').submit(function() {
418             var val = widgetNode('Query').val();
419             newSearch(val);
420             return false;
421         });
422
423         // on first page, hide the termlist
424         $(document).ready(function() {
425             var t = widgetNode("Termlists");
426             if (t) t.hide();
427         });
428         var container = findnode(".mkwsMOTDContainer");
429         if (container.length) {
430             // Move the MOTD from the provided element down into the container
431             findnode(".mkwsMOTD").appendTo(container);
432         }
433     }
434
435
436     function mkwsSetLang()  {
437         var lang = mkws.getParameterByName("lang") || m_config.lang;
438         if (!lang || !mkws.locale_lang[lang]) {
439             m_config.lang = ""
440         } else {
441             m_config.lang = lang;
442         }
443
444         log("Locale language: " + (m_config.lang ? m_config.lang : "none"));
445         return m_config.lang;
446     }
447
448     // set or re-set "lang" URL parameter
449     function lang_url(lang) {
450         var query = location.search;
451         // no query parameters? done
452         if (!query) {
453             return "?lang=" + lang;
454         }
455
456         // parameter does not exists
457         if (!query.match(/[\?&]lang=/)) {
458             return query + "&lang=" + lang;
459         }
460
461         // replace existing parameter
462         query = query.replace(/\?lang=([^&#;]*)/, "?lang=" + lang);
463         query = query.replace(/\&lang=([^&#;]*)/, "&lang=" + lang);
464
465         return query;
466     }
467    
468         // dynamic URL or static page? /path/foo?query=test
469     /* create locale language menu */
470     function mkwsHtmlLang() {
471         var lang_default = "en";
472         var lang = m_config.lang || lang_default;
473         var list = [];
474
475         /* display a list of configured languages, or all */
476         var lang_options = m_config.lang_options || [];
477         var toBeIncluded = {};
478         for (var i = 0; i < lang_options.length; i++) {
479             toBeIncluded[lang_options[i]] = true;
480         }
481
482         for (var k in mkws.locale_lang) {
483             if (toBeIncluded[k] || lang_options.length == 0)
484                 list.push(k);
485         }
486
487         // add english link
488         if (lang_options.length == 0 || toBeIncluded[lang_default])
489             list.push(lang_default);
490
491         log("Language menu for: " + list.join(", "));
492
493         /* the HTML part */
494         var data = "";
495         for(var i = 0; i < list.length; i++) {
496             var l = list[i];
497
498             if (data)
499                 data += ' | ';
500
501             if (lang == l) {
502                 data += ' <span>' + l + '</span> ';
503             } else {
504                 data += ' <a href="' + lang_url(l) + '">' + l + '</a> '
505             }
506         }
507
508         findnode(".mkwsLang").html(data);
509     }
510
511
512     function mkwsHtmlSort() {
513         log("HTML sort, m_sortOrder = '" + m_sortOrder + "'");
514         var sort_html = '<select class="mkwsSort mkwsTeam_' + m_teamName + '">';
515
516         for(var i = 0; i < m_config.sort_options.length; i++) {
517             var opt = m_config.sort_options[i];
518             var key = opt[0];
519             var val = opt.length == 1 ? opt[0] : opt[1];
520
521             sort_html += '<option value="' + key + '"';
522             if (m_sortOrder == key || m_sortOrder == val) {
523                 sort_html += ' selected="selected"';
524             }
525             sort_html += '>' + M(val) + '</option>';
526         }
527         sort_html += '</select>';
528
529         return sort_html;
530     }
531
532
533     function mkwsHtmlPerpage() {
534         log("HTML perpage, m_perpage = " + m_perpage);
535         var perpage_html = '<select class="mkwsPerpage mkwsTeam_' + m_teamName + '">';
536
537         for(var i = 0; i < m_config.perpage_options.length; i++) {
538             var key = m_config.perpage_options[i];
539
540             perpage_html += '<option value="' + key + '"';
541             if (key == m_perpage) {
542                 perpage_html += ' selected="selected"';
543             }
544             perpage_html += '>' + key + '</option>';
545         }
546         perpage_html += '</select>';
547
548         return perpage_html;
549     }
550
551
552     function mkwsHtmlSwitch() {
553         log("HTML targets");
554         var node = findnode(".mkwsTargets");
555         node.html('\
556 <div class="mkwsBytarget mkwsTeam_' + m_teamName + '">\
557   No information available yet.\
558 </div>');
559         node.css("display", "none");
560     }
561
562
563     // Translation function. At present, this is properly a
564     // global-level function (hence the assignment to mkws.M) but we
565     // want to make it per-team so different teams can operate in
566     // different languages.
567     //
568     function M(word) {
569         var lang = m_config.lang;
570
571         if (!lang || !mkws.locale_lang[lang])
572             return word;
573
574         return mkws.locale_lang[lang][word] || word;
575     }
576     mkws.M = M; // so the Handlebars helper can use it
577
578
579     // Finds the node of the specified class within the current team
580     function findnode(selector, teamName) {
581         teamName = teamName || m_teamName;
582
583         if (teamName === 'AUTO') {
584             selector = (selector + '.mkwsTeam_' + teamName + ',' +
585                         selector + ':not([class^="mkwsTeam"],[class*=" mkwsTeam"])');
586         } else {
587             selector = selector + '.mkwsTeam_' + teamName;
588         }
589
590         var node = $(selector);
591         //log('findnode(' + selector + ') found ' + node.length + ' nodes');
592         return node;
593     }
594     that.findnode = findnode;
595
596
597     // This much simpler and more efficient function should be usable
598     // in place of most uses of findnode.
599     function widgetNode(type) {
600         var w = that.widget(type);
601         return w ? $(w.node) : undefined;
602     }
603
604     function renderDetails(data, marker) {
605         var template = loadTemplate("Record");
606         var details = template(data);
607         return '<div class="details mkwsTeam_' + m_teamName + '" ' +
608             'id="' + recordDetailsId(data.recid[0]) + '">' + details + '</div>';
609     }
610     that.renderDetails = renderDetails;
611
612
613     that.registerTemplate = function(name, text) {
614         m_tempateText[name] = text;
615     };
616
617
618     function loadTemplate(name) {
619         var template = m_template[name];
620
621         if (template === undefined) {
622             // Fall back to generic template if there is no team-specific one
623             var source;
624             var node = widgetNode("Template_" + name);
625             if (!node) {
626                 node = widgetNode("Template_" + name, "ALL");
627             }
628             if (node) {
629                 source = node.html();
630             }
631
632             if (!source) {
633                 source = m_tempateText[name];
634             }
635             if (!source) {
636                 source = defaultTemplate(name);
637             }
638
639             template = Handlebars.compile(source);
640             log("compiled template '" + name + "'");
641             m_template[name] = template;
642         }
643
644         return template;
645     }
646     that.loadTemplate = loadTemplate;
647
648
649     function defaultTemplate(name) {
650         if (name === 'Record') {
651             return '\
652 <table>\
653   <tr>\
654     <th>{{translate "Title"}}</th>\
655     <td>\
656       {{md-title}}\
657       {{#if md-title-remainder}}\
658         ({{md-title-remainder}})\
659       {{/if}}\
660       {{#if md-title-responsibility}}\
661         <i>{{md-title-responsibility}}</i>\
662       {{/if}}\
663     </td>\
664   </tr>\
665   {{#if md-date}}\
666   <tr>\
667     <th>{{translate "Date"}}</th>\
668     <td>{{md-date}}</td>\
669   </tr>\
670   {{/if}}\
671   {{#if md-author}}\
672   <tr>\
673     <th>{{translate "Author"}}</th>\
674     <td>{{md-author}}</td>\
675   </tr>\
676   {{/if}}\
677   {{#if md-electronic-url}}\
678   <tr>\
679     <th>{{translate "Links"}}</th>\
680     <td>\
681       {{#each md-electronic-url}}\
682         <a href="{{this}}">Link{{index1}}</a>\
683       {{/each}}\
684     </td>\
685   </tr>\
686   {{/if}}\
687   {{#if-any location having="md-subject"}}\
688   <tr>\
689     <th>{{translate "Subject"}}</th>\
690     <td>\
691       {{#first location having="md-subject"}}\
692         {{#if md-subject}}\
693           {{#commaList md-subject}}\
694             {{this}}{{/commaList}}\
695         {{/if}}\
696       {{/first}}\
697     </td>\
698   </tr>\
699   {{/if-any}}\
700   <tr>\
701     <th>{{translate "Locations"}}</th>\
702     <td>\
703       {{#commaList location}}\
704         {{attr "@name"}}{{/commaList}}\
705     </td>\
706   </tr>\
707 </table>\
708 ';
709         } else if (name === "Summary") {
710             return '\
711 <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
712   <b>{{md-title}}</b>\
713 </a>\
714 {{#if md-title-remainder}}\
715   <span>{{md-title-remainder}}</span>\
716 {{/if}}\
717 {{#if md-title-responsibility}}\
718   <span><i>{{md-title-responsibility}}</i></span>\
719 {{/if}}\
720 ';
721         } else if (name === "Image") {
722             return '\
723       <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
724         {{#first md-thumburl}}\
725           <img src="{{this}}" alt="{{../md-title}}"/>\
726         {{/first}}\
727         <br/>\
728       </a>\
729 ';
730         }
731
732         var s = "There is no default '" + name +"' template!";
733         alert(s);
734         return s;
735     }
736
737     that.addWidget = function(w) {
738         if (!m_widgets[w.type]) {
739             m_widgets[w.type] = w;
740             log("Registered '" + w.type + "' widget in team '" + m_teamName + "'");
741         } else if (typeof(m_widgets[w.type]) !== 'number') {
742             m_widgets[w.type] = 2;
743             log("Registered duplicate '" + w.type + "' widget in team '" + m_teamName + "'");
744         } else {
745             m_widgets[w.type] += 1;
746             log("Registered '" + w.type + "' widget #" + m_widgets[w.type] + "' in team '" + m_teamName + "'");
747         }
748     }
749
750     that.widgetTypes = function() {
751         var keys = [];
752         for (var k in m_widgets) keys.push(k);
753         return keys.sort();
754     }
755
756     that.widget = function(type) {
757         return m_widgets[type];
758     }
759
760     mkwsHtmlAll()
761
762     return that;
763 };