<commit_before>var React = require('react');
var ReactDOM = require('react-dom');

var ReactBootstrap = require('react-bootstrap');
var Grid = ReactBootstrap.Grid;
var Row = ReactBootstrap.Row;
var Col = ReactBootstrap.Col;
var Form = ReactBootstrap.Form;
var FormGroup = ReactBootstrap.FormGroup;
var FormControl = ReactBootstrap.FormControl;
var Checkbox = ReactBootstrap.Checkbox;
var ControlLabel = ReactBootstrap.ControlLabel;
var Button = ReactBootstrap.Button;
var ButtonGroup = ReactBootstrap.ButtonGroup;
var Glyphicon = ReactBootstrap.Glyphicon;
var ListGroup = ReactBootstrap.ListGroup;
var ListGroupItem = ReactBootstrap.ListGroupItem;
var Alert = ReactBootstrap.Alert;
var Modal = ReactBootstrap.Modal;
var Collapse = ReactBootstrap.Collapse;
var Tabs = ReactBootstrap.Tabs;
var Tab = ReactBootstrap.Tab;
var Panel = ReactBootstrap.Panel;

var Combobox = require('react-widgets').Combobox;

var models = require('../models');
var Security = models.Security;
var Account = models.Account;
var AccountType = models.AccountType;
var AccountTypeList = models.AccountTypeList;

var AccountCombobox = require('./AccountCombobox');
var AccountRegister = require('./AccountRegister');

const AddEditAccountModal = React.createClass({
	getInitialState: function() {
		var s = {
			accountid: -1,
			security: 1,
			parentaccountid: -1,
			type: 1,
			name: "",
			ofxurl: "",
			ofxorg: "",
			ofxfid: "",
			ofxuser: "",
			ofxbankid: "",
			ofxacctid: "",
			ofxaccttype: "CHECKING",
			ofxclientuid: "",
			ofxappid: "",
			ofxappver: "",
			ofxversion: "",
			ofxnoindent: false,
		};
		if (this.props.editAccount != null) {
			s.accountid = this.props.editAccount.AccountId;
			s.name = this.props.editAccount.Name;
			s.security = this.props.editAccount.SecurityId;
			s.parentaccountid = this.props.editAccount.ParentAccountId;
			s.type = this.props.editAccount.Type;
			s.ofxurl = this.props.editAccount.OFXURL;
			s.ofxorg = this.props.editAccount.OFXORG;
			s.ofxfid = this.props.editAccount.OFXFID;
			s.ofxuser = this.props.editAccount.OFXUser;
			s.ofxbankid = this.props.editAccount.OFXBankID;
			s.ofxacctid = this.props.editAccount.OFXAcctID;
			s.ofxaccttype = this.props.editAccount.OFXAcctType;
			s.ofxclientuid = this.props.editAccount.OFXClientUID;
			s.ofxappid = this.props.editAccount.OFXAppID;
			s.ofxappver = this.props.editAccount.OFXAppVer;
			s.ofxversion = this.props.editAccount.OFXVersion;
			s.ofxnoindent = this.props.editAccount.OFXNoIndent;
		} else if (this.props.initialParentAccount != null) {
			s.security = this.props.initialParentAccount.SecurityId;
			s.parentaccountid = this.props.initialParentAccount.AccountId;
			s.type = this.props.initialParentAccount.Type;
		}
		return s;
	},
	handleCancel: function() {
		if (this.props.onCancel != null)
			this.props.onCancel();
	},
	handleChange: function() {
		this.setState({
			name: ReactDOM.findDOMNode(this.refs.name).value,
			ofxurl: ReactDOM.findDOMNode(this.refs.ofxurl).value,
			ofxorg: ReactDOM.findDOMNode(this.refs.ofxorg).value,
			ofxfid: ReactDOM.findDOMNode(this.refs.ofxfid).value,
			ofxuser: ReactDOM.findDOMNode(this.refs.ofxuser).value,
			ofxbankid: ReactDOM.findDOMNode(this.refs.ofxbankid).value,
			ofxacctid: ReactDOM.findDOMNode(this.refs.ofxacctid).value,
			ofxaccttype: ReactDOM.findDOMNode(this.refs.ofxaccttype).value,
			ofxclientuid: ReactDOM.findDOMNode(this.refs.ofxclientuid).value,
			ofxappid: ReactDOM.findDOMNode(this.refs.ofxappid).value,
			ofxappver: ReactDOM.findDOMNode(this.refs.ofxappver).value,
			ofxversion: ReactDOM.findDOMNode(this.refs.ofxversion).value,
		});
	},

	handleNoIndentClick: function() {
		this.setState({ofxnoindent: !this.state.ofxnoindent});
	},
	handleSecurityChange: function(security) {
		if (security.hasOwnProperty('SecurityId'))
			this.setState({
				security: security.SecurityId
			});
	},
	handleTypeChange: function(type) {
		if (type.hasOwnProperty('TypeId'))
			this.setState({
				type: type.TypeId
			});
	},
	handleParentChange: function(parentAccount) {
		this.setState({parentaccountid: parentAccount.AccountId});
	},
	handleSubmit: function() {
		var a = new Account();

		if (this.props.editAccount != null)
			a.AccountId = this.state.accountid;
		a.Name = this.state.name;
		a.ParentAccountId = this.state.parentaccountid;
		a.SecurityId = this.state.security;
		a.Type = this.state.type;

		a.OFXURL = this.state.ofxurl;
		a.OFXORG = this.state.ofxorg;
		a.OFXFID = this.state.ofxfid;
		a.OFXUser = this.state.ofxuser;
		a.OFXBankID = this.state.ofxbankid;
		a.OFXAcctID = this.state.ofxacctid;
		a.OFXAcctType = this.state.ofxaccttype;
		a.OFXClientUID = this.state.ofxclientuid;
		a.OFXAppID = this.state.ofxappid;
		a.OFXAppVer = this.state.ofxappver;
		a.OFXVersion = this.state.ofxversion;
		a.OFXNoIndent = this.state.ofxnoindent;

		if (this.props.onSubmit != null)
			this.props.onSubmit(a);
	},
	componentWillReceiveProps: function(nextProps) {
		if (nextProps.show && !this.props.show) {
			this.setState(this.getInitialState());
		}
	},
	render: function() {
		var headerText = (this.props.editAccount != null) ? "Edit" : "Create New";
		var buttonText = (this.props.editAccount != null) ? "Save Changes" : "Create Account";
		var rootName = (this.props.editAccount != null) ? "Top-level Account" : "New Top-level Account";
		var ofxBankIdName = "Broker ID";
		var ofxAcctType = [];
		if (this.state.type != AccountType.Investment) {
			ofxBankIdName = "Bank ID";
			ofxAcctType = (
				<FormGroup>
					<Col componentClass={ControlLabel} xs={2}>Account Type</Col>
					<Col xs={10}>
					<FormControl
							componentClass="select"
							placeholder="select"
							value={this.state.ofxaccttype}
							onChange={this.handleChange}
							ref="ofxaccttype">
						<option value="CHECKING">Checking</option>
						<option value="SAVINGS">Savings</option>
						<option value="CC">Credit Card</option>
						<option value="MONEYMRKT">Money Market</option>
						<option value="CREDITLINE">Credit Line</option>
						<option value="CD">CD</option>
					</FormControl>
					</Col>
				</FormGroup>
			);
		}
		var bankIdDisabled = (this.state.ofxaccttype == "CC") ? true : false;
		return (
			<Modal show={this.props.show} onHide={this.handleCancel}>
				<Modal.Header closeButton>
					<Modal.Title>{headerText} Account</Modal.Title>
				</Modal.Header>
				<Modal.Body>
				<Tabs defaultActiveKey={1} id="editAccountTabs">
					<Tab eventKey={1} title="General">
					<Form horizontal onSubmit={this.handleSubmit}>
					<FormGroup>
						<Col componentClass={ControlLabel} xs={2}>Name</Col>
						<Col xs={10}><commit_msg>Don't disable BankID if Investment account<commit_after>var React = require('react');
var ReactDOM = require('react-dom');

var ReactBootstrap = require('react-bootstrap');
var Grid = ReactBootstrap.Grid;
var Row = ReactBootstrap.Row;
var Col = ReactBootstrap.Col;
var Form = ReactBootstrap.Form;
var FormGroup = ReactBootstrap.FormGroup;
var FormControl = ReactBootstrap.FormControl;
var Checkbox = ReactBootstrap.Checkbox;
var ControlLabel = ReactBootstrap.ControlLabel;
var Button = ReactBootstrap.Button;
var ButtonGroup = ReactBootstrap.ButtonGroup;
var Glyphicon = ReactBootstrap.Glyphicon;
var ListGroup = ReactBootstrap.ListGroup;
var ListGroupItem = ReactBootstrap.ListGroupItem;
var Alert = ReactBootstrap.Alert;
var Modal = ReactBootstrap.Modal;
var Collapse = ReactBootstrap.Collapse;
var Tabs = ReactBootstrap.Tabs;
var Tab = ReactBootstrap.Tab;
var Panel = ReactBootstrap.Panel;

var Combobox = require('react-widgets').Combobox;

var models = require('../models');
var Security = models.Security;
var Account = models.Account;
var AccountType = models.AccountType;
var AccountTypeList = models.AccountTypeList;

var AccountCombobox = require('./AccountCombobox');
var AccountRegister = require('./AccountRegister');

const AddEditAccountModal = React.createClass({
	getInitialState: function() {
		var s = {
			accountid: -1,
			security: 1,
			parentaccountid: -1,
			type: 1,
			name: "",
			ofxurl: "",
			ofxorg: "",
			ofxfid: "",
			ofxuser: "",
			ofxbankid: "",
			ofxacctid: "",
			ofxaccttype: "CHECKING",
			ofxclientuid: "",
			ofxappid: "",
			ofxappver: "",
			ofxversion: "",
			ofxnoindent: false,
		};
		if (this.props.editAccount != null) {
			s.accountid = this.props.editAccount.AccountId;
			s.name = this.props.editAccount.Name;
			s.security = this.props.editAccount.SecurityId;
			s.parentaccountid = this.props.editAccount.ParentAccountId;
			s.type = this.props.editAccount.Type;
			s.ofxurl = this.props.editAccount.OFXURL;
			s.ofxorg = this.props.editAccount.OFXORG;
			s.ofxfid = this.props.editAccount.OFXFID;
			s.ofxuser = this.props.editAccount.OFXUser;
			s.ofxbankid = this.props.editAccount.OFXBankID;
			s.ofxacctid = this.props.editAccount.OFXAcctID;
			s.ofxaccttype = this.props.editAccount.OFXAcctType;
			s.ofxclientuid = this.props.editAccount.OFXClientUID;
			s.ofxappid = this.props.editAccount.OFXAppID;
			s.ofxappver = this.props.editAccount.OFXAppVer;
			s.ofxversion = this.props.editAccount.OFXVersion;
			s.ofxnoindent = this.props.editAccount.OFXNoIndent;
		} else if (this.props.initialParentAccount != null) {
			s.security = this.props.initialParentAccount.SecurityId;
			s.parentaccountid = this.props.initialParentAccount.AccountId;
			s.type = this.props.initialParentAccount.Type;
		}
		return s;
	},
	handleCancel: function() {
		if (this.props.onCancel != null)
			this.props.onCancel();
	},
	handleChange: function() {
		this.setState({
			name: ReactDOM.findDOMNode(this.refs.name).value,
			ofxurl: ReactDOM.findDOMNode(this.refs.ofxurl).value,
			ofxorg: ReactDOM.findDOMNode(this.refs.ofxorg).value,
			ofxfid: ReactDOM.findDOMNode(this.refs.ofxfid).value,
			ofxuser: ReactDOM.findDOMNode(this.refs.ofxuser).value,
			ofxbankid: ReactDOM.findDOMNode(this.refs.ofxbankid).value,
			ofxacctid: ReactDOM.findDOMNode(this.refs.ofxacctid).value,
			ofxaccttype: ReactDOM.findDOMNode(this.refs.ofxaccttype).value,
			ofxclientuid: ReactDOM.findDOMNode(this.refs.ofxclientuid).value,
			ofxappid: ReactDOM.findDOMNode(this.refs.ofxappid).value,
			ofxappver: ReactDOM.findDOMNode(this.refs.ofxappver).value,
			ofxversion: ReactDOM.findDOMNode(this.refs.ofxversion).value,
		});
	},

	handleNoIndentClick: function() {
		this.setState({ofxnoindent: !this.state.ofxnoindent});
	},
	handleSecurityChange: function(security) {
		if (security.hasOwnProperty('SecurityId'))
			this.setState({
				security: security.SecurityId
			});
	},
	handleTypeChange: function(type) {
		if (type.hasOwnProperty('TypeId'))
			this.setState({
				type: type.TypeId
			});
	},
	handleParentChange: function(parentAccount) {
		this.setState({parentaccountid: parentAccount.AccountId});
	},
	handleSubmit: function() {
		var a = new Account();

		if (this.props.editAccount != null)
			a.AccountId = this.state.accountid;
		a.Name = this.state.name;
		a.ParentAccountId = this.state.parentaccountid;
		a.SecurityId = this.state.security;
		a.Type = this.state.type;

		a.OFXURL = this.state.ofxurl;
		a.OFXORG = this.state.ofxorg;
		a.OFXFID = this.state.ofxfid;
		a.OFXUser = this.state.ofxuser;
		a.OFXBankID = this.state.ofxbankid;
		a.OFXAcctID = this.state.ofxacctid;
		a.OFXAcctType = this.state.ofxaccttype;
		a.OFXClientUID = this.state.ofxclientuid;
		a.OFXAppID = this.state.ofxappid;
		a.OFXAppVer = this.state.ofxappver;
		a.OFXVersion = this.state.ofxversion;
		a.OFXNoIndent = this.state.ofxnoindent;

		if (this.props.onSubmit != null)
			this.props.onSubmit(a);
	},
	componentWillReceiveProps: function(nextProps) {
		if (nextProps.show && !this.props.show) {
			this.setState(this.getInitialState());
		}
	},
	render: function() {
		var headerText = (this.props.editAccount != null) ? "Edit" : "Create New";
		var buttonText = (this.props.editAccount != null) ? "Save Changes" : "Create Account";
		var rootName = (this.props.editAccount != null) ? "Top-level Account" : "New Top-level Account";
		var ofxBankIdName = "Broker ID";
		var ofxAcctType = [];
		if (this.state.type != AccountType.Investment) {
			ofxBankIdName = "Bank ID";
			ofxAcctType = (
				<FormGroup>
					<Col componentClass={ControlLabel} xs={2}>Account Type</Col>
					<Col xs={10}>
					<FormControl
							componentClass="select"
							placeholder="select"
							value={this.state.ofxaccttype}
							onChange={this.handleChange}
							ref="ofxaccttype">
						<option value="CHECKING">Checking</option>
						<option value="SAVINGS">Savings</option>
						<option value="CC">Credit Card</option>
						<option value="MONEYMRKT">Money Market</option>
						<option value="CREDITLINE">Credit Line</option>
						<option value="CD">CD</option>
					</FormControl>
					</Col>
				</FormGroup>
			);
		}
		var bankIdDisabled = (this.state.type != AccountType.Investment && this.state.ofxaccttype == "CC") ? true : false;
		return (
			<Modal show={this.props.show} onHide={this.handleCancel}>
				<Modal.Header closeButton>
					<Modal.Title>{headerText} Account</Modal.Title>
				</Modal.Header>
				<Modal.Body>
				<Tabs defaultActiveKey={1} id="editAccountTabs">
					<Tab eventKey={1} title="General">
					<Form horizontal onSubmit={this.handleSubmit}>
					<FormGroup>
						<Col componentClass={ControlLabel} xs={2}>Name</Col>
						<Col xs={10}>
{'fraction_non_alphanumeric': 0.1384846211552888, 'fraction_numerical': 0.001800450112528132, 'mean_word_length': 4.250492319810949, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5296965', 'n_tokens_mistral': 5307, 'n_tokens_neox': 4663, 'n_words': 762}