Commit 8b0d4020 authored by Romain Courteaud's avatar Romain Courteaud

erp5_officejs_support_request_ui: control the initial rendering

parent fb7f6e3c
......@@ -3,6 +3,29 @@
(function (window, rJS) {
"use strict";
function updateResourceListField(gadget) {
var selectedProject = gadget.element.querySelector('#field_your_project').value;
return gadget.jio_getAttachment(
'support_request_module',
gadget.hateoas_url + 'support_request_module'
+ "/SupportRequest_getSupportTypeList"
+ "?project_id=" + selectedProject + "&json_flag=True"
).push(function (sp_list) {
var i, j,
sp_select = gadget.element.querySelector('#field_your_resource');
for (i = sp_select.options.length - 1; i >= 0; i -= 1) {
sp_select.remove(i);
}
for (j = 0; j < sp_list.length; j += 1) {
sp_select.options[j] = new Option(sp_list[j][0], sp_list[j][1]);
}
if (sp_select.options.length === 2) {
sp_select.selectedIndex = 1;
}
});
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -41,40 +64,22 @@
})
.push(function (hateoas_url) {
gadget.hateoas_url = hateoas_url;
}).push(function () {
gadget.updateResourceListField();
// Do it synchronously, to ensure the full form
// will be displayed only when the select field has the expected
// values
return updateResourceListField(gadget);
});
})
.declareMethod('triggerSubmit', function () {
return this.form.triggerSubmit();
})
.declareJob('updateResourceListField', function () {
var gadget = this,
selectedProject = document.getElementById('field_your_project').value;
return gadget.jio_getAttachment(
'support_request_module',
gadget.hateoas_url + 'support_request_module'
+ "/SupportRequest_getSupportTypeList"
+ "?project_id=" + selectedProject + "&json_flag=True"
).push(function (sp_list) {
var i, j,
sp_select = document.getElementById('field_your_resource');
for (i = sp_select.options.length - 1; i >= 0; i -= 1) {
sp_select.remove(i);
}
for (j = 0; j < sp_list.length; j += 1) {
sp_select.options[j] = new Option(sp_list[j][0], sp_list[j][1]);
}
if (sp_select.options.length === 2) {
sp_select.selectedIndex = 1;
}
});
.declareJob('deferUpdateResourceListField', function () {
return updateResourceListField(this);
})
.onEvent('change', function (evt) {
var gadget = this;
if (evt.target.id === "field_your_project") {
gadget.updateResourceListField();
gadget.deferUpdateResourceListField();
}
}, false, false);
}(window, rJS));
\ No newline at end of file
......@@ -69,7 +69,9 @@
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
......@@ -244,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>962.26853.29747.36369</string> </value>
<value> <string>1017.45366.38938.62225</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,8 +266,8 @@
</tuple>
<state>
<tuple>
<float>1607511772.32</float>
<string>GMT+1</string>
<float>1719991591.9</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
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