From 0bda00ae71e46137a396a0334d48a799e4ecf4b7 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 9 Aug 2013 16:46:17 +0100 Subject: [PATCH] Extend the fieldlist widget to retrieve all fields used across all tiddlers --- core/modules/widgets/fieldlist.js | 7 ++++++- core/modules/wiki.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/modules/widgets/fieldlist.js b/core/modules/widgets/fieldlist.js index 0995c0e53..937fb6c1b 100644 --- a/core/modules/widgets/fieldlist.js +++ b/core/modules/widgets/fieldlist.js @@ -22,6 +22,7 @@ var FieldListWidget = function(renderer) { FieldListWidget.prototype.generate = function() { var self = this; // Get parameters from our attributes + this.allTiddlers = this.renderer.hasAttribute("all"); this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle); this.exclude = this.renderer.getAttribute("exclude"); // Get the exclusion list @@ -85,7 +86,11 @@ FieldListWidget.prototype.removeListElement = function(index) { FieldListWidget.prototype.getFieldList = function() { var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle), fieldList = []; - if(tiddler) { + // If requested, return all fields used on all tiddlers + if(this.allTiddlers) { + fieldList = this.renderer.renderTree.wiki.getAllTiddlerFields(); + } else if(tiddler) { + // Return the fields on the specified tiddler for(var fieldName in tiddler.fields) { if(this.excludeList.indexOf(fieldName) === -1) { fieldList.push(fieldName); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 1289b7507..dd5f29bcb 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -307,6 +307,17 @@ exports.forEachTiddler = function(/* [sortField,[excludeTag,]]callback */) { } }; +exports.getAllTiddlerFields = function() { + var results = []; + for(var title in this.tiddlers) { + $tw.utils.each(this.tiddlers[title].fields,function(field,fieldName) { + $tw.utils.pushTop(results,fieldName); + }); + } + results.sort(); + return results; +}; + /* Return an array of tiddler titles that are directly linked from the specified tiddler */