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
|
|
|
|
2016-02-12 20:36:59 -05:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: "AccountCombobox",
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
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"
|
|
|
|
};
|
|
|
|
},
|
|
|
|
handleAccountChange: function(account) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
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}
|
|
|
|
onChange={this.handleAccountChange}
|
|
|
|
ref="account"
|
2016-02-15 11:28:44 -05:00
|
|
|
disabled={this.props.disabled}
|
2016-10-06 06:53:49 -04:00
|
|
|
suggest
|
2016-02-12 20:36:59 -05:00
|
|
|
className={className} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|