function renderEditIssue()

in pysteve/www/htdocs/js/steve_rest.js [427:644]


function renderEditIssue(code, response, issue) {
    if (code == 200) {
        var obj = document.getElementById('preloaderWrapper')
        obj.setAttribute("id", "contents")
        for (i in response.issues) {
            if (response.issues[i].id == issue) {
                edit_i = response.issues[i]
                break
            }
        }
        if (!edit_i) {
            obj.innerHTML = "<h3>No such issue found :( </h3>"
        }
        else if (edit_i.type == "yna") {
            obj.innerHTML = "<h3>Editing a YNA issue</h3>"
            
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("nominatedby", "Nominated by:", "text", edit_i.nominatedby))
            obj.appendChild(keyvaluepair("seconds", "Seconded by:", "text", (edit_i.seconds ? edit_i.seconds : []).join(", ")))
            obj.appendChild(document.createElement('hr'))
            obj.appendChild(keyvaluepair("description", "Description/statement:", "textarea", edit_i.description))
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveYNA();")
            div.appendChild(btn)
            obj.appendChild(div)
            
        } else if (edit_i.type == "ap") {
            obj.innerHTML = "<h3>Editing a Apache PMC Style issue</h3>"
            
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("nominatedby", "Nominated by:", "text", edit_i.nominatedby))
            obj.appendChild(keyvaluepair("seconds", "Seconded by:", "text", (edit_i.seconds ? edit_i.seconds : []).join(", ")))
            obj.appendChild(document.createElement('hr'))
            obj.appendChild(keyvaluepair("description", "Description/statement:", "textarea", edit_i.description))
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveYNA();")
            div.appendChild(btn)
            obj.appendChild(div)
        } else if (edit_i.type.match(/^stv/)) {
            
            // base data
            obj.innerHTML = "<h3>Editing an " + edit_i.type.toUpperCase() + " issue</h3>"
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("description", "Description (optional):", "textarea", edit_i.description))
            obj.appendChild(document.createElement('hr'))
            
            // candidates
            var cobj = document.createElement('div')
            cobj.setAttribute("id", "candidateList")
            cobj.setAttribute("class", "candidateEditList")
            obj.appendChild(cobj)
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveSTV();")
            div.appendChild(btn)
            obj.appendChild(div)
            renderEditCandidates()
        } else if (edit_i.type.match(/^dh/)) {
            
            // base data
            obj.innerHTML = "<h3>Editing a D'Hondt (" + edit_i.type.toUpperCase() + ") issue</h3>"
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("description", "Description (optional):", "textarea", edit_i.description))
            obj.appendChild(document.createElement('hr'))
            
            // candidates
            var cobj = document.createElement('div')
            cobj.setAttribute("id", "candidateList")
            cobj.setAttribute("class", "candidateEditList")
            obj.appendChild(cobj)
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveSTV();")
            div.appendChild(btn)
            obj.appendChild(div)
            renderEditCandidates()
        }
        else if (edit_i.type.match(/^fpp/)) {
            
            // base data
            obj.innerHTML = "<h3>Editing a First Past the Post issue</h3>"
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("description", "Description (optional):", "textarea", edit_i.description))
            obj.appendChild(document.createElement('hr'))
            
            // candidates
            var cobj = document.createElement('div')
            cobj.setAttribute("id", "candidateList")
            cobj.setAttribute("class", "candidateEditList")
            obj.appendChild(cobj)
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveSTV();")
            div.appendChild(btn)
            obj.appendChild(div)
            renderEditCandidates()
        }
        else if (edit_i.type.match(/^mntv/)) {
            
            // base data
            obj.innerHTML = "<h3>Editing a Multiple Non-Transferable Vote (" + edit_i.type.toUpperCase() + ") issue</h3>"
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("description", "Description (optional):", "textarea", edit_i.description))
            obj.appendChild(document.createElement('hr'))
            
            // candidates
            var cobj = document.createElement('div')
            cobj.setAttribute("id", "candidateList")
            cobj.setAttribute("class", "candidateEditList")
            obj.appendChild(cobj)
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveSTV();")
            div.appendChild(btn)
            obj.appendChild(div)
            renderEditCandidates()
        }
        else if (edit_i.type.match(/^fic/)) {
            
            // base data
            obj.innerHTML = "<h3>Editing a First in Class Vote (" + edit_i.type.toUpperCase() + ") issue</h3>"
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("description", "Description (optional):", "textarea", edit_i.description))
            obj.appendChild(document.createElement('hr'))
            
            // candidates
            var cobj = document.createElement('div')
            cobj.setAttribute("id", "candidateList")
            cobj.setAttribute("class", "candidateEditList")
            obj.appendChild(cobj)
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveSTV();")
            div.appendChild(btn)
            obj.appendChild(div)
            renderEditCandidates()
        }
        else if (edit_i.type.match(/^cop/)) {
            
            // base data
            obj.innerHTML = "<h3>Editing a Candidate or Party Vote (" + edit_i.type.toUpperCase() + ") issue</h3>"
            obj.appendChild(keyvaluepair("id", "Issue ID:", "text", edit_i.id, true))
            obj.appendChild(keyvaluepair("ititle", "Issue title:", "text", edit_i.title))
            obj.appendChild(keyvaluepair("description", "Description (optional):", "textarea", edit_i.description))
            obj.appendChild(document.createElement('hr'))
            
            // candidates/parties
            var p = null
            var pletter = null
            var biglist = ""
            for (i in edit_i.candidates) {
                var c = edit_i.candidates[i]
                if (c['pletter'] != pletter) {
                    biglist += "\n" + c['pletter'].toUpperCase() + ":" + c['pname'] + "\n"
                    pletter = c['pletter']
                }
                biglist += c['name'] + "\n"
            }
            obj.appendChild(keyvaluepair("candidates", "Candidate/Party List:", "textarea", biglist))
            
            var div = document.createElement('div')
            div.setAttribute("class", "keyvaluepair")
            var btn = document.createElement('input')
            btn.setAttribute("type", "button")
            btn.setAttribute("class", "btn-green")
            btn.setAttribute("value", "Save changes")
            btn.setAttribute("onclick", "saveYNA();")
            div.appendChild(btn)
            obj.appendChild(div)
        }
    } else {
        alert(response.message)
    }
}