From c087228b3385aef2193df9c9f70e98414c22242f Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 23 Oct 2012 17:13:47 +0100 Subject: [PATCH] Starting to introduce list views These are custom modules for visualising list manipulations and navigations --- core/modules/macros/list/list.js | 20 ++++++++++++++- core/modules/macros/list/listviews/classic.js | 25 +++++++++++++++++++ core/modules/startup.js | 1 + core/modules/wiki.js | 14 ++++++++++- 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 core/modules/macros/list/listviews/classic.js diff --git a/core/modules/macros/list/list.js b/core/modules/macros/list/list.js index f4f6aee1b..5769d69df 100644 --- a/core/modules/macros/list/list.js +++ b/core/modules/macros/list/list.js @@ -22,7 +22,9 @@ exports.info = { templateText: {byName: true, type: "text"}, editTemplate: {byName: true, type: "tiddler"}, editTemplateText: {byName: true, type: "text"}, - emptyMessage: {byName: true, type: "text"} + emptyMessage: {byName: true, type: "text"}, + listviewTiddler: {byName: true, type: "tiddler"}, + listview: {byName: true, type: "text"} } }; @@ -59,6 +61,22 @@ exports.executeMacro = function() { return this.listFrame; }; +exports.postRenderInDom = function() { + // Instantiate the list view + var listviewName; + if(this.hasParameter("listviewTiddler")) { + listviewName = this.wiki.getTextReference(this.params.listviewTiddler); + } + if(!listviewName && this.hasParameter("listview")) { + listviewName = this.params.listview; + } + var ListView = this.wiki.macros.list.listviews[listviewName]; + this.listview = ListView ? new ListView(this) : null; + if(this.listview) { + this.listview.test(); + } +}; + exports.getTiddlerList = function() { var filter; if(this.hasParameter("type")) { diff --git a/core/modules/macros/list/listviews/classic.js b/core/modules/macros/list/listviews/classic.js new file mode 100644 index 000000000..af33c88d0 --- /dev/null +++ b/core/modules/macros/list/listviews/classic.js @@ -0,0 +1,25 @@ +/*\ +title: $:/core/modules/macros/list/listviews/classic.js +type: application/javascript +module-type: listview + +Views the list as a linear sequence + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +function ClassicListView(listMacro) { + this.listMacro = listMacro; +}; + +ClassicListView.prototype.test = function() { + alert("In ClassicListView"); +}; + +exports["classic"] = ClassicListView; + +})(); diff --git a/core/modules/startup.js b/core/modules/startup.js index c19952df0..9c0ad3b7f 100644 --- a/core/modules/startup.js +++ b/core/modules/startup.js @@ -35,6 +35,7 @@ exports.startup = function() { $tw.wiki.initEditors(); $tw.wiki.initFieldViewers(); $tw.wiki.initStoryViews(); + $tw.wiki.initListViews(); $tw.wiki.initParsers(); // Set up the command modules $tw.Commander.initCommands(); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 756dc5bfa..58307b6b8 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -533,7 +533,7 @@ exports.initEditors = function(moduleType) { }; /* -Install field viewer modules for the edit macro +Install field viewer modules for the view macro */ exports.initFieldViewers = function(moduleType) { moduleType = moduleType || "fieldviewer"; @@ -544,6 +544,18 @@ exports.initFieldViewers = function(moduleType) { } }; +/* +Install list viewer modules for the list macro +*/ +exports.initListViews = function(moduleType) { + moduleType = moduleType || "listview"; + var listMacro = this.macros.list; + if(listMacro) { + listMacro.listviews = {}; + $tw.modules.applyMethods(moduleType,listMacro.listviews); + } +}; + /* Install view modules for the story macro */