Files
E-Vote/resources/assets/js/components/demo/voter/home/vote.vue
T

583 lines
13 KiB
Vue

<template>
<div class="vote-page row col-md-10 col-md-offset-1">
<div class="col-md-4 vote-sidebar-column">
<div class="vote-summary-card">
<div class="vote-section-kicker">Ringkasan Undian</div>
<h4 class="vote-page-title">UNDIAN CALON ANGGOTA LEMBAGA</h4>
<p class="vote-page-subtitle">Semak calon yang telah dipilih sebelum menghantar undi anda.</p>
<div class="vote-limit-pill">
Anda hanya boleh memilih <b>satu (1) orang calon</b> sahaja.
</div>
<ul class="list-group vote-summary-list">
<li class="list-group-item vote-summary-item">
<div class="vote-position-name">Calon Dipilih</div>
<div v-if="selected[0] && selected[0].nominee_id.length" class="vote-selected-list">
<div class="vote-selected-item" v-for="nominee_id in selected[0].nominee_id" :key="nominee_id">
<span class="vote-selected-badge">#{{ getNomineeNo(nominee_id) }}</span>
<span>{{ getSelectedNomineeName(nominee_id) }}</span>
</div>
</div>
<div v-else class="vote-empty-selection">
Belum ada calon dipilih.
</div>
</li>
<li class="list-group-item vote-summary-action">
<button class="btn btn-success btn-block vote-submit-button" @click="checkUndi()">UNDI</button>
</li>
</ul>
</div>
</div>
<div class="col-md-8 vote-content-column">
<div class="vote-content-header">
<div>
<div class="vote-section-kicker">Senarai Calon</div>
<h4 class="vote-content-title">Pilih Calon Anda</h4>
</div>
<div class="alert alert-warning vote-alert" role="alert">
Anda hanya boleh memilih <b>satu (1) orang calon</b> sahaja.
</div>
</div>
<div class="panel panel-info vote-panel" v-for="position in data.positions" :key="position.id">
<div class="panel-heading vote-panel-heading">
<span>{{ position.name }}</span>
<span class="vote-panel-badge">Calon Aktif</span>
</div>
<div class="panel-body table-responsive vote-panel-body">
<table class="table table-hover vote-table">
<thead>
<tr>
<th></th>
<th>No. Calon</th>
<th></th>
<th>Nama</th>
<th>Unit</th>
</tr>
</thead>
<tbody>
<tr v-for="(nominee, index) in data.nominees" v-if="nominee.position_id == position.id"
:key="nominee.id" class="vote-row">
<td class="vote-checkbox-cell"><input type="checkbox" :id="nominee.id" :disabled="disabledCheckboxes[index]"
@change="vote(position.id, nominee.id)" />
</td>
<td>{{ nominee.no_calon }}</td>
<td><img @click="view(i)" :src="createBase64ImageUrl(nominee.photo)" class="thumbnail vote-nominee-photo" />
</td>
<td>{{ nominee.name }}</td>
<td>{{ nominee.unit }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal vote-confirm-modal" id="vote-modal" tabindex="-2" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content vote-modal-content">
<div class="modal-header vote-modal-header">
<div>
<div class="vote-section-kicker">Pengesahan</div>
<h5 class="modal-title vote-modal-title" id="exampleModalLabel">Sahkan Undian Anda</h5>
</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body vote-modal-body">
<h5 class="vote-modal-note">Nota: Sila pastikan anda telah membuat undian dengan betul.</h5>
<div class="vote-modal-selection" v-if="selected[0] && selected[0].nominee_id.length">
<div class="vote-modal-selection-title">Calon dipilih</div>
<div class="vote-selected-item" v-for="nominee_id in selected[0].nominee_id" :key="nominee_id">
<span class="vote-selected-badge">#{{ getNomineeNo(nominee_id) }}</span>
<span>{{ getSelectedNomineeName(nominee_id) }}</span>
</div>
</div>
</div>
<div class="modal-footer vote-modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
<button type="button" class="btn btn-primary" @click="submit()">Hantar</button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
created: function () {
if (this.data.result.length > 0 || this.data.election.status != 2)
this.$router.push({ name: 'Voter Home' })
for (var i in this.data.positions) {
this.selected.push({
position_id: this.data.positions[i]['id'],
nominee_id: [],
});
}
},
data: function () {
return {
selected: [],
name: {},
selectedNominees: {
},
max: 1
}
},
computed: {
disabledCheckboxes() {
const selectedNomineeIds = this.selected[0]['nominee_id'];
return this.data.nominees.map(nominee => {
return selectedNomineeIds.includes(nominee.id) ? false : this.checkDisabled();
});
}
},
methods: {
test: function () {
console.log('tab');
this.util.showModal('#vote-modal')
},
submit: function () {
if (this.selected[0]['nominee_id'].length !== this.max) {
// No selections made
this.util.notify(`Sila pastikan anda memilih (${this.max}) orang calon.`, 'error');
return;
}
var vm = this;
this.util.notify('Submitting your vote, please wait...', 'loading');
console.log(this.selected)
// Prepare data to send to the server
let data = {
vote: this.selected
};
// Send a POST request to the server
axios.post(config.API + 'election/vote', data)
.then(response => {
$.notifyClose();
if (vm.util.showResult(response, 'success')) {
vm.data.result = response.data.result;
vm.$router.push({ name: 'Voter Home' });
$('.modal').modal('hide');
}
})
.catch(error => {
$.notifyClose();
vm.util.showResult(error, 'error');
});
},
hasNullVote: function () {
console.log('null' + this.selectedNominees);
let selected = this.selectedNominees;
for (var i in selected)
if (selected[i]['nominee_id'] == null) {
this.util.notify('You must vote on all position', 'error');
return true;
}
return false;
},
reset: function () {
let selected = this.selectedNominees;
for (var i in selected) {
$('#' + selected[i]['nominee_id']).selected(false);
selected[i]['nominee_id'] = null;
}
},
vote: function (position_id, nominee_id) {
if (!this.selected[0]['position_id']) {
this.$set(this.selected[0], position_id, []);
}
const index = this.selected[0]['nominee_id'].indexOf(nominee_id);
if (index === -1) {
// Nominee not found, add it
if (this.selected[0]['nominee_id'].length < this.max) {
this.selected[0]['nominee_id'].push(nominee_id);
} else {
// Display warning message if more than 2 nominees are selected
this.util.notify(`Boleh mengundi (${this.max}) calon sahaja!`, 'warning');
return;
}
} else {
// Nominee found, remove it
this.selected[0]['nominee_id'].splice(index, 1);
}
},
getSelectedNomineeName: function (id) {
return this.getNominee(id);
},
getNomineeNo(id) {
const nominee = this.data.nominees.find(n => n.id === id);
return nominee ? nominee.no_calon : '';
},
getName: function (id) {
let positions = this.data.positions;
let selected = this.selected;
for (var i in selected)
if (selected[i]['position_id'] == id)
return this.getNominee(selected[i]['nominee_id']);
return '';
},
getNominee: function (id) {
let positions = this.data.positions;
let nominees = this.data.nominees;
for (var i in nominees)
if (nominees[i]['id'] == id) return nominees[i].name;
return '';
},
// getNominee: function (id) {
// let nominees = this.data.nominees;
// for (var i in nominees)
// if (nominees[i]['id'] == id) return nominees[i]['name'];
// },
getPartylist: function (id) {
let partylists = this.data.partylists;
for (var i in partylists)
if (partylists[i]['id'] == id) return partylists[i]['name'];
return 'No Partylist';
},
view: function (index) {
this.x = this.data.nominees[index];
this.util.showModal('#nominee-information-modal');
},
createBase64ImageUrl: function (base64ImageData) {
return "data:image/png;base64," + base64ImageData;
},
checkUndi: function () {
if (this.selected[0]['nominee_id'].length <= 0) {
this.util.notify('Sila pastikan anda memilih (1) orang calon.', 'error');
} else {
this.util.showModal('#vote-modal');
}
return;
},
checkDisabled: function () {
if (this.selected[0]['nominee_id'].length >= this.max) {
return true;
}
}
// uncheck: function (checkedName) {
// this.checkedName = this.checkedNames.filter(name => name !== checkedName);
// }
}
}
</script>
<style scoped>
.vote-page {
margin-top: 18px;
margin-bottom: 36px;
}
.vote-sidebar-column,
.vote-content-column {
margin-bottom: 24px;
}
.vote-summary-card {
padding: 22px 20px;
border-radius: 20px;
background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
border: 1px solid #e2ebf5;
box-shadow: 0 16px 34px rgba(35, 64, 97, 0.08);
position: sticky;
top: 120px;
}
.vote-section-kicker {
margin-bottom: 8px;
color: #2f80ed;
font-size: 1.2rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.vote-page-title,
.vote-content-title {
margin: 0 0 8px;
color: #17324d;
font-weight: 700;
}
.vote-page-subtitle {
margin-bottom: 16px;
color: #5f7388;
line-height: 1.6;
}
.vote-limit-pill {
margin-bottom: 18px;
padding: 12px 14px;
border-radius: 12px;
background: #eef5ff;
border: 1px solid #d7e7ff;
color: #31506f;
line-height: 1.6;
}
.vote-summary-list {
margin-bottom: 0;
}
.vote-summary-item,
.vote-summary-action {
border: 0;
border-bottom: 1px solid #edf2f7;
padding: 14px 0;
background: transparent;
}
.vote-summary-list .vote-summary-item:last-of-type {
border-bottom: 1px solid #edf2f7;
}
.vote-position-name {
margin-bottom: 10px;
color: #17324d;
font-size: 1.5rem;
font-weight: 700;
}
.vote-selected-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.vote-selected-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border-radius: 12px;
background: #fff;
border: 1px solid #e6edf5;
color: #30475f;
}
.vote-selected-badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 48px;
padding: 5px 10px;
border-radius: 999px;
background: #dcecff;
color: #1e5fbf;
font-size: 1.2rem;
font-weight: 700;
}
.vote-empty-selection {
color: #7a8ea3;
font-style: italic;
}
.vote-summary-action {
padding-top: 18px;
border-bottom: 0;
}
.vote-submit-button {
padding-top: 12px;
padding-bottom: 12px;
border-radius: 12px;
font-weight: 700;
letter-spacing: 0.04em;
box-shadow: 0 12px 24px rgba(40, 167, 69, 0.24);
}
.vote-content-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
margin-bottom: 18px;
}
.vote-alert {
margin-bottom: 0;
border-radius: 12px;
box-shadow: 0 10px 24px rgba(255, 193, 7, 0.15);
}
.vote-panel {
margin-bottom: 20px;
border: 0;
border-radius: 18px;
overflow: hidden;
box-shadow: 0 16px 34px rgba(35, 64, 97, 0.1);
}
.vote-panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
background: linear-gradient(135deg, #1d4e89, #2f80ed);
color: #fff !important;
font-size: 1.7rem;
font-weight: 700;
}
.vote-panel-badge {
padding: 6px 10px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.18);
font-size: 1.2rem;
font-weight: 600;
}
.vote-panel-body {
padding: 0;
background: #fff;
}
.vote-table {
margin-bottom: 0;
}
.vote-table thead {
background: #f4f8fd;
}
.vote-table thead th {
border-bottom: 1px solid #dce7f5;
color: #48627e;
font-size: 1.25rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.03em;
}
.vote-table tbody td {
vertical-align: middle;
border-top: 1px solid #edf2f7;
color: #22384f;
}
.vote-row {
transition: background-color 0.18s ease, box-shadow 0.18s ease;
}
.vote-row:hover {
background: #f8fbff;
box-shadow: inset 4px 0 0 #2f80ed;
}
.vote-checkbox-cell input[type="checkbox"] {
width: 18px;
height: 18px;
cursor: pointer;
}
.vote-nominee-photo {
width: 64px;
height: 64px;
margin-bottom: 0;
border-radius: 16px;
border: 2px solid #dbe8ff;
object-fit: cover;
box-shadow: 0 8px 18px rgba(47, 128, 237, 0.12);
}
.vote-modal-content {
border: 0;
border-radius: 18px;
overflow: hidden;
box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
}
.vote-modal-header {
padding: 18px 22px;
background: linear-gradient(135deg, #0d6efd, #2f80ed);
color: #fff;
}
.vote-modal-title {
margin: 4px 0 0;
font-size: 2rem;
font-weight: 700;
}
.vote-modal-header .close {
color: #fff;
opacity: 0.9;
text-shadow: none;
}
.vote-modal-body {
padding: 22px;
background: #f7fbff;
}
.vote-modal-note {
margin-top: 0;
margin-bottom: 14px;
color: #17324d;
}
.vote-modal-selection-title {
margin-bottom: 10px;
font-size: 1.4rem;
font-weight: 700;
color: #17324d;
}
.vote-modal-footer {
padding: 16px 22px 20px;
background: #fff;
}
@media (max-width: 991px) {
.vote-summary-card {
position: static;
top: auto;
}
.vote-content-header {
flex-direction: column;
}
}
@media (max-width: 767px) {
.vote-page {
margin-top: 8px;
}
.vote-panel-heading {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.vote-table thead th:nth-child(5),
.vote-table tbody td:nth-child(5) {
display: none;
}
}
</style>