Commit 5eb28b1c authored by Romain Courteaud's avatar Romain Courteaud

Pass plumb url to gadget instead of hardcoding

parent d4345bd9
...@@ -32,37 +32,49 @@ ...@@ -32,37 +32,49 @@
$(this).text(errorThrown); $(this).text(errorThrown);
}, },
success: function (value, textStatus, jqXHR) { success: function (value, textStatus, jqXHR) {
var content_type = jqXHR.getResponseHeader("Content-Type") || ""; $.ajax({
// XXX Hardcoded mime type method: 'GET',
if (content_type.split(';')[0] === "application/hal+json") { // XXX Hardcoded
// XXX Will fail if response does not send expected links... url: value._links.storage.href,
$(this).html("<ul>"); context: $('body'),
for (var i in value._links.contents){ error: function (jqXHR, textStatus, errorThrown) {
$(this).append("<li><button id='" + i + "'>" + $(this).text(errorThrown);
value._links.contents[i].href + "</button></li>"); },
$(this).find("#" + i.toString()).on('click', function(e, target) { success: function (value2, textStatus, jqXHR) {
$.ajax({ var content_type = jqXHR.getResponseHeader("Content-Type") || "";
// XXX Hardcoded post and url // XXX Hardcoded mime type
// Why using postMessage? if (content_type.split(';')[0] === "application/hal+json") {
method: "POST", // XXX Will fail if response does not send expected links...
url: "browser://plumb/topwindow/", $(this).html("<ul>");
context: $(this), for (var i in value2._links.contents){
data: $(this).text(), $(this).append("<li><button id='" + i + "'>" +
error: function (jqXHR, textStatus, errorThrown) { value2._links.contents[i].href + "</button></li>");
console.log("Plumbing failed: " + errorThrown); $(this).find("#" + i.toString()).on('click', function(e, target) {
}, $.ajax({
// success: function (value, textStatus, jqXHR) { // XXX Hardcoded post and url
// console.log(value); // Why using postMessage?
// }, method: "POST",
}); url: value._links.display.href,
}); context: $(this),
} data: $(this).text(),
$(this).append("</ul>"); error: function (jqXHR, textStatus, errorThrown) {
} else { console.log("Plumbing failed: " + errorThrown);
$(this).text("Unsupported content type " + content_type); },
}; // success: function (value, textStatus, jqXHR) {
// console.log(value);
// },
});
});
}
$(this).append("</ul>");
} else {
$(this).text("Unsupported content type " + content_type);
};
},
});
}, },
}); });
} else { } else {
$("body").text("No parameter found in url"); $("body").text("No parameter found in url");
} }
......
...@@ -50,17 +50,24 @@ ...@@ -50,17 +50,24 @@
var mapUrl = function (url) { var mapUrl = function (url) {
var searchString = url.href.split("?")[1], var searchString = url.href.split("?")[1],
fileToDisplay; fileToDisplay, fileToDisplayData;
if (searchString) { if (searchString) {
fileToDisplay = getParameter(searchString, "file"); fileToDisplay = getParameter(searchString, "file");
fileToDisplayData = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({
_links: {
self: {href: 'browser://browse/ls/'},
storage: {href: 'browser://browse/ls/'},
display: {href: 'browser://plumb/parentwindow/'},
}}));
if (fileToDisplay) { if (fileToDisplay) {
$("body").html( $("body").html(
'<iframe src="' + '<iframe src="' +
// XXX Hardcoded gadget to load // XXX Hardcoded gadget to load
'filebrowser.html?file=' + fileToDisplay + 'filebrowser.html?file=' + fileToDisplayData +
'">' + '">' +
'<p>Your browser does not support iframes.</p>' + '<p>Your browser does not support iframes.</p>' +
'</iframe">'); '</iframe">');
......
...@@ -1058,7 +1058,7 @@ ...@@ -1058,7 +1058,7 @@
dispatch_data = function () { dispatch_data = function () {
// data:[<mediatype>][;base64],<data> // data:[<mediatype>][;base64],<data>
var regexp = /^data:\/\/([\w\/]+)?(;base64)?,([\w\W]+)/, var regexp = /^data:\/\/([\w\/+]+)?(;base64)?,([\w\W]+)/,
mime_type, is_base_64, data; mime_type, is_base_64, data;
// window.atob(encodedData); // window.atob(encodedData);
if (regexp.test(this.url)) { if (regexp.test(this.url)) {
...@@ -1129,10 +1129,10 @@ ...@@ -1129,10 +1129,10 @@
} else if (plumb_regexp.test(this.url)) { } else if (plumb_regexp.test(this.url)) {
key = plumb_regexp.exec(this.url)[1]; key = plumb_regexp.exec(this.url)[1];
if (this.method === "POST") { if (this.method === "POST") {
if (key === "topwindow") { if (key === "parentwindow") {
// XXX hardcoded * necessarity to send in case of file URL // XXX hardcoded * necessarity to send in case of file URL
// Fix needed!!! // Fix needed!!!
window.top.postMessage(this.requestBody, "*"); window.parent.postMessage(this.requestBody, "*");
this.respond(204, {}, ""); this.respond(204, {}, "");
} else { } else {
this.respond(404, {}, ""); this.respond(404, {}, "");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment