Drag and drop in ranked preferences input

This commit is contained in:
tayyyyyyy
2019-07-08 14:59:51 -07:00
parent 6720093a2a
commit bed6f9b0ef
2 changed files with 42 additions and 2 deletions
+16 -2
View File
@@ -100,15 +100,20 @@
height = 400
immediate_submit = TRUE
/datum/async_input/ranked/New()
..()
popup.add_script("rankedInput.js", 'html/browser/rankedInput.js')
popup.add_head_content("<title>Drag and drop or use the buttons to reorder</title>")
/datum/async_input/ranked/render_choices()
var/dat = "<div>"
dat += "<table style='margin: auto; text-align: left;'>"
dat += "<table id='choices' uid=[UID()] style='margin: auto; text-align: left;'>"
for(var/i = 1, i <= choices.len, i++)
var/choice = choices[i]
dat += "<tr>"
dat += "<td>[button("+", i != 1 ? "upvote=[i]" : "", , i == 1)]</td>"
dat += "<td>[button("-", i != choices.len ? "downvote=[i]" : "", , i == choices.len)]</td>"
dat += "<td>[i]. [choice]</td>"
dat += "<td style='cursor: move;' index='[i]' ondrop='drop(event)' ondragover='allowDrop(event)' draggable='true' ondragstart='drag(event)'>[i]. [choice]</td>"
dat += "</tr>"
dat += "</table>"
dat += "</div>"
@@ -131,6 +136,15 @@
show()
return
if(href_list["cut"] && href_list["insert"])
var/cut = text2num(href_list["cut"])
var/insert = text2num(href_list["insert"])
var/choice = choices[cut]
choices.Cut(cut, cut + 1)
choices.Insert(insert, choice)
show()
return
..()
/datum/async_input/autocomplete