WoInfoEditModal.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <modal :id="id" tabindex="-1" role="dialog" :aria-labelledby="id+'Label'">
  3. <h5 slot="header" class="modal-title" :id="id+'Label'">
  4. Edit Work Order Information
  5. </h5>
  6. <div slot="body">
  7. <div class="form-group">
  8. <label for="probdesc">Problem Description</label>
  9. <textarea id="probdesc" name="probdesc" :class="{'form-control': true, 'is-invalid': errors.probdesc}" v-model="data.probdesc"></textarea>
  10. <error-list :errors="errors.probdesc"></error-list>
  11. </div>
  12. <div class="form-group">
  13. <label for="suggested">Suggested Solution</label>
  14. <textarea id="suggested" name="suggested" :class="{'form-control': true, 'is-invalid': errors.suggested}" v-model="data.suggested"></textarea>
  15. <error-list :errors="errors.suggested"></error-list>
  16. </div>
  17. <div class="form-group">
  18. <label for="storelist">Store</label>
  19. <autocomplete-custom-dropdown :options="storeList" :value="this.store" v-model="store"></autocomplete-custom-dropdown>
  20. <!-- <select name="storelist" id="storelist" class="form-control" v-if="storeList" v-model="data.storeid">
  21. <option v-for="store in storeList" v-bind:key="store.storeid" v-bind:value="store.storeid">
  22. {{ store.storesname }}
  23. </option>
  24. </select> -->
  25. </div>
  26. </div>
  27. <div slot="footer">
  28. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  29. <button type="button" class="btn btn-primary" @click="updateWorkOrder()">
  30. <div v-if="!woInfoSaving">Save</div>
  31. <circle-spinner v-else :size="2"></circle-spinner>
  32. </button>
  33. </div>
  34. </modal>
  35. </template>
  36. <script>
  37. import Modal from '../components/Modal.vue'
  38. import AutocompleteCustomDropdown from '../components/AutocompleteCustomDropdown.vue'
  39. import ErrorList from '../components/ErrorList.vue'
  40. import CircleSpinner from '../components/CircleSpinner.vue'
  41. export default {
  42. components: {
  43. Modal,
  44. AutocompleteCustomDropdown,
  45. ErrorList,
  46. CircleSpinner,
  47. },
  48. props: {
  49. populateWith: {
  50. type: Object,
  51. required: true,
  52. },
  53. storeList: {
  54. type: Object,
  55. required: true,
  56. },
  57. modalId: {
  58. type: String,
  59. required: true,
  60. },
  61. },
  62. data () {
  63. return {
  64. // Copies object from prop, so it doesn't mutate the object
  65. // from the parent component. Parent component will be updated via
  66. // Websocket if updateWorkOrder is successful.
  67. data: JSON.parse(JSON.stringify(this.populateWith)),
  68. id: this.modalId,
  69. store: {},
  70. errors: [],
  71. woInfoSaving: false
  72. }
  73. },
  74. methods: {
  75. updateWorkOrder() {
  76. this.woInfoSaving = true
  77. this.data.storeid = this.store.id
  78. axios.put('/api/workorders/' + this.data.woid, this.data)
  79. .then((response) => {
  80. this.woInfoSaving = false
  81. $('#workordereditModal').modal('hide')
  82. })
  83. .catch((error) => {
  84. this.woInfoSaving = false
  85. this.errors = JSON.parse(error.response.request.response).errors
  86. });
  87. }
  88. },
  89. mounted () {
  90. this.store = {
  91. 'id': this.data.storeid,
  92. 'name': this.storeList[this.data.storeid]
  93. }
  94. },
  95. // This was originally here because the populateWith info would originally
  96. // not necessarily be loaded when this component was mounted. That is no
  97. // longer the case as I now don't render the parent component until the
  98. // ajax request is finised. The watch statements are still here to cover
  99. // the case where someone else updates the populateWith values while
  100. // someone is editing, although it probably should be edited so it doesn't
  101. // immediately overwrite the unsaved edits of the current user.
  102. watch: {
  103. populateWith: function (value) {
  104. this.data = JSON.parse(JSON.stringify(this.populateWith))
  105. this.store = {
  106. 'id': this.data.storeid,
  107. 'name': this.storeList[this.data.storeid]
  108. }
  109. },
  110. storeList: function (value) {
  111. this.store = {
  112. 'id': this.data.storeid,
  113. 'name': this.storeList[this.data.storeid]
  114. }
  115. }
  116. }
  117. }
  118. </script>