You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
5.2 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <urban-bucket-form>
  2. <div class="form">
  3. <form method="POST">
  4. <input type="hidden" name="_token" value={ state.csrfToken } if={ state.csrfToken } />
  5. <!-- name -->
  6. <div class="field is-horizontal">
  7. <div class="field-label is-normal">
  8. <label class="label required" for="name">
  9. name
  10. </label>
  11. </div>
  12. <div class="field-body">
  13. <div class="field">
  14. <p class="control">
  15. <input id="name" class={ getClasses('name', 'input') } type="text" name="name" value={ props.name } onkeyup={ (event) => { state.validator.handle(event, 'name') }} />
  16. <field-error errors={ state.validator.errors('name') } ></field-error>
  17. </p>
  18. </div>
  19. </div>
  20. </div>
  21. <!-- description -->
  22. <div class="field is-horizontal">
  23. <div class="field-label is-normal">
  24. <label class="label" for="description">
  25. description
  26. </label>
  27. </div>
  28. <div class="field-body">
  29. <div class="field">
  30. <p class="control">
  31. <textarea id="description" class={ getClasses('description', 'textarea') } name="description" value={ props.description } onkeyup={ (event) => { state.validator.handle(event, 'description') }}></textarea>
  32. <field-error errors={ state.validator.errors('description') } ></field-error>
  33. </p>
  34. </div>
  35. </div>
  36. </div>
  37. <!-- path -->
  38. <div class="field is-horizontal">
  39. <div class="field-label is-normal">
  40. <label class="label" for="name">
  41. path
  42. </label>
  43. </div>
  44. <div class="field-body">
  45. <div class="field">
  46. <p class="control">
  47. <input id="path" class={ getClasses('path', 'input') } type="text" name="path" value={ props.path } onkeyup={ (event) => { state.validator.handle(event, 'path') }} />
  48. <field-error errors={ state.validator.errors('path') } ></field-error>
  49. <span class="help">
  50. path for storage files, if empty default path will be used
  51. </span>
  52. </p>
  53. </div>
  54. </div>
  55. </div>
  56. <!-- is public -->
  57. <div class="field is-horizontal">
  58. <div class="field-label is-normal">
  59. <label class="label" for="public">
  60. public
  61. </label>
  62. </div>
  63. <div class="field-body">
  64. <div class="field">
  65. <input id="public" type="checkbox" name="public" value="1" checked={ props.public }>
  66. <span class="help">
  67. everyone can see bucket, files and download them
  68. </span>
  69. </div>
  70. </div>
  71. </div>
  72. <!-- submit -->
  73. <div class="field">
  74. <div class="control">
  75. <button class="button is-primary" type="submit" disabled={ state.validator.errors().length > 0 }>
  76. Create
  77. </button>
  78. </div>
  79. </div>
  80. </form>
  81. </div>
  82. <script>
  83. import Validator from '@tentakelfabrik/tiny-validator/src/validator'
  84. import FieldError from '../field-error.riot'
  85. riot.register('field-error', FieldError)
  86. /**
  87. *
  88. *
  89. *
  90. */
  91. export default {
  92. /**
  93. *
  94. * @param {[type]} props [description]
  95. * @param {[type]} state [description]
  96. *
  97. */
  98. onBeforeMount(props, state) {
  99. state.validator = new Validator({
  100. name: {
  101. presence: true,
  102. length: {
  103. maximum: 255
  104. }
  105. },
  106. description: {
  107. length: {
  108. maximum: 255
  109. }
  110. }
  111. }, this)
  112. //
  113. const meta = document.querySelector("meta[name='csrf-token']")
  114. if (meta) {
  115. state.csrfToken = meta.getAttribute("content")
  116. }
  117. },
  118. /**
  119. *
  120. *
  121. * @param {[type]} key
  122. * @param {[type]} defaultClass
  123. * @return {[type]}
  124. *
  125. */
  126. getClasses(key, defaultClass) {
  127. const classes = [
  128. defaultClass
  129. ]
  130. const errors = this.state.validator.errors(key)
  131. if (errors && errors.length > 0) {
  132. classes.push('is-danger')
  133. }
  134. return classes.join(' ')
  135. }
  136. }
  137. </script>
  138. </urban-bucket-form>