Allowance check

This commit is contained in:
ISMAIL MASSERAN
2026-04-14 02:34:00 +00:00
parent 0c4d200839
commit 3775c4a876
100 changed files with 81493 additions and 3226 deletions
@@ -12,8 +12,8 @@
<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">
<div v-if="allSelectedNomineeIds.length" class="vote-selected-list">
<div class="vote-selected-item" v-for="nominee_id in allSelectedNomineeIds" :key="nominee_id">
<span class="vote-selected-badge">#{{ getNomineeNo(nominee_id) }}</span>
<span>{{ getSelectedNomineeName(nominee_id) }}</span>
</div>
@@ -73,7 +73,7 @@
</div>
</div>
<div class="modal vote-confirm-modal" id="vote-modal" tabindex="-2" role="dialog" aria-labelledby="exampleModalLabel"
<div class="modal fade app-modal vote-confirm-modal" id="vote-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content vote-modal-content">
@@ -88,9 +88,9 @@
</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" v-if="allSelectedNomineeIds.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">
<div class="vote-selected-item" v-for="nominee_id in allSelectedNomineeIds" :key="nominee_id">
<span class="vote-selected-badge">#{{ getNomineeNo(nominee_id) }}</span>
<span>{{ getSelectedNomineeName(nominee_id) }}</span>
</div>
@@ -130,8 +130,20 @@ export default {
},
computed: {
/** All nominee ids chosen across every position (sidebar + modal must use this, not selected[0]). */
allSelectedNomineeIds() {
var ids = [];
for (var i = 0; i < this.selected.length; i++) {
var arr = this.selected[i] && Array.isArray(this.selected[i].nominee_id)
? this.selected[i].nominee_id
: [];
for (var j = 0; j < arr.length; j++) ids.push(arr[j]);
}
return ids;
},
disabledCheckboxes() {
const selectedNomineeIds = this.selected[0]['nominee_id'];
const selectedNomineeIds = this.allSelectedNomineeIds;
return this.data.nominees.map(nominee => {
return selectedNomineeIds.includes(nominee.id) ? false : this.checkDisabled();
});
@@ -139,12 +151,23 @@ export default {
},
methods: {
totalSelectedCount: function () {
return this.allSelectedNomineeIds.length;
},
selectedEntryForPosition: function (position_id) {
for (var i = 0; i < this.selected.length; i++) {
if (String(this.selected[i].position_id) === String(position_id)) return this.selected[i];
}
return null;
},
test: function () {
console.log('tab');
this.util.showModal('#vote-modal')
},
submit: function () {
if (this.selected[0]['nominee_id'].length !== this.max) {
if (this.totalSelectedCount() !== this.max) {
// No selections made
this.util.notify(`Sila pastikan anda memilih (${this.max}) orang calon.`, 'error');
return;
@@ -152,7 +175,7 @@ export default {
var vm = this;
this.util.notify('Submitting your vote, please wait...', 'loading');
console.log(this.selected)
console.log(this.selected);
// Prepare data to send to the server
let data = {
vote: this.selected
@@ -162,6 +185,10 @@ export default {
axios.post(config.API + 'election/vote', data)
.then(response => {
$.notifyClose();
// Some endpoints may not return a `message`; ensure we never notify "undefined".
if (response && response.data && typeof response.data.message === 'string' && response.data.message) {
vm.util.notify(response.data.message, 'success');
}
if (vm.util.showResult(response, 'success')) {
vm.data.result = response.data.result;
vm.$router.push({ name: 'Voter Home' });
@@ -194,22 +221,19 @@ export default {
},
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
var entry = this.selectedEntryForPosition(position_id);
if (!entry) return;
var idx = entry.nominee_id.indexOf(nominee_id);
if (idx === -1) {
// Enforce global max selection across all positions
if (this.totalSelectedCount() >= this.max) {
this.util.notify(`Boleh mengundi (${this.max}) calon sahaja!`, 'warning');
return;
}
entry.nominee_id.push(nominee_id);
} else {
// Nominee found, remove it
this.selected[0]['nominee_id'].splice(index, 1);
entry.nominee_id.splice(idx, 1);
}
},
@@ -264,7 +288,7 @@ export default {
},
checkUndi: function () {
if (this.selected[0]['nominee_id'].length <= 0) {
if (this.totalSelectedCount() <= 0) {
this.util.notify('Sila pastikan anda memilih (1) orang calon.', 'error');
} else {
this.util.showModal('#vote-modal');
@@ -273,7 +297,7 @@ export default {
},
checkDisabled: function () {
if (this.selected[0]['nominee_id'].length >= this.max) {
if (this.totalSelectedCount() >= this.max) {
return true;
}
}