UNPKG

ming-demo3

Version:
337 lines (285 loc) 11.4 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); 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 = _interopRequireWildcard(require("react")); var _redux = require("redux"); var _reactRedux = require("react-redux"); var _baseui = require("@mdf/baseui"); var _meta = require("../meta"); var _ModalLight = _interopRequireDefault(require("../common/ModalLight")); var tabsactions = _interopRequireWildcard(require("../../redux/tabs")); var portalactions = _interopRequireWildcard(require("../../redux/portal")); var modalactions = _interopRequireWildcard(require("../../redux/dynamicModal")); var _tree = require("../../redux/tree"); var _Filterkanban = _interopRequireDefault(require("../meta/Filterkanban")); var _env = _interopRequireDefault(require("../../helpers/env")); var VoucherListBillTypes = { 'VoucherList': 'voucher-list', 'ArchiveList': 'voucher-list', 'TreeList': 'voucher-list tree-list', 'Option': 'meta-option' }; var Meta = function (_Component) { (0, _inherits2["default"])(Meta, _Component); function Meta(props) { var _this; (0, _classCallCheck2["default"])(this, Meta); _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(Meta).call(this, props)); _this.state = { currentMode: _env["default"].VOUCHER_STATE_BROWSE, greaterHeight: true }; return _this; } (0, _createClass2["default"])(Meta, [{ key: "componentDidMount", value: function componentDidMount() { var _this2 = this; this.props.viewModel.addListener(this); this.props.viewModel.on('modeChange', function (mode) { _this2.setState({ currentMode: mode }); }); this.props.viewModel.on('afterRenderComponent', function () { var greaterHeight = _this2.refs.container.clientHeight <= _this2.props.height ? false : true; _this2.setState({ greaterHeight: greaterHeight }); }); if (this.refs.container && this.refs.container.clientHeight <= this.props.height) this.setState({ greaterHeight: false }); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { this.props.viewModel.removeListener(this); this.props.viewModel.execute('destroy'); } }, { key: "shouldComponentUpdate", value: function shouldComponentUpdate(nextProps, nextState) { return nextProps.id !== this.props.id || nextState.currentMode !== this.state.currentMode || nextState.greaterHeight !== this.state.greaterHeight || nextProps.width !== this.props.width; } }, { key: "communication", value: function communication(action) { var _this$props = this.props, tabsactions = _this$props.tabsactions, portalactions = _this$props.portalactions, index = _this$props.index, modalactions = _this$props.modalactions, execHandler = _this$props.execHandler, viewModel = _this$props.viewModel; if (action.type === 'asyncImport') { portalactions.doAsyncImport(action.payload); return; } if (action.type === 'refresh') return this.handleRefresh(); if (action.type === 'close') return this.handleClose(); if (action.type === 'return') return this.handleReturn(action.payload); if (action.type === 'modal') { if (action.payload.mode === 'html') { (0, _ModalLight["default"])({ content: _react["default"].createElement("div", { dangerouslySetInnerHTML: { __html: action.payload.html } }) }); return; } if (action.payload.mode === 'inner') { modalactions.openMetaModal(action.payload.groupCode, action.payload.viewModel); return; } return action.payload.data === false ? modalactions.closeModal() : modalactions.openModal(action.payload.key, action.payload.data); } if (action.type === 'menu') return execHandler(action.payload.menuCode, action.payload.carryData); var _action$payload = action.payload, params = _action$payload.params, metaData = _action$payload.metaData; var title = params && params.params && params.params.title || action.payload.title; delete action.payload.title; delete action.payload.params; if (metaData) { var metaTemplate = metaData.view; var templateType = metaTemplate.templateType && metaTemplate.templateType.trim().toLocaleLowerCase(); if (templateType === 'modal') { modalactions.openMetaRunnerModal(title, action.payload); return; } delete metaData.view.templateType; } portalactions.addItem(index, { title: title, content: action.payload, params: params || action.payload, parent: viewModel }); } }, { key: "handleReturn", value: function handleReturn(payload) { if (window.parent !== window && cb.rest.AppContext.query.random) { window.parent.postMessage({ key: 'return', random: cb.rest.AppContext.query.random }, '*'); return; } var _this$props2 = this.props, portalactions = _this$props2.portalactions, modalactions = _this$props2.modalactions, index = _this$props2.index, viewModel = _this$props2.viewModel; var _viewModel$getParams = viewModel.getParams(), callbackurl = _viewModel$getParams.callbackurl; if (callbackurl) { window.location.href = callbackurl; return; } if (index) portalactions.delItem(index);else modalactions.closeModal(); var parentViewModel = viewModel.getCache('parentViewModel'); if (viewModel.getParams().domain === false) { while (parentViewModel.getCache('parentViewModel')) { parentViewModel = parentViewModel.getCache('parentViewModel'); } } if (parentViewModel) parentViewModel.execute('back', payload); } }, { key: "handleClose", value: function handleClose() { var _this$props3 = this.props, tabsactions = _this$props3.tabsactions, index = _this$props3.index; tabsactions.deleteItem(index); } }, { key: "handleRefresh", value: function handleRefresh() { var _this$props4 = this.props, portalactions = _this$props4.portalactions, index = _this$props4.index, portal = _this$props4.portal; var current = portal.tabs[index]; if (!current || !current.panes.length) return; portalactions.delItem(index, { refresh: true }); var currentPanes = current.panes; if (currentPanes.length === 1) { var callback = function callback(returnData) { var title = returnData.title, content = returnData.content, params = returnData.params; params.refresh = true; portalactions.addItem(index, { title: title, content: content, params: params }); }; cb.loader.runCommandLine('menu', currentPanes[0].params, null, callback); } else { var _currentPanes = currentPanes[currentPanes.length - 1], title = _currentPanes.title, content = _currentPanes.content, params = _currentPanes.params, parent = _currentPanes.parent; params.refresh = true; if (content.vm) { cb.loader.runCommandLine('bill', params, parent); } else { portalactions.addItem(index, { title: title, content: content, params: params, parent: parent }); } } } }, { key: "render", value: function render() { var _this$props5 = this.props, metaData = _this$props5.metaData, viewModel = _this$props5.viewModel, width = _this$props5.width, height = _this$props5.height, index = _this$props5.index; var metaTemplate = metaData.view; var templateType = metaTemplate.templateType && metaTemplate.templateType.trim().toLocaleLowerCase(); if (templateType && templateType.indexOf('kanban') > -1) { return _react["default"].createElement(_Filterkanban["default"], { meta: metaData.view, viewModel: viewModel, index: index }); } var className = metaData && VoucherListBillTypes[metaData.cBillType] || ''; var viewModelParams = viewModel.getParams(); var component = null; var _this$state = this.state, currentMode = _this$state.currentMode, greaterHeight = _this$state.greaterHeight; var classNames = [className]; classNames.push('container-' + (currentMode === _env["default"].VOUCHER_STATE_BROWSE ? 'browse' : 'edit') + '-mode'); classNames.push('container-' + (greaterHeight ? 'greater' : 'less') + '-height'); if (viewModelParams.bWorkbench && viewModelParams.dimensionKeys && viewModelParams.targetData) component = _react["default"].createElement(_meta.Workbench, { className: "height-100", meta: metaData.view, viewModel: viewModel, width: width, height: height, index: index });else if (viewModelParams.source === 'pull') component = _react["default"].createElement(_meta.PullSelect, { meta: metaData.view, viewModel: viewModel, width: width, height: height, index: index });else if (metaData) component = _react["default"].createElement(_meta.Container, { className: "height-100", meta: metaData.view, viewModel: viewModel, width: width, height: height, index: index }); return _react["default"].createElement("div", { ref: "container", className: classNames.join(' ') }, component); } }]); return Meta; }(_react.Component); function mapStateToProps(state) { return { portal: state.portal.toJS() }; } function mapDispatchToProps(dispatch) { return { tabsactions: (0, _redux.bindActionCreators)(tabsactions, dispatch), portalactions: (0, _redux.bindActionCreators)(portalactions, dispatch), modalactions: (0, _redux.bindActionCreators)(modalactions, dispatch), execHandler: (0, _redux.bindActionCreators)(_tree.execHandler, dispatch) }; } var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(Meta); exports["default"] = _default; //# sourceMappingURL=index.js.map