Commit e504d24d authored by Romain Courteaud's avatar Romain Courteaud Committed by Xiaowu Zhang

erp5_web_renderjs_ui: fix cancellation issue

parent c70e3a6e
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
],//leapyear ],//leapyear
queue = new RSVP.Queue(), queue,
promise_list, promise_list,
input_state = { input_state = {
name: gadget.state.key, name: gadget.state.key,
...@@ -122,10 +122,7 @@ ...@@ -122,10 +122,7 @@
gadget.declareGadget('gadget_html5_element.html', {scope: 'P'}) gadget.declareGadget('gadget_html5_element.html', {scope: 'P'})
]; ];
} }
queue queue = new RSVP.Queue(RSVP.all(promise_list))
.push(function () {
return RSVP.all(promise_list);
})
.push(function (result_list) { .push(function (result_list) {
// Clear first to DOM, append after to reduce flickering/manip // Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) { while (element.firstChild) {
...@@ -148,10 +145,7 @@ ...@@ -148,10 +145,7 @@
} else { } else {
promise_list = [gadget.getDeclaredGadget('P')]; promise_list = [gadget.getDeclaredGadget('P')];
} }
queue queue = new RSVP.Queue(RSVP.all(promise_list));
.push(function () {
return RSVP.all(promise_list);
});
} }
// Calculate sub gadget states // Calculate sub gadget states
...@@ -268,9 +262,11 @@ ...@@ -268,9 +262,11 @@
} }
} else { } else {
//get timezone difference between server and local browser //get timezone difference between server and local browser
offset_time_zone = timezone + (state_date.getTimezoneOffset() / 60); offset_time_zone = timezone +
(state_date.getTimezoneOffset() / 60);
//adjust hour in order to get correct date time string //adjust hour in order to get correct date time string
state_date.setUTCHours(state_date.getUTCHours() + offset_time_zone); state_date.setUTCHours(state_date.getUTCHours() +
offset_time_zone);
text_content = state_date.toLocaleDateString(language); text_content = state_date.toLocaleDateString(language);
if (!gadget.state.date_only) { if (!gadget.state.date_only) {
text_content += " " + locale_formatted_state_date; text_content += " " + locale_formatted_state_date;
...@@ -298,10 +294,7 @@ ...@@ -298,10 +294,7 @@
if (gadget.state.timezone_style) { if (gadget.state.timezone_style) {
promise_list.push(gadget.getDeclaredGadget('SELECT')); promise_list.push(gadget.getDeclaredGadget('SELECT'));
} }
return new RSVP.Queue() return new RSVP.Queue(RSVP.all(promise_list))
.push(function () {
return RSVP.all(promise_list);
})
.push(function (result_list) { .push(function (result_list) {
var i; var i;
promise_list = []; promise_list = [];
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>980.55051.50282.19404</string> </value> <value> <string>982.20840.63890.24627</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1577775957.85</float> <float>1583399782.26</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -378,10 +378,7 @@ ...@@ -378,10 +378,7 @@
promise_list.push(null); promise_list.push(null);
} }
return new RSVP.Queue() return new RSVP.Queue(RSVP.all(promise_list))
.push(function () {
return RSVP.all(promise_list);
})
.push(function (result_list) { .push(function (result_list) {
var j; var j;
for (j = 0; j < result_list.length; j += 1) { for (j = 0; j < result_list.length; j += 1) {
......
...@@ -202,7 +202,7 @@ ...@@ -202,7 +202,7 @@
// Gadget has not yet been correctly initialized // Gadget has not yet been correctly initialized
throw error; throw error;
} }
if (error_response && error_response.text) { if (error_response && error_response.text) {
return error_response.text().then( return error_response.text().then(
function (request_error_text) { function (request_error_text) {
return gadget.changeState({ return gadget.changeState({
...@@ -243,7 +243,7 @@ ...@@ -243,7 +243,7 @@
function triggerMaximize(gadget, maximize) { function triggerMaximize(gadget, maximize) {
if (gadget.props.deferred_minimize !== undefined) { if (gadget.props.deferred_minimize !== undefined) {
gadget.props.deferred_minimize.resolve(); gadget.props.deferred_minimize.cancel();
gadget.props.deferred_minimize = undefined; gadget.props.deferred_minimize = undefined;
} }
hideDesktopPanel(gadget, maximize); hideDesktopPanel(gadget, maximize);
...@@ -253,13 +253,16 @@ ...@@ -253,13 +253,16 @@
action: "maximize" action: "maximize"
}]) }])
.push(function () { .push(function () {
gadget.props.deferred_minimize = RSVP.defer(); gadget.props.deferred_minimize = new RSVP.Promise(
return gadget.props.deferred_minimize.promise; function () {return; },
}) function () {
.push(undefined, function (error) { // Wait for cancellation
if (error instanceof RSVP.CancellationError) { // return triggerMaximize(gadget, false);
return triggerMaximize(gadget, false); hideDesktopPanel(gadget, false);
} return route(gadget, 'header', 'setButtonTitle', [{}]);
}
);
return gadget.props.deferred_minimize;
}); });
} }
return route(gadget, 'header', 'setButtonTitle', [{}]); return route(gadget, 'header', 'setButtonTitle', [{}]);
...@@ -771,7 +774,7 @@ ...@@ -771,7 +774,7 @@
element.appendChild(container); element.appendChild(container);
// make an iframe to display error page from XMLHttpRequest. // make an iframe to display error page from XMLHttpRequest.
if (gadget.state.request_error_text) { if (gadget.state.request_error_text) {
iframe = document.createElement('iframe'); iframe = document.createElement('iframe');
container.appendChild(iframe); container.appendChild(iframe);
iframe.srcdoc = gadget.state.request_error_text; iframe.srcdoc = gadget.state.request_error_text;
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>981.63449.54271.9625</string> </value> <value> <string>982.16935.24089.33911</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1582196761.8</float> <float>1583166534.25</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -248,8 +248,7 @@ ...@@ -248,8 +248,7 @@
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
var plane = gadget.element.querySelector("a"), var plane = gadget.element.querySelector("a"),
ul = gadget.element.querySelector(".search_ul"), ul = gadget.element.querySelector(".search_ul");
translation_promise;
plane.href = ''; plane.href = '';
// uid is known // uid is known
...@@ -315,114 +314,112 @@ ...@@ -315,114 +314,112 @@
return RSVP.delay(200); return RSVP.delay(200);
}) })
.push(function () { .push(function () {
translation_promise = gadget.getTranslationList([ return RSVP.all([
'Create New',
'Explore the Search Result List' gadget.jio_allDocs({
query: Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: [
QueryFactory.create(
new URI(gadget.state.query).query(true).query
),
new SimpleQuery({
key: gadget.state.catalog_index,
value: value_text
})
]
})),
limit: [0, 10],
select_list: [gadget.state.catalog_index, "uid"],
sort_on: JSON.parse(gadget.state.sort_list_json)
}),
gadget.getTranslationList([
'Create New',
'Explore the Search Result List'
])
]); ]);
})
.push(function (result_list) {
var i,
row,
portal_type_list,
translated_portal_type_list,
fragment_element = document.createDocumentFragment(),
li_element;
return gadget.jio_allDocs({ plane.className = JUMP_UNKNOWN_CLASS_STR;
query: Query.objectToSearchText(new ComplexQuery({
operator: "AND", // Documents
query_list: [
QueryFactory.create(
new URI(gadget.state.query).query(true).query
),
new SimpleQuery({
key: gadget.state.catalog_index,
value: value_text
})
]
})),
limit: [0, 10],
select_list: [gadget.state.catalog_index, "uid"],
sort_on: JSON.parse(gadget.state.sort_list_json)
})
.push(function (result) {
return new RSVP.Queue()
.push(function () {
return RSVP.all([result, translation_promise]);
})
.push(function (result_list) {
var i,
row,
portal_type_list,
translated_portal_type_list,
fragment_element = document.createDocumentFragment(),
li_element;
plane.className = JUMP_UNKNOWN_CLASS_STR;
// Documents
// <li class="ui-icon-sign-in ui-btn-icon-right" data-relative-url="{{id}}" // <li class="ui-icon-sign-in ui-btn-icon-right" data-relative-url="{{id}}"
// data-uid="{{uid}}">{{value}}</li> // data-uid="{{uid}}">{{value}}</li>
for (i = 0; i < result_list[0].data.rows.length; i += 1) { for (i = 0; i < result_list[0].data.rows.length; i += 1) {
row = result_list[0].data.rows[i]; row = result_list[0].data.rows[i];
li_element = document.createElement('li'); li_element = document.createElement('li');
li_element.setAttribute('class', li_element.setAttribute('class',
'ui-icon-sign-in ui-btn-icon-right'); 'ui-icon-sign-in ui-btn-icon-right');
li_element.setAttribute('data-relative-url', row.id); li_element.setAttribute('data-relative-url', row.id);
li_element.setAttribute('data-uid', row.value.uid); li_element.setAttribute('data-uid', row.value.uid);
li_element.textContent = li_element.textContent =
row.value[gadget.state.catalog_index]; row.value[gadget.state.catalog_index];
fragment_element.appendChild(li_element); fragment_element.appendChild(li_element);
} }
// New documents // New documents
// <li class="ui-icon-plus ui-btn-icon-right" data-i18n="Create New" // <li class="ui-icon-plus ui-btn-icon-right" data-i18n="Create New"
// data-create-object="{{value}}" name="{{name}}">Create New // data-create-object="{{value}}" name="{{name}}">Create New
// <span> {{name}}: {{../value}}</span></li> // <span> {{name}}: {{../value}}</span></li>
if (gadget.state.allow_creation) { if (gadget.state.allow_creation) {
portal_type_list = portal_type_list =
JSON.parse(gadget.state.portal_types); JSON.parse(gadget.state.portal_types);
translated_portal_type_list = translated_portal_type_list =
JSON.parse(gadget.state.translated_portal_types); JSON.parse(gadget.state.translated_portal_types);
for (i = 0; i < portal_type_list.length; i += 1) { for (i = 0; i < portal_type_list.length; i += 1) {
li_element = document.createElement('li'); li_element = document.createElement('li');
li_element.setAttribute('class', li_element.setAttribute('class',
'ui-icon-plus ui-btn-icon-right'); 'ui-icon-plus ui-btn-icon-right');
li_element.setAttribute('data-create-object', li_element.setAttribute('data-create-object',
portal_type_list[i]); portal_type_list[i]);
li_element.setAttribute('name', li_element.setAttribute('name',
translated_portal_type_list[i]); translated_portal_type_list[i]);
li_element.textContent = li_element.textContent =
result_list[1][0] + ' ' + result_list[1][0] + ' ' +
translated_portal_type_list[i] + translated_portal_type_list[i] +
': ' + value_text; ': ' + value_text;
fragment_element.appendChild(li_element); fragment_element.appendChild(li_element);
} }
} }
// Explore // Explore
// <li class="ui-icon-search ui-btn-icon-right" data-explore=true // <li class="ui-icon-search ui-btn-icon-right" data-explore=true
// data-i18n="Explore the Search Result List" ></li> // data-i18n="Explore the Search Result List" ></li>
li_element = document.createElement('li'); li_element = document.createElement('li');
li_element.setAttribute('class', li_element.setAttribute('class',
'ui-icon-search ui-btn-icon-right'); 'ui-icon-search ui-btn-icon-right');
li_element.setAttribute('data-explore', li_element.setAttribute('data-explore',
true); true);
li_element.textContent = result_list[1][1]; li_element.textContent = result_list[1][1];
fragment_element.appendChild(li_element); fragment_element.appendChild(li_element);
while (ul.firstChild) { while (ul.firstChild) {
ul.removeChild(ul.firstChild); ul.removeChild(ul.firstChild);
} }
ul.appendChild(fragment_element); ul.appendChild(fragment_element);
}); }, function (error) {
}, function (error) { if (error instanceof Error &&
if (error instanceof Error && error.hash &&
error.hash && error.hash.expected &&
error.hash.expected && error.hash.expected.length === 1 &&
error.hash.expected.length === 1 && error.hash.expected[0] === "'QUOTE'") {
error.hash.expected[0] === "'QUOTE'") { return gadget.getTranslationList([
return gadget.getTranslationList([ "Invalid search criteria"
"Invalid search criteria" ])
]) .push(function (translation_list) {
.push(function (translation_list) { return gadget.notifyInvalid(translation_list[0]);
return gadget.notifyInvalid(translation_list[0]); });
}); }
} throw error;
throw error;
});
}); });
}); });
......
...@@ -29,7 +29,9 @@ ...@@ -29,7 +29,9 @@
</tal:block> </tal:block>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<!-- Wait for Maximize button --> <tr>
<td colspan="3"><b>Maximize</b></td>
</tr>
<tr> <tr>
<td>waitForElementPresent</td> <td>waitForElementPresent</td>
<td>//div[@data-gadget-scope='maximize']//button[text()='Maximize' and @type='button']</td> <td>//div[@data-gadget-scope='maximize']//button[text()='Maximize' and @type='button']</td>
...@@ -40,10 +42,18 @@ ...@@ -40,10 +42,18 @@
<td>//div[@data-gadget-scope='maximize']//button[text()='Maximize' and @type='button']</td> <td>//div[@data-gadget-scope='maximize']//button[text()='Maximize' and @type='button']</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[@data-role='page' and @class='desktop-panel-hidden']</td>
<td></td>
</tr>
<tr>
<td colspan="3"><b>Check full screen</b></td>
</tr>
<!-- Wait For full screen --> <!-- Wait For full screen -->
<tr> <tr>
<td>waitForElementPresent</td> <td>assertElementPresent</td>
<td>//div[@data-role='page' and @class='desktop-panel-hidden']</td> <td>//div[@data-role='page' and @class='desktop-panel-hidden']</td>
<td></td> <td></td>
</tr> </tr>
...@@ -59,6 +69,9 @@ ...@@ -59,6 +69,9 @@
</tr> </tr>
<!-- minimize with header button --> <!-- minimize with header button -->
<tr>
<td colspan="3"><b>Minimize with header button</b></td>
</tr>
<tr> <tr>
<td>click</td> <td>click</td>
<td>//div[@data-gadget-scope='header']//button[@name='maximize' and @type='submit']</td> <td>//div[@data-gadget-scope='header']//button[@name='maximize' and @type='submit']</td>
...@@ -66,6 +79,9 @@ ...@@ -66,6 +79,9 @@
</tr> </tr>
<!-- Check is minimize --> <!-- Check is minimize -->
<tr>
<td colspan="3"><b>Check not full screen</b></td>
</tr>
<tr> <tr>
<td>waitForElementNotPresent</td> <td>waitForElementNotPresent</td>
<td>//div[@data-role='page' and @class='desktop-panel-hidden']</td> <td>//div[@data-role='page' and @class='desktop-panel-hidden']</td>
...@@ -83,6 +99,9 @@ ...@@ -83,6 +99,9 @@
</tr> </tr>
<!-- Re maximize --> <!-- Re maximize -->
<tr>
<td colspan="3"><b>Maximize</b></td>
</tr>
<tr> <tr>
<td>click</td> <td>click</td>
<td>//div[@data-gadget-scope='maximize']//button[text()='Maximize' and @type='button']</td> <td>//div[@data-gadget-scope='maximize']//button[text()='Maximize' and @type='button']</td>
...@@ -90,6 +109,9 @@ ...@@ -90,6 +109,9 @@
</tr> </tr>
<!-- Wait For full screen --> <!-- Wait For full screen -->
<tr>
<td colspan="3"><b>Check full screen</b></td>
</tr>
<tr> <tr>
<td>waitForElementPresent</td> <td>waitForElementPresent</td>
<td>//div[@data-role='page' and @class='desktop-panel-hidden']</td> <td>//div[@data-role='page' and @class='desktop-panel-hidden']</td>
...@@ -108,16 +130,17 @@ ...@@ -108,16 +130,17 @@
<!-- make some change in url --> <!-- make some change in url -->
<tr> <tr>
<td>open</td> <td colspan="3"><b>Minimize with url change</b></td>
<td>${base_url}/web_site_module/renderjs_runner/</td>
<td></td>
</tr> </tr>
<tal:block tal:define="click_configuration python: {'text': 'Search'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/click_on_panel_link" />
</tal:block>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<!-- Check is minimize -->
<tr> <tr>
<td>waitForElementPresent</td> <td colspan="3"><b>Check not full screen</b></td>
<td>//div[@role='main']</td>
<td></td>
</tr> </tr>
<!-- Check is minimize -->
<tr> <tr>
<td>assertElementNotPresent</td> <td>assertElementNotPresent</td>
<td>//div[@data-role='page' and @class='desktop-panel-hidden']</td> <td>//div[@data-role='page' and @class='desktop-panel-hidden']</td>
......
...@@ -38,7 +38,7 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/ ...@@ -38,7 +38,7 @@ lockGadgetInQueue, unlockGadgetInQueue, unlockGadgetInFailedQueue*/
this.element.classList.toggle('editor-maximize'); this.element.classList.toggle('editor-maximize');
} }
return this.triggerMaximize.apply(this, param_list) return this.triggerMaximize.apply(this, param_list)
.push(function () { .push(undefined, function () {
if (gadget.element.classList.contains('editor-maximize')) { if (gadget.element.classList.contains('editor-maximize')) {
gadget.element.classList.remove('editor-maximize'); gadget.element.classList.remove('editor-maximize');
} }
......
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