UPDATE
So I have applied the recommended changes but I am now stuck with adding polyfill to make it work with IE11
In my head I have
<!-- Bootstrap -->
<link href="/assets/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="/assets/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="/assets/jquery/dist/jquery.js"></script>
<script src="/assets/jquery-ui/jquery-ui.js"></script>
<script src="/assets/fetch/fetch.js"></script>
<script src="/assets/es6-promise/dist/es6-promise.min.js"></script>
The JavaScript code
//To add to window
if (!window.Promise) {
window.Promise = Promise;
}
const CommsMatrix = {
getCMDStatuses: function(){
return fetch('/api/user/list/comms/matrix/data/format/json'+'?csrf='+$.csrfParam('csrf')+'&select=distinct(status)&orderby=status', {
// body: new URLSearchParams({ csrf: $.csrfParam('csrf'), select:
// 'distinct(status)', orderby: 'status' })
credentials: 'include'
})
.then(response => {
return response.headers.error ? Promise.reject(response.headers.error) : response.json();
}).then(body => {
return body.body.recordset.record.map(v => v.STATUS)
})
},
getSupportedProtocols: function(){
return fetch('/api/user/list/sys/list/protocols/format/json'+'?csrf='+$.csrfParam('csrf')+'&orderby=name', {
// body: new URLSearchParams({ csrf: $.csrfParam('csrf'), orderby:
// 'name' })
credentials: 'include'
})
.then(response => {
return response.headers.error ? Promise.reject(response.headers.error) : response.json();
}).then(body => {
return body.body.recordset.record.map(v => v.NAME)
})
}
}
Promise.all([CommsMatrix.getCMDStatuses(), CommsMatrix.getSupportedProtocols()])
// Destructuring the 2-item array into statuses and protocols variables
.then(([ statuses, protocols ]) => {
// You've got statuses and protocols loaded
selectField = HTMLFormTag.createSelect(statuses, true, false, 'To implement');
selectField.setAttribute("name", 'status['+counter+']');
selectField = selectField.outerHTML;
selectProtocolField = HTMLFormTag.createSelect(protocols, true, false, 'TCP');
selectProtocolField.setAttribute("name", 'protocol['+counter+']');
selectProtocolField = selectProtocolField.outerHTML;
// Automatically add a first row of data
$('#addRow').click();
});
In IE11 it complains in 3 places. syntax error on .then(response => {
and .then(([ statuses, protocols ]) => {
and SCRIPT438: Object doesn't support property or method 'csrfParam'