From e5cd8313a0d1a4a3dea17457a8a883675243b9c7 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 6 Aug 2015 18:17:06 +0100 Subject: [PATCH] Update actionsetfield widget to allow timestamp to be preserved --- core/modules/widgets/action-setfield.js | 9 ++++++--- core/modules/wiki.js | 9 ++++++--- .../tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/modules/widgets/action-setfield.js b/core/modules/widgets/action-setfield.js index 89de61824..7d6681752 100644 --- a/core/modules/widgets/action-setfield.js +++ b/core/modules/widgets/action-setfield.js @@ -39,6 +39,7 @@ SetFieldWidget.prototype.execute = function() { this.actionField = this.getAttribute("$field"); this.actionIndex = this.getAttribute("$index"); this.actionValue = this.getAttribute("$value"); + this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes"; }; /* @@ -57,13 +58,15 @@ SetFieldWidget.prototype.refresh = function(changedTiddlers) { Invoke the action associated with this widget */ SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) { - var self = this; + var self = this, + options = {}; + options.timestamp = this.actionTimestamp; if(typeof this.actionValue === "string") { - this.wiki.setText(this.actionTiddler,this.actionField,this.actionIndex,this.actionValue); + this.wiki.setText(this.actionTiddler,this.actionField,this.actionIndex,this.actionValue,options); } $tw.utils.each(this.attributes,function(attribute,name) { if(name.charAt(0) !== "$") { - self.wiki.setText(self.actionTiddler,name,undefined,attribute); + self.wiki.setText(self.actionTiddler,name,undefined,attribute,options); } }); return true; // Action was invoked diff --git a/core/modules/wiki.js b/core/modules/wiki.js index c2c0e22a2..bf53e34c6 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -58,17 +58,20 @@ exports.setTextReference = function(textRef,value,currTiddlerTitle) { this.setText(title,tr.field,tr.index,value); }; -exports.setText = function(title,field,index,value) { +exports.setText = function(title,field,index,value,options) { + options = options || {}; + var creationFields = options.timestamp ? this.getCreationFields() : {}, + modificationFields = options.timestamp ? this.getModificationFields() : {}; // Check if it is a reference to a tiddler field if(index) { var data = this.getTiddlerData(title,Object.create(null)); data[index] = value; - this.setTiddlerData(title,data,this.getModificationFields()); + this.setTiddlerData(title,data,modificationFields); } else { var tiddler = this.getTiddler(title), fields = {title: title}; fields[field || "text"] = value; - this.addTiddler(new $tw.Tiddler(tiddler,fields,this.getModificationFields())); + this.addTiddler(new $tw.Tiddler(creationFields,tiddler,fields,modificationFields)); } }; diff --git a/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid index 91b267fcc..3656accfc 100644 --- a/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid @@ -1,6 +1,6 @@ caption: action-setfield created: 20141025120850184 -modified: 20150220162114000 +modified: 20150806171403798 tags: Widgets ActionWidgets title: ActionSetFieldWidget type: text/vnd.tiddlywiki @@ -18,6 +18,7 @@ The ''action-setfield'' widget is invisible. Any content within it is ignored. |$field |Optional name of a field to be assigned the $value attribute | |$index |Optional index of a property in a [[data tiddler|DataTiddlers]] to be assigned the $value attribute| |$value |The value to be assigned to the field or index identified by the $field or $index attribute. If neither is specified then the value is assigned to the text field | +|$timestamp |Specifies whether the timestamp(s) of the target tiddler will be updated (''modified'' and ''modifier'', plus ''created'' and ''creator'' for newly created tiddlers). Can be "yes" (the default) or "no" | |//{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