mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Update fieldmangler widget to be able to add and remove tags
This commit is contained in:
parent
92fee547a9
commit
0cbb89770f
@ -31,7 +31,9 @@ FieldManglerWidget.prototype.generate = function() {
|
||||
// Set event handlers
|
||||
this.events = [
|
||||
{name: "tw-remove-field", handlerObject: this, handlerMethod: "handleRemoveFieldEvent"},
|
||||
{name: "tw-add-field", handlerObject: this, handlerMethod: "handleAddFieldEvent"}
|
||||
{name: "tw-add-field", handlerObject: this, handlerMethod: "handleAddFieldEvent"},
|
||||
{name: "tw-remove-tag", handlerObject: this, handlerMethod: "handleRemoveTagEvent"},
|
||||
{name: "tw-add-tag", handlerObject: this, handlerMethod: "handleAddTagEvent"}
|
||||
];
|
||||
// Render the children
|
||||
this.children = this.renderer.renderTree.createRenderers(this.renderer,this.renderer.parseTreeNode.children);
|
||||
@ -47,7 +49,7 @@ FieldManglerWidget.prototype.handleRemoveFieldEvent = function(event) {
|
||||
|
||||
FieldManglerWidget.prototype.handleAddFieldEvent = function(event) {
|
||||
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle);
|
||||
if(typeof event.param === "string" && event.param !== "" && !$tw.utils.hop(tiddler.fields,event.param)) {
|
||||
if(tiddler && typeof event.param === "string" && event.param !== "" && !$tw.utils.hop(tiddler.fields,event.param)) {
|
||||
var addition = {};
|
||||
addition[event.param] = "";
|
||||
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,addition));
|
||||
@ -55,6 +57,31 @@ FieldManglerWidget.prototype.handleAddFieldEvent = function(event) {
|
||||
return true;
|
||||
};
|
||||
|
||||
FieldManglerWidget.prototype.handleRemoveTagEvent = function(event) {
|
||||
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle);
|
||||
if(tiddler && tiddler.fields.tags) {
|
||||
var p = tiddler.fields.tags.indexOf(event.currentTag);
|
||||
if(p !== -1) {
|
||||
var modification = {};
|
||||
modification.tags = tiddler.fields.tags.slice(0);
|
||||
modification.tags.splice(p,1);
|
||||
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,modification));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
FieldManglerWidget.prototype.handleAddTagEvent = function(event) {
|
||||
var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle);
|
||||
if(tiddler && typeof event.param === "string" && event.param !== "") {
|
||||
var modification = {};
|
||||
modification.tags = tiddler.fields.tags.slice(0);
|
||||
$tw.utils.pushTop(modification.tags,event.param);
|
||||
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,modification));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.fieldmangler = FieldManglerWidget;
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user