Add action-setfield widget

print-window-tiddler
Jermolene 2014-11-06 18:06:47 +00:00
rodzic a18af9b760
commit 741f853986
4 zmienionych plików z 117 dodań i 2 usunięć

Wyświetl plik

@ -0,0 +1,80 @@
/*\
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() {
this.actionTiddler = this.getAttribute("$tiddler",this.getVariable("currentTiddler"));
this.actionField = this.getAttribute("$field");
this.actionIndex = this.getAttribute("$index");
this.actionValue = this.getAttribute("$value");
};
/*
Refresh the widget by ensuring our attributes are up to date
*/
SetFieldWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["$tiddler"] || changedAttributes["$field"] || changedAttributes["$index"] || changedAttributes["$value"]) {
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};
/*
Invoke the action associated with this widget
*/
SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
var newFields = {};
if(this.actionIndex) {
var data = self.wiki.getTiddlerData(this.actionTiddler,{});
if(data[self.editIndex] !== value) {
data[self.editIndex] = value;
this.wiki.setTiddlerData(self.actionTiddler,data);
}
} else {
var tiddler = this.wiki.getTiddler(this.actionTiddler),
updateFields = {
title: this.actionTiddler
};
updateFields[this.editField || "text"] = this.actionValue;
this.wiki.addTiddler(new $tw.Tiddler(this.wiki.getCreationFields(),tiddler,updateFields,this.wiki.getModificationFields()));
}
return true; // Action was invoked
};
exports["action-setfield"] = SetFieldWidget;
})();

Wyświetl plik

@ -0,0 +1,33 @@
caption: action-setfield
created: 20141025120850184
modified: 20141106173455527
tags: Widgets ActionWidgets
title: ActionSetFieldWidget
type: text/vnd.tiddlywiki
! Introduction
The ''action-setfield'' widget is an [[action widget|ActionWidgets]] that assigns a value to a specified field of a tiddler. ActionWidgets are used within triggering widgets such as the ButtonWidget.
See also the ActionSetFieldsWidget (note the extra "s") that provides a more flexible way to set the value of a single field.
! Content and Attributes
The ''action-setfield'' widget is invisible. Any content within it is ignored.
|!Attribute |!Description |
|$tiddler |The title of the tiddler whose fields are to be modified (if not provided defaults to the [[WidgetVariable: currentTiddler]] |
|$field |The name of the field to be modified. If neither a field or index is specified, then the default field "text" is used |
|$index |If $field is not provided, specifies the index of a [[data tiddler|DataTiddlers]] to modify |
|$value |The value to be assigned to the field or index |
! Examples
Here is an example of a button that opens the control panel directly to the "Appearance" tabs:
<$macrocall $name='wikitext-example-without-html'
src='<$button>
<$action-setfield $tiddler="$:/state/tab-1749438307" $field="text" $value="$:/core/ui/ControlPanel/Appearance"/>
<$action-navigate $to="$:/ControlPanel"/>
Go to Control Panel "Appearance" tab
</$button>'/>

Wyświetl plik

@ -1,4 +1,4 @@
caption: action-setfield
caption: action-setfields
created: 20141025120850184
modified: 20141025120850184
tags: Widgets ActionWidgets
@ -9,6 +9,8 @@ type: text/vnd.tiddlywiki
The ''action-setfields'' widget is an [[action widget|ActionWidgets]] that assigns values to the fields of a tiddler. ActionWidgets are used within triggering widgets such as the ButtonWidget.
See also the ActionSetFieldWidget (note the lack of the "s") that provides a way to set the values of multiple fields in a single operation.
! Content and Attributes
The ''action-setfields'' widget is invisible. Any content within it is ignored.

Wyświetl plik

@ -21,7 +21,7 @@ type: text/vnd.tiddlywiki
!! Hackability Improvements
* [[Introduced|https://github.com/Jermolene/TiddlyWiki5/commit/d8248cfba709a4bcff03ebeec2bdd4683441467f]] (and [[here|https://github.com/Jermolene/TiddlyWiki5/commit/9022dfdf71bbb72791867eaece6c0c4e871dbe8e]]) new ActionSetFieldWidget and ActionDeleteFieldWidget for manipulating tiddler fields
* Introduced new ActionSetFieldWidget, ActionSetFieldsWidget and ActionDeleteFieldWidget for manipulating tiddler fields
* [[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]]