ZipFileOptionsForm.js 2.7 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!zip_file_options_form'
  19. import React from 'react'
  20. import PropTypes from 'prop-types'
  21. import Modal from 'jsx/shared/modal'
  22. import ModalContent from 'jsx/shared/modal-content'
  23. import ModalButtons from 'jsx/shared/modal-buttons'
  24. var ZipFileOptionsForm = React.createClass({
  25. displayName: 'ZipFileOptionsForm',
  26. propTypes: {
  27. onZipOptionsResolved: PropTypes.func.isRequired
  28. },
  29. handleExpandClick: function () {
  30. this.props.onZipOptionsResolved({file: this.props.fileOptions.file, expandZip: true});
  31. },
  32. handleUploadClick: function () {
  33. this.props.onZipOptionsResolved({file: this.props.fileOptions.file, expandZip: false})
  34. },
  35. buildMessage: function (fileOptions) {
  36. var message = undefined
  37. if (this.props.fileOptions) {
  38. var name = this.props.fileOptions.file.name;
  39. message = I18n.t('message', 'Would you like to expand the contents of "%{fileName}" into the current folder, or upload the zip file as is?', {fileName: name});
  40. }
  41. return message;
  42. },
  43. render: function () {
  44. return (
  45. <Modal
  46. className='ReactModal__Content--canvas ReactModal__Content--mini-modal'
  47. isOpen={!!this.props.fileOptions}
  48. ref='canvasModal'
  49. title= { I18n.t('zip_options', 'Zip file options') }
  50. onRequestClose = {this.props.onClose}
  51. >
  52. <ModalContent>
  53. <p className="modalMessage">
  54. { this.buildMessage() }
  55. </p>
  56. </ModalContent>
  57. <ModalButtons>
  58. <button
  59. className='btn'
  60. onClick= { this.handleExpandClick }
  61. >
  62. { I18n.t('expand', 'Expand It') }
  63. </button>
  64. <button
  65. className='btn btn-primary'
  66. onClick= { this.handleUploadClick }
  67. >
  68. { I18n.t('upload', 'Upload It') }
  69. </button>
  70. </ModalButtons>
  71. </Modal>
  72. );
  73. }
  74. });
  75. export default ZipFileOptionsForm