Skip to content

Instantly share code, notes, and snippets.

@markphi2013
Created August 26, 2015 09:44
Show Gist options
  • Save markphi2013/7df861a591e49aa5fb38 to your computer and use it in GitHub Desktop.
Save markphi2013/7df861a591e49aa5fb38 to your computer and use it in GitHub Desktop.
function processParticipant(participant) {
$('#simulator-profile').empty()
$("#simulator-profile").append(generateHtmlParticipant(participant));
}
function generateHtmlParticipant(participant) {
var myTemplate = "<dl> <dt>"+
"Phone: "+
"PARTICIPANT_PHONE"+
"</dt></dl>"+
"<dl> <dt>"+
"Last Optin Date: </br>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+
"PARTICIPANT_OPTIN_DATE"+
"</dt></dl>"+
"<dl> <dt>"+
"Last Optout Date: </br>"+
((participant['last-optout-date']) ? "<dl><dt>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+
moment(participant['last-optout-date']).format("DD/MM/YYYY HH:mm:ss")+
"</dt></dl>" : "&nbsp; </dt></dl>" )
/*(((participant['profile'].length) > 0) ? "<dl><dt>"+
"Labels: "+
"<?php ?> ": "&nbsp; </dt></dl>")+
(((participant['tags'].length) > 0) ? "<dl><dt>"+
"Tags: ": "&nbsp; </dt></dl>")
var profile =
*/
myTemplate = myTemplate.replace('PARTICIPANT_PHONE', participant['phone']);
myTemplate = myTemplate.replace('PARTICIPANT_OPTIN_DATE', moment(participant['last-optin-date']).format("DD/MM/YYYY HH:mm:ss"));
return myTemplate;
}
@markphi2013
Copy link
Author

if ((participant['profile'].length) > 0) {
                $("#simulator-profile").append(
                    "<dl><dt>"+
                    "Labels: ")
                for (var i = 0; i < participant['profile'].length; i++) {
                    $("#simulator-profile").append(
                        "<dl><dt>"+
                        "<div>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+
                        participant['profile'][i]['label']+
                        ": "+
                        participant['profile'][i]['value']+
                        "</div></dt></dl>"
                        )
                }
            } else {
                $("#simulator-profile").append("&nbsp;  </dt></dl>")
            }

@markphi2013
Copy link
Author

i want to add for loop inside my HTML myTemplate var

@markphi2013
Copy link
Author

function generateHtmlParticipant(participant) {
            var myTemplate = "<dl> <dt>"+
            "Phone: "+
            "PARTICIPANT_PHONE"+
            "</dt></dl>"+
            "<dl> <dt>"+
            "Last Optin Date:  </br>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+
            "PARTICIPANT_OPTIN_DATE"+
            "</dt></dl>"+
            "<dl> <dt>"+
            "Last Optout Date: </br>"+
            ((participant['last-optout-date']) ? "<dl><dt>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+
                moment(participant['last-optout-date']).format("DD/MM/YYYY HH:mm:ss")+
                "</dt></dl>" :  "&nbsp;  </dt></dl>" )+
            (((participant['profile'].length) > 0) ? "<dl><dt>"+
                    "Labels: "+
                    ((for(var i = 0; i < participant['profile'].length; i++)); do "<dl><dt>"+
                        "<div>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp"+
                        participant['profile'][i]['label']+
                        ": "+
                        participant['profile'][i]['value']+
                        "</div></dt></dl>") : "&nbsp;  </dt></dl>")+
            (((participant['tags'].length) > 0) ? "<dl><dt>"+
                    "Tags: ": "&nbsp;  </dt></dl>")


            myTemplate = myTemplate.replace('PARTICIPANT_PHONE', participant['phone']);
            myTemplate = myTemplate.replace('PARTICIPANT_OPTIN_DATE', moment(participant['last-optin-date']).format("DD/MM/YYYY HH:mm:ss"));
            return  myTemplate;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment