UNPKG

ming-demo3

Version:
206 lines (180 loc) 6.51 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _react = _interopRequireDefault(require("react")); var _baseui = require("@mdf/baseui"); var _label = _interopRequireDefault(require("./label")); var _text = _interopRequireDefault(require("./text")); var CheckboxGroup = _baseui.Checkbox.CheckboxGroup; var CheckBox = function (_React$Component) { (0, _inherits2["default"])(CheckBox, _React$Component); function CheckBox(props) { var _this; (0, _classCallCheck2["default"])(this, CheckBox); _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(CheckBox).call(this, props)); var cStyle = props.cStyle; var config = null; if (cStyle) { try { config = JSON.parse(cStyle); } catch (e) { config = {}; } } var _bHidden = props.bHidden == undefined ? props.bHidden : props.bHideen; _this.state = Object.assign({ type: props.type, bIsNull: props.bIsNull, value: props.value, visible: !_bHidden, disabled: props.disabled }, config); return _this; } (0, _createClass2["default"])(CheckBox, [{ key: "componentDidMount", value: function componentDidMount() { if (this.props.model) this.props.model.addListener(this); } }, { key: "componentDidUpdate", value: function componentDidUpdate() { if (this.props.model) this.props.model.addListener(this); } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if (nextProps.model) { if (!this.props.model) { nextProps.model.addListener(this); } } else { if (this.props.model) this.props.model.removeListener(this); if (nextProps.value != 'undefined' & nextProps.value != undefined) { this.setState({ value: nextProps.value, disabled: nextProps.disabled }); } } } }, { key: "onChange", value: function onChange(e) { var value = e.target.checked; if (this.props.model) { this.props.model.setValue(value, true); this.props.model.fireEvent('check', value); } else { this.props.onChange && this.props.onChange(value); } if (this.props.searchAfterValueChange) { this.props.searchAfterValueChange(); } } }, { key: "setDisabled", value: function setDisabled(value) { this.setState({ disabled: value }); } }, { key: "setVisible", value: function setVisible(value) { this.setState({ visible: value }); } }, { key: "baseControl", value: function baseControl(caption) { var _this2 = this; var control; if (this.props.dataSource) { if (Array.isArray(this.props.dataSource)) { control = _react["default"].createElement(CheckboxGroup, { options: this.props.dataSource, disabled: this.state.disabled, defaultValue: this.props.value || this.props.defaultValue, onChange: function onChange(e) { return _this2.onChange(e); } }); } else { control = _react["default"].createElement(_baseui.Checkbox, { onChange: function onChange(e) { return _this2.onChange(e); }, disabled: this.state.disabled || this.state.readOnly, checked: this.state.value || this.props.value }, this.props.dataSource.text); } } else { var checked = this.state.value; if (checked === '0' || checked === 'false') checked = false; control = _react["default"].createElement(_baseui.Checkbox, { onChange: function onChange(e) { return _this2.onChange(e); }, disabled: this.state.disabled || this.state.readOnly, checked: checked }, caption); if (caption && !this.state.readOnly && this.state.bIsNull === false) control = _react["default"].createElement("span", null, control, _react["default"].createElement(_baseui.Icon, { type: "star" })); } return control; } }, { key: "relatedControl", value: function relatedControl(caption) { var control = this.baseControl(caption); var relatedControl = this.props.relatedControl; if (!relatedControl) return control; return _react["default"].createElement("div", { className: "has-related" }, _react["default"].createElement("div", { className: "viewCell" }, control), relatedControl); } }, { key: "getControl", value: function getControl() { var cShowCaption = this.props.cShowCaption; var type = this.state.type; if (type === 'simple') return this.relatedControl(cShowCaption ? cShowCaption : this.props.title); var title = !this.state.readOnly && this.state.bIsNull === false && cShowCaption ? _react["default"].createElement("label", null, _react["default"].createElement(_baseui.Icon, { type: "star" }), cShowCaption) : _react["default"].createElement("label", null, cShowCaption); var control = cShowCaption ? _react["default"].createElement(_label["default"], { control: this.relatedControl(), title: title }) : this.relatedControl(); return control; } }, { key: "render", value: function render() { var control = this.getControl(); var style = this.state.visible ? {} : { display: 'none' }; return _react["default"].createElement("div", { style: style, className: this.state.classname || '' }, control); } }]); return CheckBox; }(_react["default"].Component); exports["default"] = CheckBox; //# sourceMappingURL=checkbox.js.map