// Copyright 2021 The Casdoor Authors. All Rights Reserved. // // 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 {Button, Card, Col, Input, Row, Select, Switch} from 'antd'; import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as LdapBackend from "./backend/LdapBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; import {LinkOutlined} from "@ant-design/icons"; import LdapTable from "./LdapTable"; const { Option } = Select; class OrganizationEditPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, organizationName: props.match.params.organizationName, organization: null, ldaps: null, }; } UNSAFE_componentWillMount() { this.getOrganization(); this.getLdaps(); } getOrganization() { OrganizationBackend.getOrganization("admin", this.state.organizationName) .then((organization) => { this.setState({ organization: organization, }); }); } getLdaps() { LdapBackend.getLdaps(this.state.organizationName) .then(res => { let resdata = [] if (res.status === "ok") { if (res.data !== null) { resdata = res.data; } } this.setState({ ldaps: resdata }) }) } parseOrganizationField(key, value) { // if ([].includes(key)) { // value = Setting.myParseInt(value); // } return value; } updateOrganizationField(key, value) { value = this.parseOrganizationField(key, value); let organization = this.state.organization; organization[key] = value; this.setState({ organization: organization, }); } renderOrganization() { return ( {i18next.t("organization:Edit Organization")}     } style={(Setting.isMobile())? {margin: '5px'}:{}} type="inner"> {Setting.getLabel(i18next.t("general:Name"), i18next.t("general:Name - Tooltip"))} : { this.updateOrganizationField('name', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Display name"), i18next.t("general:Display name - Tooltip"))} : { this.updateOrganizationField('displayName', e.target.value); }} /> {Setting.getLabel("Favicon", i18next.t("general:Favicon - Tooltip"))} : URL: } value={this.state.organization.favicon} onChange={e => { this.updateOrganizationField('favicon', e.target.value); }} /> {i18next.t("general:Preview")}: {this.state.organization.favicon} {Setting.getLabel(i18next.t("organization:Website URL"), i18next.t("organization:Website URL - Tooltip"))} : } value={this.state.organization.websiteUrl} onChange={e => { this.updateOrganizationField('websiteUrl', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Password type"), i18next.t("general:Password type - Tooltip"))} : {Setting.getLabel(i18next.t("general:Password salt"), i18next.t("general:Password salt - Tooltip"))} : { this.updateOrganizationField('passwordSalt', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Phone prefix"), i18next.t("general:Phone prefix - Tooltip"))} : { this.updateOrganizationField('phonePrefix', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Default avatar"), i18next.t("general:Default avatar - Tooltip"))} : URL: } value={this.state.organization.defaultAvatar} onChange={e => { this.updateOrganizationField('defaultAvatar', e.target.value); }} /> {i18next.t("general:Preview")}: {this.state.organization.defaultAvatar} {Setting.getLabel(i18next.t("general:Master password"), i18next.t("general:Master password - Tooltip"))} : { this.updateOrganizationField('masterPassword', e.target.value); }} /> {Setting.getLabel(i18next.t("organization:Soft deletion"), i18next.t("organization:Soft deletion - Tooltip"))} : { this.updateOrganizationField('enableSoftDeletion', checked); }} /> {Setting.getLabel(i18next.t("general:LDAPs"), i18next.t("general:LDAPs - Tooltip"))} : { this.setState({ldaps: value}) }} /> ) } submitOrganizationEdit(willExist) { let organization = Setting.deepCopy(this.state.organization); OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization) .then((res) => { if (res.msg === "") { Setting.showMessage("success", `Successfully saved`); this.setState({ organizationName: this.state.organization.name, }); if (willExist) { this.props.history.push(`/organizations`); } else { this.props.history.push(`/organizations/${this.state.organization.name}`); } } else { Setting.showMessage("error", res.msg); this.updateOrganizationField('name', this.state.organizationName); } }) .catch(error => { Setting.showMessage("error", `Failed to connect to server: ${error}`); }); } render() { return (
{ this.state.organization !== null ? this.renderOrganization() : null }
); } } export default OrganizationEditPage;