more style

This commit is contained in:
Gustavo Adolfo Mesa Roldán
2020-03-30 03:44:12 +02:00
parent cb5008f0ab
commit 223572f952
12 changed files with 87 additions and 83 deletions
+38 -47
View File
@@ -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>&nbsp;&nbsp;<button class="btn btn-info btn-sm" onclick="editAnimal(\''+ full[0] +'\')">Edit</button>&nbsp;&nbsp;<button class="btn btn-danger btn-sm" onclick="removeAnimal(\''+full[0]+'\')">Remove</button>';
}}
]});
$("#load").fadeOut("fast");
dataSet = data.data.map(function(item) {
return [item._id, item.name, item.initial_level + " - " + item.level, species[item.specie].name];
});
$('#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>&nbsp;&nbsp;<button class="btn btn-info btn-sm" onclick="editAnimal(\''+ full[0] +'\')">Edit</button>&nbsp;&nbsp;<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];
});
$('#species-table').DataTable({
data: dataSet,
responsive: true,
columns: [
{ title: "Name" },
{ title: "Description" }
]
});
$("#load").fadeOut("fast");
$( "#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(){
+4 -2
View File
@@ -57,13 +57,15 @@ function editAnimal(id){
function showAnimal(id){
$("#load").fadeIn(0);
$( "#body" ).load( "/templates/animal-show.html", function(){
var text = "<table>";
var text = "<table class=\"dataTable\">";
$.get( "/animal/"+ id, function( data ) {
var animal = data.data,
j = 1;
$.each(animal, function(i, val) {
if(i != "_id" && i != "__v" && i != "father" && i != "mother" && i != "name" && i.indexOf("initial") < 0)
if(i == "specie")
text += "<tr><td>"+i+"</td><td>" + species[val].name + "</td></tr>";
else if(i != "_id" && i != "__v" && i != "father" && i != "mother" && i != "name" && i.indexOf("initial") < 0)
text += "<tr><td>"+i+"</td><td>"+(val ? val.$numberDecimal ? val.$numberDecimal : val : "")+"</td></tr>";
// if(j % 3 == 0) text += "</tr><tr>"
j++;
+21 -9
View File
@@ -1,13 +1,25 @@
var species = {};
$('document').ready(function(){
$( "#body" ).load( "/templates/home.html", function(){$("#load").fadeOut("slow");
$.get("/info", function( data ) {
var text = "<table class=\"info\">"
$.each(data, function(i, obj) {
text += "<tr><td>"+i+"</td><td> "+obj+"</td></tr>";
$.get( "/species", function( species_r ) {
species_r.data.map(function(item) {
species[item._id] = item
});
$( "#body" ).load( "/templates/home.html", function(){$("#load").fadeOut("slow");
$.get("/info", function( data ) {
var text = "<table class=\"info\">"
$.each(data, function(i, obj) {
text += "<tr><td>"+i+"</td><td> "+obj+"</td></tr>";
});
text += "</table>"
$( "#info" ).html( text );
$("#load").fadeOut("slow");
});
text += "</table>"
$( "#info" ).html( text );
$("#load").fadeOut("slow");
});
$("body").bgswitcher({
images: ["/images/bg0.jpg", "/images/bg1.jpg", "/images/bg2.jpg", "/images/bg3.jpg", "/images/bg4.jpg"],
loop: true,
duration: 1500
});
});
})
});