bsw@1619: function toggleInterest(issueId) { bsw@1619: var linkEl = document.getElementById("issue_" + issueId + "_interest_link"); bsw@1619: var iconEl = document.getElementById("issue_" + issueId + "_interest_icon"); bsw@1618: var interested = iconEl.innerHTML == "star_outline"; bsw@1619: bsw@1619: if (interested) { bsw@1619: linkEl.classList.add("mdl-button--accent"); bsw@1619: linkEl.classList.add("mdl-button--feature-on"); bsw@1619: linkEl.classList.remove("mdl-button--feature-off"); bsw@1619: iconEl.innerHTML = "star"; bsw@1619: } else { bsw@1619: linkEl.classList.remove("mdl-button--accent"); bsw@1619: linkEl.classList.remove("mdl-button--feature-on"); bsw@1619: linkEl.classList.add("mdl-button--feature-off"); bsw@1619: iconEl.innerHTML = "star_outline"; bsw@1619: } bsw@1618: bsw@1618: var data = new FormData(); bsw@1619: data.append("issue_id", issueId); bsw@1618: data.append("interested", interested); bsw@1618: bsw@1649: fetch(baseURL + "interest/xhr_update", { bsw@1649: method: "POST", bsw@1649: body: data bsw@1649: }).then(response => { bsw@1649: if (response.status != 200) { bsw@1649: window.alert("Error during update"); bsw@1649: } bsw@1649: }); bsw@1618: bsw@1618: } bsw@1618: bsw@1649: function rateSuggestion(id, degree, fulfilled) { bsw@1649: document.getElementById('rating_suggestion_id').value = id; bsw@1649: document.getElementById('rating_degree' + degree).MaterialRadio.check(); bsw@1649: if (fulfilled) { bsw@1649: document.getElementById('rating_fulfilled').MaterialRadio.check(); bsw@1649: } else if (fulfilled == false) { bsw@1649: document.getElementById('rating_notfulfilled').MaterialRadio.check(); bsw@1649: } else { bsw@1649: document.getElementById('rating_fulfilled').MaterialRadio.uncheck(); bsw@1649: document.getElementById('rating_notfulfilled').MaterialRadio.uncheck(); bsw@1649: } bsw@1649: document.getElementById('rating_dialog').showModal(); bsw@1649: } bsw@1649: bsw@1649: function updateOpinion() { bsw@1649: var suggestionId = document.getElementById("rating_suggestion_id").value; bsw@1649: bsw@1649: var degree = 0; bsw@1649: if (document.getElementById("rating_degree-2").children[0].checked) bsw@1649: degree = -2; bsw@1649: else if (document.getElementById("rating_degree-1").children[0].checked) bsw@1649: degree = -1; bsw@1649: else if (document.getElementById("rating_degree1").children[0].checked) bsw@1649: degree = 1; bsw@1649: else if (document.getElementById("rating_degree2").children[0].checked) bsw@1649: degree = 2; bsw@1649: var fulfilled = false; bsw@1649: if (document.getElementById("rating_fulfilled").children[0].checked) bsw@1649: fulfilled = true; bsw@1649: if (degree == 0) bsw@1649: fulfilled = null; bsw@1649: var data = new FormData(); bsw@1649: data.append("suggestion_id", suggestionId); bsw@1649: data.append("degree", degree); bsw@1649: data.append("fulfilled", fulfilled); bsw@1649: bsw@1649: var degreeText = rateSuggestionDegreeTexts[degree]; bsw@1649: var fulfilledText = fulfilled ? rateSuggestionFulfilledText : rateSuggestionNotFulfilledText; bsw@1649: var andButText; bsw@1649: var icon; bsw@1649: var iconColor; bsw@1649: if ( bsw@1649: (degree > 0 && ! fulfilled) bsw@1649: || (degree < 0 && fulfilled) bsw@1649: ) { bsw@1649: icon = "warning"; bsw@1649: if (degree == 2 || degree == -2) { bsw@1649: iconColor = "red"; bsw@1649: } bsw@1649: andButText = rateSuggestionButText; bsw@1649: } else { bsw@1649: andButText = rateSuggestionAndText; bsw@1649: icon = "done"; bsw@1649: } bsw@1649: var text = degreeText + " " + andButText + " " + fulfilledText; bsw@1649: if (degree == 0) { bsw@1649: text = ""; bsw@1649: icon = "blank"; bsw@1649: } bsw@1649: document.getElementById("s" + suggestionId + "_rating_text").innerHTML = text; bsw@1649: document.getElementById("s" + suggestionId + "_rating_icon").innerHTML = icon; bsw@1649: if (iconColor == "red") { bsw@1649: document.getElementById("s" + suggestionId + "_rating_icon").classList.add("icon-red"); bsw@1649: } else { bsw@1649: document.getElementById("s" + suggestionId + "_rating_icon").classList.remove("icon-red"); bsw@1649: } bsw@1649: if (degree == 0) { bsw@1649: document.getElementById("s" + suggestionId + "_rate_button").innerHTML = rateSuggestionRateText; bsw@1649: } else { bsw@1649: document.getElementById("s" + suggestionId + "_rate_button").innerHTML = rateSuggestionUpdateRatingText; bsw@1649: } bsw@1649: document.getElementById("s" + suggestionId + "_rate_button").setAttribute("onclick", "rateSuggestion(" + suggestionId + ", " + degree + ", " + fulfilled + ");return false;") bsw@1649: document.getElementById('rating_dialog').close(); bsw@1649: bsw@1649: fetch(baseURL + "opinion/xhr_update", { bsw@1649: method: "POST", bsw@1649: body: data bsw@1649: }).then(response => { bsw@1649: if (response.status != 200) { bsw@1649: window.alert("Error during update"); bsw@1649: } bsw@1649: }); bsw@1649: bsw@1649: }