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 ControlLabel = ReactBootstrap.ControlLabel; var Button = ReactBootstrap.Button; var ButtonGroup = ReactBootstrap.ButtonGroup; var ButtonToolbar = ReactBootstrap.ButtonToolbar; var Glyphicon = ReactBootstrap.Glyphicon; var ListGroup = ReactBootstrap.ListGroup; var ListGroupItem = ReactBootstrap.ListGroupItem; var Modal = ReactBootstrap.Modal; var Panel = ReactBootstrap.Panel; var Combobox = require('react-widgets').Combobox; var models = require('../models'); var Security = models.Security; var SecurityType = models.SecurityType; var SecurityTypeList = models.SecurityTypeList; const SecurityTemplatePanel = React.createClass({ handleSearchChange: function(){ this.props.onSearchTemplates(ReactDOM.findDOMNode(this.refs.search).value, 0, this.props.maxResults + 1); }, renderTemplateList: function() { var templates = this.props.securityTemplates; if (this.props.search != "") { var items = []; for (var i = 0; i < templates.length && i < 15; i++) { var template = templates[i]; var self = this; var onClickFn = (function() { var j = i; return function(){self.props.onSelectTemplate(templates[j])}; })(); var key = template.Type.toString() + template.AlternateId; items.push(( {template.Name} - {template.Description} )); } if (templates.length > this.props.maxResults) { items.push(( Too many templates to display, please refine your search... )); } else if (templates.length == 0) { items.push(( Sorry, no templates matched your search... )); } return (

Select a template to populate your security: {items}
); } }, render: function() { return ( {this.renderTemplateList()} ); } }); const AddEditSecurityModal = React.createClass({ getInitialState: function() { var s = { securityid: -1, name: "", description: "", symbol: "", precision: 0, type: 1, alternateid: "" }; if (this.props.editSecurity != null) { s.securityid = this.props.editSecurity.SecurityId; s.name = this.props.editSecurity.Name; s.description = this.props.editSecurity.Description; s.symbol = this.props.editSecurity.Symbol; s.precision = this.props.editSecurity.Precision; s.type = this.props.editSecurity.Type; s.alternateid = this.props.editSecurity.AlternateId; } return s; }, onSelectTemplate: function(template) { this.setState({ name: template.Name, description: template.Description, symbol: template.Symbol, precision: template.Precision, type: template.Type, alternateid: template.AlternateId }); }, handleCancel: function() { if (this.props.onCancel != null) this.props.onCancel(); }, handleNameChange: function() { this.setState({ name: ReactDOM.findDOMNode(this.refs.name).value, }); }, handleDescriptionChange: function() { this.setState({ description: ReactDOM.findDOMNode(this.refs.description).value, }); }, handleSymbolChange: function() { this.setState({ symbol: ReactDOM.findDOMNode(this.refs.symbol).value, }); }, handlePrecisionChange: function() { this.setState({ precision: +ReactDOM.findDOMNode(this.refs.precision).value, }); }, handleTypeChange: function(type) { if (type.hasOwnProperty('TypeId')) this.setState({ type: type.TypeId }); }, handleAlternateIdChange: function() { this.setState({ alternateid: ReactDOM.findDOMNode(this.refs.alternateid).value, }); }, handleSubmit: function() { var s = new Security(); if (this.props.editSecurity != null) s.SecurityId = this.state.securityid; s.Name = this.state.name; s.Description = this.state.description; s.Symbol = this.state.symbol; s.Precision = this.state.precision; s.Type = this.state.type; s.AlternateId = this.state.alternateid; if (this.props.onSubmit != null) this.props.onSubmit(s); }, componentWillReceiveProps: function(nextProps) { if (nextProps.show && !this.props.show) { this.setState(this.getInitialState()); } }, render: function() { var headerText = (this.props.editSecurity != null) ? "Edit" : "Create New"; var buttonText = (this.props.editSecurity != null) ? "Save Changes" : "Create Security"; var alternateidname = (this.state.type == SecurityType.Currency) ? "ISO 4217 Code" : "CUSIP"; return ( {headerText} Security
Name Description Symbol or Ticker Smallest Fraction Traded Security Type {alternateidname}
); } }); const DeletionFailedModal = React.createClass({ render: function() { return ( Cannot Delete Security We are unable to delete this security because it is in use by {this.props.securityAccounts.length} account(s). Please change those accounts to use other securities and try again. ); } }); const SecurityList = React.createClass({ render: function() { var children = []; var self = this; for (var securityId in this.props.securities) { if (this.props.securities.hasOwnProperty(securityId)) { var buttonStyle = (securityId == this.props.selectedSecurity) ? "info" : "link"; var onClickFn = (function() { var id = securityId; return function(){self.props.onSelectSecurity(id)}; })(); children.push(()); } } return (
{children}
); } }); module.exports = React.createClass({ displayName: "SecuritiesTab", getInitialState: function() { return { creatingNewSecurity: false, editingSecurity: false, deletionFailedModal: false }; }, handleNewSecurity: function() { this.setState({creatingNewSecurity: true}); }, handleEditSecurity: function() { this.setState({editingSecurity: true}); }, handleDeleteSecurity: function() { if (this.props.selectedSecurityAccounts.length == 0) this.props.onDeleteSecurity(this.props.securities[this.props.selectedSecurity]); else this.setState({deletionFailedModal: true}); }, handleCreationCancel: function() { this.setState({creatingNewSecurity: false}); }, handleCreationSubmit: function(security) { this.setState({creatingNewSecurity: false}); this.props.onCreateSecurity(security); }, handleEditingCancel: function() { this.setState({editingSecurity: false}); }, handleEditingSubmit: function(security) { this.setState({editingSecurity: false}); this.props.onUpdateSecurity(security); }, closeDeletionFailedModal: function() { this.setState({deletionFailedModal: false}); }, render: function() { var noSecuritySelected = this.props.selectedSecurity == -1; var selectedSecurity = null; if (this.props.securities.hasOwnProperty(this.props.selectedSecurity)) selectedSecurity = this.props.securities[this.props.selectedSecurity]; return ( ); } });