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 @@ ...@@ -121,6 +121,7 @@
\n \n
</head>\n </head>\n
<body>\n <body>\n
<div></div>\n
</body>\n </body>\n
</html>\n </html>\n
...@@ -246,7 +247,7 @@ ...@@ -246,7 +247,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>xiaowu</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -260,7 +261,7 @@ ...@@ -260,7 +261,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>940.17402.52950.42820</string> </value> <value> <string>946.44927.40202.16725</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -278,7 +279,7 @@ ...@@ -278,7 +279,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1421153002.19</float> <float>1453306099.89</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -99,45 +99,43 @@ ...@@ -99,45 +99,43 @@
</item> </item>
<item> <item>
<key> <string>text_content</string> </key> <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 /*jslint nomen: true, indent: 2, maxerr: 3 */\n
(function (window, document, rJS, RSVP) {\n (function (window, rJS, RSVP) {\n
"use strict";\n "use strict";\n
function createGadget(gadget) {\n \n
var gadget_element = document.createElement("div"),\n function enqueueRender(gadget, options) {\n
suboptions = {},\n var loop_deferred = gadget.props.loop_defer,\n
field_json = gadget.props.field_json;\n new_loop_deferred = RSVP.defer();\n
suboptions.value = field_json.default;\n \n
suboptions.key = field_json.key;\n gadget.props.loop_defer = new_loop_deferred;\n
suboptions.editable = field_json.editable;\n \n
gadget.props.element.appendChild(gadget_element);\n gadget.props.render_queue\n
return new RSVP.Queue()\n
.push(function () {\n .push(function () {\n
return gadget.declareGadget(field_json.url, {\n return gadget.props.service_deferred.promise;\n
scope: field_json.key,\n
sandbox: field_json.sandbox,\n
element: gadget_element\n
});\n
})\n })\n
.push(function (field_gadget) {\n .push(function (field_gadget) {\n
var iframe;\n return field_gadget.render(options);\n
gadget.props.field_gadget = field_gadget;\n })\n
if (field_json.css_class) {\n .push(function () {\n
gadget_element.setAttribute("class", field_json.css_class);\n return new_loop_deferred.promise;\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
});\n });\n
loop_deferred.resolve();\n
}\n }\n
\n
rJS(window)\n rJS(window)\n
.ready(function (g) {\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 })\n
// Assign the element to a variable\n // Assign the element to a variable\n
.ready(function (g) {\n .ready(function (g) {\n
...@@ -151,32 +149,58 @@ ...@@ -151,32 +149,58 @@
/////////////////////////////////////////////////////////////////\n /////////////////////////////////////////////////////////////////\n
.declareMethod("render", function (options) {\n .declareMethod("render", function (options) {\n
var gadget = this;\n var gadget = this;\n
gadget.props.field_json = options.field_json;\n \n
if (gadget.props.field_gadget !== undefined) {\n enqueueRender(gadget, {\n
if (gadget.props.field_gadget.render !== undefined) {\n key: options.field_json.key,\n
return gadget.props.field_gadget.render({"key" : options.field_json.key,\n value: options.field_json.default,\n
"value" : options.field_json.default,\n editable: options.field_json.editable\n
"editable" : options.field_json.editable});\n });\n
}\n gadget.props.first_render_deferred.resolve(options.field_json);\n
} else if (gadget.props.field_json.sandbox !== "iframe") {\n })\n
if (gadget.props.field_json.sandbox === "") {\n \n
gadget.props.field_json.sandbox = "public";\n .declareMethod("getContent", function () {\n
}\n return this.props.field_gadget.getContent();\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 })\n
\n
.declareService(function () {\n .declareService(function () {\n
var gadget = this;\n // Add the field in the DOM after the first render method has been called\n
if (gadget.props.field_gadget === undefined) {\n var gadget = this,\n
return createGadget(gadget);\n gadget_element = gadget.props.element.querySelector(\'div\'),\n
}\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 })\n
.declareMethod("getContent", function () {\n \n
if (this.props.field_gadget.getContent) {\n \n
return this.props.field_gadget.getContent();\n .declareService(function () {\n
}\n // Defer render execution and check errors\n
return this.props.render_queue;\n
});\n });\n
}(window, document, rJS, RSVP));\n }(window, rJS, RSVP));\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -298,7 +322,7 @@ ...@@ -298,7 +322,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>xiaowu</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -312,7 +336,7 @@ ...@@ -312,7 +336,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>940.57981.32712.11997</string> </value> <value> <string>948.39131.50045.63214</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -330,7 +354,7 @@ ...@@ -330,7 +354,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1423588896.63</float> <float>1453310168.81</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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