mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Action create tiddler improvements (#4436)
* add a new-line before the log text to increase readability of the test output * make eslint, jslint happy * add $template and $overwrite parameter * documentation for new parameters + 4 new examples * remove unwanted files
This commit is contained in:
parent
7cbe766bde
commit
22802b4be8
@ -9,7 +9,7 @@ Action widget to create a new tiddler with a unique name and specified fields.
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
/*global $tw:false, require:false, exports:false */
|
||||
"use strict";
|
||||
|
||||
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
||||
@ -36,9 +36,15 @@ Compute the internal state of the widget
|
||||
*/
|
||||
CreateTiddlerWidget.prototype.execute = function() {
|
||||
this.actionBaseTitle = this.getAttribute("$basetitle");
|
||||
this.hasBase = !!this.actionBaseTitle;
|
||||
this.actionSaveTitle = this.getAttribute("$savetitle");
|
||||
this.actionSaveDraftTitle = this.getAttribute("$savedrafttitle");
|
||||
this.actionTimestamp = this.getAttribute("$timestamp","yes") === "yes";
|
||||
//Following params are new since 5.1.22
|
||||
this.actionTemplate = this.getAttribute("$template");
|
||||
this.useTemplate = !!this.actionTemplate;
|
||||
this.actionOverwrite = this.getAttribute("$overwrite","no");
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
@ -57,7 +63,7 @@ CreateTiddlerWidget.prototype.refresh = function(changedTiddlers) {
|
||||
Invoke the action associated with this widget
|
||||
*/
|
||||
CreateTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
var title = this.wiki.generateNewTitle(this.actionBaseTitle),
|
||||
var title = this.wiki.getTiddlerText("$:/language/DefaultNewTiddlerTitle"), // Get the initial new-tiddler title
|
||||
fields = {},
|
||||
creationFields,
|
||||
modificationFields;
|
||||
@ -70,7 +76,22 @@ CreateTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
creationFields = this.wiki.getCreationFields();
|
||||
modificationFields = this.wiki.getModificationFields();
|
||||
}
|
||||
var tiddler = this.wiki.addTiddler(new $tw.Tiddler(creationFields,fields,modificationFields,{title: title}));
|
||||
if(this.hasBase && this.actionOverwrite === "no") {
|
||||
title = this.wiki.generateNewTitle(this.actionBaseTitle);
|
||||
} else if (this.hasBase && this.actionOverwrite === "yes") {
|
||||
title = this.actionBaseTitle
|
||||
}
|
||||
// NO $basetitle BUT $template parameter is available
|
||||
// the title MUST be unique, otherwise the template would be overwritten
|
||||
if (!this.hasBase && this.useTemplate) {
|
||||
title = this.wiki.generateNewTitle(this.actionTemplate);
|
||||
} else if (!this.hasBase && !this.useTemplate) {
|
||||
// If NO $basetitle AND NO $template use initial title
|
||||
// DON'T overwrite any stuff
|
||||
title = this.wiki.generateNewTitle(title);
|
||||
}
|
||||
var templateTiddler = this.wiki.getTiddler(this.actionTemplate) || {};
|
||||
var tiddler = this.wiki.addTiddler(new $tw.Tiddler(templateTiddler.fields,creationFields,fields,modificationFields,{title: title}));
|
||||
if(this.actionSaveTitle) {
|
||||
this.wiki.setTextReference(this.actionSaveTitle,title,this.getVariable("currentTiddler"));
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
created: 20200131142401129
|
||||
modified: 20200131152023958
|
||||
tags: ActionCreateTiddlerWidget
|
||||
title: ActionCreateTiddlerWidget Example 1
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
\define testCreate()
|
||||
<$action-createtiddler />
|
||||
\end
|
||||
|
||||
This example will create "New Tiddler", "New Tiddler 1", " New Tiddler 2" and so on
|
||||
|
||||
```
|
||||
\define testCreate()
|
||||
<$action-createtiddler />
|
||||
\end
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
Create Tiddler
|
||||
</$button>
|
||||
```
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
<$action-setfield $tiddler="$:/state/tab/sidebar-1206596165" text="$:/core/ui/SideBar/Recent"/>
|
||||
Create Tiddler
|
||||
</$button> - Clicking this button, will also open the Right sidebar: Recent tab
|
@ -0,0 +1,28 @@
|
||||
created: 20200131144828713
|
||||
modified: 20200131152102232
|
||||
tags: ActionCreateTiddlerWidget
|
||||
title: ActionCreateTiddlerWidget Example 2
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
\define testCreate()
|
||||
<$action-createtiddler $basetitle={{$:/language/DefaultNewTiddlerTitle}} $overwrite="yes"/>
|
||||
\end
|
||||
|
||||
This example will use the base title defined in [[$:/language/DefaultNewTiddlerTitle]].
|
||||
|
||||
It will overwrite the tiddler, if the button is clicked several times.
|
||||
|
||||
```
|
||||
\define testCreate()
|
||||
<$action-createtiddler $basetitle={{$:/language/DefaultNewTiddlerTitle}} $overwrite="yes"/>
|
||||
\end
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
Create Tiddler
|
||||
</$button>
|
||||
```
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
<$action-setfield $tiddler="$:/state/tab/sidebar-1206596165" text="$:/core/ui/SideBar/Recent"/>
|
||||
Create Tiddler
|
||||
</$button> - Clicking this button, will also open the Right sidebar: Recent tab
|
@ -0,0 +1,28 @@
|
||||
created: 20200131145355658
|
||||
modified: 20200131152045990
|
||||
tags: ActionCreateTiddlerWidget
|
||||
title: ActionCreateTiddlerWidget Example 3
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
\define testCreate()
|
||||
<$action-createtiddler $basetitle="base" $template="ActionCreateTiddlerWidget Template"/>
|
||||
\end
|
||||
|
||||
This example will uses a base-title and a template: [[ActionCreateTiddlerWidget Template]]
|
||||
|
||||
It will create: "base", "base 1", "base 2" and so on
|
||||
|
||||
```
|
||||
\define testCreate()
|
||||
<$action-createtiddler $basetitle="base" $template="ActionCreateTiddlerWidget Template"/>
|
||||
\end
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
Create Tiddler
|
||||
</$button>
|
||||
```
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
<$action-setfield $tiddler="$:/state/tab/sidebar-1206596165" text="$:/core/ui/SideBar/Recent"/>
|
||||
Create Tiddler
|
||||
</$button> - Clicking this button, will also open the Right sidebar: Recent tab
|
@ -0,0 +1,28 @@
|
||||
created: 20200131150229551
|
||||
modified: 20200131152051626
|
||||
tags: ActionCreateTiddlerWidget
|
||||
title: ActionCreateTiddlerWidget Example 4
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
\define testCreate()
|
||||
<$action-createtiddler $basetitle="base" $template="ActionCreateTiddlerWidget Template" aa="new field aa" bb="new field bb" />
|
||||
\end
|
||||
|
||||
This example will uses a base-title: "base" and a template: [[ActionCreateTiddlerWidget Template]].
|
||||
|
||||
There will be new fields "aa" and "bb" which are added to the new tiddlers.
|
||||
|
||||
```
|
||||
\define testCreate()
|
||||
<$action-createtiddler $basetitle="base" $template="ActionCreateTiddlerWidget Template" aa="new field aa" bb="new field bb" />
|
||||
\end
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
Create Tiddler
|
||||
</$button>
|
||||
```
|
||||
|
||||
<$button actions=<<testCreate>> >
|
||||
<$action-setfield $tiddler="$:/state/tab/sidebar-1206596165" text="$:/core/ui/SideBar/Recent"/>
|
||||
Create Tiddler
|
||||
</$button> - Clicking this button, will also open the Right sidebar: Recent tab
|
@ -0,0 +1,8 @@
|
||||
created: 20200131145608087
|
||||
modified: 20200131150801682
|
||||
tags: test
|
||||
title: ActionCreateTiddlerWidget Template
|
||||
type: text/vnd.tiddlywiki
|
||||
x: x
|
||||
|
||||
This is a tiddler used as a template in: [[ActionCreateTiddlerWidget Example 3]]
|
@ -1,6 +1,6 @@
|
||||
caption: action-createtiddler
|
||||
created: 20161020152745942
|
||||
modified: 20190604113017742
|
||||
modified: 20200131151847266
|
||||
tags: Widgets ActionWidgets
|
||||
title: ActionCreateTiddlerWidget
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -23,9 +23,38 @@ The ''action-createtiddler'' widget is invisible. Any content within it is ignor
|
||||
|$savetitle |A text reference identifying a field or index into which the title of the newly created tiddler will be stored after it is created |
|
||||
|$savedrafttitle |<<.from-version "5.1.20">> A text reference identifying a field or index into which the draft title associated with the newly created tiddler will be stored after it is created. This is useful when using a sequence of action widgets to create a new tiddler, put it into edit mode, and position it within the list of its parent tag |
|
||||
|$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" |
|
||||
|$template |<<.from-version "5.1.22">> The title of a template tiddler, that will be used to create a new tiddler |
|
||||
|$overwrite |<<.from-version "5.1.22">> If set to "yes", it will overwrite existing tiddlers. ''Be careful!'' |
|
||||
|//{any attributes not starting with $}// |Each attribute name specifies a field to be created in the new tiddler |
|
||||
|
||||
! Examples
|
||||
|
||||
<$macrocall $name='wikitext-example-without-html'
|
||||
src={{ActionCreateTiddlerWidget Example}}/>
|
||||
<<<
|
||||
<$macrocall $name='wikitext-example-without-html' src={{ActionCreateTiddlerWidget Example}}/>
|
||||
<<<
|
||||
|
||||
---
|
||||
|
||||
<<<
|
||||
<$transclude tiddler="ActionCreateTiddlerWidget Example 1" mode=block/>
|
||||
<<<
|
||||
|
||||
---
|
||||
|
||||
<<<
|
||||
{{ActionCreateTiddlerWidget Example 2}}
|
||||
<<<
|
||||
|
||||
---
|
||||
|
||||
<<<
|
||||
{{ActionCreateTiddlerWidget Example 3}}
|
||||
<<<
|
||||
|
||||
---
|
||||
|
||||
<<<
|
||||
{{ActionCreateTiddlerWidget Example 4}}
|
||||
<<<
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user