diff --git a/familyark/app/public/css/main.css b/familyark/app/public/css/main.css index f2517a9..7a0ed7c 100644 --- a/familyark/app/public/css/main.css +++ b/familyark/app/public/css/main.css @@ -100,7 +100,15 @@ td.options-table-species{ text-align: center; } - table.info{ margin: auto; +} + +#a-father button, .Male{ + background-color: blue; + color: white; +} + +#a-mother button, .Female{ + background-color: pink; } \ No newline at end of file diff --git a/familyark/app/public/js/buttons.js b/familyark/app/public/js/buttons.js index 7633341..56d9fe4 100644 --- a/familyark/app/public/js/buttons.js +++ b/familyark/app/public/js/buttons.js @@ -4,6 +4,14 @@ $('document').ready(function(){ // Botones $("#home").click(function(){ $( "#body" ).load( "/templates/home.html" ); + $.get("/info", function( data ) { + var text = "" + $.each(data, function(i, obj) { + text += ""; + }); + text += "
"+i+" "+obj+"
" + $( "#info" ).html( text ); + }); }); $("#animals").click(function(){ @@ -16,11 +24,20 @@ $('document').ready(function(){ $( "#body" ).html("

Yours Dinos



"); $( "#animal-add").click(function(){ - $( "#body" ).load( "/templates/animal-form.html" ); + $( "#body" ).load( "/templates/animal-form.html", function (){ + set_animal_include(""); + }); }) dataSet = data.data.map(function(item) { return [item._id, item.name, item.initial_level + " - " + item.level, species[item.specie]]; }); + + // dataSet = data.data.reduce(function(acc, item, i) { + // if(i == 1) acc = [] + // acc.push([item._id, item.name, item.initial_level + " - " + item.level, species[item.specie]]); + // return acc + // }); + $('#animals-table').DataTable({ data: dataSet, responsive: true, diff --git a/familyark/app/public/js/functions.js b/familyark/app/public/js/functions.js index 5068d30..036e60e 100644 --- a/familyark/app/public/js/functions.js +++ b/familyark/app/public/js/functions.js @@ -13,7 +13,7 @@ function onSubmitAnimal(form){ type: "PUT", url: "/animal/"+data._id, data: JSON.stringify(data), - success: function() { $("#animals").click() }, + success: function() { showAnimal(data._id) }, contentType : "application/json" }); }else{ @@ -39,47 +39,40 @@ function editAnimal(id){ 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'); + $('#a-'+a+' option[value='+animal[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] : ""); + $('input[name='+key+']').val( animal[key] ?animal[key].$numberDecimal ? animal[key].$numberDecimal : animal[key] : ""); } } } - - $.get( "/species", function( data ) { - data.data.map(function(item){ - $("#a-specie").append(""); - }) - }); + set_animal_include(animal._id); 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 = ""; + var text = "
"; $.get( "/animal/"+ id, function( data ) { var animal = data.data, j = 1; $.each(animal, function(i, val) { - text += ""; - if(j % 3 == 0) text += "" + + if(i != "_id" && i != "__v" && i.indexOf("initial") < 0) + text += ""; + // if(j % 3 == 0) text += "" j++; }); - text += "
"+i+""+(val ? val.$numberDecimal ? val.$numberDecimal : val : "")+"
"+i+""+(val ? val.$numberDecimal ? val.$numberDecimal : val : "")+"
"; - $("#a-name").html( ); + text += ""; + + $("#button").html('') + $(".a-name").html( animal.name ); $("#data").append( text ); - // console.log(11) + get_parrents(animal); - // console.log(22) get_childrens(animal); - // console.log(33) }); }); @@ -114,17 +107,26 @@ function paint_male_female(specie, id){ function get_parrents(animal){ $.get( "/animal/parrents/" + animal._id, function( data ) { data.data.map(function(item){ - console.log(item); + $(item.sex == "Male" ? "#a-father" : "#a-mother").html(""); }); }); } - - function get_childrens(animal){ $.get( "/animal/childrens/" + animal._id, function( data ) { data.data.map(function(item){ - console.log(item) + $("#a-childrens").append("
"); }) }); +} + +function set_animal_include(id){ + $.get( "/species", function( data ) { + data.data.map(function(item){ + $("#a-specie").append(""); + }); + }); + $("#a-specie").change(function(e){ + paint_male_female($( this ).val(), id); + }); } \ No newline at end of file diff --git a/familyark/app/public/templates/animal-show.html b/familyark/app/public/templates/animal-show.html index d599c56..83412f9 100644 --- a/familyark/app/public/templates/animal-show.html +++ b/familyark/app/public/templates/animal-show.html @@ -1,6 +1,24 @@

Un dino

-
-
+
+
+
+
+
+
+ Father +
---
+
+
+ Mother +
---
+
+
+
+
+
Childrens
+
+
+
Aqui vendran graficas de cada atributo con el inicial y el actual, para que se pueda ver el crecimiento.