Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
Votacion
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
Votacion
Commits
cc42398d
Commit
cc42398d
authored
6 years ago
by
Miguel Braidot
Browse files
Options
Downloads
Patches
Plain Diff
El formulario de votación envía la transacción al SC
parent
b47c83b4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
web/dist/js/vendor/ballot.js
+36
-3
36 additions, 3 deletions
web/dist/js/vendor/ballot.js
web/dist/smartVotar.html
+47
-7
47 additions, 7 deletions
web/dist/smartVotar.html
with
83 additions
and
10 deletions
web/dist/js/vendor/ballot.js
+
36
−
3
View file @
cc42398d
...
...
@@ -496,6 +496,39 @@ async function ver_votacion2(addr, code) {
}
}
async
function
votar
(
addr
,
proposal
){
await
access_accounts
();
return
new
Promise
(
function
(
resolve
,
reject
)
{
window
.
web3
.
eth
.
getCode
(
addr
,
function
(
err
,
code
)
{
if
(
err
)
{
reject
(
'
No es posible obtener el bytecode del contrato:
'
+
err
+
''
);
}
if
(
code
==
'
0x
'
)
{
reject
(
'
No existe un contrato con esa dirección
'
);
}
var
contract
=
setup_existing_instance
(
abiBallot
,
addr
);
if
(
!
contract
){
reject
(
"
No existe un contrato en esa dirección
"
);
}
contract
.
vote
.
sendTransaction
(
proposal
,
{
gas
:
2111000
},
function
(
error
,
result
)
{
if
(
error
)
{
reject
(
error
);
}
else
{
resolve
(
result
);
}
});
});
});
}
///////////////////////////////////////////////////////////
// UTILS for ballot form creation
///////////////////////////////////////////////////////////
...
...
@@ -517,7 +550,7 @@ async function getBallotVoteStarts(err, rcpt){
}
else
{
$
(
'
#comienza_votacion
'
).
text
(
getDateFromTimestamp
(
rcpt
));
var
today
=
new
Date
();
if
(
rcpt
>
today
.
getTime
()){
if
(
rcpt
>
today
.
getTime
()
/
1000
){
$
(
"
#form_votacion :input
"
).
prop
(
"
disabled
"
,
true
);
alertar
(
"
La votación no ha comenzado aún.
"
);
}
...
...
@@ -529,7 +562,7 @@ async function getBallotVoteBefore(err, rcpt){
}
else
{
$
(
'
#termina_votacion
'
).
text
(
getDateFromTimestamp
(
rcpt
));
var
today
=
new
Date
();
if
(
rcpt
<
today
.
getTime
()){
if
(
rcpt
<
today
.
getTime
()
/
1000
){
$
(
"
#form_votacion :input
"
).
prop
(
"
disabled
"
,
true
);
alertar
(
"
La votación ha finalizado.
"
);
}
...
...
@@ -551,7 +584,7 @@ async function getProposalList(err, rcpt){
}
else
{
var
num
=
$
(
'
#proposals div
'
).
length
;
var
element
=
'
<div class="radio">
\
<input type="radio" name="votacion" id="vote_
'
+
num
+
'
" required="required" aria-required="true">
\
<input type="radio" name="votacion" id="vote_
'
+
num
+
'
"
value="
'
+
num
+
'
"
required="required" aria-required="true">
\
<label for="vote_
'
+
num
+
'
">
'
+
hex2ascii
(
rcpt
)
+
'
</label>
\
</div>
'
;
$
(
'
#proposals
'
).
append
(
element
);
...
...
This diff is collapsed.
Click to expand it.
web/dist/smartVotar.html
+
47
−
7
View file @
cc42398d
...
...
@@ -180,6 +180,36 @@
ver_votacion
(
input_address
);
}
async
function
sendVotacion
(){
$
(
"
#voterow :input
"
).
attr
(
"
disabled
"
,
true
);
$
(
"
#voterow .btn
"
).
hide
();
try
{
if
(
typeof
input_address
!=
"
undefined
"
&&
input_address
!=
""
){
var
proposal
=
$
(
"
input[name='votacion']:checked
"
).
val
();
let
resultado
=
await
votar
(
input_address
,
proposal
);
console
.
log
(
"
resultado:
"
);
console
.
log
(
resultado
.
toString
(
10
));
alertarSuccess
(
'
¡Votaste con éxito!
'
);
$
(
"
form
"
).
hide
();
$
(
"
.resultados
"
).
show
();
$
(
"
.votar legend
"
).
text
(
'
Tu voto
'
);
}
else
{
alertar
(
'
Ocurrió un error
'
);
$
(
"
#voterow .btn
"
).
show
();
}
}
catch
(
error
){
alertar
(
error
);
$
(
"
#voterow .btn
"
).
show
();
return
false
;
}
}
$
(
"
form
"
).
validate
({
focusInvalid
:
false
,
errorContainer
:
container
,
...
...
@@ -203,18 +233,28 @@
}
},
submitHandler
:
function
(
form
)
{
// do other things for a valid form
//form.submit();
var
body
=
$
(
"
html, body
"
);
body
.
stop
().
animate
({
scrollTop
:
0
},
200
)
alertarSuccess
(
'
¡Votaste con éxito!
'
);
$
(
"
#voterow :input
"
).
attr
(
"
disabled
"
,
true
);
sendVotacion
();
/*$("#voterow :input").attr("disabled", true);
$("#voterow .btn").hide();
$
(
"
form
"
).
hide
();
$
(
"
.resultados
"
).
show
();
$
(
"
.votar legend
"
).
text
(
'
Tu voto
'
);
var result = sendVotacion();
console.log(result);
if (result === true){
alertarSuccess('¡Votaste con éxito!');
$("form").hide();
$(".resultados").show();
$(".votar legend").text('Tu voto');
}else{
alertar('Ocurrió un error');
$("#voterow :input").attr("disabled", false);
$("#voterow .btn").show();
}*/
},
messages
:
{
votacion
:
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment