More
This commit is contained in:
@@ -2,51 +2,59 @@ $('document').ready(function(){
|
||||
$( "#body" ).load( "/templates/home.html" );
|
||||
|
||||
// Botones
|
||||
$("#home").click(function(){
|
||||
$( "#body" ).load( "/templates/home.html" );
|
||||
});
|
||||
$("#home").click(function(){
|
||||
$( "#body" ).load( "/templates/home.html" );
|
||||
});
|
||||
|
||||
$("#animals").click(function(){
|
||||
$.get( "/animal", function( data ) {
|
||||
$( "#body" ).html("<h1>Yours Dinos</h1><button id='animal-add' class='btn btn-success btn-sm float-right'>+ New Dino</button><br><br><table id='animals-table'></table>");
|
||||
$( "#animal-add").click(function(){
|
||||
$( "#body" ).load( "/templates/animal-form.html" );
|
||||
})
|
||||
dataSet = data.data.map(function(item) {
|
||||
return [item._id, item.name, item.initial_level + " - " + item.level];
|
||||
$.get( "/species", function( species_r ) {
|
||||
var species = {};
|
||||
species_r.data.map(function(item) {
|
||||
species[item._id] = item.name
|
||||
});
|
||||
|
||||
$( "#body" ).html("<h1>Yours Dinos</h1><button id='animal-add' class='btn btn-success btn-sm float-right'>+ New Dino</button><br><br><table id='animals-table'></table>");
|
||||
$( "#animal-add").click(function(){
|
||||
$( "#body" ).load( "/templates/animal-form.html" );
|
||||
})
|
||||
dataSet = data.data.map(function(item) {
|
||||
return [item._id, item.name, item.initial_level + " - " + item.level, species[item.specie]];
|
||||
});
|
||||
$('#animals-table').DataTable({
|
||||
data: dataSet,
|
||||
responsive: true,
|
||||
columns: [
|
||||
{ title: "id", visible: false},
|
||||
{ title: "Name" },
|
||||
{ title: "Level" },
|
||||
{ title: "Specie" },
|
||||
{ title: "Options", className: "options-table", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) {
|
||||
return '<button class="btn btn-primary btn-sm" onclick="showAnimal(\''+ full[0] +'\')">Show</button> <button class="btn btn-info btn-sm" onclick="editAnimal(\''+ full[0] +'\')">Edit</button> <button class="btn btn-danger btn-sm" onclick="removeAnimal(\''+full[0]+'\')">Remove</button>';
|
||||
}}
|
||||
]});
|
||||
});
|
||||
$('#animals-table').DataTable({
|
||||
data: dataSet,
|
||||
responsive: true,
|
||||
columns: [
|
||||
{ title: "id", visible: false},
|
||||
{ title: "Name" },
|
||||
{ title: "Level" },
|
||||
{ title: "Options", className: "options-table", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) {
|
||||
return '<button class="btn btn-primary btn-sm" onclick="showAnimal(\''+ full[0] +'\')">Show</button> <button class="btn btn-info btn-sm" onclick="editAnimal(\''+ full[0] +'\')">Edit</button> <button class="btn btn-danger btn-sm" onclick="removeAnimal(\''+full[0]+'\')">Remove</button>';
|
||||
}}
|
||||
]});
|
||||
});
|
||||
});
|
||||
$("#species").click(function(){
|
||||
$.get( "/species", function( data ) {
|
||||
$("#species").click(function(){
|
||||
$.get( "/species", function( data ) {
|
||||
$( "#body" ).html("<h1>All Species</h1><table id='species-table'></table>");
|
||||
dataSet = data.data.map(function(item) {
|
||||
dataSet = data.data.map(function(item) {
|
||||
return [item.name, item.description];
|
||||
});
|
||||
$('#species-table').DataTable({
|
||||
data: dataSet,
|
||||
data: dataSet,
|
||||
responsive: true,
|
||||
columns: [
|
||||
{ title: "Name" },
|
||||
{ title: "Description" },
|
||||
{ title: "Options", className: "options-table-species", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) {
|
||||
return '<button class="btn btn-primary btn-sm" onclick="alert(\'En desarollo\')">Show</button>'
|
||||
}}
|
||||
]
|
||||
columns: [
|
||||
{ title: "Name" },
|
||||
{ title: "Description" },
|
||||
{ title: "Options", className: "options-table-species", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) {
|
||||
return '<button class="btn btn-primary btn-sm" onclick="alert(\'En desarollo\')">Show</button>'
|
||||
}}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$("#about").click(function(){
|
||||
$( "#body" ).load( "/templates/about.html" );
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
|
||||
//Funtions
|
||||
function onSubmitAnimal(form){
|
||||
var data = {};
|
||||
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"
|
||||
});
|
||||
$.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"
|
||||
type: "POST",
|
||||
url: "/animal",
|
||||
data: JSON.stringify(data),
|
||||
success: function() { $("#animals").click() },
|
||||
contentType : "application/json"
|
||||
});
|
||||
}
|
||||
return false;
|
||||
@@ -30,61 +30,58 @@ function onSubmitAnimal(form){
|
||||
|
||||
function editAnimal(id){
|
||||
$( "#body" ).load( "/templates/animal-form.html", function(){
|
||||
var animal;
|
||||
$.get( "/animal/"+id, function( data ) {
|
||||
for(key in data.data[0])
|
||||
animal = data.data
|
||||
for(key in animal)
|
||||
{
|
||||
if(data.data[0].hasOwnProperty(key)){
|
||||
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');
|
||||
console.log(data.data[0][a]);
|
||||
console.log(a);
|
||||
$('#a-'+a+' option[value='+data.data[0][a]+']').attr('selected','selected');
|
||||
}, 200)
|
||||
}else{
|
||||
$('input[name='+key+']').val( data.data[0][key].$numberDecimal ? data.data[0][key].$numberDecimal : data.data[0][key]);
|
||||
}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("<option value='"+item._id+"'>"+item.name+"</option>");
|
||||
})
|
||||
});
|
||||
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(){
|
||||
/* $.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>");
|
||||
});
|
||||
var text = "<table><tr>";
|
||||
$.get( "/animal/"+ id, function( data ) {
|
||||
var animal = data.data,
|
||||
j = 1;
|
||||
$.each(animal, function(i, val) {
|
||||
text += "<td>"+i+"</td><td>"+(val ? val.$numberDecimal ? val.$numberDecimal : val : "")+"</td>";
|
||||
if(j % 3 == 0) text += "</tr><tr>"
|
||||
j++;
|
||||
});
|
||||
});*/
|
||||
$.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)
|
||||
}]
|
||||
})
|
||||
text += "</tr></table>";
|
||||
$("#a-name").html( );
|
||||
$("#data").append( text );
|
||||
// console.log(11)
|
||||
get_parrents(animal);
|
||||
// console.log(22)
|
||||
get_childrens(animal);
|
||||
// console.log(33)
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,3 +94,35 @@ function removeAnimal(id){
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function paint_male_female(specie, id){
|
||||
$(".option").remove();
|
||||
$.get( "/animal/"+specie+"/Male", function( data ) {
|
||||
data.data.map(function(item){
|
||||
if(item._id != id) $("#a-father").append("<option class=\"option\" value='"+item._id+"'>"+item.name+" - "+ item.level +"</option>");
|
||||
})
|
||||
});
|
||||
|
||||
$.get( "/animal/"+specie+"/Female", function( data ) {
|
||||
data.data.map(function(item){
|
||||
if(item._id != id) $("#a-mother").append("<option class=\"option\" value='"+item._id+"'>"+item.name+" - "+ item.level +"</option>");
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function get_parrents(animal){
|
||||
$.get( "/animal/parrents/" + animal._id, function( data ) {
|
||||
data.data.map(function(item){
|
||||
console.log(item);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function get_childrens(animal){
|
||||
$.get( "/animal/childrens/" + animal._id, function( data ) {
|
||||
data.data.map(function(item){
|
||||
console.log(item)
|
||||
})
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user