2014-11-03 22:06:31 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/widgets/action-deletefield.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: widget
|
|
|
|
|
|
|
|
Action widget to delete fields of a tiddler.
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
|
|
|
|
|
|
|
var DeleteFieldWidget = function(parseTreeNode,options) {
|
|
|
|
this.initialise(parseTreeNode,options);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Inherit from the base widget class
|
|
|
|
*/
|
|
|
|
DeleteFieldWidget.prototype = new Widget();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Render this widget into the DOM
|
|
|
|
*/
|
|
|
|
DeleteFieldWidget.prototype.render = function(parent,nextSibling) {
|
|
|
|
this.computeAttributes();
|
|
|
|
this.execute();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compute the internal state of the widget
|
|
|
|
*/
|
|
|
|
DeleteFieldWidget.prototype.execute = function() {
|
|
|
|
this.actionTiddler = this.getAttribute("$tiddler",this.getVariable("currentTiddler"));
|
2022-08-09 16:44:45 +00:00
|
|
|
this.actionField = this.getAttribute("$field",null);
|
2024-04-04 15:03:15 +00:00
|
|
|
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
2014-11-03 22:06:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Refresh the widget by ensuring our attributes are up to date
|
|
|
|
*/
|
|
|
|
DeleteFieldWidget.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
|
|
|
|
*/
|
|
|
|
DeleteFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
|
|
|
var self = this,
|
|
|
|
tiddler = this.wiki.getTiddler(self.actionTiddler),
|
2017-03-19 19:30:52 +00:00
|
|
|
removeFields = {},
|
|
|
|
hasChanged = false;
|
2022-08-09 16:44:45 +00:00
|
|
|
if((this.actionField !== null) && tiddler) {
|
2014-11-06 18:32:11 +00:00
|
|
|
removeFields[this.actionField] = undefined;
|
2017-03-19 19:30:52 +00:00
|
|
|
if(this.actionField in tiddler.fields) {
|
|
|
|
hasChanged = true;
|
|
|
|
}
|
2014-11-06 18:32:11 +00:00
|
|
|
}
|
2014-11-03 22:06:31 +00:00
|
|
|
if(tiddler) {
|
|
|
|
$tw.utils.each(this.attributes,function(attribute,name) {
|
|
|
|
if(name.charAt(0) !== "$" && name !== "title") {
|
|
|
|
removeFields[name] = undefined;
|
2024-04-04 15:03:15 +00:00
|
|
|
if(name in tiddler.fields) {
|
|
|
|
hasChanged = true;
|
|
|
|
}
|
2014-11-03 22:06:31 +00:00
|
|
|
}
|
|
|
|
});
|
2017-03-19 19:30:52 +00:00
|
|
|
if(hasChanged) {
|
2024-04-04 15:03:15 +00:00
|
|
|
var creationFields = this.actionTimestamp ? this.wiki.getCreationFields() : {};
|
|
|
|
var modificationFields = this.actionTimestamp ? this.wiki.getModificationFields() : {};
|
|
|
|
this.wiki.addTiddler(new $tw.Tiddler(creationFields,tiddler,removeFields,modificationFields));
|
2017-03-19 19:30:52 +00:00
|
|
|
}
|
2014-11-03 22:06:31 +00:00
|
|
|
}
|
|
|
|
return true; // Action was invoked
|
|
|
|
};
|
|
|
|
|
|
|
|
exports["action-deletefield"] = DeleteFieldWidget;
|
|
|
|
|
|
|
|
})();
|