Commit 1ec0842a authored by Sven Franck's avatar Sven Franck

switched to renderJs.mapUrl, cleaned up code

parent a0a78541
...@@ -2,39 +2,14 @@ ...@@ -2,39 +2,14 @@
(function (document, $) { (function (document, $) {
"use strict"; "use strict";
var getParameter = function(searchString, paramName) { var setup = function () {
var i, val, params = searchString.split("&"); renderJs.mapUrl(window.location.search, function (value, textStatus, jqXHR) {
for (i=0;i<params.length;i++) { var scope = value._links.scope.href.slice(0,-1).split(/[/]+/).pop(),
val = params[i].split("=");
if (val[0] == paramName) {
return decodeURIComponent(val[1]);
}
}
return null;
};
var mapUrl = function (searchString) {
var fileToDisplay = getParameter(searchString, "file"),
scope,
register,
service;
if (fileToDisplay) {
$.ajax({
method: 'GET',
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
scope = value._links.scope.href.slice(0,-1).split(/[/]+/).pop();
register = value._links.call.href register = value._links.call.href
.replace("{method}", "register") .replace("{method}", "register")
.replace("{scope}", scope ) .replace("{scope}", scope )
.replace("{interaction}", ""); .replace("{interaction}", ""),
service = { service = {
"type": "register/any", "type": "register/any",
"src": encodeURIComponent(window.location.href), "src": encodeURIComponent(window.location.href),
...@@ -82,6 +57,7 @@ ...@@ -82,6 +57,7 @@
value2._links.contents[i].href + "</button></li>"); value2._links.contents[i].href + "</button></li>");
$(this).find("#" + i.toString()).on('click', function(e, target) { $(this).find("#" + i.toString()).on('click', function(e, target) {
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: request, url: request,
...@@ -90,9 +66,9 @@ ...@@ -90,9 +66,9 @@
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
console.log("request failed: " + errorThrown); console.log("request failed: " + errorThrown);
}, },
// success: function (value, textStatus, jqXHR) { success: function (value, textStatus, jqXHR) {
// console.log("request sent"); console.log("request sent");
// } }
}); });
}); });
} }
...@@ -102,20 +78,11 @@ ...@@ -102,20 +78,11 @@
}; };
} }
}); });
},
}); });
} else {
$("body").text("No parameter found in url");
}
}; };
$(document).ready(function () { $(document).ready(function () {
var search = window.location.search; setup();
if (search) {
mapUrl(search.slice(1));
} else {
$("body").text("No parameter found in url");
}
}); });
}(document, jQuery)); }(document, jQuery));
...@@ -2,44 +2,10 @@ ...@@ -2,44 +2,10 @@
(function (document, $) { (function (document, $) {
"use strict"; "use strict";
var getParameter = function(searchString, paramName) { var setup = function () {
var i, val, params = searchString.split("&"); renderJs.mapUrl(window.location.search, function (value, textStatus, jqXHR) {
for (i=0;i<params.length;i++) { var sendAPI = "data://application/hal+json;base64," +
val = params[i].split("=");
if (val[0] == paramName) {
return decodeURIComponent(val[1]);
}
}
return null;
};
var mapUrl = function (searchString) {
var fileToDisplay = getParameter(searchString, "file"),
browserAPI,
previewAPI;
if (fileToDisplay) {
$.ajax({
method: 'GET',
// XXX Hardcoded
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
// merge again once working!
browserAPI = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({
_links: {
self: {href:''},
scope: {href: value._links.scope.href},
call: {href:'browser://call/{method}/{scope}/{interaction}'}
}}));
previewAPI = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({ window.btoa(JSON.stringify({
_links: { _links: {
self: {href:''}, self: {href:''},
...@@ -48,28 +14,19 @@ ...@@ -48,28 +14,19 @@
}})); }}));
$("body").addGadget({ $("body").addGadget({
"src": 'filebrowser.html?file=' + browserAPI, "src": 'filebrowser.html?file=' + sendAPI,
"iframe": "true" "iframe": "true"
}); });
$("body").addGadget({ $("body").addGadget({
"src": value._links.target.href + '?file=' + previewAPI, "src": value._links.target.href + '?file=' + sendAPI,
"iframe": "true" "iframe": "true"
}); });
}
}); });
} else {
$("body").text("No parameter found in url");
}
}; };
$(document).ready(function () { $(document).ready(function () {
var search = window.location.search; setup();
if (search) {
mapUrl(search.slice(1));
} else {
$("body").text("No parameter found in url");
}
}); });
}(document, jQuery)); }(document, jQuery));
...@@ -9,12 +9,8 @@ ...@@ -9,12 +9,8 @@
sessionStorage.setItem("schnick", "schnack"); sessionStorage.setItem("schnick", "schnack");
var setup = function () { var setup = function () {
// instance1 and 2 should be passed through the URl, mapped here!
// TODO: I don't like scope/target for passing too specific information renderJs.mapUrl(window.location.search, function (value, textStatus, jqXHR) {
// like scope = which storage to use and target = which file to load in
// the next target
// TODO: Should be in window.location.href, not declared here
// TODO: how to pass multiple instances of _links? allow at all?
var instance1 = "data://application/hal+json;base64," + var instance1 = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({ window.btoa(JSON.stringify({
...@@ -41,6 +37,7 @@ ...@@ -41,6 +37,7 @@
"src": "filebrowser_and_preview.html?file=" + instance2, "src": "filebrowser_and_preview.html?file=" + instance2,
"iframe": "true" "iframe": "true"
}); });
});
}; };
$(document).ready(function () { $(document).ready(function () {
......
...@@ -2,39 +2,14 @@ ...@@ -2,39 +2,14 @@
"use strict"; "use strict";
(function (document, $) { (function (document, $) {
var getParameter = function(searchString, paramName) { var setup = function () {
var i, val, params = searchString.split("&"); renderJs.mapUrl(window.location.search, function (value, textStatus, jqXHR) {
for (i=0;i<params.length;i++) { var scope = value._links.scope.href.slice(0,-1).split(/[/]+/).pop(),
val = params[i].split("=");
if (val[0] == paramName) {
return decodeURIComponent(val[1]);
}
}
return null;
};
var mapUrl = function (searchString) {
var fileToDisplay = getParameter(searchString, "file"),
scope,
register,
service;
if (fileToDisplay) {
$.ajax({
method: 'GET',
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
scope = value._links.scope.href.slice(0,-1).split(/[/]+/).pop();
register = value._links.call.href register = value._links.call.href
.replace("{method}", "register") .replace("{method}", "register")
.replace("{scope}", scope ) .replace("{scope}", scope )
.replace("{interaction}", ""); .replace("{interaction}", ""),
service = { service = {
"type": "register/any", "type": "register/any",
"src": encodeURIComponent(window.location.href), "src": encodeURIComponent(window.location.href),
...@@ -54,18 +29,11 @@ ...@@ -54,18 +29,11 @@
// console.log("registration successful"); // console.log("registration successful");
} }
}); });
}
}); });
} };
}
$(document).ready(function () { $(document).ready(function () {
var search = window.location.search; setup();
if (search) {
mapUrl(search.slice(1));
} else {
$("body").text("No parameter found in url");
}
}); });
}(document, jQuery)); }(document, jQuery));
\ No newline at end of file
...@@ -2,39 +2,14 @@ ...@@ -2,39 +2,14 @@
"use strict"; "use strict";
(function (document, $) { (function (document, $) {
var getParameter = function(searchString, paramName) { var setup = function () {
var i, val, params = searchString.split("&"); renderJs.mapUrl(window.location.search, function (value, textStatus, jqXHR) {
for (i=0;i<params.length;i++) { var scope = value._links.scope.href.slice(0,-1).split(/[/]+/).pop(),
val = params[i].split("=");
if (val[0] == paramName) {
return decodeURIComponent(val[1]);
}
}
return null;
};
var mapUrl = function (searchString) {
var fileToDisplay = getParameter(searchString, "file"),
scope,
register,
service;
if (fileToDisplay) {
$.ajax({
method: 'GET',
url: fileToDisplay,
context: $('body'),
error: function (jqXHR, textStatus, errorThrown) {
$(this).text(errorThrown);
},
success: function (value, textStatus, jqXHR) {
scope = value._links.scope.href.slice(0,-1).split(/[/]+/).pop();
register = value._links.call.href register = value._links.call.href
.replace("{method}", "register") .replace("{method}", "register")
.replace("{scope}", scope ) .replace("{scope}", scope )
.replace("{interaction}", ""); .replace("{interaction}", ""),
service = { service = {
"type": "register/any", "type": "register/any",
"src": encodeURIComponent(window.location.href), "src": encodeURIComponent(window.location.href),
...@@ -54,24 +29,11 @@ ...@@ -54,24 +29,11 @@
// console.log("registration successful"); // console.log("registration successful");
} }
}); });
// renderJs.addService(service, function (response, error) {
// console.log("registration happened");
// console.log(error);
// console.log(response);
// });
}
}); });
} };
}
$(document).ready(function () { $(document).ready(function () {
var search = window.location.search; setup();
if (search) {
mapUrl(search.slice(1));
} else {
$("body").text("No parameter found in url");
}
}); });
}(document, jQuery)); }(document, jQuery));
\ No newline at end of file
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