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 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
<style lang="scss">

#csvUrl {
	display: block;
	margin-top: 15px;
}

#lpOptionalFields {
	margin: 0;
	padding: 0;
}

.lpOptionalField {
	list-style-type: none;
	margin: 0;
	padding: 0;
}

#lpPriceSettings {
	input {
		display: inline-block;
		margin-left: 10px;
		width: 50px;
	}
}

#share .lpContent {
	width: 330px;
}

#settings .lpContent {
	width: 200px;
}
</style>

<template>
	<span id="settings" class="headerItem hasPopover">
		<PopoverHover>
			<span slot="target"><i class="lpSprite lpSettings" /> Settings</span>
			<div slot="content">
				<ul id="lpOptionalFields">
					<li v-for="optionalField in optionalFieldsLookup" :key="optionalField.name" class="lpOptionalField">
						<label>
							<input v-model="optionalField.value" type="checkbox" @change="toggleOptionalField($event, optionalField.name)">
							{{ optionalField.displayName }}
						</label>
					</li>
				</ul>
				<div v-if="library.optionalFields['price']" id="lpPriceSettings">
					<hr>
					<label>
						Currency:
						<input id="currencySymbol" type="text" maxlength="4" :value="library.currencySymbol" @input="updateCurrencySymbol($event)">
					</label>
				</div>
			</div>
		</PopoverHover>
	</span>
</template>

<script>
import PopoverHover from './popoverHover.vue';

export default {
	name: 'ListSettings',
	components: {
		PopoverHover,
	},
	data() {
		return {
			optionalFieldsLookup: [{
				name: 'images',
				displayName: 'Item images',
				cssClass: 'lpShowImages',
				value: false,
			}, {
				name: 'price',
				displayName: 'Item prices',
				cssClass: 'lpShowPrices',
				value: false,
			}, {
				name: 'worn',
				displayName: 'Worn items',
				cssClass: 'lpShowWorn',
				value: false,
			}, {
				name: 'consumable',
				displayName: 'Consumable items',
				cssClass: 'lpShowConsumable',
				value: false,
			}, {
				name: 'listDescription',
				displayName: 'List descriptions',
				cssClass: 'lpShowListDescription',
				value: false,
			}],
		};
	},
	computed: {
		library() {
			return this.$store.state.library;
		},
	},
	beforeMount() {
		this.updateOptionalFieldValues();
	},
	mounted() {
		bus.$on('optionalFieldChanged', () => {
			this.updateOptionalFieldValues();
		});
	},
	methods: {
		toggleOptionalField(evt, optionalField) {
			this.$store.commit('toggleOptionalField', optionalField);
		},
		updateCurrencySymbol(evt) {
			this.$store.commit('updateCurrencySymbol', evt.target.value);
		},
		updateOptionalFieldValues() {
			let i;
			let fieldLookup;

			for (i = 0; i < this.optionalFieldsLookup.length; i++) {
				fieldLookup = this.optionalFieldsLookup[i];
				fieldLookup.value = this.library.optionalFields[fieldLookup.name];
			}
		},
	},
};
</script>