1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 22:33:50 +00:00

Fix view widget to display friendly text of tiddler values

This commit is contained in:
Jeremy Ruston 2013-10-14 21:02:03 +01:00
parent 7c0cc36739
commit e3dcb8cdc1

View File

@ -71,6 +71,31 @@ ViewWidget.prototype.execute = function() {
The various formatter functions are baked into this widget for the moment. Eventually they will be replaced by macro functions The various formatter functions are baked into this widget for the moment. Eventually they will be replaced by macro functions
*/ */
ViewWidget.prototype.getValue = function() {
// Get the value to display
var value,
tiddler = this.wiki.getTiddler(this.viewTitle);
if(tiddler) {
if(this.viewField === "text") {
// Calling getTiddlerText() triggers lazy loading of skinny tiddlers
value = this.wiki.getTiddlerText(this.viewTitle);
} else {
if($tw.utils.hop(tiddler.fields,this.viewField)) {
value = tiddler.fields[this.viewField];
} else {
value = "";
}
}
} else {
if(this.viewField === "title") {
value = this.viewTitle;
} else {
value = undefined;
}
}
return value;
};
ViewWidget.prototype.getValueAsText = function() { ViewWidget.prototype.getValueAsText = function() {
// Get the value to display // Get the value to display
var text, var text,
@ -80,24 +105,13 @@ ViewWidget.prototype.getValueAsText = function() {
// Calling getTiddlerText() triggers lazy loading of skinny tiddlers // Calling getTiddlerText() triggers lazy loading of skinny tiddlers
text = this.wiki.getTiddlerText(this.viewTitle); text = this.wiki.getTiddlerText(this.viewTitle);
} else { } else {
if($tw.utils.hop(tiddler.fields,this.viewField)) { text = tiddler.getFieldString(this.viewField);
text = tiddler.fields[this.viewField];
} else {
text = "";
}
} }
} else { // Use a special value if the tiddler is missing } else { // Use a special value if the tiddler is missing
switch(this.viewField) { if(this.viewField === "title") {
case "title": text = this.viewTitle;
text = this.getVariable("tiddlerTitle"); } else {
break; text = "";
case "modified":
case "created":
text = new Date();
break;
default:
text = "";
break;
} }
} }
return text; return text;
@ -112,11 +126,11 @@ ViewWidget.prototype.getValueAsHtmlEncoded = function() {
}; };
ViewWidget.prototype.getValueAsDate = function(format) { ViewWidget.prototype.getValueAsDate = function(format) {
return $tw.utils.formatDateString(this.getValueAsText(),format); return $tw.utils.formatDateString(this.getValue(),format);
}; };
ViewWidget.prototype.getValueAsRelativeDate = function(format) { ViewWidget.prototype.getValueAsRelativeDate = function(format) {
var value = this.getValueAsText(); var value = this.getValue();
if(value) { if(value) {
return $tw.utils.getRelativeDate((new Date()) - (new Date(value))).description; return $tw.utils.getRelativeDate((new Date()) - (new Date(value))).description;
} else { } else {