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