|
|
@ -17,61 +17,52 @@ $('document').ready(function(){ |
|
|
|
$("#animals").click(function(){ |
|
|
|
$("#load").fadeIn(0); |
|
|
|
$.get( "/animal", function( data ) { |
|
|
|
$.get( "/species", function( species_r ) { |
|
|
|
var species = {}; |
|
|
|
species_r.data.map(function(item) { |
|
|
|
species[item._id] = item.name |
|
|
|
$( "#body" ).html("<h1>Yours <span>Dinos</span> <button id='animal-add' class='btn btn-success btn-sm float-right'>+ New Dino</button></h1><table id='animals-table'></table>"); |
|
|
|
$( "#animal-add").click(function(){ |
|
|
|
$( "#body" ).load( "/templates/animal-form.html", function (){ |
|
|
|
set_animal_include(""); |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
$( "#body" ).html("<h1>Yours Dinos <button id='animal-add' class='btn btn-success btn-sm float-right'>+ New Dino</button></h1><table id='animals-table'></table>"); |
|
|
|
$( "#animal-add").click(function(){ |
|
|
|
$( "#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, |
|
|
|
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>'; |
|
|
|
}} |
|
|
|
]}); |
|
|
|
$("#load").fadeOut("fast"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
$("#species").click(function(){ |
|
|
|
$("#load").fadeIn(0); |
|
|
|
$.get( "/species", function( data ) { |
|
|
|
$( "#body" ).html("<h1>All Species</h1><table id='species-table'></table>"); |
|
|
|
dataSet = data.data.map(function(item) { |
|
|
|
return [item.name, item.description]; |
|
|
|
dataSet = data.data.map(function(item) { |
|
|
|
return [item._id, item.name, item.initial_level + " - " + item.level, species[item.specie].name]; |
|
|
|
}); |
|
|
|
$('#species-table').DataTable({ |
|
|
|
|
|
|
|
$('#animals-table').DataTable({ |
|
|
|
data: dataSet, |
|
|
|
responsive: true, |
|
|
|
columns: [ |
|
|
|
{ title: "id", visible: false}, |
|
|
|
{ title: "Name" }, |
|
|
|
{ title: "Description" } |
|
|
|
] |
|
|
|
}); |
|
|
|
{ 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>'; |
|
|
|
}} |
|
|
|
]}); |
|
|
|
$("#load").fadeOut("fast"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
$("#species").click(function(){ |
|
|
|
$("#load").fadeIn(0); |
|
|
|
|
|
|
|
$( "#body" ).html("<h1>All <span>Species</span></h1><table id='species-table'></table>") |
|
|
|
|
|
|
|
dataSet = []; |
|
|
|
|
|
|
|
for(var i in species){ |
|
|
|
dataSet.push([species[i].name, species[i].description]); |
|
|
|
} |
|
|
|
|
|
|
|
$('#species-table').DataTable({ |
|
|
|
data: dataSet, |
|
|
|
responsive: true, |
|
|
|
columns: [ |
|
|
|
{ title: "Name" }, |
|
|
|
{ title: "Description" } |
|
|
|
] |
|
|
|
}); |
|
|
|
$("#load").fadeOut("fast"); |
|
|
|
}); |
|
|
|
|
|
|
|
$("#about").click(function(){ |
|
|
|