meraproject/lib/js/bws/react/table/table.js
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

232 lines
5.8 KiB
JavaScript

var Table;
import './thead.js';
import './tbody.js';
import './TableTitle.js';
import './../ui/pagination.js';
import './../ui/modal.js';
import './../common.js';
import autoBind from 'react-autobind';
export default window.Table = Table = class Table extends React.Component {
constructor(props) {
super(props);
this.state = this.prepareProps(props);
this.pagination = null;
this.force_page = null;
autoBind(this);
}
prepareProps(props) {
var data, ref, ref1, ref10, ref11, ref12, ref13, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, s;
data = props.data;
console.log('query', data, data.query);
return s = {
columns: (ref = data.columns) != null ? ref : [],
data: (ref1 = data.data) != null ? ref1 : [],
pages: (ref2 = data.pages) != null ? ref2 : 0,
page: (ref3 = data.page) != null ? ref3 : 0,
controller: (ref4 = data.controller) != null ? ref4 : '',
column_render: (ref5 = data.column_render) != null ? ref5 : {},
title: (ref6 = data.title) != null ? ref6 : {},
init_data: (ref7 = data.init_data) != null ? ref7 : {},
row_click: (ref8 = data.row_click) != null ? ref8 : -1,
count: (ref9 = data.count) != null ? ref9 : 10,
where: (ref10 = data.where) != null ? ref10 : null,
hide_thead: data.hide_thead === true,
hide_title: data.hide_title === true,
sortable: data.sortable === true,
hide_columns: (ref11 = data.hide_columns) != null ? ref11 : [],
sort: (ref12 = data.sort) != null ? ref12 : [],
filter: (ref13 = data.filter) != null ? ref13 : []
};
}
destroy() {
return Controllers.remove(this.state.controller, this);
}
componentDidMount() {
$(this.wrap).on('destroyed ', this.destroy);
Controllers.add(this.state.controller, this);
return A.P.initMini($(this.wrap));
}
aReload(data) {
var a, e;
try {
data = JSON.parse(data);
} catch (error) {
e = error;
data = {};
}
a = this.prepareProps({
data
}); //this.onSelectAll(false)
this.setState(a, function () {
psUpdate();
return this.tbody.init();
});
return A.P.initMini($(this.wrap));
}
openUadd() {
var ref;
return (ref = this.title) != null ? ref.createNew() : void 0;
}
reload() {
var count, filter, hide_columns, hide_thead, hide_title, history, init_data, page, row_click, s, sort, sortable, where;
({
count,
row_click,
init_data,
where,
hide_thead,
hide_title,
hide_columns,
sortable,
sort,
filter
} = this.state);
page = 0;
if (this.force_page !== null) {
page = this.force_page;
this.force_page = null;
} else {
if (this.pagination != null) {
page = this.pagination.state.now - 1;
}
}
s = {
page: page,
2: sort,
// sort
7: count,
// query::count per page
4: where,
// query::where
row_click: row_click,
init_data: init_data,
hide_thead: hide_thead,
hide_title: hide_title,
HIDE_COLUMNS: hide_columns,
sortable: sortable,
filter: filter
}; //console.log 'reload table',s
API(this.state.controller + '/getTableData', s, this.aReload.bind(this));
history = {
page: page,
count: count,
filter: filter
};
return H.SEARCH.setValue(this.state.controller, JSON.stringify(history));
}
onDelete() {
var i, ids, j, len, s;
s = this.tbody.getSelected();
ids = [];
this.onSelectAll(false);
for (j = 0, len = s.length; j < len; j++) {
i = s[j];
ids.push(i.state.id);
}
return API(this.state.controller + '/removeByIds', {
ids
}, this.reload);
}
onSelectAll(x) {
this.tbody.selectAll(x);
this.title.setSelectCount(x ? this.state.data.length : 0);
return this.thead.setSelected(x);
}
onSelectRow() {
var s;
s = this.tbody.getSelected();
this.title.setSelectCount(s.length);
return this.thead.setSelected(s.length === this.state.data.length);
}
setFilter(f) {
this.force_page = 0;
this.pagination.setNow(1);
return this.setState({
filter: f
}, this.reload);
}
render() {
var _this = this;
var columns, controller, data, hide_thead, hide_title, init_data, page, pages, sortable, title;
({
columns,
data,
pages,
page,
controller,
title,
init_data,
hide_thead,
hide_title,
sortable
} = this.state);
return /*#__PURE__*/React.createElement("div", {
ref: function (i) {
return _this.wrap = i;
}
}, /*#__PURE__*/React.createElement(TableTitle, {
controller: controller,
title: title,
init_data: init_data,
ref: function (i) {
return _this.title = i;
},
hide_title: hide_title,
onDelete: this.onDelete
}), /*#__PURE__*/React.createElement("table", {
cellPadding: 0,
cellSpacing: 0
}, /*#__PURE__*/React.createElement(Thead, {
columns: columns,
hide_thead: hide_thead,
sortable: sortable,
ref: function (i) {
return _this.thead = i;
},
onSelect: this.onSelectAll,
onSetFilter: this.setFilter
}), /*#__PURE__*/React.createElement(Tbody, {
columns: columns,
data: data,
controller: controller,
column_render: this.state.column_render,
row_click: this.state.row_click,
openUadd: this.openUadd,
sortable: sortable,
onSelect: this.onSelectRow,
ref: function (i) {
return _this.tbody = i;
}
})), /*#__PURE__*/React.createElement(Pagination, {
ref: function (i) {
return _this.pagination = i;
},
pages: pages,
now: page + 1,
onChange: this.reload
}));
}
};
//# sourceMappingURL=table.js.map