-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
450 lines (416 loc) · 15 KB
/
index.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<!DOCTYPE html>
<html lang="en">
<head>
<title>NebVoter</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/vee-validate@latest/dist/vee-validate.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<style>
html {
position: relative;
min-height: 100%;
}
body {
font-family: "Verdana", sans-serif;
margin-bottom: 40px;
}
.logo {
margin-top: -10px;
}
.navbar {
margin-bottom: 0;
border-radius: 0;
background-color: #2cc185;
padding: 5px 40px 2px 0;
}
.navbar-inverse a.navbar-brand {
color: #FFFFFF;
font-size: 2.2rem;
font-weight: 600;
}
.navbar-brand.brand-discription {
color: #FFFFFF;
font-size: 1.3rem;
margin-top: -38px;
padding-top: 24px;
}
.navbar-nav a.router-link-active, .navbar-nav a.router-link-exact-active {
background-color: #FFFFFF !important;
color: #2cc185 !important;
}
.navbar-nav> li > a.nav-link {
color: #FFFFFF;
font-size: 1.6rem;
font-weight: 600;
line-height: 54px;
min-width: 85px;
padding: 0 17px;
text-align: center;
}
.nav-link .glyphicon {
margin-right: 6px;
font-size: 1.2em;
}
.navbar-nav > li > a.nav-link:hover {
background-color: transparent;
color: #337f61;
}
.main-poll label.control-label {
text-align: left;
padding-top: 0;
}
.poll-answer-header {
margin-bottom: 10px;
}
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
.row.content {height: 450px}
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 40px;
background-color: #2cc185;
color: #FFFFFF;
padding: 5px;
}
.bold {
font-weight: 600;
}
.remove-poll-variant {
margin-top: 7px;
margin-left: -22px;
color: red;
cursor: pointer;
font-size: 1.3em;
}
.poll-save-button {
text-align: right;
}
.poll-buttons {
margin-top: 25px;
}
.form-subtitle {
padding-bottom: 15px;
border-bottom: 1px solid #e6e6e6;
margin-bottom: 15px;
}
.alert-margin {
margin-top: 20px;
font-size: 1.4em;
}
.poll-input {
margin-top: 10px;
}
@media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;}
.navbar-brand.brand-discription {
display: none;
}
}
</style>
</head>
<body>
<div id='app'>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="logo"><router-link class="navbar-brand" to="/home">NebVoter</router-link></div><div class="navbar-brand brand-discription">Voting tool on Nebulas blockchain</div>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right" >
<li><router-link class="nav-link" to="/home"><span class="glyphicon glyphicon-home"></span>Home</router-link></li>
<li><router-link class="nav-link" to="/poll"><span class="glyphicon glyphicon-list-alt"></span>Work with poll</router-lin</li>
<li><a href="#" class="nav-link"><span class="glyphicon glyphicon-question-sign"></span>Help</a></li>
<li><a href="#" class="nav-link"><span class="glyphicon glyphicon-envelope"></span>Contact</a></li>
</ul>
</div>
</div>
</nav>
<router-view></router-view>
</div>
<script id="main-page" type="text/x-template">
<div class="container-fluid text-center">
<div class="row content">
<div class="col-sm-5 col-sm-offset-1 text-left">
<h2>Welcome to NebVoter</h2>
<p><span class="bold">NebVoter</span> is a voting tool based on the Nebulas blockchain. Using blockchain we can guarantee transperancy of the voting.</p>
<p>There are another voting sites and tools, but NebVoter has several key advanages:</p>
<ul>
<li>voting is processed on Nebulas blockchain</li>
<li>every Nebulas address could vote only once</li>
<li>every Nebulas user can create his one voting polls for free</li>
<li>while creating poll you can set voting price - to prevent scum voting from empty addresses or to use poll for some crowd funding</li>
<li>you can set maximum numbers of voters and final date of voting</li>
<li>when the poll is closed, the poll creator could withdraw funds received from voters</li>
</ul>
<p class="bold">To create your own poll on NebVoter please use the form on the right!</p>
<p>You must have Nebulas Web Extension wallet installed to use NebVoter.</p>
<p>To use existing poll - Work with poll</p>
</div>
<div class="col-sm-4 col-sm-offset-1 text-left">
<div v-if="!checkNebulasExtensionWallet()" class="alert alert-warning alert-margin">Please install <a href="https://github.com/ChengOrangeJu/WebExtensionWallet">Nebulas Web Extension wallet.</a></div>
<div v-if="checkNebulasExtensionWallet() && !createdPollId">
<h2>Create your poll</h2>
<div class="form-subtitle">Fill all poll details in form and click "Create poll" button!</div>
<div v-if="contractError" class="alert alert-danger alert-margin">{{contractError}}</div>
<form class="form-horizontal main-poll" @submit.prevent="savePoll">
<div class="form-group" :class="{'has-error': errors.has('pollName') }">
<label for="pollName" class="control-label col-sm-4">Poll name</label>
<div class="col-sm-8">
<input id="pollName" name="pollName" type="text" placeholder="Enter poll name" maxlength="50"
class="form-control" v-model="pollName" v-validate="{required: true}" >
<p class="text-danger" v-if="errors.has('pollName')">The Poll Name field is required.</p>
</div>
</div>
<div class="form-group" :class="{'has-error': errors.has('pollMaxVoters') }">
<label for="pollMaxVoters" class="control-label col-sm-4">Maximum number of voters</label>
<div class="col-sm-8">
<input id="pollMaxVoters" name="pollMaxVoters" type="number" min="1" class="form-control"
v-model="pollMaxVoters" v-validate="{required: true, min_value: 1, numeric: true}">
<p class="text-danger" v-if="errors.has('pollMaxVoters')">The Poll Maximum Voters field is required and should be integer</p>
</div>
</div>
<div class="form-group" :class="{'has-error': errors.has('pollPrice') }">
<label for="pollPrice" class="control-label col-sm-4">Voting price (NAS)</label>
<div class="col-sm-8">
<input id="pollPrice" type="number" step="0.001" class="form-control" name="pollPrice"
v-model="pollPrice" v-validate="{required: true, min_value: 0, decimal: true}">
<p class="text-danger" v-if="errors.has('pollPrice')">The Poll Price field is required.</p>
</div>
</div>
<div class="form-group" :class="{'has-error': errors.has('pollEndDate') }">
<label for="pollEndDate" class="control-label col-sm-4">Poll end date</label>
<div class="col-sm-8">
<input id="pollEndDate" type="date" class="form-control" name="pollEndDate"
v-model="pollEndDate" v-validate="{required: true}">
<p class="text-danger" v-if="errors.has('pollEndDate')">The Poll End Date field is required.</p>
</div>
</div>
<div class="poll-answer-header bold">Poll answer options:</div>
<div v-for="(variant, index) in pollOptions">
<div class="form-group" :class="{'has-error': errors.has('name_' + index) }">
<div class="col-sm-11">
<input type="text" class="form-control" placeholder="Enter poll option"
v-model="pollOptions[index]" v-validate="{required: true}"
:name="'name_' + index">
<p class="text-danger" v-if="errors.has('name_' + index)">Poll option field is required.</p>
</div>
<div class="col-sm-1">
<span class="glyphicon glyphicon-minus-sign remove-poll-variant" @click="removePollOption(index)" v-if='pollOptions.length > 2 '></span>
</div>
</div>
</div>
<div class="form-group poll-buttons">
<div class="col-sm-4">
<button class="btn btn-space btn-primary" type="button" @click="addPollOption">
Add poll answer
</button>
</div>
<div class="col-sm-offset-4 col-sm-4 poll-save-button">
<button class="btn btn-space btn-success"
v-bind:disabled="errors.any()">Create poll</button>
</div>
</div>
</form>
</div>
<div v-if="createdPollId" class="alert alert-success alert-margin">
Your poll was successfully created! Poll ID is {{createdPollId}}
</div>
</div>
</div>
</div>
</script>
<script id="poll-details" type="text/x-template">
<div class="container-fluid">
<div class="row" v-if="selectedPoll === null">
<div class="col-sm-7 col-sm-offset-2">
<h2>Work with poll</h2>
<p>On this page you can work with specific poll - check results, vote and withdraw funds if poll is already close.
To work with poll, <span class="bold">enter the poll ID in the input field below and click GO!</span></p>
<div class="col-sm-7 col-sm-offset-2 poll-input">
<div class="input-group">
<input type="text" class="form-control" id="pollId" name="pollId" placeholder="Enter poll ID..."
v-model="pollId" v-validate="{required: true}">
<span class="input-group-btn">
<button class="btn btn-success" type="button" v-on:click='getPoll'>GO!</button>
</span>
</div>
<p class="text-danger" v-if="errors.has('pollId') || pollIdError">Please enter valid poll ID</p>
</div>
</div>
</div>
<div class="row" v-if="selectedPoll !== null">
<div class="col-sm-7 col-sm-offset-2">
<h2>POLL: {{selectedPoll.poll.pollName}}</h2>
</div>
<div v-for="(value, key) in selectedPoll.poll.pollResults">
<div class="row">
<div class="col-sm-3 col-sm-offset-1">
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar"
aria-valuemin="0" aria-valuemax="100" v-bind:style="{ width: votedWidth(value) }">
{{ value + " votes : " + votedWidth(value) }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</script>
<footer class="container-fluid text-center">
<p>Footer Text</p>
</footer>
<script src=nebPay.min.js></script>
<script type="text/javascript">
var contract_address = "n1xcCKoVJYmN83iZA6PeAs79stGQNJjGSvV";
var NebPay = require("nebpay");
var nebPay = new NebPay();
Vue.use(VeeValidate);
Vue.use(VueRouter);
var Main = Vue.component('main-page',{
template:'#main-page',
data: function(){
return {
pollOptions: ["", ""],
pollName: "",
pollMaxVoters: 1,
pollPrice: 0,
pollEndDate: "",
contractError: "",
createdPollId: null
}
},
methods:{
savePoll: function() {
var self = this;
this.$validator.validateAll().then(function(result) {
if (result) {
nebPay.simulateCall(contract_address, 0, "createPoll", self.getPollArgumets(),
{
listener: self.onCreatePoll
});
}
});
},
addPollOption: function() {
this.pollOptions.push("");
},
removePollOption: function(index) {
this.pollOptions.splice(index, 1);
},
checkNebulasExtensionWallet: function() {
return typeof(webExtensionWallet) !== "undefined";
},
getPollArgumets: function() {
var pollVariants = this.pollOptions.filter(function(opt) {
return opt !== "";
});
var args = [];
args.push(pollName.value, pollVariants, pollPrice.value,
pollMaxVoters.value, pollEndDate.value);
return JSON.stringify(args);
},
onCreatePoll: function(response) {
var self = this;
if (response.execute_err !== "") {
this.contractError = response.result;
console.log(this.contractError);
} else {
this.contractError = null;
nebPay.call(contract_address, 0, "createPoll", this.getPollArgumets(),
{
listener: function(resp) {
console.log(response);
self.createdPollId = JSON.parse(response.result);
}
});
}
}
},
});
//n1KCbiKqnD3vQQTB4Ni7yXWNss6ePnHBPqupoll5
var Poll = Vue.component('poll-details',{
template:'#poll-details',
created: function() {
console.log(this.$route.params.pollId);
if (this.$route.params.pollId) {
this.pollId = this.$route.params.pollId;
this.getPoll();
} else {
this.pollId = "";
}
},
beforeRouteUpdate (to, from, next) {
if (to.params.pollId) {
this.pollId = to.params.pollId;
this.getPoll();
}
next();
},
data: function(){
return {
pollIdError: "",
selectedPoll: null
}
},
methods:{
getPoll: function() {
var self = this;
this.$validator.validateAll().then(function(poll_id){
nebPay.simulateCall(contract_address, 0, "requestPoll", JSON.stringify([self.pollId]),
{
listener: self.onGetPoll
});
});
},
onGetPoll: function(response) {
console.log("onGetPoll", response);
if (response.execute_err !== "") {
this.pollIdError = "Please enter valid Poll ID."
} else {
this.pollIdError = "";
this.selectedPoll = JSON.parse(response.result);
this.selectedPoll.poll.votedUsersCount = 10; // mock
this.selectedPoll.poll.pollResults = {"f" : "2", "g": "3", "h": "5", "z": 0}; // mock
console.log(this.selectedPoll);
}
},
votedWidth: function(value) {
var width = this.selectedPoll.poll.votedUsersCount === "0" ? 0 : Math.floor((+value / +this.selectedPoll.poll.votedUsersCount) * 100);
console.log(width + "%");
return width + "%";
}
}
});
var routes = [
{ path: '/', redirect: '/home' },
{ path: '/home', component: Main },
{ path: '/poll/:pollId?', component: Poll }
];
var router = new VueRouter({
routes: routes
});
var app = new Vue({
el: "#app",
router: router,
data: {},
methods: {}
});
</script>
</body>
</html>