So I settled on making an action widget that you can put into the contents
of a delete button. The default <$remove /> removes the current tiddler
from all tags fields.
/*\
title: $:/core/modules/widgets/remove.js
type: application/javascript
module-type: widget
Action widget to remove all references to a tiddler from a specified field.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var RemoveWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
RemoveWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
RemoveWidget.prototype.render = function(parent,nextSibling) {
this.computeAttributes();
this.execute();
};
/*
Compute the internal state of the widget
*/
RemoveWidget.prototype.execute = function() {
this.removeThis =
this.getAttribute("remove",this.getVariable("currentTiddler"));
this.removeFromField = this.getAttribute("removeFromField","tags");
this.removeFromField = this.removeFromField.toLowerCase();
var defaultFilter = "[search:" + this.removeFromField + "[" +
this.removeThis + "]]";
this.removeFromTiddlers =
this.getTiddlerList(this.getAttribute("removeFilter",defaultFilter));
};
RemoveWidget.prototype.getTiddlerList = function(filter) {
return this.wiki.filterTiddlers(filter,this);
};
/*
Refresh the widget by ensuring our attributes are up to date
*/
RemoveWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["remove"] || changedAttributes["removeFromField"]
|| changedAttributes["removeFilter"]) {
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};
/*
Create a new string for the field to be "cleaned" of the deleted tiddler
*/
RemoveWidget.prototype.getUpdatedFieldString= function(tiddler) {
var fieldFilter = "[list[" + tiddler + "!!" + this.removeFromField
+"]]";
var list = this.getTiddlerList(fieldFilter);
var newList = "";
var self=this;
$tw.utils.each(list,function(title) {
if (title != self.removeThis) {newList = newList + " [[" +
title + "]]";}
});
return newList;
};
/*
Invoke the action associated with this widget
*/
RemoveWidget.prototype.invokeAction = function(triggeringWidget,event) {
var self = this;
var value = "";
var appendString="";
if(this.removeFromTiddlers.length > 0) {
$tw.utils.each(self.removeFromTiddlers,function(title,
index) {
value = self.getUpdatedFieldString(title);
self.wiki.setText(title,self.removeFromField,undefined,value);
});
}
return true; // Action was invoked
};
exports["remove"] = RemoveWidget;
})();
On Thursday, January 15, 2015 at 9:04:13 PM UTC-5, PE Pat wrote:
>
> I'm using TiddlyWiki to help with lesson planning - I'm a teacher. As part
> of the program, I have a list of tiddlers that correspond to skills I want
> students to learn. Each skill has an associated list of tasks that I could
> use to help teach the skill.
>
> However, if I decide to delete a task, it's title still remains in all the
> lists. If I create a new task, it might have the same title (e.g. "Task 2")
> as the deleted task, and then it pops up in a list where I don't want it.
> I'm using a slightly modified version of BJ's taglist widget. I made this
> modification:
>
> TagListWidget.prototype.getTiddlerList = function() {
> var defaultFilter = "[list["+ this.listtag + "!!" + this.listField +
> "]is[tiddler]]";
> return
> this.wiki.filterTiddlers(this.getAttribute("filter",defaultFilter),this);//BJ
> FIXME should not allow user defined filters
> };
>
>
> Somehow, this immediately filters out all deleted tiddlers visually -- the
> display refreshes, the deleted tiddlers are removed -- but the list still
> contains the deleted tiddler until I make some other change to the list.
>
> How can I make it so that if I delete a tiddler, it is removed from all
> lists? Btw this also applies to tiddlers that are used as tags.
>
> Thanks,
> Patrick
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.