mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 00:50:28 +00:00
Added fields macro and put it in the default view template
This commit is contained in:
parent
6819365dfc
commit
bb10222b8d
67
core/modules/macros/fields.js
Normal file
67
core/modules/macros/fields.js
Normal file
@ -0,0 +1,67 @@
|
||||
/*\
|
||||
title: $:/core/modules/macros/fields.js
|
||||
type: application/javascript
|
||||
module-type: macro
|
||||
|
||||
Fields macro
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.info = {
|
||||
name: "fields",
|
||||
dependentOnContextTiddler: true,
|
||||
params: {
|
||||
}
|
||||
};
|
||||
|
||||
exports.executeMacro = function() {
|
||||
// Create the table
|
||||
var attributes = {
|
||||
"class": ["tw-fields-table"]
|
||||
};
|
||||
if(this.classes) {
|
||||
$tw.utils.pushTop(attributes["class"],this.classes);
|
||||
}
|
||||
var rows = [
|
||||
$tw.Tree.Element("tr",{},[
|
||||
$tw.Tree.Element("th",{},[$tw.Tree.Text("Field")]),
|
||||
$tw.Tree.Element("th",{},[$tw.Tree.Text("Value")])
|
||||
])
|
||||
];
|
||||
// Get the value to display
|
||||
var tiddler = this.wiki.getTiddler(this.tiddlerTitle);
|
||||
if(tiddler) {
|
||||
var fields = [];
|
||||
for(var f in tiddler.fields) {
|
||||
fields.push(f);
|
||||
}
|
||||
fields.sort();
|
||||
for(f=0; f<fields.length; f++) {
|
||||
var value;
|
||||
if(fields[f] === "text") {
|
||||
value = $tw.Tree.Element("em",{},[
|
||||
$tw.Tree.Text("(length: " + tiddler.fields.text.length + ")")
|
||||
]);
|
||||
} else {
|
||||
value = $tw.Tree.Text(tiddler.getFieldString(fields[f]));
|
||||
}
|
||||
rows.push($tw.Tree.Element("tr",{},[
|
||||
$tw.Tree.Element("td",{},[$tw.Tree.Text(fields[f])]),
|
||||
$tw.Tree.Element("td",{},[value])
|
||||
]));
|
||||
}
|
||||
}
|
||||
var child = $tw.Tree.Element("table",attributes,[
|
||||
$tw.Tree.Element("tbody",{},rows)
|
||||
]);
|
||||
child.execute(this.parents,this.tiddlerTitle);
|
||||
return child;
|
||||
return this.viewer.render();
|
||||
};
|
||||
|
||||
})();
|
@ -1,11 +1,28 @@
|
||||
title: $:/templates/ViewTemplate
|
||||
modifier: JeremyRuston
|
||||
|
||||
<div class="title">
|
||||
<span><<view title>></span> <span> <<reveal state:[[$:/EditMode]] type:match text:yes>< <<button EditTiddler class:"btn-invisible"><[img[$:/core/images/edit-button.svg]]>> >> </span>
|
||||
<<button popup:FieldsDropDownLocation qualifyTiddlerTitles:yes class:"btn-invisible"><
|
||||
<span class="title"><<view title>> </span>
|
||||
>>
|
||||
<span> <<reveal state:[[$:/EditMode]] type:match text:yes>< <<button EditTiddler class:"btn-invisible"><[img[$:/core/images/edit-button.svg]]>> >> </span>
|
||||
<<button close class:"btn-invisible pull-right"><[img[$:/core/images/close-button.svg]]>>
|
||||
|
||||
<div class:"small"><<view modifier link>> <<view modified relativedate>></div>
|
||||
|
||||
<<reveal state:FieldsDropDownLocation type:popup qualifyTiddlerTitles:yes><
|
||||
|
||||
<div class="open">
|
||||
|
||||
{{dropdown-menu table table-condensed{
|
||||
|
||||
<<fields>>
|
||||
|
||||
}}}
|
||||
|
||||
</div>
|
||||
<div class="small"><<view modifier link>> <<view modified relativedate>></div>
|
||||
|
||||
>>
|
||||
|
||||
{{tw-tags-wrapper{
|
||||
((([is[current]tags[]]))($:/templates/TagTemplate))
|
||||
}}}
|
||||
|
Loading…
Reference in New Issue
Block a user