/* * << * Davinci * == * Copyright (C) 2016 - 2017 EDP * == * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * >> */ import React from 'react' import { Form, Row, Col, Input, Radio, Button, Tabs, Modal, Checkbox } from 'antd' import { FormComponentProps } from 'antd/lib/form/Form' const TextArea = Input.TextArea const FormItem = Form.Item const RadioGroup = Radio.Group const TabPane = Tabs.TabPane import { Display, DisplayFormType } from './types' const styles = require('containers/Viz/Viz.less') import {IExludeRoles} from 'containers/Viz/components/PortalList' const utilStyles = require('assets/less/util.less') interface IDisplayFormModalProps { projectId: number display: Display, visible: boolean loading: boolean type: DisplayFormType onCheckName: (type, data, resolve, reject) => void onSave: (display: Display, type: string) => void onCancel: () => void exludeRoles?: IExludeRoles[] onChangePermission: (scope: object, e: any) => any } export class DisplayFormModal extends React.PureComponent { private formTypeTitleMapping = { add: '新增', edit: '修改', copy: '复制' } public componentWillReceiveProps (nextProps: IDisplayFormModalProps & FormComponentProps) { const { form, display } = nextProps if (display !== this.props.display) { this.initFormValue(form, display) } } public componentDidMount () { const { form, display } = this.props this.initFormValue(form, display) } private initFormValue (form, display: Display) { if (display) { form.setFieldsValue({ ...display }) } else { form.resetFields() } } private checkNameUnique = (_, value = '', callback) => { const { projectId, onCheckName, type, form } = this.props const id = type === 'edit' ? { id: form.getFieldsValue().id } : void 0 const typeName = 'display' if (!value) { callback() } onCheckName(typeName, { projectId, ...id, name: value }, () => { callback() }, (err) => { callback(err) }) } private onModalOk = () => { const { type, display, projectId, onSave } = this.props this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { onSave({ ...display, ...values, projectId }, type) } }) } private commonFormItemStyle = { labelCol: { span: 6 }, wrapperCol: { span: 16 } } public render () { const { type, visible, loading, form, onCancel, exludeRoles } = this.props const { getFieldDecorator } = form const authControl = exludeRoles && exludeRoles.length ? exludeRoles.map((role) => (
{role.name}
)) : [] const modalButtons = [( ), ( )] return (
{getFieldDecorator('projectId')( )} {getFieldDecorator('id')( )} {getFieldDecorator('name', { rules: [{ required: true, message: '名称 不能为空' }, { validator: this.checkNameUnique }] })( )} {getFieldDecorator('description', { initialValue: '' })(