FileRenameForm.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 FileRenameForm from 'compiled/react_files/components/FileRenameForm'
  20. import Modal from 'jsx/shared/modal'
  21. import ModalContent from 'jsx/shared/modal-content'
  22. import ModalButtons from 'jsx/shared/modal-buttons'
  23. import I18n from 'i18n!file_rename_form'
  24. FileRenameForm.buildContent = function () {
  25. var nameToUse = this.state.fileOptions.name || this.state.fileOptions.file.name;
  26. var buildContentToRender;
  27. if (!this.state.isEditing && !this.state.fileOptions.cannotOverwrite) {
  28. buildContentToRender = (
  29. <div ref='bodyContent'>
  30. <p id='renameFileMessage'>
  31. {I18n.t('An item named "%{name}" already exists in this location. Do you want to replace the existing file?', {name: nameToUse})}
  32. </p>
  33. </div>
  34. );
  35. } else {
  36. var renameMessage;
  37. if (this.state.fileOptions.cannotOverwrite) {
  38. renameMessage = I18n.t('A locked item named "%{name}" already exists in this location. Please enter a new name.', {name: nameToUse});
  39. } else {
  40. renameMessage = I18n.t('Change "%{name}" to', {name: nameToUse});
  41. }
  42. buildContentToRender = (
  43. <div ref='bodyContent'>
  44. <p>
  45. {renameMessage}
  46. </p>
  47. <form onSubmit={this.handleFormSubmit}>
  48. <label className='file-rename-form__form-label'>
  49. {I18n.t('Name')}
  50. </label>
  51. <input
  52. className='input-block-level'
  53. type='text'
  54. defaultValue={nameToUse}
  55. ref='newName'
  56. >
  57. </input>
  58. </form>
  59. </div>
  60. );
  61. }
  62. return buildContentToRender;
  63. };
  64. FileRenameForm.buildButtons = function () {
  65. var buildButtonsToRender;
  66. if (this.state.fileOptions.cannotOverwrite) {
  67. buildButtonsToRender = (
  68. [
  69. <button
  70. key='commitChangeBtn'
  71. ref='commitChangeBtn'
  72. className='btn btn-primary'
  73. onClick={this.handleChangeClick}
  74. >
  75. {I18n.t('Change')}
  76. </button>
  77. ]
  78. );
  79. } else if (!this.state.isEditing) {
  80. buildButtonsToRender = (
  81. [
  82. <button
  83. key='renameBtn'
  84. ref='renameBtn'
  85. className='btn btn-default'
  86. onClick={this.handleRenameClick}
  87. >
  88. {I18n.t('Change Name')}
  89. </button>
  90. ,
  91. <button
  92. key='replaceBtn'
  93. ref='replaceBtn'
  94. className='btn btn-primary'
  95. onClick={this.handleReplaceClick}
  96. >
  97. {I18n.t('Replace')}
  98. </button>
  99. ]
  100. );
  101. } else {
  102. buildButtonsToRender = (
  103. [
  104. <button
  105. key='backBtn'
  106. ref='backBtn'
  107. className='btn btn-default'
  108. onClick={this.handleBackClick}
  109. >
  110. {I18n.t('Back')}
  111. </button>
  112. ,
  113. <button
  114. key='commitChangeBtn'
  115. ref='commitChangeBtn'
  116. className='btn btn-primary'
  117. onClick={this.handleChangeClick}
  118. >
  119. {I18n.t('Change')}
  120. </button>
  121. ]
  122. );
  123. }
  124. return buildButtonsToRender;
  125. };
  126. FileRenameForm.render = function () {
  127. return (
  128. <div>
  129. <Modal
  130. className='ReactModal__Content--canvas ReactModal__Content--mini-modal'
  131. ref='canvasModal'
  132. isOpen={this.props.fileOptions}
  133. title={I18n.t('Copy')}
  134. onRequestClose={this.props.onClose}
  135. closeWithX={this.props.closeWithX}
  136. >
  137. <ModalContent>
  138. {this.buildContent()}
  139. <ModalButtons>
  140. {this.buildButtons()}
  141. </ModalButtons>
  142. </ModalContent>
  143. </Modal>
  144. </div>
  145. );
  146. };
  147. export default React.createClass(FileRenameForm)