meraproject/lib/js/bws/react/card/card.js

310 lines
8.2 KiB
JavaScript
Raw Normal View History

var Card, eTab, eTabType;
import '../form/class/form.js';
eTabType = function () {
class eTabType {}
;
eTabType.FORM = 1;
eTabType.TABLE = 2;
return eTabType;
}.call(this);
eTab = function () {
class eTab {}
;
eTab.NAME = 1;
eTab.CONTENT = 2;
eTab.TYPE = 3;
eTab.INIT_OPEN = 4;
return eTab;
}.call(this);
export default window.Card = Card = class Card extends React.Component {
constructor(props) {
var controller_method, options, ref, ref1, ref2, ref3, ref4;
super(props);
options = (ref = props.options) != null ? ref : {};
controller_method = (ref1 = options.controller_method) != null ? ref1 : 'getCardInfo';
this.state = {
ajax: props.ajax === true,
controller: (ref2 = props.controller) != null ? ref2 : '',
id: (ref3 = props.id) != null ? ref3 : '',
loading: props.ajax === true,
data: (ref4 = props.data) != null ? ref4 : [],
tab: null,
in_modal: props.in_modal === true,
controller_method: controller_method
};
this.aRefresh = this.aRefresh.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.onSubmitAndClose = this.onSubmitAndClose.bind(this);
this.uaddEntity = this.uaddEntity.bind(this);
this.aUaddEntity = this.aUaddEntity.bind(this);
this.updateRender = this.updateRender.bind(this);
this.tabs = null;
this.pages = null;
}
onSubmitAndClose(x) {
var base;
this.uaddEntity(x);
return typeof (base = this.props).onClose === "function" ? base.onClose() : void 0;
}
onSubmit(x) {
return this.uaddEntity(x);
}
aUaddEntity(data, cd) {
console.log('aUaddEntity', data, cd);
if (data.success) {
Notify.create({
text: 'Успешно сохранено'
});
return Controllers.update(cd.controller);
} else {
return Notify.create({
color: 'red',
text: 'Ошибка при сохранении: ' + x.error
});
}
}
uaddEntity(x) {
var controller, values; //console.log 'uaddEntity',x
values = x.values;
controller = values.controller;
return API(controller + '/uadd', {
values: values,
dataType: "JSON"
}, this.aUaddEntity, {
controller
});
}
updateRender() {
$(this.pages).perfectScrollbar('update');
$(this.tabs).perfectScrollbar('update');
return $(".content").perfectScrollbar('update');
}
aRefresh(data, cd) {
console.log('aRefresh', data);
return this.setState({
loading: false,
data: data,
tab: null
}, function () {
$(this.pages).perfectScrollbar();
$(this.tabs).perfectScrollbar();
return this.checkInitTab();
});
}
refresh() {
var controller, controller_method, id;
({
controller,
id,
controller_method
} = this.state);
return API(controller + '/' + controller_method, {
id: id,
dataType: "JSON"
}, this.aRefresh);
}
checkInitTab() {
var data, i, results, t, tab, v;
t = this;
({
tab,
data
} = this.state);
if (tab === null) {
if (data.tabs !== void 0 && Array.isArray(data.tabs)) {
results = [];
for (i in data.tabs) {
v = data.tabs[i];
if (v === null) {
continue;
}
console.log(i, v, v[eTab.INIT_OPEN]);
if (v[eTab.INIT_OPEN] === true) {
tab = i;
t.setTab(tab);
break;
} else {
results.push(void 0);
}
}
return results;
}
}
}
componentDidMount() {
if (this.state.ajax === true) {
return this.refresh();
} else {
return this.checkInitTab();
}
}
setTab(x = null) {
return this.setState({
tab: x
}, this.updateRender);
}
render() {
var _this = this;
var cont, content, data, hideSubmitAndClose, i, image, in_modal, index, isForm, loading, page, pages, tab, tabs, title;
({
loading,
data,
tab,
title,
in_modal
} = this.state);
hideSubmitAndClose = !in_modal;
pages = [];
tabs = [];
content = null;
image = null;
if (!loading) {
isForm = data.form !== void 0;
if (isForm) {
content = /*#__PURE__*/React.createElement("div", {
class: "f1_db card_form_edit"
}, /*#__PURE__*/React.createElement("div", {
class: "row"
}, /*#__PURE__*/React.createElement("div", {
class: "c"
}, /*#__PURE__*/React.createElement("div", {
class: "h"
}, data.title, ". \u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435"))), /*#__PURE__*/React.createElement("div", {
class: "block"
}, /*#__PURE__*/React.createElement("div", {
class: "body"
}, /*#__PURE__*/React.createElement("div", {
class: "cont"
}, /*#__PURE__*/React.createElement(Form, {
values: data.values,
inputs: data.form,
onSubmit: this.onSubmit,
onSubmitAndClose: this.onSubmitAndClose,
hideSubmitAndClose: hideSubmitAndClose
})))));
} else {
for (index in data.tabs) {
i = data.tabs[index];
if (i === null) {
continue;
}
if (data.image !== '') {
image = /*#__PURE__*/React.createElement("img", {
src: data.image
});
} // console.log i
tabs.push( /*#__PURE__*/React.createElement("div", {
onClick: this.setTab.bind(this, index),
key: index,
className: "tab" + (index === tab ? ' selected' : '')
}, i[eTab.NAME]));
cont = i[eTab.CONTENT];
content = null;
if (i[eTab.TYPE] === eTabType.TABLE) {
content = /*#__PURE__*/React.createElement("div", {
className: "table"
}, /*#__PURE__*/React.createElement(Table, {
data: cont
}));
}
if (i[eTab.TYPE] === eTabType.FORM) {
content = /*#__PURE__*/React.createElement("div", {
className: "cont"
}, /*#__PURE__*/React.createElement(Form, {
values: cont.values,
inputs: cont.inputs,
onSubmit: this.onSubmit,
onSubmitAndClose: this.onSubmitAndClose,
hideSubmitAndClose: hideSubmitAndClose
}));
}
page = /*#__PURE__*/React.createElement("div", {
className: "card_page",
key: index
}, /*#__PURE__*/React.createElement("div", {
className: "h"
}, i[eTab.NAME]), /*#__PURE__*/React.createElement("div", {
className: "page_content"
}, /*#__PURE__*/React.createElement("div", {
className: "block"
}, /*#__PURE__*/React.createElement("div", {
className: "body"
}, content))));
if (tab === null || tab === -1) {
pages.push(page);
} else if (tab === index) {
pages.push(page);
}
}
if (tabs.length > 0 && tab !== null && tab !== -1) {
tabs.push( /*#__PURE__*/React.createElement("div", {
onClick: this.setTab.bind(this, -1),
key: tabs.length,
className: "tab"
}, "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0432\u0441\u0451"));
}
content = /*#__PURE__*/React.createElement("div", {
className: "card_content"
}, /*#__PURE__*/React.createElement("div", {
className: "pages",
ref: function (i) {
return _this.pages = i;
}
}, /*#__PURE__*/React.createElement("div", {
className: "pages_content"
}, pages)), /*#__PURE__*/React.createElement("div", {
className: "tabs",
ref: function (i) {
return _this.tabs = i;
}
}, /*#__PURE__*/React.createElement("div", null, image, tabs)));
}
}
return /*#__PURE__*/React.createElement("div", {
className: "card"
}, loading ? /*#__PURE__*/React.createElement("div", {
className: "card_loading"
}, "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430...") : content);
}
};
//# sourceMappingURL=card.js.map