mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 22:33:50 +00:00
Make HTTP handler use wiki of widget that sent the message
This commit is contained in:
parent
d527ae9cd7
commit
88f4ad0efd
@ -18,12 +18,12 @@ wiki - the wiki object to use
|
|||||||
*/
|
*/
|
||||||
function HttpClient(options) {
|
function HttpClient(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.wiki = options.wiki || $tw.wiki;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpClient.prototype.handleHttpRequest = function(event) {
|
HttpClient.prototype.handleHttpRequest = function(event) {
|
||||||
console.log("Making an HTTP request",event)
|
console.log("Making an HTTP request",event)
|
||||||
var self = this,
|
var self = this,
|
||||||
|
wiki = event.widget.wiki,
|
||||||
paramObject = event.paramObject || {},
|
paramObject = event.paramObject || {},
|
||||||
url = paramObject.url,
|
url = paramObject.url,
|
||||||
completionActions = paramObject.oncompletion || "",
|
completionActions = paramObject.oncompletion || "",
|
||||||
@ -40,7 +40,7 @@ HttpClient.prototype.handleHttpRequest = function(event) {
|
|||||||
contextVariables = {},
|
contextVariables = {},
|
||||||
setBinding = function(title,text) {
|
setBinding = function(title,text) {
|
||||||
if(title) {
|
if(title) {
|
||||||
self.wiki.addTiddler(new $tw.Tiddler({title: title, text: text}));
|
wiki.addTiddler(new $tw.Tiddler({title: title, text: text}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if(url) {
|
if(url) {
|
||||||
@ -69,8 +69,8 @@ HttpClient.prototype.handleHttpRequest = function(event) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Set the request tracker tiddler
|
// Set the request tracker tiddler
|
||||||
var requestTrackerTitle = this.wiki.generateNewTitle("$:/temp/HttpRequest");
|
var requestTrackerTitle = wiki.generateNewTitle("$:/temp/HttpRequest");
|
||||||
this.wiki.addTiddler({
|
wiki.addTiddler({
|
||||||
title: requestTrackerTitle,
|
title: requestTrackerTitle,
|
||||||
tags: "$:/tags/HttpRequest",
|
tags: "$:/tags/HttpRequest",
|
||||||
text: JSON.stringify({
|
text: JSON.stringify({
|
||||||
@ -105,17 +105,17 @@ HttpClient.prototype.handleHttpRequest = function(event) {
|
|||||||
headers: JSON.stringify(headers)
|
headers: JSON.stringify(headers)
|
||||||
};
|
};
|
||||||
// Update the request tracker tiddler
|
// 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,
|
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);
|
// console.log("Back!",err,data,xhr);
|
||||||
},
|
},
|
||||||
progress: function(lengthComputable,loaded,total) {
|
progress: function(lengthComputable,loaded,total) {
|
||||||
if(lengthComputable) {
|
if(lengthComputable) {
|
||||||
setBinding(bindProgress,"" + Math.floor((loaded/total) * 100))
|
setBinding(bindProgress,"" + Math.floor((loaded/total) * 100))
|
||||||
}
|
}
|
||||||
$tw.rootWidget.invokeActionString(progressActions,undefined,undefined,{
|
wiki.invokeActionString(progressActions,undefined,{
|
||||||
lengthComputable: lengthComputable ? "yes" : "no",
|
lengthComputable: lengthComputable ? "yes" : "no",
|
||||||
loaded: loaded,
|
loaded: loaded,
|
||||||
total: total
|
total: total
|
||||||
|
@ -1415,6 +1415,14 @@ exports.checkTiddlerText = function(title,targetText,options) {
|
|||||||
return text === targetText;
|
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
|
Read an array of browser File objects, invoking callback(tiddlerFieldsArray) once they're all read
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user