diff --git a/core/modules/widgets/action-setfield.js b/core/modules/widgets/action-setfield.js new file mode 100644 index 000000000..d23dab587 --- /dev/null +++ b/core/modules/widgets/action-setfield.js @@ -0,0 +1,68 @@ +/*\ +title: $:/core/modules/widgets/action-setfield.js +type: application/javascript +module-type: widget + +Action widget to send a message + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget; + +var SetFieldWidget = function(parseTreeNode,options) { + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +SetFieldWidget.prototype = new Widget(); + +/* +Render this widget into the DOM +*/ +SetFieldWidget.prototype.render = function(parent,nextSibling) { + this.computeAttributes(); + this.execute(); +}; + +/* +Compute the internal state of the widget +*/ +SetFieldWidget.prototype.execute = function() { + this.actionTiddler = this.getAttribute("$tiddler",this.getVariable("currentTiddler")); +}; + +/* +Refresh the widget by ensuring our attributes are up to date +*/ +SetFieldWidget.prototype.refresh = function(changedTiddlers) { + var changedAttributes = this.computeAttributes(); + if(changedAttributes["$tiddler"]) { + this.refreshSelf(); + return true; + } + return this.refreshChildren(changedTiddlers); +}; + +/* +Invoke the action associated with this widget +*/ +SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) { + var self = this; + $tw.utils.each(this.attributes,function(attribute,name) { + if(name.charAt(0) !== "$") { + self.wiki.setText(self.actionTiddler,name,undefined,attribute); + } + }); + return true; // Action was invoked +}; + +exports["action-setfield"] = SetFieldWidget; + +})(); diff --git a/editions/tw5.com/tiddlers/widgets/ActionSendMessageWidget.tid b/editions/tw5.com/tiddlers/widgets/ActionSendMessageWidget.tid index eceea9634..2f7e8f1c6 100644 --- a/editions/tw5.com/tiddlers/widgets/ActionSendMessageWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ActionSendMessageWidget.tid @@ -29,3 +29,12 @@ src='<$button> <$action-sendmessage $message="tm-new-tiddler" title="This is newly created tiddler" tags="OneTag [[Another Tag]]" text=<>/> Click me! '/> + +Here is an example of a button that assigns tags and fields to the tiddler HelloThere, and then initiates editing it: + +<$macrocall $name='wikitext-example-without-html' +src='<$button> +<$action-setfield $tiddler="HelloThere" tags="MoreTag [[Further More Tags]]" color="green"/> +<$action-sendmessage $message="tm-edit-tiddler" $param="HelloThere"/> +Edit ~HelloThere +'/> diff --git a/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid new file mode 100644 index 000000000..6b70a9568 --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid @@ -0,0 +1,46 @@ +caption: action-setfield +created: 20141025120850184 +modified: 20141025120850184 +tags: Widgets ActionWidgets +title: ActionSetFieldWidget +type: text/vnd.tiddlywiki + +! Introduction + +The ''action-setfield'' widget is an [[action widget|ActionWidgets]] that assigns values to the fields of a tiddler. ActionWidgets are used within triggering widgets such as the ButtonWidget. + +! Content and Attributes + +The ''action-setfield'' widget is invisible. Any content within it is ignored. + +|!Attribute |!Description | +|$tiddler |The title of the tiddler whose fields are to be modified (if not provided defaults to the [[WidgetVariable: currentTiddler]] | +|//{any attributes not starting with $}// |Each attribute name specifies a field to be modified with the attribute value providing the value to assign to the field | + +! Examples + +Here is an example of a pair of buttons that open the control panel directly to specified tabs. They work by using ''action-setfield'' to set the state tiddler for the control panel tabs. + +<$macrocall $name='wikitext-example-without-html' +src='<$button> +<$action-setfield $tiddler="$:/state/tab-1749438307" text="$:/core/ui/ControlPanel/Appearance"/> +<$action-navigate $to="$:/ControlPanel"/> +Go to Control Panel "Appearance" tab + + +<$button> +<$action-setfield $tiddler="$:/state/tab-1749438307" text="$:/core/ui/ControlPanel/Settings"/> +<$action-navigate $to="$:/ControlPanel"/> +Go to Control Panel "Settings" tab +'/> + +Here is an example of a button that assigns tags and fields to the tiddler HelloThere, and then navigates to it and opens the tiddler info panel on the "Fields" tab: + +<$macrocall $name='wikitext-example-without-html' +src='<$button> +<$action-setfield $tiddler="HelloThere" tags="NewTag [[Another New Tag]]" color="red"/> +<$action-setfield $tiddler="$:/state/popup/tiddler-info--1779055697" text="(568,1443,33,39)"/> +<$action-setfield $tiddler="$:/state/tab--1890574033" text="$:/core/ui/TiddlerInfo/Fields"/> +<$action-navigate $to="HelloThere"/> +Modify ~HelloThere +'/>