<template>
<div class="panel panel-default">
	<div class="panel-body">
		<h4>Tambah Pengundi</h4>
		<form @submit.prevent="add()" id="add-form">
			<div class="form-group">
				<label for="name">Nama Anggota</label>
				<input type="text" name="name" class="form-control" required>
			</div>

			<div class="form-group">
				<label for="no_kp">No. Kad Pengenalan</label>
				<input type="text" name="no_kp" class="form-control" required>
			</div>

			<div class="form-group">
				<label for="no_anggota">No. Anggota</label>
				<input type="text" name="no_anggota" class="form-control" required>
			</div>


			<div class="form-group">
				<label for="unit">Unit</label>
				<input type="text" name="unit" class="form-control" required>
			</div>

			<div class="form-group">
				<label for="alamat">Alamat</label>
				<input type="text" name="alamat" class="form-control" required>
			</div>

			<div class="form-group">
				<label for="telefon">No. Telefon</label>
				<input type="text" name="telefon" class="form-control" required>
			</div>

			<div class="form-group">
				<label for="saham">Saham</label>
				<input type="text" name="saham" class="form-control" required>
			</div>

			<div class="form-group">
				<label for="yuran">Yuran</label>
				<input type="text" name="yuran" class="form-control" required>
			</div>

			<div class="form-group">
				<button type="submit" class="btn btn-success">Submit</button>
				<router-link :to="{name: 'Manage Voter'}" class="btn btn-default">Back</router-link>
			</div>
		</form>
	</div>
</div>
</template>

<script>
export default{
	data: function () {
		return {
			loading: false
		}
	},
	methods: {
		add: function () {
			if (this.loading) return;
			this.loading = true;
			var vm = this;
			this.util.notify('Adding Voter', 'loading')
			axios.post(config.API+'voter', $('#add-form').serialize())
				.then(response=>{
					$.notifyClose();
					vm.loading = false;
					if (vm.util.showResult(response, 'success')) {
						vm.$router.push({name:'Manage Voter'});
					}
				})
				.catch(error=>{
					$.notifyClose();
					vm.loading = false;
					vm.util.showResult(error);
				})
		}
	}
}
</script>