ctucx.git: ctucx.things

simple inventory management web-app

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
<style lang="scss">

</style>

<template>
	<modal id="speedbump" :shown="shown" @hide="shown = false">
		<h2 v-if="messages.title">
			{{ messages.title }}
		</h2>

		<p>{{ messages.body }}</p>

		<div class="buttons">
			<button v-focus-on-create class="lpButton" @click="confirmSpeedbump()">
				{{ messages.confirm }}
			</button>
			&nbsp;<button class="lpButton" @click="shown = false">
				{{ messages.cancel }}
			</button>
		</div>
	</modal>
</template>

<script>
import modal from './modal.vue';

export default {
	name: 'Speedbump',
	components: {
		modal,
	},
	data() {
		return {
			defaultMessages: {
				title: '',
				body: '',
				confirm: 'Yes',
				cancel: 'No',
			},
			messages: {},
			callback: null,
			shown: false,
		};
	},
	beforeMount() {
		bus.$on('initSpeedbump', (callback, options) => {
			this.initSpeedbump(callback, options);
		});
	},
	methods: {
		initSpeedbump(callback, options) {
			this.callback = callback;
			this.messages = Vue.util.extend({}, this.defaultMessages);
			if (typeof options === 'string') {
				this.messages.body = options;
			} else {
				this.messages = Vue.util.extend(this.messages, options);
			}
			this.shown = true;
		},
		confirmSpeedbump() {
			if (this.callback && typeof this.callback === 'function') {
				this.callback(true);
			}
			this.shown = false;
		},
	},
};
</script>