From 0a2a5184c48345dd1d51bd8d81181da1f90c57bb Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 6 Nov 2014 18:23:48 +0000 Subject: [PATCH] Add action-deletetiddler widget --- core/modules/widgets/action-deletetiddler.js | 65 +++++++++++++++++++ .../tiddlers/ActionDeleteTiddlerWidget.tid | 33 ++++++++++ .../prerelease/tiddlers/Release 5.1.5.tid | 2 +- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 core/modules/widgets/action-deletetiddler.js create mode 100644 editions/prerelease/tiddlers/ActionDeleteTiddlerWidget.tid diff --git a/core/modules/widgets/action-deletetiddler.js b/core/modules/widgets/action-deletetiddler.js new file mode 100644 index 000000000..61186d638 --- /dev/null +++ b/core/modules/widgets/action-deletetiddler.js @@ -0,0 +1,65 @@ +/*\ +title: $:/core/modules/widgets/action-deletetiddler.js +type: application/javascript +module-type: widget + +Action widget to delete a tiddler. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var Widget = require("$:/core/modules/widgets/widget.js").widget; + +var DeleteTiddlerWidget = function(parseTreeNode,options) { + this.initialise(parseTreeNode,options); +}; + +/* +Inherit from the base widget class +*/ +DeleteTiddlerWidget.prototype = new Widget(); + +/* +Render this widget into the DOM +*/ +DeleteTiddlerWidget.prototype.render = function(parent,nextSibling) { + this.computeAttributes(); + this.execute(); +}; + +/* +Compute the internal state of the widget +*/ +DeleteTiddlerWidget.prototype.execute = function() { + this.actionTiddler = this.getAttribute("$tiddler",this.getVariable("currentTiddler")); + this.actionConfirm = this.getAttribute("$confirm"); +}; + +/* +Refresh the widget by ensuring our attributes are up to date +*/ +DeleteTiddlerWidget.prototype.refresh = function(changedTiddlers) { + var changedAttributes = this.computeAttributes(); + if(changedAttributes["$tiddler"] || changedAttributes["$confirm"]) { + this.refreshSelf(); + return true; + } + return this.refreshChildren(changedTiddlers); +}; + +/* +Invoke the action associated with this widget +*/ +DeleteTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) { + + this.wiki.setText(this.actionTiddler,this.actionField,this.actionIndex,this.actionValue); + return true; // Action was invoked +}; + +exports["action-deletetiddler"] = DeleteTiddlerWidget; + +})(); diff --git a/editions/prerelease/tiddlers/ActionDeleteTiddlerWidget.tid b/editions/prerelease/tiddlers/ActionDeleteTiddlerWidget.tid new file mode 100644 index 000000000..291050d98 --- /dev/null +++ b/editions/prerelease/tiddlers/ActionDeleteTiddlerWidget.tid @@ -0,0 +1,33 @@ +caption: action-deletetiddler +created: 20141025120850184 +modified: 20141106173455527 +tags: Widgets ActionWidgets +title: ActionDeleteTiddlerWidget +type: text/vnd.tiddlywiki + +! Introduction + +The ''action-deletetiddler'' widget is an [[action widget|ActionWidgets]] that deletes a tiddler. ActionWidgets are used within triggering widgets such as the ButtonWidget. + +There are several differences compared to the [[WidgetMessage: tm-delete-tiddler]]: + +* The user is not prompted to confirm the deletion +* No automatic updating of the story list +* No special handling of draft tiddlers + +! Content and Attributes + +The ''action-deletetiddler'' widget is invisible. Any content within it is ignored. + +|!Attribute |!Description | +|$tiddler |The title of the tiddler to be deleted (if not provided defaults to the [[WidgetVariable: currentTiddler]] | + +! Examples + +Here is an example of a button that deletes the tiddler HelloThere. Note: + +<$macrocall $name='wikitext-example-without-html' +src='<$button> +<$action-deletetiddler $tiddler="HelloThere"/> +Go to Control Panel "Appearance" tab +'/> diff --git a/editions/prerelease/tiddlers/Release 5.1.5.tid b/editions/prerelease/tiddlers/Release 5.1.5.tid index d22b95a3b..527b03b97 100644 --- a/editions/prerelease/tiddlers/Release 5.1.5.tid +++ b/editions/prerelease/tiddlers/Release 5.1.5.tid @@ -21,7 +21,7 @@ type: text/vnd.tiddlywiki !! Hackability Improvements -* Introduced new ActionSetFieldWidget, ActionSetFieldsWidget and ActionDeleteFieldWidget for manipulating tiddler fields +* Introduced new ActionSetFieldWidget, ActionSetFieldsWidget, ActionDeleteFieldWidget and ActionDeleteTiddlerWidget for manipulating tiddler fields and values * [[Enhanced|https://github.com/Jermolene/TiddlyWiki5/commit/4a172125768e3b33c30e725e8550454a9d26c5c4]] the EditTextWidget to allow more control over the sizing of textarea editors * [[Added|https://github.com/Jermolene/TiddlyWiki5/commit/13726ef73157d9e9d65ae4027d9c32aaa7cdcc90]] new canned filter for recently modified system tiddlers in [[$:/AdvancedSearch]] * [[Added|https://github.com/Jermolene/TiddlyWiki5/commit/c20c935faabbb63f679bc4720b52162c56b6af64]] new system image for videos: [[$:/core/images/video]]