Commit 4dfd0c6e authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Ensure that iframe GadgetField are correctly loaded with their data

parent 533a81c4
......@@ -121,6 +121,7 @@
\n
</head>\n
<body>\n
<div></div>\n
</body>\n
</html>\n
......@@ -246,7 +247,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>xiaowu</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -260,7 +261,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.17402.52950.42820</string> </value>
<value> <string>946.44927.40202.16725</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -278,7 +279,7 @@
</tuple>
<state>
<tuple>
<float>1421153002.19</float>
<float>1453306099.89</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -99,45 +99,43 @@
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>/*global window, rJS, RSVP, document*/\n
<value> <string>/*global window, rJS, RSVP*/\n
/*jslint nomen: true, indent: 2, maxerr: 3 */\n
(function (window, document, rJS, RSVP) {\n
(function (window, rJS, RSVP) {\n
"use strict";\n
function createGadget(gadget) {\n
var gadget_element = document.createElement("div"),\n
suboptions = {},\n
field_json = gadget.props.field_json;\n
suboptions.value = field_json.default;\n
suboptions.key = field_json.key;\n
suboptions.editable = field_json.editable;\n
gadget.props.element.appendChild(gadget_element);\n
return new RSVP.Queue()\n
\n
function enqueueRender(gadget, options) {\n
var loop_deferred = gadget.props.loop_defer,\n
new_loop_deferred = RSVP.defer();\n
\n
gadget.props.loop_defer = new_loop_deferred;\n
\n
gadget.props.render_queue\n
.push(function () {\n
return gadget.declareGadget(field_json.url, {\n
scope: field_json.key,\n
sandbox: field_json.sandbox,\n
element: gadget_element\n
});\n
return gadget.props.service_deferred.promise;\n
})\n
.push(function (field_gadget) {\n
var iframe;\n
gadget.props.field_gadget = field_gadget;\n
if (field_json.css_class) {\n
gadget_element.setAttribute("class", field_json.css_class);\n
}\n
if (field_json.sandbox === "iframe") {\n
iframe = gadget_element.querySelector("iframe");\n
iframe.style.width = "100%";\n
iframe.style.height = "100%";\n
}\n
if (field_gadget.render !== undefined) {\n
return field_gadget.render(suboptions);\n
}\n
return field_gadget.render(options);\n
})\n
.push(function () {\n
return new_loop_deferred.promise;\n
});\n
loop_deferred.resolve();\n
}\n
\n
rJS(window)\n
.ready(function (g) {\n
g.props = {};\n
var loop_defer = RSVP.defer();\n
g.props = {\n
service_deferred: RSVP.defer(),\n
first_render_deferred: RSVP.defer(),\n
render_queue: new RSVP.Queue(),\n
loop_defer: loop_defer\n
};\n
g.props.render_queue\n
.push(function () {\n
return loop_defer.promise;\n
});\n
})\n
// Assign the element to a variable\n
.ready(function (g) {\n
......@@ -151,32 +149,58 @@
/////////////////////////////////////////////////////////////////\n
.declareMethod("render", function (options) {\n
var gadget = this;\n
gadget.props.field_json = options.field_json;\n
if (gadget.props.field_gadget !== undefined) {\n
if (gadget.props.field_gadget.render !== undefined) {\n
return gadget.props.field_gadget.render({"key" : options.field_json.key,\n
"value" : options.field_json.default,\n
"editable" : options.field_json.editable});\n
}\n
} else if (gadget.props.field_json.sandbox !== "iframe") {\n
if (gadget.props.field_json.sandbox === "") {\n
gadget.props.field_json.sandbox = "public";\n
}\n
  • @romain, it seems that after this change GadgetFields with no js_sandbox set on the gadget field will not load with Error: Error: Unsupported sandbox options ''.

Please register or sign in to reply
Please register or sign in to reply
  • I confirm this fixed the issue we had in our project test suite, thanks.

Please register or sign in to reply
return createGadget(gadget);\n
}\n
\n
enqueueRender(gadget, {\n
key: options.field_json.key,\n
value: options.field_json.default,\n
editable: options.field_json.editable\n
});\n
gadget.props.first_render_deferred.resolve(options.field_json);\n
})\n
\n
.declareMethod("getContent", function () {\n
return this.props.field_gadget.getContent();\n
})\n
\n
.declareService(function () {\n
var gadget = this;\n
if (gadget.props.field_gadget === undefined) {\n
return createGadget(gadget);\n
}\n
// Add the field in the DOM after the first render method has been called\n
var gadget = this,\n
gadget_element = gadget.props.element.querySelector(\'div\'),\n
field_json;\n
return new RSVP.Queue()\n
.push(function () {\n
return gadget.props.first_render_deferred.promise;\n
})\n
.push(function (result) {\n
field_json = result;\n
return gadget.declareGadget(field_json.url, {\n
scope: field_json.key,\n
sandbox: field_json.sandbox,\n
element: gadget_element\n
});\n
})\n
.push(function (field_gadget) {\n
var iframe;\n
if (field_json.css_class) {\n
gadget_element.setAttribute("class", field_json.css_class);\n
}\n
if (field_json.sandbox === "iframe") {\n
iframe = gadget_element.querySelector("iframe");\n
iframe.style.width = "100%";\n
iframe.style.height = "100%";\n
}\n
// Trigger render methods\n
gadget.props.field_gadget = field_gadget;\n
gadget.props.service_deferred.resolve(field_gadget);\n
});\n
})\n
.declareMethod("getContent", function () {\n
if (this.props.field_gadget.getContent) {\n
return this.props.field_gadget.getContent();\n
}\n
\n
\n
.declareService(function () {\n
// Defer render execution and check errors\n
return this.props.render_queue;\n
});\n
}(window, document, rJS, RSVP));\n
}(window, rJS, RSVP));\n
</string> </value>
</item>
<item>
......@@ -298,7 +322,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>xiaowu</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -312,7 +336,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.57981.32712.11997</string> </value>
<value> <string>948.39131.50045.63214</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -330,7 +354,7 @@
</tuple>
<state>
<tuple>
<float>1423588896.63</float>
<float>1453310168.81</float>
<string>UTC</string>
</tuple>
</state>
......
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