forked from rDrama/rDrama
1
0
Fork 0

make the poll code much worse

master
Aevann1 2022-09-06 01:33:58 +02:00
parent ed60cafb24
commit f8cd1bea03
4 changed files with 46 additions and 42 deletions

View File

@ -81,43 +81,46 @@ function post(url) {
xhr.send(form); xhr.send(form);
}; };
function poll_vote(cid, kind) { function poll_vote_0(oid, parentid, kind) {
var type = document.getElementById(cid).checked; const full_oid = kind + '-' + oid
var scoretext = document.getElementById('option-' + cid); const type = document.getElementById(full_oid).checked;
var score = Number(scoretext.textContent); const scoretext = document.getElementById('score-' + full_oid);
const score = Number(scoretext.textContent);
if (type == true) scoretext.textContent = score + 1; if (type == true) scoretext.textContent = score + 1;
else scoretext.textContent = score - 1; else scoretext.textContent = score - 1;
post(`/vote/${kind}/option/${cid}`); post(`/vote/${kind}/option/${oid}`);
} }
function choice_vote(cid, parentid, kind) { function poll_vote_1(oid, parentid, kind) {
let curr = document.getElementById(`current-${parentid}`) const full_oid = kind + '-' + oid
let curr = document.getElementById(`current-${kind}-${parentid}`)
if (curr && curr.value) if (curr && curr.value)
{ {
var scoretext = document.getElementById('option-' + curr.value); console.log(curr.value)
var score = Number(scoretext.textContent); const scoretext = document.getElementById('score-' + curr.value);
const score = Number(scoretext.textContent);
scoretext.textContent = score - 1; scoretext.textContent = score - 1;
} }
var scoretext = document.getElementById('option-' + cid); const scoretext = document.getElementById('score-' + full_oid);
var score = Number(scoretext.textContent); const score = Number(scoretext.textContent);
scoretext.textContent = score + 1; scoretext.textContent = score + 1;
post(`/vote/${kind}/option/${cid}`); post(`/vote/${kind}/option/${oid}`);
curr.value = cid curr.value = full_oid
} }
function bet_vote(cid) { function bet_vote(oid) {
for(let el of document.getElementsByClassName('bet')) { for(let el of document.getElementsByClassName('bet')) {
el.disabled = true; el.disabled = true;
} }
for(let el of document.getElementsByClassName('cost')) { for(let el of document.getElementsByClassName('cost')) {
el.classList.add('d-none') el.classList.add('d-none')
} }
var scoretext = document.getElementById('option-' + cid); var scoretext = document.getElementById('option-' + oid);
var score = Number(scoretext.textContent); var score = Number(scoretext.textContent);
scoretext.textContent = score + 1; scoretext.textContent = score + 1;
post(`/vote/post/option/${cid}`); post(`/vote/post/option/${oid}`);
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200; document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200;
} }

View File

@ -365,24 +365,24 @@ class Comment(Base):
if self.options: if self.options:
curr = [x for x in self.options if x.exclusive and x.voted(v)] curr = [x for x in self.options if x.exclusive and x.voted(v)]
if curr: curr = " value=" + str(curr[0].id) if curr: curr = " value=comment-" + str(curr[0].id)
else: curr = '' else: curr = ''
body += f'<input class="d-none" id="current-{self.id}"{curr}>' body += f'<input class="d-none" id="current-comment-{self.id}"{curr}>'
for o in self.options: for o in self.options:
if o.exclusive: input_type = 'radio' if o.exclusive else 'checkbox'
body += f'''<div class="custom-control"><input name="option-{self.id}" autocomplete="off" class="custom-control-input" type="radio" id="{o.id}" onchange="choice_vote('{o.id}','{self.id}','comment')"''' body += f'<div class="custom-control"><input type="{input_type}" class="custom-control-input" id="comment-{o.id}" name="option-{self.id}"'
else:
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{o.id}" name="option"'
if o.voted(v): body += " checked" if o.voted(v): body += " checked"
if v: if v:
sub = self.post.sub sub = self.post.sub
if sub in ('furry','vampire','racist','femboy') and not (v.house and v.house.lower().startswith(sub)): body += ' disabled ' if sub in ('furry','vampire','racist','femboy') and not (v.house and v.house.lower().startswith(sub)): body += ' disabled '
body += f''' onchange="poll_vote('{o.id}', 'comment')"''' body += f''' onchange="poll_vote_{o.exclusive}('{o.id}', '{self.id}', 'comment')"'''
else: body += f''' onchange="poll_vote_no_v('{o.id}', '{self.id}')"''' else:
body += f'''><label class="custom-control-label" for="{o.id}">{o.body_html}<span class="presult-{self.id}''' body += f''' onchange="poll_vote_no_v()"'''
body += f'"> - <a href="/votes/comment/option/{o.id}"><span id="option-{o.id}">{o.upvotes}</span> votes</a></span></label></div>'
body += f'''><label class="custom-control-label" for="comment-{o.id}">{o.body_html} -
<a href="/votes/comment/option/{o.id}"><span id="score-comment-{o.id}">{o.upvotes}</span> votes</a></label></div>'''
if self.author.sig_html and (self.author_id == MOOSE_ID or (not self.ghost and not (v and (v.sigs_disabled or v.poor)))): if self.author.sig_html and (self.author_id == MOOSE_ID or (not self.ghost and not (v and (v.sigs_disabled or v.poor)))):
body += f"<hr>{self.author.sig_html}" body += f"<hr>{self.author.sig_html}"

View File

@ -355,9 +355,9 @@ class Submission(Base):
if self.options: if self.options:
curr = [x for x in self.options if x.exclusive and x.voted(v)] curr = [x for x in self.options if x.exclusive and x.voted(v)]
if curr: curr = " value=" + str(curr[0].id) if curr: curr = " value=post-" + str(curr[0].id)
else: curr = '' else: curr = ''
body += f'<input class="d-none" id="current-{self.id}"{curr}>' body += f'<input class="d-none" id="current-post-{self.id}"{curr}>'
for o in self.options: for o in self.options:
if o.exclusive == 2: if o.exclusive == 2:
@ -373,19 +373,20 @@ class Submission(Base):
if v and v.admin_level > 2: if v and v.admin_level > 2:
body += f'''<button class="btn btn-primary px-2 mx-2" style="font-size:10px;padding:2px" onclick="post_toast(this,'/distribute/{o.id}')">Declare winner</button>''' body += f'''<button class="btn btn-primary px-2 mx-2" style="font-size:10px;padding:2px" onclick="post_toast(this,'/distribute/{o.id}')">Declare winner</button>'''
body += "</div>" body += "</div>"
elif o.exclusive == 1:
body += f'''<div class="custom-control"><input name="option-{self.id}" autocomplete="off" class="custom-control-input" type="radio" id="{o.id}" onchange="choice_vote('{o.id}','{self.id}','post')"'''
else: else:
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{o.id}" name="option"' input_type = 'radio' if o.exclusive else 'checkbox'
body += f'<div class="custom-control"><input type="{input_type}" class="custom-control-input" id="post-{o.id}" name="option-{self.id}"'
if o.voted(v): body += " checked" if o.voted(v): body += " checked"
if v:
if self.sub in ('furry','vampire','racist','femboy') and not (v.house and v.house.lower().startswith(self.sub)): body += ' disabled ' if v:
body += f''' onchange="poll_vote('{o.id}', 'post')"''' sub = self.sub
else: body += f''' onchange="poll_vote_no_v('{o.id}', '{self.id}')"''' if sub in ('furry','vampire','racist','femboy') and not (v.house and v.house.lower().startswith(sub)): body += ' disabled '
body += f'''><label class="custom-control-label" for="{o.id}">{o.body_html}<span class="presult-{self.id}''' body += f''' onchange="poll_vote_{o.exclusive}('{o.id}', '{self.id}', 'post')"'''
body += f'"> - <a href="/votes/post/option/{o.id}"><span id="option-{o.id}">{o.upvotes}</span> votes</a></span></label></div>' else:
body += f''' onchange="poll_vote_no_v()"'''
body += f'''><label class="custom-control-label" for="post-{o.id}">{o.body_html} -
<a href="/votes/post/option/{o.id}"><span id="score-post-{o.id}">{o.upvotes}</span> votes</a></label></div>'''

View File

@ -18,7 +18,7 @@ set CACHE_VER = {
'js/award_modal.js': 4000, 'js/award_modal.js': 4000,
'js/bootstrap.js': 4000, 'js/bootstrap.js': 4000,
'js/category_modal.js': 4000, 'js/category_modal.js': 4000,
'js/comments+submission_listing.js': 4006, 'js/comments+submission_listing.js': 4007,
'js/comments_admin.js': 4000, 'js/comments_admin.js': 4000,
'js/comments_v.js': 4000, 'js/comments_v.js': 4000,
'js/submission_listing.js': 4000, 'js/submission_listing.js': 4000,