2016-02-12 20:36:59 -05:00
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
var Combobox = require('react-widgets').Combobox;
|
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var getAccountDisplayList = require('../utils').getAccountDisplayList;
|
2016-02-13 16:41:44 -05:00
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class AccountCombobox extends React.Component {
|
2017-06-08 05:49:58 -04:00
|
|
|
static get defaultProps() {
|
|
|
|
return {
|
2016-02-12 20:36:59 -05:00
|
|
|
includeRoot: true,
|
2016-02-15 11:28:44 -05:00
|
|
|
disabled: false,
|
2016-02-12 20:36:59 -05:00
|
|
|
rootName: "New Top-level Account"
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
}
|
2017-06-08 05:49:58 -04:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.onAccountChange = this.handleAccountChange.bind(this);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
handleAccountChange(account) {
|
2016-02-12 20:36:59 -05:00
|
|
|
if (this.props.onChange != null &&
|
|
|
|
account.hasOwnProperty('AccountId') &&
|
2016-10-05 13:36:47 -04:00
|
|
|
(this.props.accounts.hasOwnProperty([account.AccountId]) ||
|
2016-02-12 20:36:59 -05:00
|
|
|
account.AccountId == -1)) {
|
|
|
|
this.props.onChange(account)
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2016-10-05 13:36:47 -04:00
|
|
|
var accounts = getAccountDisplayList(this.props.accounts, this.props.accountChildren, this.props.includeRoot, this.props.rootName);
|
2016-02-12 20:36:59 -05:00
|
|
|
var className = "";
|
|
|
|
if (this.props.className)
|
|
|
|
className = this.props.className;
|
|
|
|
return (
|
|
|
|
<Combobox
|
|
|
|
data={accounts}
|
|
|
|
valueField='AccountId'
|
|
|
|
textField='Name'
|
|
|
|
defaultValue={this.props.value}
|
2017-06-07 19:12:53 -04:00
|
|
|
onChange={this.onAccountChange}
|
2016-02-12 20:36:59 -05:00
|
|
|
ref="account"
|
2016-02-15 11:28:44 -05:00
|
|
|
disabled={this.props.disabled}
|
2016-10-06 06:53:49 -04:00
|
|
|
suggest
|
2017-05-28 21:17:08 -04:00
|
|
|
filter='contains'
|
2016-02-12 20:36:59 -05:00
|
|
|
className={className} />
|
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AccountCombobox;
|