NoteFormModal.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div>
  3. <modal v-if="changeType" :id="modalId" tabindex="-1" role="dialog" :aria-labelledby="modalId+'Label'">
  4. <!-- We want the original notetype, if we used note.notetype the text would change as soon as we hit the Confirm button.
  5. This way the change in text occurs when we receive the updated info from the backend, so we can make sure there are no
  6. errors preventing the data from actually changing first -->
  7. <h5 v-if="populateWith.notetype === 0 " slot="header" class="modal-title" :id="modalId+'Label'">
  8. Change to Private Note
  9. </h5>
  10. <h5 v-else slot="header" class="modal-title" :id="modalId+'Label'">
  11. Change to Public Note
  12. </h5>
  13. <div slot="body">
  14. Are you sure?
  15. </div>
  16. <div slot="footer">
  17. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  18. <button type="button" class="btn btn-primary" @click="updateNote()">
  19. <div v-if="!noteSaving">Confirm</div>
  20. <circle-spinner v-else :size="2"></circle-spinner>
  21. </button>
  22. </div>
  23. </modal>
  24. <modal v-else :id="modalId" tabindex="-1" role="dialog" :aria-labelledby="modalId+'Label'">
  25. <h5 slot="header" class="modal-title" :id="modalId+'Label'">
  26. Edit Note
  27. </h5>
  28. <div slot="body">
  29. <div class="form-group">
  30. <label for="content">Content</label>
  31. <textarea :name="'content'+note.noteid" :id="'content'+note.noteid" class="form-control" v-model="note.thenote"></textarea>
  32. </div>
  33. </div>
  34. <div slot="footer">
  35. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  36. <button type="button" class="btn btn-primary" @click="updateNote()">
  37. <div v-if="!noteSaving">Save</div>
  38. <circle-spinner v-else :size="2"></circle-spinner>
  39. </button>
  40. </div>
  41. </modal>
  42. </div>
  43. </template>
  44. <script>
  45. import Modal from '../components/Modal.vue'
  46. import CircleSpinner from '../components/CircleSpinner.vue'
  47. export default {
  48. components: {
  49. Modal,
  50. CircleSpinner,
  51. },
  52. props: {
  53. populateWith: {
  54. type: Object,
  55. require: true
  56. },
  57. modalId: {
  58. type: String,
  59. require: true
  60. },
  61. noteUser: {
  62. type: String
  63. },
  64. woid: {
  65. type: Number
  66. },
  67. // If true, user is intending to switch the note
  68. // from public to private or vice/versa. Modal
  69. // Will be displayed differently, but the update
  70. // logic is only different for one line of code.
  71. changeType: {
  72. type: Boolean,
  73. default: false,
  74. }
  75. },
  76. data () {
  77. return {
  78. note: JSON.parse(JSON.stringify(this.populateWith)),
  79. noteSaving: false,
  80. }
  81. },
  82. methods: {
  83. updateNote () {
  84. this.noteSaving = true
  85. if (this.changeType) {
  86. this.note.notetype = (this.note.notetype === 1 ? 0 : 1)
  87. }
  88. axios.put('/api/workorders/notes/' + this.note.noteid, this.note)
  89. .then((response) => {
  90. this.noteSaving = false
  91. this.hideModal()
  92. })
  93. },
  94. hideModal () {
  95. $('#'+this.modalId).modal('hide')
  96. }
  97. }
  98. }
  99. </script>