You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

99 lines
3.2 KiB

//Funtions
function onSubmitAnimal(form){
var data = {};
$.map($(form).serializeArray(), function(n, i){
if(n['value']!= "") data[n['name']] = n['value'];
else data[n['name']] = null;
});
if(data._id){
$.ajax({
type: "PUT",
url: "/animal/"+data._id,
data: JSON.stringify(data),
success: function() { $("#animals").click() },
contentType : "application/json"
});
}else{
$.ajax({
type: "POST",
url: "/animal",
data: JSON.stringify(data),
success: function() { $("#animals").click() },
contentType : "application/json"
});
}
return false;
};
function editAnimal(id){
$( "#body" ).load( "/templates/animal-form.html", function(){
$.get( "/animal/"+id, function( data ) {
for(key in data.data[0])
{
if(data.data[0].hasOwnProperty(key)){
if(key == "father" || key == "mother" || key == "specie" || key == "sex"){
let a = key;
setTimeout(function(){
$('#a-'+a+' option[value='+data.data[0][a]+']').attr('selected','selected');
console.log(data.data[0][a]);
console.log(a);
}, 200)
}else{
$('input[name='+key+']').val( data.data[0][key].$numberDecimal ? data.data[0][key].$numberDecimal : data.data[0][key]);
}
}
}
});
});
}
function showAnimal(id){
$( "#body" ).load( "/templates/animal-show.html", function(){
/* $.get( "/animal/"+id, function( data ) {
$.get( "/animal", function( animalsData ) {
$.each(data.data[0], function(i, val) {
$("#data").append( "<div>"+i+": "+(val.$numberDecimal ? val.$numberDecimal : val)+"</div>");
});
});
});*/
$.get('/animal/tree/' + id, function(data) {
var chart_config = [{
container: "#tree",
connectors: {
type: 'step'
}
},
{
text: {
name: data[0].name
},
//parent: data[0].ancestorsmother.filter(ancestor => ancestor.depth === 0),
//parent: data[0].ancestorsfather.filter(ancestor => ancestor.depth === 0),
//children: data[0].childrensmother.filter(ancestor => ancestor.depth === 0),
//children: data[0].childrensfather.filter(ancestor => ancestor.depth === 0)
},
{
text: {
name: "test"
},
parent: data[0].ancestors.filter(ancestor => ancestor.depth === 0)
}]
})
});
}
function removeAnimal(id){
if(confirm("¿Surely you want to erase this dino?")){
$.ajax({
url: '/animal/'+id,
type: 'DELETE',
success: function() { $("#animals").click() }
});
}
}