UploadProgress.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2015 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react'
  19. import I18n from 'i18n!react_files'
  20. import classnames from 'classnames'
  21. import UploadProgress from 'compiled/react_files/components/UploadProgress'
  22. import ProgressBar from 'jsx/shared/ProgressBar'
  23. import mimeClass from 'compiled/util/mimeClass'
  24. UploadProgress.renderProgressBar = function () {
  25. if (this.props.uploader.error) {
  26. var errorMessage = (this.props.uploader.error.message) ?
  27. I18n.t('Error: %{message}', {message: this.props.uploader.error.message}) :
  28. I18n.t('Error uploading file.')
  29. return (
  30. <span>
  31. {errorMessage}
  32. <button type='button' className='btn-link' onClick={ () => this.props.uploader.upload()}>
  33. {I18n.t('Retry')}
  34. </button>
  35. </span>
  36. );
  37. } else {
  38. return <ProgressBar progress={this.props.uploader.roundProgress()} />
  39. }
  40. };
  41. UploadProgress.render = function () {
  42. var rowClassNames = classnames({
  43. 'ef-item-row': true,
  44. 'text-error': this.props.uploader.error
  45. });
  46. return (
  47. <div className={rowClassNames}>
  48. <div className='col-xs-6'>
  49. <div className='media ellipsis'>
  50. <span className='pull-left'>
  51. <i className={`media-object mimeClass-${mimeClass(this.props.uploader.file.type)}`} />
  52. </span>
  53. <span className='media-body' ref='fileName'>
  54. {this.props.uploader.getFileName()}
  55. </span>
  56. </div>
  57. </div>
  58. <div className='col-xs-5'>
  59. {this.renderProgressBar()}
  60. </div>
  61. <button
  62. type='button'
  63. onClick={this.props.uploader.cancel}
  64. aria-label={I18n.t('Cancel')}
  65. className='btn-link upload-progress-view__button'
  66. >
  67. x
  68. </button>
  69. </div>
  70. );
  71. };
  72. export default React.createClass(UploadProgress)