WoInfoEditModal.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. <errorlist :errors="errors.probdesc"></errorlist>
  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. <errorlist :errors="errors.suggested"></errorlist>
  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()">Save</button>
  30. </div>
  31. </modal>
  32. </template>
  33. <script>
  34. import Modal from '../components/Modal'
  35. import AutocompleteCustomDropdown from '../components/AutocompleteCustomDropdown'
  36. export default {
  37. components: {
  38. Modal,
  39. AutocompleteCustomDropdown
  40. },
  41. props: {
  42. populateWith: {
  43. type: Object,
  44. required: true,
  45. },
  46. storeList: {
  47. type: Object,
  48. required: true,
  49. },
  50. modalId: {
  51. type: String,
  52. required: true,
  53. },
  54. },
  55. data () {
  56. return {
  57. // Copies object from prop, so it doesn't mutate the object
  58. // from the parent component. Parent component will be updated via
  59. // Websocket if updateWorkOrder is successful.
  60. data: JSON.parse(JSON.stringify(this.populateWith)),
  61. id: this.modalId,
  62. store: {},
  63. errors: []
  64. }
  65. },
  66. methods: {
  67. updateWorkOrder() {
  68. this.data.storeid = this.store.id
  69. axios.put('/api/workorders/' + this.data.woid, this.data)
  70. .then((response) => { $('#workordereditModal').modal('hide'); })
  71. .catch((error) => { this.errors = JSON.parse(error.response.request.response).errors; });
  72. }
  73. },
  74. mounted () {
  75. this.store = {
  76. 'id': this.data.storeid,
  77. 'name': this.storeList[this.data.storeid]
  78. }
  79. },
  80. // This was originally here because the populateWith info would originally
  81. // not necessarily be loaded when this component was mounted. That is no
  82. // longer the case as I now don't render the parent component until the
  83. // ajax request is finised. The watch statements are still here to cover
  84. // the case where someone else updates the populateWith values while
  85. // someone is editing, although it probably should be edited so it doesn't
  86. // immediately overwrite the unsaved edits of the current user.
  87. watch: {
  88. populateWith: function (value) {
  89. this.data = JSON.parse(JSON.stringify(this.populateWith))
  90. this.store = {
  91. 'id': this.data.storeid,
  92. 'name': this.storeList[this.data.storeid]
  93. }
  94. },
  95. storeList: function (value) {
  96. this.store = {
  97. 'id': this.data.storeid,
  98. 'name': this.storeList[this.data.storeid]
  99. }
  100. }
  101. }
  102. }
  103. </script>