Commit 96cb6422 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] RelationInput: always listen to the click event

This allow to separate management of click/blur events.
Blur is only used to remove the li elements.
Click check if user selected a li element.
parent 9db00ea6
/*jslint indent: 2, maxerr: 3, nomen: true, maxlen: 80 */
/*global window, rJS, RSVP, URI, Handlebars,
SimpleQuery, ComplexQuery, Query, QueryFactory, promiseEventListener*/
(function (window, rJS, RSVP, URI, promiseEventListener,
SimpleQuery, ComplexQuery, Query, QueryFactory*/
(function (window, rJS, RSVP, URI,
SimpleQuery, ComplexQuery, Query, QueryFactory, Handlebars) {
"use strict";
......@@ -286,96 +286,73 @@
/////////////////////////////////////////////////////////////////
// declared services
/////////////////////////////////////////////////////////////////
.onEvent('blur', function () {
.onEvent('click', function (evt) {
var gadget = this,
ul,
new_state = {
has_focus: false
};
if (!gadget.state.editable) {
return;
}
ul = gadget.element.querySelector(".search_ul");
return new RSVP.Queue()
.push(function () {
return RSVP.any([
new RSVP.Queue()
.push(function () {
return RSVP.delay(200);
})
.push(function () {
return gadget.changeState(new_state);
}),
new RSVP.Queue()
.push(function () {
return promiseEventListener(ul, "click", true);
})
.push(function (event) {
// Check which 'li' element was clicked
var li = event.target,
data_relative_url = li.getAttribute("data-relative-url"),
data_uid = li.getAttribute("data-uid"),
data_portal_type = li.getAttribute("data-create-object"),
data_explore = li.getAttribute("data-explore");
// User want to create a new document
if (data_portal_type) {
new_state.value_portal_type = data_portal_type;
return gadget.changeState(new_state);
}
li,
data_relative_url,
data_uid,
data_portal_type,
data_explore,
new_state = {};
if (evt.target.tagName.toLowerCase() === 'li') {
li = evt.target;
data_relative_url = li.getAttribute("data-relative-url");
data_uid = li.getAttribute("data-uid");
data_portal_type = li.getAttribute("data-create-object");
data_explore = li.getAttribute("data-explore");
// User want to create a new document
if (data_portal_type) {
new_state.value_portal_type = data_portal_type;
return gadget.changeState(new_state);
}
// User selected an existing document
if (data_relative_url) {
new_state.value_text = li.textContent;
new_state.value_relative_url = data_relative_url;
new_state.value_uid = data_uid;
return gadget.changeState(new_state);
}
// User selected an existing document
if (data_relative_url) {
new_state.value_text = li.textContent;
new_state.value_relative_url = data_relative_url;
new_state.value_uid = data_uid;
return gadget.changeState(new_state);
}
// Go to the search listbox
if (data_explore) {
return gadget.getFormContent({
format: "json"
})
.push(function (content) {
var input = gadget.element.querySelector('input');
return gadget.redirect({
command: 'index',
options: {
page: "relation_search",
url: gadget.state.url,
extended_search: Query.objectToSearchText(
new SimpleQuery({
key: gadget.state.catalog_index,
value: input.value
})
),
view: gadget.state.view,
back_field: gadget.state.key,
relation_index: gadget.state.relation_index
},
form_content: content
});
});
}
// Go to the search listbox
if (data_explore) {
return gadget.getFormContent({
format: "json"
})
.push(function (content) {
var input = gadget.element.querySelector('input');
return gadget.redirect({
command: 'index',
options: {
page: "relation_search",
url: gadget.state.url,
extended_search: Query.objectToSearchText(
new SimpleQuery({
key: gadget.state.catalog_index,
value: input.value
})
),
view: gadget.state.view,
back_field: gadget.state.key,
relation_index: gadget.state.relation_index
},
form_content: content
});
});
}
}
}, false, false)
// No idea what has been clicked...
return gadget.changeState({
has_focus: false
});
})
.push(function () {
return gadget.notifyChange();
})
]);
.onEvent('blur', function (evt) {
if (evt.target === this.element.querySelector(".search_ul")) {
return this.changeState({
has_focus: false
});
}
}, true, false)
.declareMethod('checkValidity', function () {
return true;
})
......@@ -412,5 +389,5 @@
});
}, true, false);
}(window, rJS, RSVP, URI, promiseEventListener,
}(window, rJS, RSVP, URI,
SimpleQuery, ComplexQuery, Query, QueryFactory, Handlebars));
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.20665.33421.35549</string> </value>
<value> <string>955.62393.33328.52019</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1479294380.88</float>
<float>1481711639.59</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