Move registration of 'link' helper down so it can use debug()
[mkws-moved-to-github.git] / tools / htdocs / mkws.js
index 15157a7..1a58f58 100644 (file)
@@ -100,6 +100,17 @@ mkws.debug_function = function (string) {
 }
 var debug = mkws.debug_function; // local alias
 
+
+Handlebars.registerHelper('link', function(text, url) {
+  text = Handlebars.Utils.escapeExpression(text);
+  url  = Handlebars.Utils.escapeExpression(url);
+
+  var result = '<a href="' + url + '">' + text + '</a>';
+
+  return new Handlebars.SafeString(result);
+});
+
+
 {
     /* default mkws config */
     var config_default = {
@@ -640,23 +651,38 @@ function replaceHtml(el, html) {
 
 function renderDetails(data, marker)
 {
-    var details = '<div class="details" id="mkwsDet_'+data.recid+'">';
-
     if (mkws.templateRecord === undefined) {
        maybeLoadTemplate("Record");
     }
 
+    var details;
     if (mkws.templateRecord) {
        var template = mkws.templateRecord;
-       details += template(data);
+       details = template(data);
     } else {
-       details += defaultRenderDetails(data, marker);
+       details = defaultRenderDetails(data, marker);
     }
 
-    details += '</div>';
-    return details;
+    return '<div class="details" id="mkwsDet_' + data.recid + '">' + details + '</div>';
 }
 
+
+function maybeLoadTemplate(name)
+{
+    var source = $("#mkwsTemplate" + name).html();
+    if (!source) {
+       debug("no template '" + name + "': falling back to default behaviour");
+       // Mark template as not provided
+       mkws['template' + name] = 0;
+       return;
+    }
+
+    var template = Handlebars.compile(source);
+    debug("compiled template '" + name + "'");
+    mkws['template' + name] = template;
+}
+
+
 function defaultRenderDetails(data, marker)
 {
     var details = '<table>';
@@ -682,22 +708,6 @@ function defaultRenderDetails(data, marker)
 }
 
 
-function maybeLoadTemplate(name)
-{
-    var source = $("#mkwsTemplate" + name).html();
-    if (!source) {
-       debug("no template '" + name + "': falling back to default behaviour");
-       // Mark template as not provided
-       mkws['template' + name] = 0;
-       return;
-    }
-
-    var template = Handlebars.compile(source);
-    debug("compiled template '" + name + "'");
-    mkws['template' + name] = template;
-}
-
-
 function renderField(caption, data, data2, data3) {
     if (data === undefined) {
        return "";