1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-21 10:47:39 +00:00

Extend the set widget with tiddler, field and index attributes

This commit is contained in:
Jermolene
2017-07-12 16:59:56 +01:00
parent c25a1eef33
commit 5dd3d97760
2 changed files with 40 additions and 5 deletions

View File

@@ -41,6 +41,9 @@ SetWidget.prototype.execute = function() {
this.setName = this.getAttribute("name","currentTiddler");
this.setFilter = this.getAttribute("filter");
this.setSelect = this.getAttribute("select");
this.setTiddler = this.getAttribute("tiddler");
this.setField = this.getAttribute("field");
this.setIndex = this.getAttribute("index");
this.setValue = this.getAttribute("value");
this.setEmptyValue = this.getAttribute("emptyValue");
// Set context variable
@@ -54,7 +57,18 @@ Get the value to be assigned
*/
SetWidget.prototype.getValue = function() {
var value = this.setValue;
if(this.setFilter) {
if(this.setTiddler) {
var tiddler = this.wiki.getTiddler(this.setTiddler);
if(!tiddler) {
value = this.setEmptyValue;
} else if(this.setField) {
value = tiddler.getFieldString(this.setField) || this.setEmptyValue;
} else if(this.setIndex) {
value = this.wiki.extractTiddlerDataItem(this.setTiddler,this.setIndex,this.setEmptyValue);
} else {
value = tiddler.fields.text || this.setEmptyValue ;
}
} else if(this.setFilter) {
var results = this.wiki.filterTiddlers(this.setFilter,this);
if(!this.setValue) {
var select;
@@ -73,7 +87,7 @@ SetWidget.prototype.getValue = function() {
} else if(!value && this.setEmptyValue) {
value = this.setEmptyValue;
}
return value;
return value || "";
};
/*
@@ -81,7 +95,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/
SetWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.name || changedAttributes.filter || changedAttributes.select ||changedAttributes.value || changedAttributes.emptyValue ||
if(changedAttributes.name || changedAttributes.filter || changedAttributes.select || changedAttributes.tiddler || (this.setTiddler && changedTiddlers[this.setTiddler]) || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes.emptyValue ||
(this.setFilter && this.getValue() != this.variables[this.setName].value)) {
this.refreshSelf();
return true;