|
|
@@ -1,12 +1,14 @@
|
|
|
import {AjaxReq, fetchHeaders} from "./OMGUtils";
|
|
|
|
|
|
let CSS_EDITOR_ACTIVE = 'shadow rounded-lg bg-dark text-light';
|
|
|
+let CSS_EDITOR_ROW_ACTIVE = 'bg-info';
|
|
|
|
|
|
-let tableSelector = null;
|
|
|
+let _tableSelector = null;
|
|
|
+let _controllerURL = '';
|
|
|
|
|
|
function GetTableFieldNames() {
|
|
|
let columnNames = [];
|
|
|
- $(`${tableSelector} thead th`).each(function (i, e) {
|
|
|
+ $(`${_tableSelector} thead th`).each(function (i, e) {
|
|
|
columnNames.push(e.innerText);
|
|
|
});
|
|
|
|
|
|
@@ -14,47 +16,63 @@ function GetTableFieldNames() {
|
|
|
}
|
|
|
|
|
|
function GetColumnDef(colIndex, name) {
|
|
|
- return $(`${tableSelector} thead th:eq(${colIndex})`).attr(name);
|
|
|
+ return $(`${_tableSelector} thead th:eq(${colIndex})`).attr(name);
|
|
|
}
|
|
|
|
|
|
function cancelEdit(el) {
|
|
|
el.innerText = $(el).data('oldvalue');
|
|
|
- $(el).parent('tr').removeClass('dt-editing-cell bg-warning');
|
|
|
+ $(el).parent('tr').removeClass(`dt-editing-cell ${CSS_EDITOR_ROW_ACTIVE}`);
|
|
|
$(el).removeClass(CSS_EDITOR_ACTIVE);
|
|
|
$('body').focus();
|
|
|
el.contentEditable = false;
|
|
|
}
|
|
|
|
|
|
-function EditTableInit(tableRef) {
|
|
|
+function EditTableInit(tableRef, controllerURL) {
|
|
|
|
|
|
- tableSelector = tableRef;
|
|
|
- let tableBodyRef = $(`${tableSelector} tbody`);
|
|
|
+ _tableSelector = tableRef;
|
|
|
+ _controllerURL = controllerURL;
|
|
|
+
|
|
|
+ let tableBodyRef = $(`${_tableSelector} tbody`);
|
|
|
|
|
|
$(tableRef).DataTable({
|
|
|
"ajax": {
|
|
|
- "url": `${BASEURL}/masterdataset`,
|
|
|
+ "url": _controllerURL,
|
|
|
"type": 'POST',
|
|
|
"data": {
|
|
|
'action': 'getData'
|
|
|
},
|
|
|
'dataSrc': function (data) {
|
|
|
- $(tableSelector).parent('.dataTables_wrapper').parent().removeClass('d-none');
|
|
|
+ $(_tableSelector).parent('.dataTables_wrapper').parent().removeClass('d-none');
|
|
|
return data;
|
|
|
}
|
|
|
},
|
|
|
'lengthChange': false,
|
|
|
- dom: 'Bfrtip', // for buttons
|
|
|
+ dom: 'frtBip', // for buttons
|
|
|
order: [[0, "asc"]],
|
|
|
buttons: [
|
|
|
{
|
|
|
- text: 'Save all',
|
|
|
+ text: 'Completa lista',
|
|
|
+ action: function (e, dt, node, config) {
|
|
|
+ let postHeadersContentType = fetchHeaders;
|
|
|
+ postHeadersContentType['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
+ AjaxReq(_controllerURL, {
|
|
|
+ headers: postHeadersContentType,
|
|
|
+ method: 'POST',
|
|
|
+ body: 'action=closelist'
|
|
|
+ }).fetchPromise()
|
|
|
+ .then(json => alert(`${json.code} - ${json.err}`))
|
|
|
+ .catch(err => alert(err.url, `${err.status} (${err.statusText})`));
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: 'Annulla lista',
|
|
|
action: function (e, dt, node, config) {
|
|
|
let postHeadersContentType = fetchHeaders;
|
|
|
postHeadersContentType['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
- AjaxReq(`${BASEURL}/masterdataset`, {
|
|
|
+ AjaxReq(_controllerURL, {
|
|
|
headers: postHeadersContentType,
|
|
|
method: 'POST',
|
|
|
- body: 'action=saveall'
|
|
|
+ body: 'action=cancellist'
|
|
|
}).fetchPromise()
|
|
|
.then(json => alert(`${json.code} - ${json.err}`))
|
|
|
.catch(err => alert(err.url, `${err.status} (${err.statusText})`));
|
|
|
@@ -72,7 +90,7 @@ function EditTableInit(tableRef) {
|
|
|
|
|
|
this.contentEditable = true; // enable html edit
|
|
|
$this.data('oldvalue', this.innerText); // backup actual value
|
|
|
- $this.parent('tr').addClass('dt-editing-cell bg-warning'); // mark the row of current cell
|
|
|
+ $this.parent('tr').addClass(`dt-editing-cell ${CSS_EDITOR_ROW_ACTIVE}`); // mark the row of current cell
|
|
|
$this.addClass(CSS_EDITOR_ACTIVE);
|
|
|
$this.focus();
|
|
|
});
|
|
|
@@ -103,7 +121,7 @@ function EditTableInit(tableRef) {
|
|
|
let postHeadersContentType = fetchHeaders;
|
|
|
delete postHeadersContentType['Content-Type'];
|
|
|
|
|
|
- AjaxReq(`${BASEURL}/masterdataset`, {
|
|
|
+ AjaxReq(_controllerURL, {
|
|
|
headers: postHeadersContentType,
|
|
|
method: 'POST',
|
|
|
body: ajaxData
|