liquid_feedback_frontend

annotate static/js/xhr.js @ 1805:dadba1e28226

Avoid counter overlapping with question text
author bsw
date Thu Nov 18 14:33:00 2021 +0100 (2021-11-18)
parents fe28be5403e2
children
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@1762 44 // document.getElementById('rating_dialog').showModal();
bsw@1762 45 document.getElementById('rating_dialog').classList.remove("hidden");
bsw@1762 46
bsw@1649 47 }
bsw@1649 48
bsw@1649 49 function updateOpinion() {
bsw@1649 50 var suggestionId = document.getElementById("rating_suggestion_id").value;
bsw@1649 51
bsw@1649 52 var degree = 0;
bsw@1649 53 if (document.getElementById("rating_degree-2").children[0].checked)
bsw@1649 54 degree = -2;
bsw@1649 55 else if (document.getElementById("rating_degree-1").children[0].checked)
bsw@1649 56 degree = -1;
bsw@1649 57 else if (document.getElementById("rating_degree1").children[0].checked)
bsw@1649 58 degree = 1;
bsw@1649 59 else if (document.getElementById("rating_degree2").children[0].checked)
bsw@1649 60 degree = 2;
bsw@1649 61 var fulfilled = false;
bsw@1649 62 if (document.getElementById("rating_fulfilled").children[0].checked)
bsw@1649 63 fulfilled = true;
bsw@1649 64 if (degree == 0)
bsw@1649 65 fulfilled = null;
bsw@1649 66 var data = new FormData();
bsw@1649 67 data.append("suggestion_id", suggestionId);
bsw@1649 68 data.append("degree", degree);
bsw@1649 69 data.append("fulfilled", fulfilled);
bsw@1649 70
bsw@1649 71 var degreeText = rateSuggestionDegreeTexts[degree];
bsw@1649 72 var fulfilledText = fulfilled ? rateSuggestionFulfilledText : rateSuggestionNotFulfilledText;
bsw@1792 73 var textTemplate;
bsw@1649 74 var icon;
bsw@1649 75 var iconColor;
bsw@1649 76 if (
bsw@1649 77 (degree > 0 && ! fulfilled)
bsw@1649 78 || (degree < 0 && fulfilled)
bsw@1649 79 ) {
bsw@1649 80 icon = "warning";
bsw@1649 81 if (degree == 2 || degree == -2) {
bsw@1649 82 iconColor = "red";
bsw@1649 83 }
bsw@1792 84 textTemplate = rateSuggestionButText;
bsw@1649 85 } else {
bsw@1792 86 textTemplate = rateSuggestionAndText;
bsw@1649 87 icon = "done";
bsw@1649 88 }
bsw@1792 89 textTemplate = textTemplate.replace("#{opinion}", degreeText);
bsw@1792 90 textTemplate = textTemplate.replace("#{implemented}", fulfilledText);
bsw@1792 91 var text = textTemplate;
bsw@1649 92 if (degree == 0) {
bsw@1649 93 text = "";
bsw@1649 94 icon = "blank";
bsw@1649 95 }
bsw@1649 96 document.getElementById("s" + suggestionId + "_rating_text").innerHTML = text;
bsw@1649 97 document.getElementById("s" + suggestionId + "_rating_icon").innerHTML = icon;
bsw@1649 98 if (iconColor == "red") {
bsw@1649 99 document.getElementById("s" + suggestionId + "_rating_icon").classList.add("icon-red");
bsw@1649 100 } else {
bsw@1649 101 document.getElementById("s" + suggestionId + "_rating_icon").classList.remove("icon-red");
bsw@1649 102 }
bsw@1649 103 if (degree == 0) {
bsw@1649 104 document.getElementById("s" + suggestionId + "_rate_button").innerHTML = rateSuggestionRateText;
bsw@1649 105 } else {
bsw@1649 106 document.getElementById("s" + suggestionId + "_rate_button").innerHTML = rateSuggestionUpdateRatingText;
bsw@1649 107 }
bsw@1649 108 document.getElementById("s" + suggestionId + "_rate_button").setAttribute("onclick", "rateSuggestion(" + suggestionId + ", " + degree + ", " + fulfilled + ");return false;")
bsw@1762 109 // document.getElementById('rating_dialog').close();
bsw@1762 110 document.getElementById('rating_dialog').classList.add("hidden");
bsw@1649 111
bsw@1649 112 fetch(baseURL + "opinion/xhr_update", {
bsw@1649 113 method: "POST",
bsw@1649 114 body: data
bsw@1649 115 }).then(response => {
bsw@1649 116 if (response.status != 200) {
bsw@1649 117 window.alert("Error during update");
bsw@1649 118 }
bsw@1649 119 });
bsw@1649 120
bsw@1649 121 }

Impressum / About Us