Commit 0ff0e9c2 authored by Romain Courteaud's avatar Romain Courteaud

Fetch parameter from url

parent b82bce7b
/*global document, jQuery */ /*global document, jQuery */
// filebrowser.html?file=browser%3A%2F%2Fbrowse%2Fls%2F
"use strict"; "use strict";
(function (document, $) { (function (document, $) {
$(document).ready(function () {
$.ajax({ var getParameter = function(searchString, paramName) {
method: 'GET', var i, val, params = searchString.split("&");
// XXX Hardcoded
url: "browser://browse/ls/", for (i=0;i<params.length;i++) {
context: $('body'), val = params[i].split("=");
error: function (jqXHR, textStatus, errorThrown) { if (val[0] == paramName) {
$(this).text(errorThrown); return decodeURIComponent(val[1]);
}, }
success: function (value, textStatus, jqXHR) { }
var content_type = jqXHR.getResponseHeader("Content-Type") || ""; return null;
// XXX Hardcoded mime type };
if (content_type.split(';')[0] === "application/hal+json") {
// XXX Will fail if response does not send expected links... var mapUrl = function (url) {
$(this).html("<ul>"); var searchString = url.href.split("?")[1],
for (var i in value._links.contents){ fileToDisplay;
$(this).append("<li>" + value._links.contents[i].href + "</li>");
} if (searchString) {
$(this).append("</ul>"); fileToDisplay = getParameter(searchString, "file");
} else { if (fileToDisplay) {
$(this).text("Unsupported content type " + content_type);
}; $.ajax({
}, method: 'GET',
}); // XXX Hardcoded
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(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) {
// XXX What to do with the url info?
console.log($(this).text());
});
}
$(this).append("</ul>");
} else {
$(this).text("Unsupported content type " + content_type);
};
},
});
} else {
$(this).text("No parameter found in url");
}
}
};
$(document).ready(function () {
mapUrl(window.location);
}); });
}(document, jQuery)); }(document, jQuery));
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