|
| 1 | +<template> |
| 2 | + <div class="flex" v-if="Object.keys(transactions).length > 0"> |
| 3 | + <div class="flex-1 m-1" v-for="(showModal, transaction) in transactions"> |
| 4 | + <button class="bg-50 w-full btn m-1 p-2 rounded" @click.prevent="openModal(transaction)">{{transaction}}</button> |
| 5 | + <modal v-if="showModal" @modal-close="close(transaction)"> |
| 6 | + <form |
| 7 | + class="bg-white rounded-lg shadow-lg overflow-hidden" |
| 8 | + style="width: 460px" |
| 9 | + > |
| 10 | + <slot> |
| 11 | + <div class="p-8"> |
| 12 | + <heading :level="2" class="mb-6">{{ __('Choose one of the reasons') }}</heading> |
| 13 | + <p class="text-80 leading-normal"> |
| 14 | + <select v-if="reasons(transaction) != 'textarea'" v-model="reason" class="form-control form-select w-full"> |
| 15 | + <option v-for="(item, index) in reasons(transaction)" :value="index">{{ item}}</option> |
| 16 | + </select> |
| 17 | + <textarea v-else v-model="reason" class="form-control form-input-bordered h-auto w-full"></textarea> |
| 18 | + </p> |
| 19 | + </div> |
| 20 | + </slot> |
| 21 | + |
| 22 | + <div class="bg-30 px-6 py-3 flex"> |
| 23 | + <div class="ml-auto"> |
| 24 | + <button |
| 25 | + type="button" |
| 26 | + data-testid="cancel-button" |
| 27 | + dusk="cancel-delete-button" |
| 28 | + @click.prevent="close(transaction)" |
| 29 | + class="btn text-80 font-normal h-9 px-3 mr-3 btn-link" |
| 30 | + > |
| 31 | + {{ __('Cancel') }} |
| 32 | + </button> |
| 33 | + <button |
| 34 | + id="confirm-delete-button" |
| 35 | + ref="confirmButton" |
| 36 | + data-testid="confirm-button" |
| 37 | + type="submit" |
| 38 | + @click="action(transaction)" |
| 39 | + class="btn btn-default btn-primary" |
| 40 | + > |
| 41 | + OK |
| 42 | + </button> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + </form> |
| 46 | + </modal> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + <div v-else> |
| 50 | + No action required |
| 51 | + </div> |
| 52 | +</template> |
| 53 | + |
| 54 | +<script> |
| 55 | +
|
| 56 | + export default { |
| 57 | + props: ['resourceName', 'resourceId', 'field'], |
| 58 | +
|
| 59 | + data() { |
| 60 | + return { |
| 61 | + transactions: this.field.transactions, |
| 62 | + reason:'' |
| 63 | + } |
| 64 | + }, |
| 65 | +
|
| 66 | + methods: { |
| 67 | + close(transaction) { |
| 68 | + this.transactions[transaction] = false; |
| 69 | +
|
| 70 | + this.$emit('close') |
| 71 | + }, |
| 72 | +
|
| 73 | + reasons(transaction) { |
| 74 | + try { |
| 75 | + return this.field.reasons[transaction] || []; |
| 76 | + } catch (e) { |
| 77 | + return []; |
| 78 | + } |
| 79 | + }, |
| 80 | + async action(transaction) { |
| 81 | + var self = this, |
| 82 | + slug = `${this.field.workflow}/${this.resourceId}/${transaction.replace(/\s/g, '_')}/${this.reason}`; |
| 83 | +
|
| 84 | + await Nova.request().get(`/nova-vendor/workflow/${slug}`); |
| 85 | +
|
| 86 | + self.close(transaction); |
| 87 | +
|
| 88 | + self.$toasted.show('Resource successfully changed to ' + transaction, {type: 'success'}); |
| 89 | +
|
| 90 | + self.$router.push({ |
| 91 | + name: 'index', |
| 92 | + params: { |
| 93 | + resourceName: self.resourceName, |
| 94 | + resourceId: self.resourceId, |
| 95 | + }, |
| 96 | + }) |
| 97 | + }, |
| 98 | +
|
| 99 | + reject: function () { |
| 100 | + console.log('reject') |
| 101 | + }, |
| 102 | + openModal: function (transaction) { |
| 103 | + if (Object.keys(this.reasons(transaction)).length > 0) { |
| 104 | + this.transactions[transaction] = true; |
| 105 | + } else { |
| 106 | + this.action(transaction); |
| 107 | + } |
| 108 | + }, |
| 109 | + }, |
| 110 | + } |
| 111 | +</script> |
0 commit comments