make the poll code much worse

remotes/1693045480750635534/spooky-22
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);
};
function poll_vote(cid, kind) {
var type = document.getElementById(cid).checked;
var scoretext = document.getElementById('option-' + cid);
var score = Number(scoretext.textContent);
function poll_vote_0(oid, parentid, kind) {
const full_oid = kind + '-' + oid
const type = document.getElementById(full_oid).checked;
const scoretext = document.getElementById('score-' + full_oid);
const score = Number(scoretext.textContent);
if (type == true) 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) {
let curr = document.getElementById(`current-${parentid}`)
function poll_vote_1(oid, parentid, kind) {
const full_oid = kind + '-' + oid
let curr = document.getElementById(`current-${kind}-${parentid}`)
if (curr && curr.value)
{
var scoretext = document.getElementById('option-' + curr.value);
var score = Number(scoretext.textContent);
console.log(curr.value)
const scoretext = document.getElementById('score-' + curr.value);
const score = Number(scoretext.textContent);
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;
post(`/vote/${kind}/option/${cid}`);
curr.value = cid
post(`/vote/${kind}/option/${oid}`);
curr.value = full_oid
}
function bet_vote(cid) {
function bet_vote(oid) {
for(let el of document.getElementsByClassName('bet')) {
el.disabled = true;
}
for(let el of document.getElementsByClassName('cost')) {
el.classList.add('d-none')
}
var scoretext = document.getElementById('option-' + cid);
var scoretext = document.getElementById('option-' + oid);
var score = Number(scoretext.textContent);
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;
}

View File

@ -365,24 +365,24 @@ class Comment(Base):
if self.options:
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 = ''
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:
if o.exclusive:
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')"'''
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="comment-{o.id}" name="option-{self.id}"'
if o.voted(v): body += " checked"
if v:
sub = self.post.sub
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')"'''
else: body += f''' onchange="poll_vote_no_v('{o.id}', '{self.id}')"'''
body += f'''><label class="custom-control-label" for="{o.id}">{o.body_html}<span class="presult-{self.id}'''
body += f'"> - <a href="/votes/comment/option/{o.id}"><span id="option-{o.id}">{o.upvotes}</span> votes</a></span></label></div>'
body += f''' onchange="poll_vote_{o.exclusive}('{o.id}', '{self.id}', 'comment')"'''
else:
body += f''' onchange="poll_vote_no_v()"'''
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)))):
body += f"<hr>{self.author.sig_html}"

View File

@ -355,9 +355,9 @@ class Submission(Base):
if self.options:
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 = ''
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:
if o.exclusive == 2:
@ -373,19 +373,20 @@ class Submission(Base):
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 += "</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:
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 v:
if self.sub in ('furry','vampire','racist','femboy') and not (v.house and v.house.lower().startswith(self.sub)): body += ' disabled '
body += f''' onchange="poll_vote('{o.id}', 'post')"'''
else: body += f''' onchange="poll_vote_no_v('{o.id}', '{self.id}')"'''
body += f'''><label class="custom-control-label" for="{o.id}">{o.body_html}<span class="presult-{self.id}'''
body += f'"> - <a href="/votes/post/option/{o.id}"><span id="option-{o.id}">{o.upvotes}</span> votes</a></span></label></div>'
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 v:
sub = self.sub
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.exclusive}('{o.id}', '{self.id}', 'post')"'''
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/bootstrap.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_v.js': 4000,
'js/submission_listing.js': 4000,