Commit 961d8235 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: do not duplicate Source document in the indexeddb

Update existing document if there is a source with same title
parent e41236ef
......@@ -18,6 +18,7 @@
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.ready(function () {
var indices = [], db;
......@@ -112,6 +113,7 @@
})
.declareMethod("createIndexDoc", function (doc) {
var gadget = this;
return gadget.getSetting("portal_type")
.push(function (portal_type) {
doc.portal_type = portal_type;
......@@ -119,6 +121,20 @@
})
.push(function (parent_portal_type) {
doc.parent_portal_type = parent_portal_type;
return gadget.jio_allDocs({
query: '(portal_type: "' + doc.portal_type + '") AND (title: "' +
doc.title + '")',
"select_list": ["title"]
});
})
.push(function (result_list) {
if (result_list.data.rows.length > 0) {
// There is a document, update it
return gadget.jio_put(result_list.data.rows[0].id, doc)
.push(function () {
return result_list.data.rows[0].id;
});
}
return gadget.jio_post(doc);
});
})
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.8620.48638.3003</string> </value>
<value> <string>994.49367.10232.59852</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1630509683.61</float>
<float>1631519569.02</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