2014-11-06 18:06:47 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/widgets/action-setfield.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: widget
|
|
|
|
|
|
|
|
Action widget to set a single field or index on a tiddler.
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(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() {
|
2022-04-16 17:02:27 +00:00
|
|
|
this.actionTiddler = this.getAttribute("$tiddler") || (!this.hasParseTreeNodeAttribute("$tiddler") && this.getVariable("currentTiddler"));
|
2014-11-06 18:06:47 +00:00
|
|
|
this.actionField = this.getAttribute("$field");
|
|
|
|
this.actionIndex = this.getAttribute("$index");
|
|
|
|
this.actionValue = this.getAttribute("$value");
|
2015-08-06 17:17:06 +00:00
|
|
|
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
2014-11-06 18:06:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Refresh the widget by ensuring our attributes are up to date
|
|
|
|
*/
|
|
|
|
SetFieldWidget.prototype.refresh = function(changedTiddlers) {
|
2022-04-16 17:02:27 +00:00
|
|
|
// Nothing to refresh
|
2014-11-06 18:06:47 +00:00
|
|
|
return this.refreshChildren(changedTiddlers);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Invoke the action associated with this widget
|
|
|
|
*/
|
|
|
|
SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
2015-08-06 17:17:06 +00:00
|
|
|
var self = this,
|
2016-01-06 09:38:39 +00:00
|
|
|
options = {};
|
2022-04-16 17:02:27 +00:00
|
|
|
if(this.actionTiddler) {
|
|
|
|
options.suppressTimestamp = !this.actionTimestamp;
|
|
|
|
if((typeof this.actionField == "string") || (typeof this.actionIndex == "string") || (typeof this.actionValue == "string")) {
|
|
|
|
this.wiki.setText(this.actionTiddler,this.actionField,this.actionIndex,this.actionValue,options);
|
2014-11-06 19:27:14 +00:00
|
|
|
}
|
2022-04-16 17:02:27 +00:00
|
|
|
$tw.utils.each(this.attributes,function(attribute,name) {
|
|
|
|
if(name.charAt(0) !== "$") {
|
|
|
|
self.wiki.setText(self.actionTiddler,name,undefined,attribute,options);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-11-06 18:06:47 +00:00
|
|
|
return true; // Action was invoked
|
|
|
|
};
|
|
|
|
|
|
|
|
exports["action-setfield"] = SetFieldWidget;
|
|
|
|
|
|
|
|
})();
|