Commit 734051d3 authored by Sven Franck's avatar Sven Franck

started relocating functionality to renderjs

parent 8ab4b629
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
.replace("{scope}", scope ) .replace("{scope}", scope )
.replace("{interaction}", ""); .replace("{interaction}", "");
service = { service = {
"type": "service/test", "type": "register/any",
"src": encodeURIComponent(window.location.href), "src": encodeURIComponent(window.location.href),
"rel": "browse", "rel": "browse",
"self": window.frameElement.id "self": window.frameElement.id
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
success: function (value2, textStatus, jqXHR) { success: function (value2, textStatus, jqXHR) {
var content_type = jqXHR.getResponseHeader("Content-Type") || "", var content_type = jqXHR.getResponseHeader("Content-Type") || "",
request = value._links.call.href request = value._links.call.href
.replace("{method}", "service") .replace("{method}", "request")
.replace("{scope}", scope ) .replace("{scope}", scope )
.replace("{interaction}", "preview"); .replace("{interaction}", "preview");
......
/*global document, jQuery */ /*global document, jQuery */
"use strict";
(function (document, $) { (function (document, $) {
"use strict";
var getParameter = function(searchString, paramName) { var getParameter = function(searchString, paramName) {
var i, val, params = searchString.split("&"); var i, val, params = searchString.split("&");
...@@ -14,52 +14,6 @@ ...@@ -14,52 +14,6 @@
return null; return null;
}; };
var handler = function (event) {
// prevent registrations to renderJs from triggering here
var type = event.data.type,
service,
scope,
request;
if (type === undefined) {
$.ajax({
method: "GET",
url: event.data,
error: function (jqXHR, textStatus, errorThrown) {
console.log("request failed: " + errorThrown);
},
success: function (value, textStatus, jqXHR) {
// we now have the URL to handle and the method
// to request. We need to POST this, because
// we can't access renderJS.gadgetService from here...
// when optimizing all the secondary ajax calls should be removed
// question also is, whether we need POST at all, if we could
// pass everything through the URL?
scope = value._links.self.href.split("/").slice(0,-1).pop();
service = {
"service" : value._links.self.href.split(/[/]+/).pop(),
"parameters" : [value._links.request.href],
"scope" : scope
}
request = 'browser://request/' + scope + '/';
$.ajax({
method: "POST",
url: request,
context: $(this),
data: JSON.stringify(service),
error: function (jqXHR, textStatus, errorThrown) {
console.log("request for service failed");
},
// success: function () {
// console.log("service requested from renderJS");
// }
});
}
});
}
};
var mapUrl = function (searchString) { var mapUrl = function (searchString) {
var fileToDisplay = getParameter(searchString, "file"), var fileToDisplay = getParameter(searchString, "file"),
browserAPI, browserAPI,
...@@ -117,11 +71,11 @@ ...@@ -117,11 +71,11 @@
$("body").text("No parameter found in url"); $("body").text("No parameter found in url");
} }
if (window.addEventListener){ // if (window.addEventListener){
window.addEventListener("message", handler, false) // window.addEventListener("message", handler, false)
} else { // } else {
window.attachEvent("onmessage", handler) // window.attachEvent("onmessage", handler)
} // }
}); });
}(document, jQuery)); }(document, jQuery));
/*global document, jQuery */ /*global document, jQuery */
"use strict";
(function (document, $) { (function (document, $) {
"use strict";
// sample contents // sample contents
localStorage.setItem("foo", "bar"); localStorage.setItem("foo", "bar");
...@@ -10,7 +10,14 @@ ...@@ -10,7 +10,14 @@
var setup = function () { var setup = function () {
// not an easy API... // not an easy API...
// can this be done automatically? // can this be done internally?
// TODO:
// "call" default API need not be passed,
// "self" can be added automatically
// "scope" (previous "storage") don't like... too gadget-specific?
// "target" (previous "display") don't like, as above
var instance1 = "data://application/hal+json;base64," + var instance1 = "data://application/hal+json;base64," +
window.btoa(JSON.stringify({ window.btoa(JSON.stringify({
_links: { _links: {
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
.replace("{scope}", scope ) .replace("{scope}", scope )
.replace("{interaction}", ""); .replace("{interaction}", "");
service = { service = {
"type": "service/test", "type": "register/any",
"src": encodeURIComponent(window.location.href), "src": encodeURIComponent(window.location.href),
"rel": "preview", "rel": "preview",
"self": window.frameElement.id "self": window.frameElement.id
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
.replace("{scope}", scope ) .replace("{scope}", scope )
.replace("{interaction}", ""); .replace("{interaction}", "");
service = { service = {
"type": "service/test", "type": "register/any",
"src": encodeURIComponent(window.location.href), "src": encodeURIComponent(window.location.href),
"rel": "preview", "rel": "preview",
"self": window.frameElement.id "self": window.frameElement.id
...@@ -85,6 +85,12 @@ ...@@ -85,6 +85,12 @@
// console.log("registration successful"); // console.log("registration successful");
} }
}); });
// renderJs.addService(service, function (response, error) {
// console.log("registration happened");
// console.log(error);
// console.log(response);
// });
} }
}); });
} }
......
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