@handie/squirtle
Version:
Widgets for Handie-React
69 lines (68 loc) • 2.84 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { getRenderer, resolveSafePropsFromConfig, } from 'handie-react';
import { DialogViewStructuralWidget } from 'handie-react/dist/widgets/class';
import { isOpenerInlineObjectView } from './helper';
import style from './style.scss';
export default class FormDialogViewWidget extends DialogViewStructuralWidget {
get dialogTitle() {
const { title, moduleLabel } = this.config;
if (title) {
return title;
}
return moduleLabel
? `${isOpenerInlineObjectView(this.$$view.getOpener()) ? '修改' : '新增'}${moduleLabel}`
: '';
}
initFormDialogViewContextEvents() {
const opener = this.$$view.getOpener();
const callback = () => {
if (opener.getView().category === 'list') {
opener.reload();
}
else if (isOpenerInlineObjectView(opener)) {
opener.getParent().reload();
}
else {
opener.emit(`dialog-view-submit.${`${opener.getId()}:${[
this.$$module.getModuleName(),
this.$$view.getView().name,
].join('-')}`}`, this.state.value);
}
this.closeDialog();
};
this.on('submit', () => {
this.$$view.setBusy(true);
if (isOpenerInlineObjectView(opener)) {
this.$$view
.update(this.state.value, callback, message => this.$$app.error(message))
.finally(() => this.$$view.setBusy(false));
}
else {
this.$$view
.insert(this.state.value, callback, message => this.$$app.error(message))
.finally(() => this.$$view.setBusy(false));
}
});
}
render() {
const FormRenderer = getRenderer('FormRenderer');
const props = {
fields: this.fields,
value: this.state.value,
validation: this.state.validation,
config: Object.assign({ formControlLabelWidth: 90, formControlSize: 'small' }, resolveSafePropsFromConfig(this.config, ['moduleLabel'])),
onChange: this.onFieldValueChange,
};
return this.renderDialog({
className: this.getStyleClassName('FormDialogViewWidget'),
actionBarClassName: this.getStyleClassName('FormDialogViewWidget-actionBar'),
actionText: { submitActionText: '确定' },
children: FormRenderer ? _jsx(FormRenderer, Object.assign({}, props, { children: this.props.children }), void 0) : null,
});
}
componentWillMount() {
super.componentWillMount();
this.setStyleClassNames(style);
this.initFormDialogViewContextEvents();
}
}