|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 3 | + * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +const React = require('react') |
| 6 | +const messages = require('../constants/messages') |
| 7 | +const Immutable = require('immutable') |
| 8 | +const ImmutableComponent = require('../components/immutableComponent') |
| 9 | +const aboutActions = require('./aboutActions') |
| 10 | +const Button = require('../components/button') |
| 11 | + |
| 12 | +const ipc = window.chrome.ipc |
| 13 | + |
| 14 | +require('../../less/about/autofill.less') |
| 15 | +require('../../node_modules/font-awesome/css/font-awesome.css') |
| 16 | + |
| 17 | +class AddressItem extends ImmutableComponent { |
| 18 | + constructor () { |
| 19 | + super() |
| 20 | + this.onDelete = this.onDelete.bind(this) |
| 21 | + this.onEdit = this.onEdit.bind(this) |
| 22 | + } |
| 23 | + |
| 24 | + onDelete () { |
| 25 | + aboutActions.removeAutofillAddress(this.props.address.toJS()) |
| 26 | + } |
| 27 | + |
| 28 | + onEdit () { |
| 29 | + aboutActions.editAutofillAddress(this.props.address.toJS()) |
| 30 | + } |
| 31 | + |
| 32 | + render () { |
| 33 | + const address = this.props.address |
| 34 | + return <tr className='autofillItem'> |
| 35 | + <td className='autofillActions'> |
| 36 | + <span className='autofillAction fa fa-times' title='Delete address' |
| 37 | + onClick={this.onDelete}> |
| 38 | + </span> |
| 39 | + </td> |
| 40 | + <td className='addressName'>{address.get('name')}</td> |
| 41 | + <td className='organization'>{address.get('organization')}</td> |
| 42 | + <td className='streetAddress'>{address.get('streetAddress')}</td> |
| 43 | + <td className='city'>{address.get('city')}</td> |
| 44 | + <td className='state'>{address.get('state')}</td> |
| 45 | + <td className='postalCode'>{address.get('postalCode')}</td> |
| 46 | + <td className='country'>{address.get('country')}</td> |
| 47 | + <td className='phone'>{address.get('phone')}</td> |
| 48 | + <td className='email'>{address.get('email')}</td> |
| 49 | + <td className='autofillActions'> |
| 50 | + <span className='autofillAction fa fa-pencil-square-o' title='Edit address' |
| 51 | + onClick={this.onEdit}> |
| 52 | + </span> |
| 53 | + </td> |
| 54 | + </tr> |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +class CreditCardItem extends ImmutableComponent { |
| 59 | + constructor () { |
| 60 | + super() |
| 61 | + this.onDelete = this.onDelete.bind(this) |
| 62 | + this.onEdit = this.onEdit.bind(this) |
| 63 | + } |
| 64 | + |
| 65 | + onDelete () { |
| 66 | + aboutActions.removeAutofillCreditCard(this.props.creditCard.toJS()) |
| 67 | + } |
| 68 | + |
| 69 | + onEdit () { |
| 70 | + aboutActions.editAutofillCreditCard(this.props.creditCard.toJS()) |
| 71 | + } |
| 72 | + |
| 73 | + render () { |
| 74 | + const creditCard = this.props.creditCard |
| 75 | + return <tr className='autofillItem'> |
| 76 | + <td className='autofillActions'> |
| 77 | + <span className='autofillAction fa fa-times' title='Delete creditCard' |
| 78 | + onClick={this.onDelete}> |
| 79 | + </span> |
| 80 | + </td> |
| 81 | + <td className='creditCardName'>{creditCard.get('name')}</td> |
| 82 | + <td className='creditCardNumber'>{creditCard.get('card')}</td> |
| 83 | + <td className='creditCardPExpirationDate'> |
| 84 | + {creditCard.get('month') + '/' + creditCard.get('year')} |
| 85 | + </td> |
| 86 | + <td className='autofillActions'> |
| 87 | + <span className='autofillAction fa fa-pencil-square-o' title='Edit creditCard' |
| 88 | + onClick={this.onEdit}> |
| 89 | + </span> |
| 90 | + </td> |
| 91 | + </tr> |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +class AboutAutofill extends React.Component { |
| 96 | + constructor () { |
| 97 | + super() |
| 98 | + this.state = { |
| 99 | + addressesDetails: new Immutable.List(), |
| 100 | + creditCardsDetails: new Immutable.List() |
| 101 | + } |
| 102 | + ipc.on(messages.AUTOFILL_ADDRESSES_UPDATED, (e, detail) => { |
| 103 | + if (detail) { |
| 104 | + this.setState({ |
| 105 | + addressesDetails: Immutable.fromJS(detail) |
| 106 | + }) |
| 107 | + } |
| 108 | + }) |
| 109 | + ipc.on(messages.AUTOFILL_CREDIT_CARDS_UPDATED, (e, detail) => { |
| 110 | + if (detail) { |
| 111 | + this.setState({ |
| 112 | + creditCardsDetails: Immutable.fromJS(detail) |
| 113 | + }) |
| 114 | + } |
| 115 | + }) |
| 116 | + this.onAddAddress = this.onAddAddress.bind(this) |
| 117 | + this.onAddCreditCard = this.onAddCreditCard.bind(this) |
| 118 | + } |
| 119 | + |
| 120 | + onAddAddress () { |
| 121 | + aboutActions.addAutofillAddress() |
| 122 | + } |
| 123 | + |
| 124 | + onAddCreditCard () { |
| 125 | + aboutActions.addAutofillCreditCard() |
| 126 | + } |
| 127 | + |
| 128 | + get isAddresssEmpty () { |
| 129 | + return !this.state.addressesDetails || !this.state.addressesDetails.size |
| 130 | + } |
| 131 | + |
| 132 | + get isCreditCardsEmpty () { |
| 133 | + return !this.state.creditCardsDetails || !this.state.creditCardsDetails.size |
| 134 | + } |
| 135 | + |
| 136 | + render () { |
| 137 | + var savedAddresssPage = this.isAddresssEmpty |
| 138 | + ? <div><span data-l10n-id='noAddressesSaved' /></div> |
| 139 | + : <div> |
| 140 | + <h2 data-l10n-id='addresses' /> |
| 141 | + <div className='autofillPageContent'> |
| 142 | + <table className='autofillList'> |
| 143 | + <thead> |
| 144 | + <tr> |
| 145 | + <th></th> |
| 146 | + <th data-l10n-id='nameOnAddress'></th> |
| 147 | + <th data-l10n-id='organization'></th> |
| 148 | + <th data-l10n-id='streetAddress'></th> |
| 149 | + <th data-l10n-id='city'></th> |
| 150 | + <th data-l10n-id='state'></th> |
| 151 | + <th data-l10n-id='postalCode'></th> |
| 152 | + <th data-l10n-id='country'></th> |
| 153 | + <th data-l10n-id='phone'></th> |
| 154 | + <th data-l10n-id='email'></th> |
| 155 | + </tr> |
| 156 | + </thead> |
| 157 | + <tbody> |
| 158 | + { |
| 159 | + this.state.addressesDetails.sort((a, b) => { |
| 160 | + return a.get('name') > b.get('name') ? 1 : -1 |
| 161 | + }).map((item) => |
| 162 | + <AddressItem address={item} />) |
| 163 | + } |
| 164 | + </tbody> |
| 165 | + </table> |
| 166 | + </div> |
| 167 | + </div> |
| 168 | + |
| 169 | + var savedCreditCardsPage = this.isCreditCardsEmpty |
| 170 | + ? <div><span data-l10n-id='noCreditCardsSaved' /></div> |
| 171 | + : <div> |
| 172 | + <h2 data-l10n-id='creditCards' /> |
| 173 | + <div className='autofillPageContent'> |
| 174 | + <table className='autofillList'> |
| 175 | + <thead> |
| 176 | + <tr> |
| 177 | + <th></th> |
| 178 | + <th data-l10n-id='nameOnCard'></th> |
| 179 | + <th data-l10n-id='creditCardNumber'></th> |
| 180 | + <th data-l10n-id='expirationDate'></th> |
| 181 | + </tr> |
| 182 | + </thead> |
| 183 | + <tbody> |
| 184 | + { |
| 185 | + this.state.creditCardsDetails.sort((a, b) => { |
| 186 | + return a.get('name') > b.get('name') ? 1 : -1 |
| 187 | + }).map((item) => |
| 188 | + <CreditCardItem creditCard={item} />) |
| 189 | + } |
| 190 | + </tbody> |
| 191 | + </table> |
| 192 | + </div> |
| 193 | + </div> |
| 194 | + return <div className='autofillPage'> |
| 195 | + <h1 data-l10n-id='autofillTitle' /> |
| 196 | + {savedAddresssPage} |
| 197 | + <Button l10nId='addAddress' className='primaryButton' onClick={this.onAddAddress} /> |
| 198 | + {savedCreditCardsPage} |
| 199 | + <Button l10nId='addCreditCard' className='primaryButton' onClick={this.onAddCreditCard} /> |
| 200 | + </div> |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +module.exports = <AboutAutofill /> |
0 commit comments