2012-12-26 19:36:54 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/widgets/fields.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: widget
|
|
|
|
|
|
|
|
The view widget displays the fields of a tiddler through a text substitution template.
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2013-01-01 17:51:02 +00:00
|
|
|
var FieldsWidget = function(renderer) {
|
2012-12-26 19:36:54 +00:00
|
|
|
// Save state
|
|
|
|
this.renderer = renderer;
|
|
|
|
// Generate child nodes
|
2013-01-03 16:27:55 +00:00
|
|
|
this.generate();
|
2012-12-26 19:36:54 +00:00
|
|
|
};
|
|
|
|
|
2013-01-03 16:27:55 +00:00
|
|
|
FieldsWidget.prototype.generate = function() {
|
2012-12-26 19:36:54 +00:00
|
|
|
// Get parameters from our attributes
|
|
|
|
this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle());
|
|
|
|
this.template = this.renderer.getAttribute("template");
|
|
|
|
this.exclude = this.renderer.getAttribute("exclude");
|
|
|
|
// Get the tiddler we're displaying
|
|
|
|
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle);
|
|
|
|
// Get the exclusion list
|
|
|
|
var exclude;
|
|
|
|
if(this.exclude) {
|
|
|
|
exclude = this.exclude.split(" ");
|
|
|
|
} else {
|
|
|
|
exclude = ["text"];
|
|
|
|
}
|
|
|
|
// Compose the template
|
|
|
|
var text = [];
|
|
|
|
if(this.template && tiddler) {
|
|
|
|
for(var field in tiddler.fields) {
|
|
|
|
if(exclude.indexOf(field) === -1) {
|
|
|
|
var row = this.template;
|
|
|
|
row = row.replace("$name$",field);
|
|
|
|
row = row.replace("$value$",tiddler.getFieldString(field));
|
|
|
|
row = row.replace("$encoded_value$",$tw.utils.htmlEncode(tiddler.getFieldString(field)));
|
|
|
|
text.push(row)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-03 16:27:55 +00:00
|
|
|
// Set the element
|
|
|
|
this.tag = "pre";
|
|
|
|
this.attributes = {
|
|
|
|
"class": "tw-fields"
|
2012-12-26 19:36:54 +00:00
|
|
|
};
|
|
|
|
// Set up the attributes for the wrapper element
|
|
|
|
var classes = [];
|
|
|
|
if(this.renderer.hasAttribute("class")) {
|
|
|
|
$tw.utils.pushTop(classes,this.renderer.getAttribute("class").split(" "));
|
|
|
|
}
|
|
|
|
if(classes.length > 0) {
|
2013-01-03 16:27:55 +00:00
|
|
|
this.attributes["class"] = classes.join(" ");
|
2012-12-26 19:36:54 +00:00
|
|
|
}
|
|
|
|
if(this.renderer.hasAttribute("style")) {
|
2013-01-03 16:27:55 +00:00
|
|
|
this.attributes.style = this.renderer.getAttribute("style");
|
2012-12-26 19:36:54 +00:00
|
|
|
}
|
|
|
|
if(this.renderer.hasAttribute("tooltip")) {
|
2013-01-03 16:27:55 +00:00
|
|
|
this.attributes.title = this.renderer.getAttribute("tooltip");
|
2012-12-26 19:36:54 +00:00
|
|
|
}
|
|
|
|
// Create the renderers for the wrapper and the children
|
2013-01-03 16:27:55 +00:00
|
|
|
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,[{
|
|
|
|
type: "text",
|
|
|
|
text: text.join("")
|
|
|
|
}]);
|
2012-12-26 19:36:54 +00:00
|
|
|
};
|
|
|
|
|
2013-01-01 17:51:02 +00:00
|
|
|
exports.fields = FieldsWidget;
|
|
|
|
|
2012-12-26 19:36:54 +00:00
|
|
|
})();
|