mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
Update edit macro to be able to edit a specified tiddler
Previously you could only edit fields on the current tiddler
This commit is contained in:
parent
a7c1b1896e
commit
6e86de5652
@ -14,20 +14,39 @@ Edit macro for editting fields and tiddlers
|
|||||||
|
|
||||||
exports.info = {
|
exports.info = {
|
||||||
name: "edit",
|
name: "edit",
|
||||||
dependentOnContextTiddler: true,
|
|
||||||
params: {
|
params: {
|
||||||
field: {byPos: 0, type: "text"}
|
field: {byPos: 0, type: "text"},
|
||||||
|
tiddler: {byName: true, type: "tiddler"}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.evaluateDependencies = function() {
|
||||||
|
var dependencies = new $tw.Dependencies();
|
||||||
|
if(!this.srcParams.tiddler) {
|
||||||
|
dependencies.dependentOnContextTiddler = true;
|
||||||
|
}
|
||||||
|
for(var m in this.info.params) {
|
||||||
|
var paramInfo = this.info.params[m];
|
||||||
|
if(m in this.srcParams && paramInfo.type === "tiddler") {
|
||||||
|
if(typeof this.srcParams[m] === "function") {
|
||||||
|
dependencies.dependentAll = true;
|
||||||
|
} else {
|
||||||
|
dependencies.addDependency(this.srcParams[m],!paramInfo.skinny);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dependencies;
|
||||||
|
};
|
||||||
|
|
||||||
exports.executeMacro = function() {
|
exports.executeMacro = function() {
|
||||||
// Get the tiddler being editted
|
// Get the tiddler being editted
|
||||||
var field = this.hasParameter("field") ? this.params.field : "text",
|
this.editField = this.hasParameter("field") ? this.params.field : "text";
|
||||||
tiddler = this.wiki.getTiddler(this.tiddlerTitle),
|
this.editTiddler = this.hasParameter("tiddler") ? this.params.tiddler : this.tiddlerTitle;
|
||||||
|
var tiddler = this.wiki.getTiddler(this.editTiddler),
|
||||||
Editor;
|
Editor;
|
||||||
// Figure out which editor to use
|
// Figure out which editor to use
|
||||||
// TODO: Tiddler field plugins should be able to specify a field type from which the editor is derived
|
// TODO: Tiddler field plugins should be able to specify a field type from which the editor is derived
|
||||||
if(field === "text" && tiddler.fields.type) {
|
if(this.editField === "text" && tiddler && tiddler.fields.type) {
|
||||||
Editor = this.wiki.macros.edit.editors[tiddler.fields.type];
|
Editor = this.wiki.macros.edit.editors[tiddler.fields.type];
|
||||||
}
|
}
|
||||||
if(!Editor) {
|
if(!Editor) {
|
||||||
|
@ -26,7 +26,7 @@ BitmapEditor.prototype.getChild = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
BitmapEditor.prototype.postRenderInDom = function() {
|
BitmapEditor.prototype.postRenderInDom = function() {
|
||||||
var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle),
|
var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.editTiddler),
|
||||||
canvas = this.macroNode.child.domNode,
|
canvas = this.macroNode.child.domNode,
|
||||||
currImage = new Image();
|
currImage = new Image();
|
||||||
///////////////////// // Set the macro node itself to be position: relative
|
///////////////////// // Set the macro node itself to be position: relative
|
||||||
@ -142,7 +142,7 @@ BitmapEditor.prototype.strokeEnd = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
BitmapEditor.prototype.saveChanges = function() {
|
BitmapEditor.prototype.saveChanges = function() {
|
||||||
var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle);
|
var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.editTiddler);
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
// data URIs look like "data:<type>;base64,<text>"
|
// data URIs look like "data:<type>;base64,<text>"
|
||||||
var dataURL = this.macroNode.child.domNode.toDataURL(tiddler.fields.type,1.0),
|
var dataURL = this.macroNode.child.domNode.toDataURL(tiddler.fields.type,1.0),
|
||||||
|
@ -23,27 +23,26 @@ Get the tiddler being editted, field name and current value
|
|||||||
*/
|
*/
|
||||||
TextEditor.prototype.getEditText = function() {
|
TextEditor.prototype.getEditText = function() {
|
||||||
// Get the current tiddler and the field name
|
// Get the current tiddler and the field name
|
||||||
var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle),
|
var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.editTiddler),
|
||||||
field = this.macroNode.hasParameter("field") ? this.macroNode.params.field : "title",
|
|
||||||
value;
|
value;
|
||||||
// If we've got a tiddler, the value to display is the field string value
|
// If we've got a tiddler, the value to display is the field string value
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
value = tiddler.getFieldString(field);
|
value = tiddler.getFieldString(this.macroNode.editField);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, we need to construct a default value for the editor
|
// Otherwise, we need to construct a default value for the editor
|
||||||
switch(field) {
|
switch(this.macroNode.editField) {
|
||||||
case "text":
|
case "text":
|
||||||
value = "Type the text for the tiddler '" + this.macroNode.tiddlerTitle + "'";
|
value = "Type the text for the tiddler '" + this.macroNode.editTiddler + "'";
|
||||||
break;
|
break;
|
||||||
case "title":
|
case "title":
|
||||||
value = this.macroNode.tiddlerTitle;
|
value = this.macroNode.editTiddler;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value = "";
|
value = "";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {tiddler: tiddler, field: field, value: value};
|
return {tiddler: tiddler, field: this.macroNode.editField, value: value};
|
||||||
};
|
};
|
||||||
|
|
||||||
TextEditor.prototype.getChild = function() {
|
TextEditor.prototype.getChild = function() {
|
||||||
@ -84,10 +83,13 @@ TextEditor.prototype.handleEvent = function(event) {
|
|||||||
|
|
||||||
TextEditor.prototype.saveChanges = function() {
|
TextEditor.prototype.saveChanges = function() {
|
||||||
var text = this.macroNode.child.children[0].domNode.value,
|
var text = this.macroNode.child.children[0].domNode.value,
|
||||||
tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle);
|
tiddler = this.macroNode.wiki.getTiddler(this.macroNode.editTiddler);
|
||||||
if(tiddler && text !== tiddler.fields[this.macroNode.params.field]) {
|
if(!tiddler) {
|
||||||
|
tiddler = new $tw.Tiddler({title: this.macroNode.editTiddler});
|
||||||
|
}
|
||||||
|
if(text !== tiddler.fields[this.macroNode.editField]) {
|
||||||
var update = {};
|
var update = {};
|
||||||
update[this.macroNode.params.field] = text;
|
update[this.macroNode.editField] = text;
|
||||||
this.macroNode.wiki.addTiddler(new $tw.Tiddler(tiddler,update));
|
this.macroNode.wiki.addTiddler(new $tw.Tiddler(tiddler,update));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user