CreateApplication.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div>
  3. <h1>Create application</h1>
  4. <div v-if="user">
  5. <span>{{ instruction }}</span>
  6. <div class="question_block" v-for="(element, index) in pattern" :key="index">
  7. <h3 class="question">- {{ element.text }}</h3>
  8. <span v-if="element.optional"> (Optional)</span>
  9. <br>
  10. <ApplicationInputSwitch class="textfield" :highlight="highlight" :type="element.type" :options="element.options" :ref="index"></ApplicationInputSwitch>
  11. <span class="hint">{{ element.hint }}</span>
  12. </div>
  13. <button @click="update">Create/Update</button>
  14. <span class="error"> {{ error }}</span>
  15. </div>
  16. <span v-else>You are not logged in.</span>
  17. </div>
  18. </template>
  19. <script>
  20. import ApplicationInputSwitch from '../components/ApplicationInputSwitch.vue'
  21. export default {
  22. data () {
  23. return {
  24. instruction: '',
  25. pattern: null,
  26. highlight: false,
  27. error: '',
  28. }
  29. },
  30. created () {
  31. this.core.get('/app-pattern').then((response) => {
  32. this.instruction = response.data.instruction;
  33. this.pattern = response.data.fields;
  34. })
  35. },
  36. computed: {
  37. user() {
  38. return this.$store.state.user
  39. },
  40. },
  41. methods: {
  42. isReady() {
  43. for(let key in this.$refs) {
  44. //TBI What is that 0
  45. let el = this.$refs[key][0]
  46. if(!el.isOkay) {
  47. return false;
  48. }
  49. }
  50. return true
  51. },
  52. getContent() {
  53. let answers = []
  54. for(let key in this.$refs) {
  55. //TBI What is that 0
  56. answers.push(this.$refs[key][0].getContent())
  57. }
  58. return answers
  59. },
  60. update() {
  61. if(this.isReady()) {
  62. this.core.post('/application', {
  63. //TODO: Pattern, User-token
  64. answers: this.getContent(),
  65. creator: this.user.username,
  66. }).then((response) => {
  67. console.log('Response: ', response.data);
  68. });
  69. this.error = ''
  70. } else {
  71. this.highlight = true
  72. this.error = 'Please fill the required fields'
  73. }
  74. },
  75. },
  76. components: {
  77. ApplicationInputSwitch,
  78. },
  79. }
  80. </script>
  81. <style scoped>
  82. .question_block {
  83. margin: 0.5em 0em;
  84. }
  85. .question {
  86. display: inline;
  87. color: #ccc;
  88. }
  89. .hint {
  90. font-size: 0.8em;
  91. }
  92. .error {
  93. color: red;
  94. }
  95. </style>