1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-04 17:56:56 +00:00

Added support for committing edits to a draft tiddler

This commit is contained in:
Jeremy Ruston 2012-03-30 13:48:59 +01:00
parent 1df0a50760
commit 65b55925de

View File

@ -54,6 +54,32 @@ exports.macro = {
this.store.addTiddler(new Tiddler(storyTiddler,{text: JSON.stringify(story)}));
event.stopPropagation();
return false;
},
"tw-SaveTiddler": function(event) {
var template = this.hasParameter("defaultViewTemplate") ? this.params.defaultEditTemplate : "SimpleTemplate",
storyTiddler = this.store.getTiddler(this.params.story),
story = {tiddlers: []};
if(storyTiddler && storyTiddler.hasOwnProperty("text")) {
story = JSON.parse(storyTiddler.text);
}
for(var t=0; t<story.tiddlers.length; t++) {
var storyRecord = story.tiddlers[t];
if(storyRecord.title === event.tiddlerTitle && storyRecord.template !== template) {
var tiddler = this.store.getTiddler(storyRecord.title);
if(tiddler && tiddler.hasOwnProperty("draft.title")) {
// Save the draft tiddler as the real tiddler
this.store.addTiddler(new Tiddler(tiddler,{title: tiddler["draft.title"],"draft.title": undefined}));
// Remove the draft tiddler
this.store.deleteTiddler(storyRecord.title);
// Make the story record point to the newly saved tiddler
storyRecord.title = tiddler["draft.title"];
storyRecord.template = template;
}
}
}
this.store.addTiddler(new Tiddler(storyTiddler,{text: JSON.stringify(story)}));
event.stopPropagation();
return false;
}
},
execute: function() {