From 6fc4e5db7c789a216f540131678cd68c693aa409 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 15 Aug 2013 18:17:11 +0100 Subject: [PATCH] Get rid of the old "fieldgrid" and "fieldlist" widgets Instead, we'll use the "list" widget with the new support for macros. --- core/modules/widgets/fieldgrid.js | 85 --------------- core/modules/widgets/fieldlist.js | 155 --------------------------- core/modules/widgets/fieldmangler.js | 4 +- core/modules/widgets/transclude.js | 11 -- core/modules/wiki.js | 11 -- core/ui/FieldEditor.tid | 7 +- core/ui/TagsEditor.tid | 2 +- core/ui/TiddlerFields.tid | 6 ++ core/ui/TiddlerInfo.tid | 2 +- core/wiki/allfields.tid | 7 +- themes/tiddlywiki/snowwhite/base.tid | 15 ++- 11 files changed, 32 insertions(+), 273 deletions(-) delete mode 100644 core/modules/widgets/fieldgrid.js delete mode 100644 core/modules/widgets/fieldlist.js create mode 100644 core/ui/TiddlerFields.tid diff --git a/core/modules/widgets/fieldgrid.js b/core/modules/widgets/fieldgrid.js deleted file mode 100644 index dd47b5272..000000000 --- a/core/modules/widgets/fieldgrid.js +++ /dev/null @@ -1,85 +0,0 @@ -/*\ -title: $:/core/modules/widgets/fieldgrid.js -type: application/javascript -module-type: widget - -Implements the fieldgrid widget. - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var FieldGridWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate child nodes - this.generate(); -}; - -FieldGridWidget.prototype.generate = function() { - // Get attributes - this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle); - this.exclude = this.renderer.getAttribute("exclude"); - this["class"] = this.renderer.getAttribute("class"); - // Set up the exclusion array - var exclude = []; - if(this.exclude) { - exclude = this.exclude.split(" "); - } - // Get the tiddler - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - // Set up the classes - var classes = ["tw-fieldgrid-table"]; - if(this["class"]) { - $tw.utils.pushTop(classes,this["class"]); - } - // Set up the header row - var rows = [ - {type: "element", tag: "tr", children: [ - {type: "element", tag: "th", children: [ - {type: "text", text: "Field"}]}, - {type: "element", tag: "th", children: [ - {type: "text", text: "Value"}]}]} - ]; - // Add the rows for each field - if(tiddler) { - var fields = []; - for(var f in tiddler.fields) { - if(exclude.indexOf(f) === -1) { - fields.push(f); - } - } - fields.sort(); - for(f=0; f 0) { - this.attributes["class"] = classes.join(" "); - } - if(this.renderer.hasAttribute("style")) { - this.attributes.style = this.renderer.getAttribute("style"); - } - if(this.renderer.hasAttribute("tooltip")) { - this.attributes.title = this.renderer.getAttribute("tooltip"); - } - // Create the renderers for each list item - var items = []; - $tw.utils.each(fieldList,function(fieldName) { - items.push(self.createListElement(fieldName)); - }); - this.children = this.renderer.renderTree.createRenderers(this.renderer,items); -}; - -FieldListWidget.prototype.createListElement = function(fieldName) { - return { - type: "element", - tag: "$transclude", - isBlock: true, - attributes: { - currentField: {type: "string", value: fieldName}, - target: {type: "string", value: this.tiddlerTitle} - }, - children: this.renderer.parseTreeNode.children - }; -}; - -FieldListWidget.prototype.removeListElement = function(index) { - // Get the list element - var listElement = this.children[index]; - // Delete the DOM node - listElement.domNode.parentNode.removeChild(listElement.domNode); - // Then delete the actual renderer node - this.children.splice(index,1); -}; - -FieldListWidget.prototype.getFieldList = function() { - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle), - fieldList = []; - // 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); - } - } - } - fieldList.sort(); - return fieldList; -}; - -FieldListWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { - // Check if any of our attributes have changed, or if a tiddler we're interested in has changed - if(changedAttributes.tiddler || changedAttributes.exclude || changedAttributes.style || changedAttributes.tooltip || changedAttributes["class"]) { - // Regenerate and rerender the widget and replace the existing DOM node - this.generate(); - var oldDomNode = this.renderer.domNode, - newDomNode = this.renderer.renderInDom(); - oldDomNode.parentNode.replaceChild(newDomNode,oldDomNode); - } else { - // Get the potentially updated list of fields - var fieldList = this.getFieldList(); - // Walk through the fields - for(var fieldIndex = 0; fieldIndex=fieldIndex; n--) { - this.removeListElement(n); - } - // Refresh the node we're reusing - this.children[fieldIndex].refreshInDom(changedTiddlers); - } - } - // Remove any left over elements - for(fieldIndex = this.children.length-1; fieldIndex>=fieldList.length; fieldIndex--) { - this.removeListElement(fieldIndex); - } - } -}; - -/* -Find the index of the child node representing the named field (or -1 if not present) -*/ -FieldListWidget.prototype.findChildNode = function(startIndex,fieldName) { - var index = startIndex; - while(index < this.children.length) { - if(this.children[index].attributes.currentField === fieldName) { - return index; - } - index++; - } - return -1; -}; - -exports.fieldlist = FieldListWidget; - -})(); diff --git a/core/modules/widgets/fieldmangler.js b/core/modules/widgets/fieldmangler.js index 2e5d75eb4..3d5f3de09 100644 --- a/core/modules/widgets/fieldmangler.js +++ b/core/modules/widgets/fieldmangler.js @@ -42,7 +42,7 @@ FieldManglerWidget.prototype.generate = function() { FieldManglerWidget.prototype.handleRemoveFieldEvent = function(event) { var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle), deletion = {}; - deletion[event.currentField] = undefined; + deletion[event.param] = undefined; this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,deletion)); return true; }; @@ -60,7 +60,7 @@ FieldManglerWidget.prototype.handleAddFieldEvent = function(event) { FieldManglerWidget.prototype.handleRemoveTagEvent = function(event) { var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); if(tiddler && tiddler.fields.tags) { - var p = tiddler.fields.tags.indexOf(event.currentTag); + var p = tiddler.fields.tags.indexOf(event.param); if(p !== -1) { var modification = {}; modification.tags = (tiddler.fields.tags || []).slice(0); diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index 478770508..125c1fc0d 100644 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -60,7 +60,6 @@ TranscludeWidget.prototype.generate = function() { this.targetTitle = this.renderer.getAttribute("target",this.renderer.tiddlerTitle); this.targetField = this.renderer.getAttribute("field"); this.targetIndex = this.renderer.getAttribute("index"); - this.currentField = this.renderer.getAttribute("currentField"); // Get the render tree for the template this.templateTitle = undefined; if(this.renderer.parseTreeNode.children && this.renderer.parseTreeNode.children.length > 0) { @@ -110,16 +109,6 @@ TranscludeWidget.prototype.generate = function() { }; // Initialise events this.events = []; - // If a current field is specified - if(this.currentField) { - // Record the current field in the render context - this.renderer.context.field = this.currentField; - // Add an event handler to record the current field - this.events.push({name: "tw-remove-field", handlerFunction: function(event) { - event.currentField = self.currentField; - return true; - }}); - } // Trap and update tag modification events this.events.push({name: "tw-remove-tag", handlerFunction: function(event) { event.currentTag = self.targetTitle; diff --git a/core/modules/wiki.js b/core/modules/wiki.js index dd5f29bcb..1289b7507 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -307,17 +307,6 @@ 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 */ diff --git a/core/ui/FieldEditor.tid b/core/ui/FieldEditor.tid index fbd9b293f..03af4a349 100644 --- a/core/ui/FieldEditor.tid +++ b/core/ui/FieldEditor.tid @@ -1,7 +1,10 @@ title: $:/core/ui/FieldEditor -<$fieldmangler>
<$fieldlist exclude="title tags text modified modifier draft.title draft.of">
<$info type="currentField"/>: <$edit placeholder="field value"/> <$button message="tw-remove-field" class="btn-invisible">{{$:/core/images/delete-button}}
- +\define renderfield(title) +
$title$: <$edit field="$title$" placeholder="field value"/> <$button message="tw-remove-field" param="$title$" class="btn-invisible">{{$:/core/images/delete-button}}
+\end +<$fieldmangler>
+<$list filter="[is[current]fields[]] -title -tags -text -creator -created -modified -modifier -[[draft.title]] -[[draft.of]]" macro="renderfield" itemClass="tw-fieldlist"/>
Add a new field: <$edit tiddler="$:/NewFieldName" type="input" default="" placeholder="field name"/> <$button message="tw-add-field" param={{$:/NewFieldName}} set="$:/NewFieldName" setTo="" class="">add
diff --git a/core/ui/TagsEditor.tid b/core/ui/TagsEditor.tid index 272fb9d89..a215be504 100644 --- a/core/ui/TagsEditor.tid +++ b/core/ui/TagsEditor.tid @@ -1,6 +1,6 @@ title: $:/core/ui/TagsEditor -<$fieldmangler>
<$list filter="[is[current]tags[]sort[title]]" listview="pop" itemClass="tw-tag-editor-label"><$setstyle name="background-color" value={{!!color}} class="tw-tag-label"><$view field="title" format="text" /><$button message="tw-remove-tag" class="btn-invisible tw-remove-tag-button">× +<$fieldmangler>
<$list filter="[is[current]tags[]sort[title]]" listview="pop" itemClass="tw-tag-editor-label"><$setstyle name="background-color" value={{!!color}} class="tw-tag-label"><$view field="title" format="text" /><$button message="tw-remove-tag" param={{!!title}} class="btn-invisible tw-remove-tag-button">×
Add a new tag: <$edit tiddler="$:/NewTagName" type="input" default="" placeholder="tag name" focusSet="$:/state/tagsAutoComplete" qualifyTiddlerTitles="yes"/> <$button popup="$:/state/tagsAutoComplete" qualifyTiddlerTitles="yes" class="btn-invisible">{{$:/core/images/down-arrow}} <$button message="tw-add-tag" param={{$:/NewTagName}} set="$:/NewTagName" setTo="" class="">add
diff --git a/core/ui/TiddlerFields.tid b/core/ui/TiddlerFields.tid new file mode 100644 index 000000000..2f473075f --- /dev/null +++ b/core/ui/TiddlerFields.tid @@ -0,0 +1,6 @@ +title: $:/core/ui/TiddlerFields + +\define renderfield(title) +
//$title$//: <$view field="$title$"/>
+\end +<$list filter="[is[current]fields[]sort[title]] -text" macro="renderfield"/> diff --git a/core/ui/TiddlerInfo.tid b/core/ui/TiddlerInfo.tid index 809d00bea..25ed7018f 100644 --- a/core/ui/TiddlerInfo.tid +++ b/core/ui/TiddlerInfo.tid @@ -12,7 +12,7 @@ title: $:/core/ui/TiddlerInfo <$list filter="[is[current]tagging[]]" itemClass="tw-menu-list-item" emptyMessage="No tiddlers are tagged with this one"/> <$reveal type="match" state="$:/state/tiddlerDropDownTabSet" text="fieldsTab" qualifyTiddlerTitles="yes"> -<$fieldgrid /> +<$transclude template="$:/core/ui/TiddlerFields"/>
\ No newline at end of file diff --git a/core/wiki/allfields.tid b/core/wiki/allfields.tid index 4a0cad328..25ea4177c 100644 --- a/core/wiki/allfields.tid +++ b/core/wiki/allfields.tid @@ -1,5 +1,6 @@ title: $:/snippets/allfields -<$fieldlist all> -''<$info type="currentField"/>'': //<$info type="currentFieldDescription"/>// - +\define renderfield(title) +
''$title$'': //{{$:/docs/fields/$title$}}//
+\end +<$list filter="[fields[]sort[title]]" macro="renderfield"/> diff --git a/themes/tiddlywiki/snowwhite/base.tid b/themes/tiddlywiki/snowwhite/base.tid index 6494ec6ac..5b534ee07 100644 --- a/themes/tiddlywiki/snowwhite/base.tid +++ b/themes/tiddlywiki/snowwhite/base.tid @@ -402,6 +402,17 @@ a.tw-tiddlylink-external { <> } +.tw-view-field-name { + display: inline-block; + width: 15%; + text-align: right; +} + +.tw-view-field-value { + display: inline-block; + width: 75%; +} + @media screen { .tw-tiddler-frame { <> @@ -590,11 +601,11 @@ canvas.tw-edit-bitmapeditor { width: 48%; } -.tw-edit-fields .tw-fieldlist > div:nth-child(odd) { +.tw-edit-fields > .tw-list-frame > div:nth-child(odd) { background-color: #f0f4f0; } -.tw-edit-fields .tw-fieldlist > div:nth-child(even) { +.tw-edit-fields > .tw-list-frame > div:nth-child(even) { background-color: #e0e8e0; }