Re-enable main "entries" subwidget, and place the Facet in the same
[mkws-moved-to-github.git] / examples / htdocs / mkws-widget-credo.js
1 // ### This works inefficiently by having multiple teams all run the
2 // same search against different sets of targets. A much better
3 // approach would be run a single search, with all these panels
4 // members of the same team, but picking out only the results relevant
5 // to them. That will be more work.
6
7 mkws.registerWidgetType('Credo', function() {
8   var that = this;
9
10   this.team.registerTemplate('CredoImage', '\
11       <div>\
12        <a href="{{md-electronic-url}}" target="_blank">\
13         {{#mkws-first md-thumburl}}\
14           <img src="{{this}}" alt="{{../md-title}}"/>\
15         {{/mkws-first}}\
16         <br/>\
17        </a>\
18        <p>{{md-title}}</p>\
19       </div>\
20 ');
21
22   var s = []
23   s.push('<table>');
24
25   // Main panel: encylopaedia and images on the left, topics on the right
26   s.push('<tr class="front">');
27
28   s.push('<td class="main">');
29   s.push(section('encyclopaedia', 'Topic Page: ### title',
30                  this.subwidget('Reference', { _team: 'ref' })));
31   // The Images widget needs to be in our team so we can set its template
32   s.push(section('image', 'Images',
33                  this.subwidget('GoogleImage', { maxrecs: 4, template: 'CredoImage' })));
34   s.push('</td>');
35
36   s.push('<td class="side">');
37   s.push(section('mindmap', 'Create a Mind Map for ### title',
38                  '### Is there a way to make a mind-map?'));
39   s.push(section('topics', 'Related Topics',
40                  this.subwidget('Facet', { _team: 'main', facet: 'subject' })));
41   s.push('</td>');
42
43   s.push('</tr>');
44
45   s.push(sectionRow('entries', 'Credo Entries',
46                     this.subwidget('Records', { _team: 'main' })));
47   s.push(sectionRow('articles', 'Articles',
48                     1 || this.subwidget('Records', { /* ### config */ })));
49   s.push(sectionRow('books', 'Books',
50                     1 || this.subwidget('Records', { /* ### config */ })));
51   s.push(sectionRow('news', 'News',
52                     1 || this.subwidget('Records', { /* ### config */ })));
53   s.push(sectionRow('resources', 'Suggested Resources',
54                     1 || this.subwidget('Records', { /* ### config */ })));
55
56   s.push('</table>');
57
58   this.node.html(s.join(''));
59
60
61   function section(xclass, title, content) {
62     var s = [];
63     s.push('<div class="' + xclass + ' section">');
64     s.push('<div class="title">' + title + '</div>');
65     s.push('<div class="content">' + content + '</div>');
66     s.push('</div>');
67     return s.join('');
68   }
69
70   function sectionRow(xclass, title, content) {
71     var s = [];
72     s.push('<tr>');
73     s.push('<td colspan="2">');
74     s.push(section(xclass, title, content));
75     s.push('</td>');
76     s.push('</tr>');
77     return s.join('');
78   }
79 });