0

i would that : If my status is equal to "open" I have the background-color yellow or if it's equal to "closed" I have the background-color red etc.... but i don't succeed it can you help me pls ?:

script.js :

   //fonction pour afficher les tickets de l'associé
function displaytickets(y){
    console.log(y);
    var newid = {};
    $("#mylist").empty();
    $("#nbtick").html("");
    $("#mycontent").html("");
    $("#name").html("");
    var newv = y;
    $.ajax({
      url: "https://cubber.zendesk.com/api/v2/users/"+y+"/tickets/requested.json?sort_by=date",
      type: 'GET',
      dataType: 'json',
      cors: true ,
            contentType:'application/json',
            secure: true,
            beforeSend: function (xhr) {
                xhr.setRequestHeader ("Authorization", "Basic " + btoa(""));
            },
            success: function (data){

        var sortbydate = data.tickets.sort(function(a,b){ return new Date(b.created_at)- new Date(a.created_at); });
        var named = data.tickets[0].via.source.from.name;

        localStorage.setItem("namestock", named);
                for (i = 0; i < data.tickets.length; i++) {

          var myticket = data.tickets[i];
          var mydate = data.tickets[i].created_at;
          var created = moment(mydate).format("MM-DD-YY");
                    var mytitle = data.tickets[i].subject;
            var description = data.tickets[i].description;
            var status = data.tickets[i].status;

            var myid = data.tickets[i].id;
            
            switch(status){
              case "open":
              console.log("open")
              $("")
              break;
              case "closed":
              console.log("closed")
              break;
              case "pending":
              console.log("pending")
              break;
              case "solved":
              console.log("solved")
              break;

            }
            
            localStorage.setItem("mydescription", description);
                      $("#mylist").append('<li class="row col-md-12" id="newlist" value="'+myid+'" onclick="ticketcontent('+myid+')">'+ '<div class="open">'+status+ '</div>'+'<div class="identifiant col-md-2">'+" #"+ myid +'</div>'+'<div class="identifiant col-md-6">'+mytitle +'</div>'+'<div class="identifiant col-md-2">'+created+'</div>'+'</li><hr><br>')
                }
      var nbticket = data.tickets.length;
      var monnom = localStorage.getItem("namestock");
      $("#name").append('<h2 class="title">'+monnom+"  "+nbticket+" ticket(s)"+'</h2>');
        localStorage.clear();
            },
  });
  $("#idisplay").css("display", "none");


}

and here what i get it is not the right colors !:

enter image description here

7
  • 1
    What do you expect cors: true to do? That isn't a property jQuery will do anything with. Ditto secure: true, Commented Apr 4, 2016 at 8:34
  • 1
    You are making a GET request, why are you setting contentType:'application/json', when there is no request body to describe the content type of? Commented Apr 4, 2016 at 8:34
  • Where is the code to print status ? Commented Apr 4, 2016 at 8:35
  • 1
    I don't see any code in the question that would set a background colour, or mention either red or yellow. Commented Apr 4, 2016 at 8:36
  • 1
    How do add a background-color here? can't see it Commented Apr 4, 2016 at 8:36

1 Answer 1

3

Put this CSS

.class_closed{
  background-color:#ff0000;
}

.class_open{
  background-color:#fff000;
}

now in jQuery append this (assuming status is the variable storing the status either open or closed)

<span class="class_'+status+' otherClasses">' + status + '</span>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.