UploadButton.js 2.4 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 I18n from 'i18n!upload_button'
  19. import React from 'react'
  20. import FileRenameForm from 'jsx/files/FileRenameForm'
  21. import ZipFileOptionsForm from './ZipFileOptionsForm'
  22. import UploadButton from 'compiled/react_files/components/UploadButton'
  23. UploadButton.buildPotentialModal = function () {
  24. if (this.state.zipOptions.length) {
  25. return (
  26. <ZipFileOptionsForm
  27. fileOptions= {this.state.zipOptions[0]}
  28. onZipOptionsResolved= {this.onZipOptionsResolved}
  29. onClose={this.onClose}
  30. />
  31. );
  32. } else if (this.state.nameCollisions.length) {
  33. return (
  34. <FileRenameForm
  35. fileOptions= {this.state.nameCollisions[0]}
  36. onNameConflictResolved= {this.onNameConflictResolved}
  37. onClose= {this.onClose}
  38. />
  39. );
  40. }
  41. }
  42. UploadButton.hiddenPhoneClassname = function () {
  43. if (this.props.showingButtons) {
  44. return('hidden-phone');
  45. }
  46. }
  47. UploadButton.render = function () {
  48. return (
  49. <span>
  50. <form
  51. ref= 'form'
  52. className= 'hidden'
  53. >
  54. <input
  55. type='file'
  56. ref='addFileInput'
  57. onChange= {this.handleFilesInputChange}
  58. multiple= {true}
  59. />
  60. </form>
  61. <button
  62. type= 'button'
  63. className= 'btn btn-primary btn-upload'
  64. onClick= {this.handleAddFilesClick}
  65. >
  66. <i className='icon-upload' aria-hidden />&nbsp;
  67. <span className= {this.hiddenPhoneClassname()} >
  68. { I18n.t('Upload') }
  69. </span>
  70. </button>
  71. { this.buildPotentialModal() }
  72. </span>
  73. );
  74. }
  75. export default React.createClass(UploadButton)