| rev | line source | 
| bsw@1619 | 1 function toggleInterest(issueId) { | 
| bsw@1619 | 2   var linkEl = document.getElementById("issue_" + issueId + "_interest_link"); | 
| bsw@1619 | 3   var iconEl = document.getElementById("issue_" + issueId + "_interest_icon"); | 
| bsw@1618 | 4   var interested = iconEl.innerHTML == "star_outline"; | 
| bsw@1619 | 5 | 
| bsw@1619 | 6   if (interested) { | 
| bsw@1619 | 7     linkEl.classList.add("mdl-button--accent"); | 
| bsw@1619 | 8     linkEl.classList.add("mdl-button--feature-on"); | 
| bsw@1619 | 9     linkEl.classList.remove("mdl-button--feature-off"); | 
| bsw@1619 | 10     iconEl.innerHTML = "star"; | 
| bsw@1619 | 11   } else { | 
| bsw@1619 | 12     linkEl.classList.remove("mdl-button--accent"); | 
| bsw@1619 | 13     linkEl.classList.remove("mdl-button--feature-on"); | 
| bsw@1619 | 14     linkEl.classList.add("mdl-button--feature-off"); | 
| bsw@1619 | 15     iconEl.innerHTML = "star_outline"; | 
| bsw@1619 | 16   } | 
| bsw@1618 | 17 | 
| bsw@1618 | 18   var data = new FormData(); | 
| bsw@1619 | 19   data.append("issue_id", issueId); | 
| bsw@1618 | 20   data.append("interested", interested); | 
| bsw@1618 | 21 | 
| bsw@1649 | 22   fetch(baseURL + "interest/xhr_update", { | 
| bsw@1649 | 23     method: "POST", | 
| bsw@1649 | 24     body: data | 
| bsw@1649 | 25   }).then(response => { | 
| bsw@1649 | 26     if (response.status != 200) { | 
| bsw@1649 | 27       window.alert("Error during update"); | 
| bsw@1649 | 28     } | 
| bsw@1649 | 29   }); | 
| bsw@1618 | 30 | 
| bsw@1618 | 31 } | 
| bsw@1618 | 32 | 
| bsw@1649 | 33 function rateSuggestion(id, degree, fulfilled) { | 
| bsw@1649 | 34   document.getElementById('rating_suggestion_id').value = id; | 
| bsw@1649 | 35   document.getElementById('rating_degree' + degree).MaterialRadio.check(); | 
| bsw@1649 | 36   if (fulfilled) { | 
| bsw@1649 | 37     document.getElementById('rating_fulfilled').MaterialRadio.check(); | 
| bsw@1649 | 38   } else if (fulfilled == false) { | 
| bsw@1649 | 39     document.getElementById('rating_notfulfilled').MaterialRadio.check(); | 
| bsw@1649 | 40   } else { | 
| bsw@1649 | 41     document.getElementById('rating_fulfilled').MaterialRadio.uncheck(); | 
| bsw@1649 | 42     document.getElementById('rating_notfulfilled').MaterialRadio.uncheck(); | 
| bsw@1649 | 43   } | 
| bsw@1649 | 44   document.getElementById('rating_dialog').showModal(); | 
| bsw@1649 | 45 } | 
| bsw@1649 | 46 | 
| bsw@1649 | 47 function updateOpinion() { | 
| bsw@1649 | 48   var suggestionId = document.getElementById("rating_suggestion_id").value; | 
| bsw@1649 | 49 | 
| bsw@1649 | 50   var degree = 0; | 
| bsw@1649 | 51   if (document.getElementById("rating_degree-2").children[0].checked) | 
| bsw@1649 | 52     degree = -2; | 
| bsw@1649 | 53   else if (document.getElementById("rating_degree-1").children[0].checked) | 
| bsw@1649 | 54     degree = -1; | 
| bsw@1649 | 55   else if (document.getElementById("rating_degree1").children[0].checked) | 
| bsw@1649 | 56     degree = 1; | 
| bsw@1649 | 57   else if (document.getElementById("rating_degree2").children[0].checked) | 
| bsw@1649 | 58     degree = 2; | 
| bsw@1649 | 59   var fulfilled = false; | 
| bsw@1649 | 60   if (document.getElementById("rating_fulfilled").children[0].checked) | 
| bsw@1649 | 61     fulfilled = true; | 
| bsw@1649 | 62   if (degree == 0) | 
| bsw@1649 | 63     fulfilled = null; | 
| bsw@1649 | 64   var data = new FormData(); | 
| bsw@1649 | 65   data.append("suggestion_id", suggestionId); | 
| bsw@1649 | 66   data.append("degree", degree); | 
| bsw@1649 | 67   data.append("fulfilled", fulfilled); | 
| bsw@1649 | 68 | 
| bsw@1649 | 69   var degreeText = rateSuggestionDegreeTexts[degree]; | 
| bsw@1649 | 70   var fulfilledText = fulfilled ? rateSuggestionFulfilledText : rateSuggestionNotFulfilledText; | 
| bsw@1649 | 71   var andButText; | 
| bsw@1649 | 72   var icon; | 
| bsw@1649 | 73   var iconColor; | 
| bsw@1649 | 74   if ( | 
| bsw@1649 | 75     (degree > 0 && ! fulfilled) | 
| bsw@1649 | 76     || (degree < 0 && fulfilled) | 
| bsw@1649 | 77   ) { | 
| bsw@1649 | 78     icon = "warning"; | 
| bsw@1649 | 79     if (degree == 2 || degree == -2) { | 
| bsw@1649 | 80       iconColor = "red"; | 
| bsw@1649 | 81     } | 
| bsw@1649 | 82     andButText = rateSuggestionButText; | 
| bsw@1649 | 83   } else { | 
| bsw@1649 | 84     andButText = rateSuggestionAndText; | 
| bsw@1649 | 85     icon = "done"; | 
| bsw@1649 | 86   } | 
| bsw@1649 | 87   var text = degreeText + " " + andButText + " " + fulfilledText; | 
| bsw@1649 | 88   if (degree == 0) { | 
| bsw@1649 | 89     text = ""; | 
| bsw@1649 | 90     icon = "blank"; | 
| bsw@1649 | 91   } | 
| bsw@1649 | 92   document.getElementById("s" + suggestionId + "_rating_text").innerHTML = text; | 
| bsw@1649 | 93   document.getElementById("s" + suggestionId + "_rating_icon").innerHTML = icon; | 
| bsw@1649 | 94   if (iconColor == "red") { | 
| bsw@1649 | 95     document.getElementById("s" + suggestionId + "_rating_icon").classList.add("icon-red"); | 
| bsw@1649 | 96   } else { | 
| bsw@1649 | 97     document.getElementById("s" + suggestionId + "_rating_icon").classList.remove("icon-red"); | 
| bsw@1649 | 98   } | 
| bsw@1649 | 99   if (degree == 0) { | 
| bsw@1649 | 100     document.getElementById("s" + suggestionId + "_rate_button").innerHTML = rateSuggestionRateText; | 
| bsw@1649 | 101   } else { | 
| bsw@1649 | 102     document.getElementById("s" + suggestionId + "_rate_button").innerHTML = rateSuggestionUpdateRatingText; | 
| bsw@1649 | 103   } | 
| bsw@1649 | 104   document.getElementById("s" + suggestionId + "_rate_button").setAttribute("onclick", "rateSuggestion(" + suggestionId + ", " + degree + ", " + fulfilled + ");return false;") | 
| bsw@1649 | 105   document.getElementById('rating_dialog').close(); | 
| bsw@1649 | 106 | 
| bsw@1649 | 107   fetch(baseURL + "opinion/xhr_update", { | 
| bsw@1649 | 108     method: "POST", | 
| bsw@1649 | 109     body: data | 
| bsw@1649 | 110   }).then(response => { | 
| bsw@1649 | 111     if (response.status != 200) { | 
| bsw@1649 | 112       window.alert("Error during update"); | 
| bsw@1649 | 113     } | 
| bsw@1649 | 114   }); | 
| bsw@1649 | 115 | 
| bsw@1649 | 116 } |