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