<script type="text/javascript" src="http://mkws.indexdata.com/jquery.json-2.4.js"></script>
<script type="text/javascript" src="http://mkws.indexdata.com/handlebars-v1.1.2.js"></script>
<script type="text/javascript" src="http://mkws.indexdata.com/pazpar2/js/pz2.js"></script>
- <script type="text/javascript" src="http://mkws.indexdata.com/mkws.js"></script>
+ <script type="text/javascript" src="http://mkws.local/src/mkws.js"></script>
</head>
<body>
<table width="100%" border="1">
JQUERY_UI_URL = http://code.jquery.com/ui/1.10.3/jquery-ui.js
VERSION = $(shell tr -d '\012' < VERSION)
-COMPONENTS = mkws-handlebars.js \
+COMPONENTS = mkws-handlebars.js\
mkws-core.js mkws-team.js mkws-filter.js \
+ mkws-templates.js\
mkws-widget.js mkws-widget-main.js mkws-widget-termlists.js \
mkws-widget-authname.js mkws-widget-categories.js mkws-widget-log.js \
mkws-widget-record.js mkws-widget-reference.js mkws-widget-builder.js
GENERATED = ${HANDLEBARS_FILE} ${JQUERY_FILE} ${JQUERY_JSON_FILE} ${PP2_FILE} \
- mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js
+ mkws.js mkws.min.js mkws-complete.js mkws-complete.min.js mkws-templates.js
INSTALLABLE = mkws-jquery.js VERSION NEWS $(GENERATED)
cat $(COMPONENTS) > $@
chmod 444 $@
+mkws-templates.js:
+ handlebars -n mkws.defaultTemplates *.templates/*.handlebars -f mkws-templates.js
+
distclean: clean
rm -f *.orig *.bak *.rej
// initial value allows jQuery popup to use logging.
teams: {},
widgetType2function: {},
+ defaultTemplates: {},
locale_lang: {
"de": {
}
-mkws.defaultTemplate = function(name) {
- if (name === 'Record') {
- return '\
-<table>\
- <tr>\
- <th>{{mkws-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>{{mkws-translate "Date"}}</th>\
- <td>{{md-date}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-author}}\
- <tr>\
- <th>{{mkws-translate "Author"}}</th>\
- <td>{{md-author}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-electronic-url}}\
- <tr>\
- <th>{{mkws-translate "Links"}}</th>\
- <td>\
- {{#each md-electronic-url}}\
- <a href="{{this}}">Link{{mkws-index1}}</a>\
- {{/each}}\
- </td>\
- </tr>\
- {{/if}}\
- {{#mkws-if-any location having="md-subject"}}\
- <tr>\
- <th>{{mkws-translate "Subject"}}</th>\
- <td>\
- {{#mkws-first location having="md-subject"}}\
- {{#if md-subject}}\
- {{#mkws-commaList md-subject}}\
- {{this}}{{/mkws-commaList}}\
- {{/if}}\
- {{/mkws-first}}\
- </td>\
- </tr>\
- {{/mkws-if-any}}\
- <tr>\
- <th>{{mkws-translate "Locations"}}</th>\
- <td>\
- {{#mkws-commaList location}}\
- {{mkws-attr "@name"}}{{/mkws-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}}\
-';
- } else if (name === "Image") {
- return '\
- <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
- {{#mkws-first md-thumburl}}\
- <img src="{{this}}" alt="{{../md-title}}"/>\
- {{/mkws-first}}\
- <br/>\
- </a>\
-';
- }
-
- var s = "There is no default '" + name +"' template!";
- alert(s);
- return s;
-};
-
-
// The following functions are dispatchers for team methods that
// are called from the UI using a team-name rather than implicit
// context.
function loadTemplate(name) {
var template = m_template[name];
-
- if (template === undefined) {
- // Fall back to generic template if there is no team-specific one
+ if (template === undefined && Handlebars.compile) {
var source;
var node = $(".mkwsTemplate_" + name + " .mkwsTeam_" + that.name());
if (node && node.length < 1) {
node = $(".mkwsTemplate_" + name);
}
- if (node) {
- source = node.html();
- }
-
- if (!source) {
- source = m_templateText[name];
- }
- if (!source) {
- source = mkws.defaultTemplate(name);
+ if (node) source = node.html();
+ if (!source) source = m_templateText[name];
+ if (source) {
+ template = Handlebars.compile(source);
+ log("compiled template '" + name + "'");
}
-
- template = Handlebars.compile(source);
- log("compiled template '" + name + "'");
+ }
+ //if (template === undefined) template = mkws_templatesbyteam[m_teamName][name];
+ if (template === undefined && Handlebars.templates) {
+ template = Handlebars.templates[name];
+ }
+ if (template === undefined && mkws.defaultTemplates) {
+ template = mkws.defaultTemplates[name];
+ }
+ if (template) {
m_template[name] = template;
+ return template;
+ }
+ else {
+ alert("Missing MKWS template for " + name);
+ }
}
-
- return template;
- }
that.loadTemplate = loadTemplate;
var team = this.team;
this.team.queue("records").subscribe(function(data) {
- var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
that.team.queue("record").publish(hit);
- var divId = team.recordElementId(hit.recid[0]);
- html.push('<div class="mkwsSummary mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
+ hit.detailLinkId = team.recordElementId(hit.recid[0]);
+ hit.detailClick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
+ hit.containerClass = "mkwsSummary mkwsTeam_" + team.name();
+ hit.containerClass += " " + hit.detailLinkId;
// ### At some point, we may be able to move the
// m_currentRecordId and m_currentRecordData members
// from the team object into this widget.
if (hit.recid == team.currentRecordId()) {
- if (team.currentRecordData())
- html.push(team.renderDetails(team.currentRecordData()));
+ if (team.currentRecordData()) {
+ hit.renderedDetails = team.renderDetails(team.currentRecordData());
+ console.log(hit.renderedDetails);
+ }
}
}
- that.node.html(html.join(''));
-
- function renderSummary(hit) {
- var template = team.loadTemplate(that.config.template || "Summary");
- hit._id = team.recordElementId(hit.recid[0]);
- hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
- return template(hit);
- }
+ var template = team.loadTemplate(that.config.template || "Records");
+ that.node.html(template({"hits": data.hits}));
});
that.autosearch();
--- /dev/null
+ <a href="#" id="{{_id}}" onclick="{{_onclick}}">
+ {{#mkws-first md-thumburl}}
+ <img src="{{this}}" alt="{{../md-title}}"/>
+ {{/mkws-first}}
+ <br/>
+ </a>
--- /dev/null
+{{!
+Full record display.
+}}
+<table>
+ <tr>
+ <th>{{mkws-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>{{mkws-translate "Date"}}</th>
+ <td>{{md-date}}</td>
+ </tr>
+ {{/if}}
+ {{#if md-author}}
+ <tr>
+ <th>{{mkws-translate "Author"}}</th>
+ <td>{{md-author}}</td>
+ </tr>
+ {{/if}}
+ {{#if md-electronic-url}}
+ <tr>
+ <th>{{mkws-translate "Links"}}</th>
+ <td>
+ {{#each md-electronic-url}}
+ <a href="{{this}}">Link{{mkws-index1}}</a>
+ {{/each}}
+ </td>
+ </tr>
+ {{/if}}
+ {{#mkws-if-any location having="md-subject"}}
+ <tr>
+ <th>{{mkws-translate "Subject"}}</th>
+ <td>
+ {{#mkws-first location having="md-subject"}}
+ {{#if md-subject}}
+ {{#mkws-commaList md-subject}}
+ {{this}}{{/mkws-commaList}}
+ {{/if}}
+ {{/mkws-first}}
+ </td>
+ </tr>
+ {{/mkws-if-any}}
+ <tr>
+ <th>{{mkws-translate "Locations"}}</th>
+ <td>
+ {{#mkws-commaList location}}
+ {{mkws-attr "@name"}}{{/mkws-commaList}}
+ </td>
+ </tr>
+</table>
--- /dev/null
+{{!
+Records from a search.
+
+hits:
+ containerClass - class attribute for same
+ detailLinkId - id for the element triggering detail display
+ detailClick - a click event handler for details
+ renderedDetails - active record details rendered from the Record template
+ md-* - metadata fields passed through from backend
+}}
+{{#each hits}}
+ <div class="{{containerClass}}">
+ <a href="#" id="{{detailLinkId}}" onclick="{{detailClick}}">
+ <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}}
+ {{#if renderedDetails}}
+ {{{renderedDetails}}}
+ {{/if}}
+ </div>
+{{/each}}