mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Update actionsetfield widget to allow timestamp to be preserved
This commit is contained in:
parent
821617058d
commit
e5cd8313a0
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user