//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(){ var animal; $.get( "/animal/"+id, function( data ) { animal = data.data for(key in animal) { if(animal.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'); }, 200) }else{ $('input[name='+key+']').val( data.data[0][key] ? data.data[0][key].$numberDecimal ? data.data[0][key].$numberDecimal : data.data[0][key] : ""); } } } $.get( "/species", function( data ) { data.data.map(function(item){ $("#a-specie").append(""); }) }); paint_male_female(animal.specie, animal._id); $("#a-specie").change(function(e){ paint_male_female($( this ).val(), animal._id); }) }); }); } function showAnimal(id){ $( "#body" ).load( "/templates/animal-show.html", function(){ var text = "
"+i+" | "+(val ? val.$numberDecimal ? val.$numberDecimal : val : "")+" | "; if(j % 3 == 0) text += "