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

Pass plumb url to gadget instead of hardcoding

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