Commit 4506074f authored by Romain Courteaud's avatar Romain Courteaud

erp5_core: use renderjs mutex

parent f67a4273
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2 */
/*global window, rJS, RSVP, document, FileReader, Blob, /*global window, rJS, RSVP, document, FileReader, Blob*/
lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ (function (window, rJS, RSVP, document, FileReader, Blob) {
(function (window, rJS, RSVP, document, FileReader, Blob,
lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue) {
"use strict"; "use strict";
var editor_dict = { var editor_dict = {
...@@ -44,8 +42,12 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -44,8 +42,12 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
} }
}); });
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
return this.renderAsynchronously(options);
})
.declareJob('renderAsynchronously', function (options) {
var state_dict = { var state_dict = {
value: options.value || "", value: options.value || "",
editor: options.editor, editor: options.editor,
...@@ -62,16 +64,12 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -62,16 +64,12 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
}) })
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
return this.renderAsynchronously(modification_dict);
})
.declareJob('renderAsynchronously', function (modification_dict) {
var element = this.element, var element = this.element,
gadget = this, gadget = this,
url, url,
div = document.createElement('div'), div = document.createElement('div'),
div_max = document.createElement('div'), div_max = document.createElement('div'),
queue = lockGadgetInQueue(gadget)(); queue = new RSVP.Queue();
if ((modification_dict.hasOwnProperty('editable')) || if ((modification_dict.hasOwnProperty('editable')) ||
(modification_dict.hasOwnProperty('editor')) || (modification_dict.hasOwnProperty('editor')) ||
...@@ -179,8 +177,7 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -179,8 +177,7 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
} else { } else {
element.querySelector('pre').textContent = gadget.state.value; element.querySelector('pre').textContent = gadget.state.value;
} }
return queue return queue;
.push(unlockGadgetInQueue(gadget), unlockGadgetInFailedQueue(gadget));
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
...@@ -189,14 +186,10 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -189,14 +186,10 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
result; result;
if (this.state.editable && if (this.state.editable &&
editor_dict.hasOwnProperty(gadget.state.editor)) { editor_dict.hasOwnProperty(gadget.state.editor)) {
return lockGadgetInQueue(gadget)() return gadget.getDeclaredGadget('editor')
.push(function () {
return gadget.getDeclaredGadget('editor');
})
.push(function (editor_gadget) { .push(function (editor_gadget) {
return editor_gadget.getContent.apply(editor_gadget, argument_list); return editor_gadget.getContent.apply(editor_gadget, argument_list);
}) });
.push(unlockGadgetInQueue(gadget), unlockGadgetInFailedQueue(gadget));
/* /*
.push(function (result) { .push(function (result) {
var value = result[context.state.key] || ''; var value = result[context.state.key] || '';
...@@ -215,12 +208,11 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -215,12 +208,11 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
return result; return result;
} }
return {}; return {};
}) }, {mutex: 'changestate'})
.declareMethod('checkValidity', function () { .declareMethod('checkValidity', function () {
// XXX How to implement this for editors? // XXX How to implement this for editors?
return true; return true;
}); });
}(window, rJS, RSVP, document, FileReader, Blob, }(window, rJS, RSVP, document, FileReader, Blob));
lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue)); \ No newline at end of file
\ No newline at end of file
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