summaryrefslogtreecommitdiff
path: root/ui/app/components/wizard/provider_select_stage.js
blob: 20674be15f62228dbc14a04c4b95c44687175a67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react'
import {Button, ButtonGroup, ButtonToolbar, Glyphicon} from 'react-bootstrap'

import App from 'app'
import ListEdit from 'components/list_edit'
import StageLayout from './stage_layout'
import AddProviderModal from './add_provider_modal'

export default class ProviderSelectStage extends React.Component {

  static get defaultProps() {return{
    title: "Choose a provider",
    subtitle: "This doesn't work yet"
  }}

  constructor(props) {
    super(props)
    let domains = this.currentDomains()
    this.state = {
      domains: domains,
      showModal: false
    }
    this.add = this.add.bind(this)
    this.remove = this.remove.bind(this)
    this.close = this.close.bind(this)
    this.previous = this.previous.bind(this)
  }

  currentDomains() {
    // return(App.providers.domains().slice() || [])
    return ['domain1', 'domain2', 'domain3']
  }

  add() {
    this.setState({showModal: true})
  }

  remove(provider) {
    // App.providers.remove(provider)
    this.setState({domains: this.currentDomains()})
  }

  close() {
    let domains = this.currentDomains()
    if (domains.length != this.state.domains.length) {
      // this is ugly, but i could not get selection working
      // by passing it as a property
      this.refs.list.setSelected(0)
    }
    this.setState({
      domains: domains,
      showModal: false
    })
  }

  previous() {
    App.start()
  }

  render() {
    let modal = null
    if (this.state.showModal) {
      modal = <AddProviderModal onClose={this.close} />
    }
    let buttons = (
      <ButtonToolbar className="pull-right">
        <Button onClick={this.previous}>
          <Glyphicon glyph="chevron-left" />
          Previous
        </Button>
        <Button>
          Next
          <Glyphicon glyph="chevron-right" />
        </Button>
      </ButtonToolbar>
    )
    let select = <ListEdit ref="list" items={this.state.domains}
      onRemove={this.remove} onAdd={this.add} />
    return(
      <StageLayout title={this.props.title} subtitle={this.props.subtitle} buttons={buttons}>
        {select}
        {modal}
      </StageLayout>
    )
  }
}