|
| 1 | +export default function flowforge({state}) { |
| 2 | + return { |
| 3 | + state, |
| 4 | + currentColumn: null, |
| 5 | + currentCard: null, |
| 6 | + formData: { |
| 7 | + a: '23', |
| 8 | + }, |
| 9 | + |
| 10 | + init: function () { |
| 11 | + console.log('FlowForge Alpine component initialized') |
| 12 | + // Initialise the Alpine component here, if you need to. |
| 13 | + }, |
| 14 | + |
| 15 | + openCreateModal(columnId) { |
| 16 | + this.currentColumn = columnId; |
| 17 | + this.formData = { |
| 18 | + [state.statusField]: columnId |
| 19 | + }; |
| 20 | + this.$dispatch('open-modal', { id: 'create-card-modal' }) |
| 21 | + }, |
| 22 | + |
| 23 | + submitCreateForm() { |
| 24 | + console.log(this.formData); |
| 25 | + this.$wire.createCard(this.formData).then(cardId => { |
| 26 | + if (cardId) { |
| 27 | + this.$dispatch('close-modal', { id: 'create-card-modal' }); |
| 28 | + this.formData = {}; |
| 29 | + } |
| 30 | + }); |
| 31 | + }, |
| 32 | + |
| 33 | + openEditModal(card, columnId) { |
| 34 | + this.currentCard = card; |
| 35 | + this.currentColumn = columnId; |
| 36 | + |
| 37 | + // Initialize form data with current card values |
| 38 | + this.formData = {...card}; |
| 39 | + this.formData[state.statusField] = columnId; |
| 40 | + |
| 41 | + this.$dispatch('open-modal', { id: 'edit-card-modal' }) |
| 42 | + }, |
| 43 | + |
| 44 | + submitEditForm() { |
| 45 | + this.$wire.updateCard(this.currentCard.id, this.formData).then(result => { |
| 46 | + if (result) { |
| 47 | + this.$dispatch('close-modal', { id: 'edit-card-modal' }); |
| 48 | + this.formData = {}; |
| 49 | + } |
| 50 | + }); |
| 51 | + }, |
| 52 | + |
| 53 | + deleteCard() { |
| 54 | + if (confirm('Are you sure you want to delete this card? This action cannot be undone.')) { |
| 55 | + this.$wire.deleteCard(this.currentCard.id).then(result => { |
| 56 | + if (result) { |
| 57 | + this.$dispatch('close-modal', { id: 'delete-card-modal' }); |
| 58 | + this.formData = {}; |
| 59 | + } |
| 60 | + }); |
| 61 | + } |
| 62 | + }, |
| 63 | + } |
| 64 | +} |
0 commit comments