2012-01-07 17:33:42 +00:00
|
|
|
/*\
|
|
|
|
title: js/macros/list.js
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
2012-02-16 20:38:10 +00:00
|
|
|
var Renderer = require("../Renderer.js").Renderer;
|
2012-01-07 17:33:42 +00:00
|
|
|
|
2012-01-07 21:54:14 +00:00
|
|
|
var handlers = {
|
|
|
|
all: function(store) {
|
|
|
|
return store.getTitles("title","excludeLists");
|
|
|
|
},
|
|
|
|
missing: function(store) {
|
|
|
|
return store.getMissingTitles();
|
|
|
|
},
|
|
|
|
orphans: function(store) {
|
|
|
|
return store.getOrphanTitles();
|
|
|
|
},
|
|
|
|
shadowed: function(store) {
|
|
|
|
return store.getShadowTitles();
|
|
|
|
},
|
|
|
|
touched: function(store) {
|
|
|
|
// Server syncing isn't implemented yet
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
filter: function(store) {
|
|
|
|
// Filters aren't implemented yet
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-07 17:33:42 +00:00
|
|
|
exports.macro = {
|
|
|
|
name: "list",
|
2012-01-07 18:34:20 +00:00
|
|
|
dependentAll: true, // Tiddlers containing <<list>> macro are dependent on every tiddler
|
2012-01-07 17:33:42 +00:00
|
|
|
params: {
|
2012-02-17 17:32:32 +00:00
|
|
|
type: {byName: "default", type: "text"},
|
|
|
|
template: {byName: true, type: "tiddler"},
|
|
|
|
emptyMessage: {byName: true, type: "text"}
|
2012-01-07 17:33:42 +00:00
|
|
|
},
|
2012-02-21 21:57:30 +00:00
|
|
|
execute: function() {
|
2012-01-07 21:54:14 +00:00
|
|
|
var templateType = "text/x-tiddlywiki",
|
|
|
|
templateText = "<<view title link>>",
|
2012-02-21 21:57:30 +00:00
|
|
|
template = this.params.template ? this.store.getTiddler(this.params.template) : null,
|
2012-02-16 20:38:10 +00:00
|
|
|
content = [],
|
2012-02-19 17:20:16 +00:00
|
|
|
t,
|
2012-02-21 21:57:30 +00:00
|
|
|
parents = this.parents;
|
2012-01-07 21:54:14 +00:00
|
|
|
if(template) {
|
2012-02-19 17:20:16 +00:00
|
|
|
parents = parents.slice(0);
|
|
|
|
parents.push(template.title);
|
2012-01-17 13:01:55 +00:00
|
|
|
templateType = template.type;
|
|
|
|
templateText = template.text;
|
2012-01-07 21:54:14 +00:00
|
|
|
}
|
2012-02-21 21:57:30 +00:00
|
|
|
var handler = handlers[this.params.type];
|
2012-01-07 21:54:14 +00:00
|
|
|
handler = handler || handlers.all;
|
2012-02-21 21:57:30 +00:00
|
|
|
var tiddlers = handler(this.store);
|
2012-01-07 21:54:14 +00:00
|
|
|
if(tiddlers.length === 0) {
|
2012-02-21 21:57:30 +00:00
|
|
|
return [Renderer.TextNode(this.params.emptyMessage || "")];
|
2012-01-07 21:54:14 +00:00
|
|
|
} else {
|
2012-03-03 18:39:13 +00:00
|
|
|
var templateTree = this.store.parseText(templateType,templateText).nodes;
|
2012-01-07 21:54:14 +00:00
|
|
|
for(t=0; t<tiddlers.length; t++) {
|
2012-02-16 20:38:10 +00:00
|
|
|
var cloneTemplate = [];
|
|
|
|
for(var c=0; c<templateTree.length; c++) {
|
|
|
|
cloneTemplate.push(templateTree[c].clone());
|
|
|
|
}
|
|
|
|
var listNode = Renderer.ElementNode("li",null,cloneTemplate);
|
2012-02-21 21:57:30 +00:00
|
|
|
listNode.execute(parents,this.store.getTiddler(tiddlers[t]));
|
2012-02-16 20:38:10 +00:00
|
|
|
content.push(listNode);
|
2012-01-07 21:54:14 +00:00
|
|
|
}
|
2012-02-16 20:38:10 +00:00
|
|
|
return [Renderer.ElementNode("ul",null,content)];
|
2012-01-07 21:54:14 +00:00
|
|
|
}
|
2012-01-07 17:33:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|