fix modal bootstrap

This commit is contained in:
nurafrinaalimi16
2024-03-26 15:08:52 +08:00
parent aef1324eef
commit 3ca2855c1d
2 changed files with 209 additions and 168 deletions
@@ -1,118 +1,142 @@
<template> <template>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<h4> Recent Elections</h4> <h4> Recent Elections</h4>
<div class="form-group"> <div class="form-group">
<button class="btn btn-success" v-if="data.election.status == 1" @click="util.showModal('#start-election-modal')">Start Election</button> <button class="btn btn-success" v-if="data.election.status == 1 && data.user.role==1"
@click="util.showModal('#start-election-modal')">Start Election</button>
<router-link :to="{name: 'Current Result'}" class="btn btn-info" v-if="data.election.status == 2">
View Results
</router-link>
<button class="btn btn-danger" v-if="data.election.status == 2" @click="util.showModal('#stop-election-modal')">End Election</button>
<label v-if="data.election.status == 2">Election has Started {{ start_date }}</label> <router-link :to="{ name: 'Current Result' }" class="btn btn-info" v-if="data.election.status == 2">
View Results
</router-link>
<button class="btn btn-danger" v-if="data.election.status == 2"
@click="util.showModal('#stop-election-modal')">End Election</button>
<label v-if="data.election.status == 2">Election has Started {{ start_date }}</label>
</div>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Election Name</th>
<th>Election Start</th>
<th>Election End</th>
<th>View</th>
</tr>
</thead>
<tbody>
<tr v-for="election in data.elections">
<td>{{ election.id }}</td>
<td>{{ election.name }}</td>
<td>{{ election.start }}</td>
<td>{{ election.end }}</td>
<td>
<router-link :to="{ name: 'Election Result', params: { election_id: election.id } }"
class="btn btn-info">View Result</router-link>
</td>
</tr>
<tr v-if="data.elections.length < 1">
<td colspan="5">No elections yet</td>
</tr>
</tbody>
</table>
</div>
<form @submit.prevent="start" id="start_form">
<div class="modal fade" id="start-election-modal" tabindex="-1" role="dialog"
aria-labelledby="start-election-modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Start Election</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name">Election Name</label>
<input type="text" name="name" autocomplete="on" class="form-control" placeholder="(Optional)" />
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<input type="password" name="password" class="form-control" required />
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-info" value="Start" />
<input type="button" data-dismiss="modal" class="btn btn-default" value="Cancel" />
</div>
</div>
</div>
</div>
</form>
<form @submit.prevent="stop" id="stop_form">
<div class="modal fade" id="stop-election-modal" tabindex="-1" role="dialog"
aria-labelledby="stop-election-modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Stop Election</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name">Election Name</label>
<input type="text" name="name" :value="data.election.name" autocomplete="on" class="form-control" placeholder="(Optional)" />
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<input type="password" name="password" autocomplete="on" class="form-control" required />
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-info" value="Stop Election" />
<input type="button" data-dismiss="modal" class="btn btn-default" value="Cancel" />
</div>
</div>
</div>
</div>
</form>
</div> </div>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Election Name</th>
<th>Election Start</th>
<th>Election End</th>
<th>View</th>
</tr>
</thead>
<tbody>
<tr v-for="election in data.elections">
<td>{{ election.id }}</td>
<td>{{ election.name }}</td>
<td>{{ election.start}}</td>
<td>{{ election.end}}</td>
<td>
<router-link :to="{name: 'Election Result', params:{election_id:election.id}}" class="btn btn-info">View Result</router-link></td>
</tr>
<tr v-if="data.elections.length < 1">
<td colspan="5">No elections yet</td>
</tr>
</tbody>
</table>
</div>
<form @submit.prevent="start" id="start_form">
<modal id="start-election-modal">
<modal-header>Start Election</modal-header>
<modal-body>
<div class="form-group">
<label for="name">Election Name</label>
<input type="text" name="name" class="form-control" placeholder="(Optional)"/>
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<input type="password" name="password" class="form-control" required/>
</div>
</modal-body>
<modal-footer>
<input type="submit" class="btn btn-info" value="Start"/>
<input type="button" data-dismiss="modal" class="btn btn-default" value="Cancel"/>
</modal-footer>
</modal>
</form>
<form @submit.prevent="stop" id="stop_form">
<modal id="stop-election-modal">
<modal-header>Stop Election</modal-header>
<modal-body>
<div class="form-group">
<label for="name">Election Name</label>
<input type="text" name="name" :value="data.election.name" class="form-control" placeholder="(Optional)"/>
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<input type="password" name="password" class="form-control" required/>
</div>
</modal-body>
<modal-footer>
<input type="submit" class="btn btn-danger" value="Stop Election"/>
<input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel"/>
</modal-footer>
</modal>
</form>
</div> </div>
</div>
</template> </template>
<script> <script>
export default{ export default {
data: ()=>({ data: () => ({
start_date: null start_date: null
}), }),
created: function () { created: function () {
this.refreshElection(); this.refreshElection();
var vm = this; var vm = this;
setInterval(()=>{ setInterval(() => {
vm.start_date = moment(vm.data.election.start).fromNow(); vm.start_date = moment(vm.data.election.start).fromNow();
},1000); }, 1000);
}, },
methods: { methods: {
stop: function () { stop: function () {
var vm = this; var vm = this;
this.util.hideModal('#stop-election-modal'); // this.util.hideModal('#stop-election-modal');
this.util.notify('Stopping Election', 'loading'); this.util.notify('Stopping Election', 'loading');
axios.post(config.API+'election/stop', $('#stop_form').serialize()) axios.post(config.API + 'election/stop', $('#stop_form').serialize())
.then(response=>{ .then(response => {
$.notifyClose(); $.notifyClose();
if (vm.util.showResult(response,'success')) { if (vm.util.showResult(response, 'success')) {
vm.refreshElection(); vm.refreshElection();
vm.data.election =response.data.election; vm.data.election = response.data.election;
vm.data.positions = []; vm.data.positions = [];
vm.data.partylists = []; vm.data.partylists = [];
vm.data.voters = []; vm.data.voters = [];
@@ -120,7 +144,7 @@ export default{
vm.data.results = []; vm.data.results = [];
} }
}) })
.catch(error=>{ .catch(error => {
$.notifyClose(); $.notifyClose();
vm.util.showResult(error, 'error'); vm.util.showResult(error, 'error');
}) })
@@ -128,31 +152,32 @@ export default{
start: function () { start: function () {
var vm = this; var vm = this;
this.util.hideModal('#start-election-modal'); // this.util.hideModal('#start-election-modal');
console.log('this');
this.util.notify('Loading please wait', 'loading'); this.util.notify('Loading please wait', 'loading');
axios.post(config.API+'election/start', $('#start_form').serialize()) axios.post(config.API + 'election/start', $('#start_form').serialize())
.then(response=>{ .then(response => {
$.notifyClose(); $.notifyClose();
if(vm.util.showResult(response, 'success')){ if (vm.util.showResult(response, 'success')) {
vm.refreshElection(); vm.refreshElection();
vm.data.election = response.data.election; vm.data.election = response.data.election;
} }
}) })
.catch(error=>{ .catch(error => {
$.notifyClose(); $.notifyClose();
vm.util.showResult(error, 'error'); vm.util.showResult(error, 'error');
}) })
}, },
refreshElection: function(){ refreshElection: function () {
this.util.notify('Refreshing Election', 'loading'); this.util.notify('Refreshing Election', 'loading');
var vm = this; var vm = this;
axios.get(config.API+'election') axios.get(config.API + 'election')
.then(response=>{ .then(response => {
$.notifyClose(); $.notifyClose();
vm.data.elections = response.data; vm.data.elections = response.data;
}) })
.catch(error=>{ .catch(error => {
$.notifyClose(); $.notifyClose();
vm.util.showResult(error, 'error'); vm.util.showResult(error, 'error');
}) })
@@ -1,69 +1,82 @@
<template> <template>
<div class="row col-md-10 col-md-offset-1"> <div class="row col-md-10 col-md-offset-1">
<div class="col-md-4"> <div class="col-md-4">
<h4>Vote Information</h4><hr/> <h4>Vote Information</h4>
<ul class="list-group"> <hr />
<li class="list-group-item" v-for="position in data.positions"> <ul class="list-group">
<b>{{ position.name }} : </b>{{ getName(position.id) }} <li class="list-group-item" v-for="position in data.positions">
</li> <b>{{ position.name }} : </b>{{ getName(position.id) }}
<li class="list-group-item"> </li>
<center> <li class="list-group-item">
<button class="btn btn-success" @click="util.showModal('#vote-modal')">Submit Vote</button> <center>
<button class="btn btn-default" @click="reset()">Reset</button> <button class="btn btn-success" @click="util.showModal('#vote-modal')">Submit Vote</button>
</center> <button class="btn btn-default" @click="reset()">Reset</button>
</li> </center>
</ul> </li>
</div> </ul>
<div class="col-md-8"> </div>
<h4>Select Candidates</h4><hr/> <div class="col-md-8">
<div class="panel panel-info" v-for="position in data.positions"> <h4>Select Candidates</h4>
<div class="panel-heading">{{ position.name }}</div> <hr />
<div class="panel-body table-responsive"> <div class="panel panel-info" v-for="position in data.positions">
<table class="table table-hover"> <div class="panel-heading">{{ position.name }}</div>
<thead> <div class="panel-body table-responsive">
<tr> <table class="table table-hover">
<th></th> <thead>
<th>Name</th> <tr>
<th>Partylist</th> <th></th>
<th>Unit</th> <th>Name</th>
</tr> <th>Partylist</th>
</thead> <th>Unit</th>
<tbody> </tr>
<tr v-for="nominee in data.nominees" v-if="nominee.position_id==position.id" @click="vote(position.id,nominee.id)"> </thead>
<td><input type="radio" :name="position.id" :id="nominee.id"/></td> <tbody>
<td>{{ nominee.name }}</td> <tr v-for="nominee in data.nominees" v-if="nominee.position_id==position.id"
<td>{{ getPartylist(nominee.partylist_id) }}</td> @click="vote(position.id,nominee.id)">
<td>{{ nominee.unit }}</td> <td><input type="radio" :name="position.id" :id="nominee.id"/></td>
</tr> <td>{{ nominee.name }}</td>
</tbody> <td>{{ getPartylist(nominee.partylist_id) }}</td>
</table> <td>{{ nominee.unit }}</td>
</tr>
</tbody>
</table>
</div>
</div> </div>
</div> </div>
<div class="modal fade" id="vote-modal" tabindex="-2" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Vote</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<h3>Note: You can only vote once, so vote wisely.</h3>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" @click="submit()">Submit Vote</button>
</div>
</div>
</div>
</div>
</div> </div>
<modal id="vote-modal">
<modal-header>Vote</modal-header>
<modal-body>
<h3>Note: You can only vote once, so vote wisely.</h3>
</modal-body>
<modal-footer>
<button class="btn btn-success" @click="submit()">Submit Vote</button>
<button class="btn btn-default" data-dismiss="modal">Cancel</button>
</modal-footer>
</modal>
</div>
</template> </template>
<script> <script>
export default{ export default {
created: function () { created: function () {
if (this.data.result.length > 0 || this.data.election.status != 2) if (this.data.result.length > 0 || this.data.election.status != 2)
this.$router.push({name: 'Voter Home'}) this.$router.push({ name: 'Voter Home' })
for (var i in this.data.positions) { for (var i in this.data.positions) {
this.selected.push({ this.selected.push({
position_id: this.data.positions[i]['id'], position_id: this.data.positions[i]['id'],
nominee_id: null, nominee_id: null,
}); });
} }
}, },
@@ -76,9 +89,12 @@ export default{
}, },
methods: { methods: {
test: function(){
console.log('tab');
this.util.showModal('#vote-modal')
},
submit: function () { submit: function () {
this.util.hideModal('#vote-modal'); // this.util.hideModal('#vote-modal');
if (this.hasNullVote()) return; if (this.hasNullVote()) return;
var vm = this; var vm = this;
this.util.notify('Submitting your vote, please wait...', 'loading'); this.util.notify('Submitting your vote, please wait...', 'loading');
@@ -87,9 +103,9 @@ export default{
axios.post(config.API+'election/vote', data) axios.post(config.API+'election/vote', data)
.then(response=>{ .then(response=>{
$.notifyClose(); $.notifyClose();
if (vm.util.showResult(response, 'success')){ if (vm.util.showResult(response, 'success')) {
vm.data.result = response.data.result; vm.data.result = response.data.result;
vm.$router.push({name: 'Voter Home'}); vm.$router.push({ name: 'Voter Home' });
} }
}) })
@@ -102,8 +118,8 @@ export default{
hasNullVote: function () { hasNullVote: function () {
let selected = this.selected; let selected = this.selected;
for (var i in selected) for (var i in selected)
if (selected[i]['nominee_id'] == null){ if (selected[i]['nominee_id'] == null) {
this.util.notify('You must vote on all position', 'error'); this.util.notify('You must vote on all position', 'error');
return true; return true;
} }
@@ -112,7 +128,7 @@ export default{
reset: function () { reset: function () {
let selected = this.selected; let selected = this.selected;
for (var i in selected){ for (var i in selected) {
$('#'+selected[i]['nominee_id']).selected(false); $('#'+selected[i]['nominee_id']).selected(false);
selected[i]['nominee_id'] = null; selected[i]['nominee_id'] = null;
} }
@@ -129,8 +145,8 @@ export default{
getName: function (id) { getName: function (id) {
let positions = this.data.positions; let positions = this.data.positions;
let selected = this.selected; let selected = this.selected;
for (var i in selected) for (var i in selected)
if (selected[i]['position_id'] == id) if (selected[i]['position_id'] == id)
return this.getNominee(selected[i]['nominee_id']); return this.getNominee(selected[i]['nominee_id']);
return ''; return '';
}, },
@@ -144,7 +160,7 @@ export default{
getPartylist: function (id) { getPartylist: function (id) {
let partylists = this.data.partylists; let partylists = this.data.partylists;
for (var i in partylists) for (var i in partylists)
if (partylists[i]['id']==id) return partylists[i]['name']; if (partylists[i]['id'] == id) return partylists[i]['name'];
return 'No Partylist'; return 'No Partylist';
} }
} }