Skip to content

Instantly share code, notes, and snippets.

@montycheese
Created July 2, 2015 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save montycheese/b4c1bd859ee2ca533530 to your computer and use it in GitHub Desktop.
Save montycheese/b4c1bd859ee2ca533530 to your computer and use it in GitHub Desktop.
Customer service decision tree in javascript
<script>
$(document).ready( function () {
$('#customerTripsTable').DataTable();
$('#customerNotesTable').DataTable();
} );
//reset all children nodes in tree if the parent is clicked
document.getElementById("contacttype").onclick = destroyChildren;
//listener for contact type dropdown
document.getElementById("contacttype").onchange = function() {
var selected = document.getElementById("contacttype").value;
if(selected == 'initial'){
//alert(selected);
// display another dropdown
document.getElementById("initial").style.display ='block';
}
else if(selected == 'incoming'){
showNotesField();
}
else if(selected == 'outgoing'){
document.getElementById("outgoing").style.display ='block';
showNotesField();
}
else if(selected == 'custom'){
showNotesField();
}
else{
alert('error');
}
}
//listener for INITIAL contact dropdown
document.getElementById("initial_contact").onchange = function(){
var selected = document.getElementById("initial_contact").value;
if(selected == 'vm'){
document.getElementById("how_you_heard").style.display ='none';
removeNotesField();
}
else if (selected == 'telephone' ||
selected == 'email' ||
selected == 'text')
{
document.getElementById("how_you_heard").style.display ='block';
showNotesField();
}
}
/**
* Destroys children nodes if the decision tree is changed
*/
function destroyChildren(){
document.getElementById("initial").style.display ='none';
document.getElementById("outgoing").style.display ='none';
document.getElementById("how_you_heard").style.display ='none';
removeNotesField();
}
/**
* Reveals the contact notes field
*/
function showNotesField(){
document.getElementById("notes").style.display ='block';
}
/**
* Hides the contact notes field
*/
function removeNotesField(){
document.getElementById("notes").style.display ='none';
}
/**
* Ajax request to call process that resets customer password and sends them a new password via email
*/
function resetPassword(){
if(confirm('Are you sure you want to reset?')){
$.ajax
({
url: 'php/doResetCustomerPassword.php',
type: 'post',
success: function(data)
{
if(data){
alert("Reset!");
}
else {
alert("Password NOT reset");
}
}
});
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment