From 88f4ad0efdc371fccedb6138e86db507e5def9fc Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Wed, 26 Apr 2023 12:15:40 +0100 Subject: [PATCH] Make HTTP handler use wiki of widget that sent the message --- core/modules/utils/dom/http.js | 14 +++++++------- core/modules/wiki.js | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/modules/utils/dom/http.js b/core/modules/utils/dom/http.js index f29a52077..d4754bd01 100644 --- a/core/modules/utils/dom/http.js +++ b/core/modules/utils/dom/http.js @@ -18,12 +18,12 @@ wiki - the wiki object to use */ function HttpClient(options) { options = options || {}; - this.wiki = options.wiki || $tw.wiki; } HttpClient.prototype.handleHttpRequest = function(event) { console.log("Making an HTTP request",event) var self = this, + wiki = event.widget.wiki, paramObject = event.paramObject || {}, url = paramObject.url, completionActions = paramObject.oncompletion || "", @@ -40,7 +40,7 @@ HttpClient.prototype.handleHttpRequest = function(event) { contextVariables = {}, setBinding = function(title,text) { if(title) { - self.wiki.addTiddler(new $tw.Tiddler({title: title, text: text})); + wiki.addTiddler(new $tw.Tiddler({title: title, text: text})); } }; if(url) { @@ -69,8 +69,8 @@ HttpClient.prototype.handleHttpRequest = function(event) { } }); // Set the request tracker tiddler - var requestTrackerTitle = this.wiki.generateNewTitle("$:/temp/HttpRequest"); - this.wiki.addTiddler({ + var requestTrackerTitle = wiki.generateNewTitle("$:/temp/HttpRequest"); + wiki.addTiddler({ title: requestTrackerTitle, tags: "$:/tags/HttpRequest", text: JSON.stringify({ @@ -105,17 +105,17 @@ HttpClient.prototype.handleHttpRequest = function(event) { headers: JSON.stringify(headers) }; // Update the request tracker tiddler - self.wiki.addTiddler(new $tw.Tiddler(self.wiki.getTiddler(requestTrackerTitle),{ + wiki.addTiddler(new $tw.Tiddler(wiki.getTiddler(requestTrackerTitle),{ status: success, })); - $tw.rootWidget.invokeActionString(completionActions,undefined,undefined,$tw.utils.extend({},contextVariables,results)); + wiki.invokeActionString(completionActions,undefined,$tw.utils.extend({},contextVariables,results)); // console.log("Back!",err,data,xhr); }, progress: function(lengthComputable,loaded,total) { if(lengthComputable) { setBinding(bindProgress,"" + Math.floor((loaded/total) * 100)) } - $tw.rootWidget.invokeActionString(progressActions,undefined,undefined,{ + wiki.invokeActionString(progressActions,undefined,{ lengthComputable: lengthComputable ? "yes" : "no", loaded: loaded, total: total diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 6ae16a2b4..1a08c3980 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1415,6 +1415,14 @@ exports.checkTiddlerText = function(title,targetText,options) { return text === targetText; } +/* +Execute an action string without an associated context widget +*/ +exports.invokeActionString = function(actions,event,variables) { + var widget = this.makeWidget(null,{}); + widget.invokeActionString(actions,null,event,variables); +}; + /* Read an array of browser File objects, invoking callback(tiddlerFieldsArray) once they're all read */