Commit e3af03a2 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Update WIP renderJS version

parent 2f3d99e2
...@@ -1087,7 +1087,7 @@ if (typeof document.contains !== 'function') { ...@@ -1087,7 +1087,7 @@ if (typeof document.contains !== 'function') {
} }
function loadSubGadgetDOMDeclaration(g) { function loadSubGadgetDOMDeclaration(g) {
var element_list = g.__element.querySelectorAll('[data-gadget-url]'), var element_list = g.element.querySelectorAll('[data-gadget-url]'),
element, element,
promise_list = [], promise_list = [],
scope, scope,
...@@ -1124,6 +1124,10 @@ if (typeof document.contains !== 'function') { ...@@ -1124,6 +1124,10 @@ if (typeof document.contains !== 'function') {
this.state = JSON.parse(json_state); this.state = JSON.parse(json_state);
}); });
}; };
RenderJSGadget.onStateChange = function (callback) {
this.prototype.__state_change_callback = callback;
return this;
};
RenderJSGadget.__service_list = []; RenderJSGadget.__service_list = [];
RenderJSGadget.declareService = function (callback) { RenderJSGadget.declareService = function (callback) {
...@@ -1133,7 +1137,7 @@ if (typeof document.contains !== 'function') { ...@@ -1133,7 +1137,7 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.onEvent = function (type, callback, use_capture, RenderJSGadget.onEvent = function (type, callback, use_capture,
prevent_default) { prevent_default) {
this.__service_list.push(function () { this.__service_list.push(function () {
return loopEventListener(this.__element, type, use_capture, return loopEventListener(this.element, type, use_capture,
callback.bind(this), prevent_default); callback.bind(this), prevent_default);
}); });
return this; return this;
...@@ -1237,16 +1241,11 @@ if (typeof document.contains !== 'function') { ...@@ -1237,16 +1241,11 @@ if (typeof document.contains !== 'function') {
}) })
.declareMethod('getElement', function () { .declareMethod('getElement', function () {
// Returns the DOM Element of a gadget // Returns the DOM Element of a gadget
if (this.__element === undefined) { // XXX Kept for compatibility. Use element property directly
if (this.element === undefined) {
throw new Error("No element defined"); throw new Error("No element defined");
} }
return this.__element; return this.element;
})
.declareMethod('render', function () {
return;
})
.declareMethod('updateDOM', function () {
return;
}) })
.declareMethod('changeState', function (state_dict) { .declareMethod('changeState', function (state_dict) {
var key, var key,
...@@ -1259,8 +1258,8 @@ if (typeof document.contains !== 'function') { ...@@ -1259,8 +1258,8 @@ if (typeof document.contains !== 'function') {
modified = true; modified = true;
} }
} }
if (modified) { if (modified && this.__state_change_callback !== undefined) {
return this.updateDOM(modification_dict); return this.__state_change_callback(modification_dict);
} }
}); });
...@@ -1352,6 +1351,8 @@ if (typeof document.contains !== 'function') { ...@@ -1352,6 +1351,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.ready; RenderJSGadget.ready;
RenderJSEmbeddedGadget.setState = RenderJSEmbeddedGadget.setState =
RenderJSGadget.setState; RenderJSGadget.setState;
RenderJSEmbeddedGadget.onStateChange =
RenderJSGadget.onStateChange;
RenderJSEmbeddedGadget.declareService = RenderJSEmbeddedGadget.declareService =
RenderJSGadget.declareService; RenderJSGadget.declareService;
RenderJSEmbeddedGadget.onEvent = RenderJSEmbeddedGadget.onEvent =
...@@ -1384,11 +1385,10 @@ if (typeof document.contains !== 'function') { ...@@ -1384,11 +1385,10 @@ if (typeof document.contains !== 'function') {
template_node_list = Klass.__template_element.body.childNodes; template_node_list = Klass.__template_element.body.childNodes;
gadget_loading_klass = Klass; gadget_loading_klass = Klass;
gadget_instance = new Klass(); gadget_instance = new Klass();
gadget_instance.__element = options.element;
gadget_instance.element = options.element; gadget_instance.element = options.element;
gadget_instance.state = {}; gadget_instance.state = {};
for (i = 0; i < template_node_list.length; i += 1) { for (i = 0; i < template_node_list.length; i += 1) {
gadget_instance.__element.appendChild( gadget_instance.element.appendChild(
template_node_list[i].cloneNode(true) template_node_list[i].cloneNode(true)
); );
} }
...@@ -1432,6 +1432,8 @@ if (typeof document.contains !== 'function') { ...@@ -1432,6 +1432,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.ready; RenderJSGadget.ready;
RenderJSIframeGadget.setState = RenderJSIframeGadget.setState =
RenderJSGadget.setState; RenderJSGadget.setState;
RenderJSIframeGadget.onStateChange =
RenderJSGadget.onStateChange;
RenderJSIframeGadget.__service_list = RenderJSGadget.__service_list.slice(); RenderJSIframeGadget.__service_list = RenderJSGadget.__service_list.slice();
RenderJSIframeGadget.declareService = RenderJSIframeGadget.declareService =
RenderJSGadget.declareService; RenderJSGadget.declareService;
...@@ -1464,7 +1466,6 @@ if (typeof document.contains !== 'function') { ...@@ -1464,7 +1466,6 @@ if (typeof document.contains !== 'function') {
// gadget_instance.element.setAttribute("seamless", "seamless"); // gadget_instance.element.setAttribute("seamless", "seamless");
iframe.setAttribute("src", url); iframe.setAttribute("src", url);
gadget_instance.__path = url; gadget_instance.__path = url;
gadget_instance.__element = options.element;
gadget_instance.element = options.element; gadget_instance.element = options.element;
gadget_instance.state = {}; gadget_instance.state = {};
// Attach it to the DOM // Attach it to the DOM
...@@ -1661,16 +1662,16 @@ if (typeof document.contains !== 'function') { ...@@ -1661,16 +1662,16 @@ if (typeof document.contains !== 'function') {
} }
} }
parent_gadget.__sub_gadget_dict[scope] = gadget_instance; parent_gadget.__sub_gadget_dict[scope] = gadget_instance;
gadget_instance.__element.setAttribute("data-gadget-scope", gadget_instance.element.setAttribute("data-gadget-scope",
scope); scope);
// Put some attribute to ease page layout comprehension // Put some attribute to ease page layout comprehension
gadget_instance.__element.setAttribute("data-gadget-url", url); gadget_instance.element.setAttribute("data-gadget-url", url);
gadget_instance.__element.setAttribute("data-gadget-sandbox", gadget_instance.element.setAttribute("data-gadget-sandbox",
options.sandbox); options.sandbox);
gadget_instance.__element._gadget = gadget_instance; gadget_instance.element._gadget = gadget_instance;
if (document.contains(gadget_instance.__element)) { if (document.contains(gadget_instance.element)) {
// Put a timeout // Put a timeout
queue.push(startService); queue.push(startService);
} }
...@@ -1833,6 +1834,8 @@ if (typeof document.contains !== 'function') { ...@@ -1833,6 +1834,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.ready; RenderJSGadget.ready;
tmp_constructor.setState = tmp_constructor.setState =
RenderJSGadget.setState; RenderJSGadget.setState;
tmp_constructor.onStateChange =
RenderJSGadget.onStateChange;
tmp_constructor.declareService = tmp_constructor.declareService =
RenderJSGadget.declareService; RenderJSGadget.declareService;
tmp_constructor.onEvent = tmp_constructor.onEvent =
...@@ -2010,6 +2013,7 @@ if (typeof document.contains !== 'function') { ...@@ -2010,6 +2013,7 @@ if (typeof document.contains !== 'function') {
tmp_constructor.__ready_list = RenderJSGadget.__ready_list.slice(); tmp_constructor.__ready_list = RenderJSGadget.__ready_list.slice();
tmp_constructor.ready = RenderJSGadget.ready; tmp_constructor.ready = RenderJSGadget.ready;
tmp_constructor.setState = RenderJSGadget.setState; tmp_constructor.setState = RenderJSGadget.setState;
tmp_constructor.onStateChange = RenderJSGadget.onStateChange;
tmp_constructor.__service_list = RenderJSGadget.__service_list.slice(); tmp_constructor.__service_list = RenderJSGadget.__service_list.slice();
tmp_constructor.declareService = tmp_constructor.declareService =
RenderJSGadget.declareService; RenderJSGadget.declareService;
...@@ -2163,12 +2167,11 @@ if (typeof document.contains !== 'function') { ...@@ -2163,12 +2167,11 @@ if (typeof document.contains !== 'function') {
} }
} }
tmp_constructor.__template_element = document.createElement("div"); tmp_constructor.__template_element = document.createElement("div");
root_gadget.__element = document.body;
root_gadget.element = document.body; root_gadget.element = document.body;
root_gadget.state = {}; root_gadget.state = {};
for (j = 0; j < root_gadget.__element.childNodes.length; j += 1) { for (j = 0; j < root_gadget.element.childNodes.length; j += 1) {
tmp_constructor.__template_element.appendChild( tmp_constructor.__template_element.appendChild(
root_gadget.__element.childNodes[j].cloneNode(true) root_gadget.element.childNodes[j].cloneNode(true)
); );
} }
RSVP.all([root_gadget.getRequiredJSList(), RSVP.all([root_gadget.getRequiredJSList(),
...@@ -2322,4 +2325,4 @@ if (typeof document.contains !== 'function') { ...@@ -2322,4 +2325,4 @@ if (typeof document.contains !== 'function') {
bootstrap(); bootstrap();
}(document, window, RSVP, DOMParser, Channel, MutationObserver, Node, }(document, window, RSVP, DOMParser, Channel, MutationObserver, Node,
FileReader, Blob, navigator, Event)); FileReader, Blob, navigator, Event));
\ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>954.12913.34971.42393</string> </value> <value> <string>954.33025.37475.1638</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1475850999.47</float> <float>1476192938.84</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