diff --git a/core/modules/widgets/fieldmangler.js b/core/modules/widgets/fieldmangler.js index 980ce5b83..4b9b58f5a 100644 --- a/core/modules/widgets/fieldmangler.js +++ b/core/modules/widgets/fieldmangler.js @@ -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; })();