liquid_feedback_frontend

diff static/js/xhr.js @ 1619:62856200414d

Animate interest button
author bsw
date Tue Feb 02 12:42:54 2021 +0100 (2021-02-02)
parents 2f9e1e882de6
children 123eb46b4d3e
line diff
     1.1 --- a/static/js/xhr.js	Mon Feb 01 23:43:54 2021 +0100
     1.2 +++ b/static/js/xhr.js	Tue Feb 02 12:42:54 2021 +0100
     1.3 @@ -1,9 +1,22 @@
     1.4 -function toggleInterest(issue_id, iconElId) {
     1.5 -  var iconEl = document.getElementById(iconElId);
     1.6 +function toggleInterest(issueId) {
     1.7 +  var linkEl = document.getElementById("issue_" + issueId + "_interest_link");
     1.8 +  var iconEl = document.getElementById("issue_" + issueId + "_interest_icon");
     1.9    var interested = iconEl.innerHTML == "star_outline";
    1.10 +
    1.11 +  if (interested) {
    1.12 +    linkEl.classList.add("mdl-button--accent");
    1.13 +    linkEl.classList.add("mdl-button--feature-on");
    1.14 +    linkEl.classList.remove("mdl-button--feature-off");
    1.15 +    iconEl.innerHTML = "star";
    1.16 +  } else {
    1.17 +    linkEl.classList.remove("mdl-button--accent");
    1.18 +    linkEl.classList.remove("mdl-button--feature-on");
    1.19 +    linkEl.classList.add("mdl-button--feature-off");
    1.20 +    iconEl.innerHTML = "star_outline";
    1.21 +  }
    1.22    
    1.23    var data = new FormData();
    1.24 -  data.append("issue_id", issue_id);
    1.25 +  data.append("issue_id", issueId);
    1.26    data.append("interested", interested);
    1.27  
    1.28    fetch("/lf/interest/xhr_update", {
    1.29 @@ -11,8 +24,8 @@
    1.30        body: data
    1.31    }).then(
    1.32        response => {
    1.33 -        if (response.status == 200) {
    1.34 -          iconEl.innerHTML = interested ? "star" : "star_outline";
    1.35 +        if (response.status != 200) {
    1.36 +          window.alert("Error during update");
    1.37          }
    1.38        }
    1.39    );

Impressum / About Us