Difference between revisions of "MediaWiki:CreatureList.js"
Jump to navigation
Jump to search
Nussnougat (talk | contribs) |
Nussnougat (talk | contribs) |
||
Line 2: | Line 2: | ||
var output = $("#creatures-list"); | var output = $("#creatures-list"); | ||
var html = "<div><a href='/index.php/Data:CreatureForm'><button>Add</button></a></div>"; | var html = "<div><a href='/index.php/Data:CreatureForm'><button>Add</button></a></div>"; | ||
− | html += "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th><th>Maturity</th></tr>"; | + | html += "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th><th>Maturity</th><th>Planets</th></tr>"; |
mobs.forEach(function(mob) { | mobs.forEach(function(mob) { | ||
var url = "/index.php/Creatures:"+mob["name"]; | var url = "/index.php/Creatures:"+mob["name"]; | ||
+ | var planets = mob["planets"]; | ||
+ | var planetURLs = ""; | ||
+ | planets.forEach(function(planet) { | ||
+ | planetURLs += "<a href='index.php/Story:"+planet+"'>"+planet+"</a> "; | ||
+ | }); | ||
+ | |||
html += "<tr>"; | html += "<tr>"; | ||
html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>"; | html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>"; | ||
Line 10: | Line 16: | ||
html += "<td>"+mob["min_damage"]+" - "+mob["max_damage"]+"</td>"; | html += "<td>"+mob["min_damage"]+" - "+mob["max_damage"]+"</td>"; | ||
html += "<td>"+mob["maturity"]+"</td>"; | html += "<td>"+mob["maturity"]+"</td>"; | ||
+ | html += "<td>"+planetURLs+"</td>"; | ||
html += "</tr>" | html += "</tr>" | ||
}); | }); |
Revision as of 14:54, 6 August 2019
function drawTable(mobs) { var output = $("#creatures-list"); var html = "<div><a href='/index.php/Data:CreatureForm'><button>Add</button></a></div>"; html += "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th><th>Maturity</th><th>Planets</th></tr>"; mobs.forEach(function(mob) { var url = "/index.php/Creatures:"+mob["name"]; var planets = mob["planets"]; var planetURLs = ""; planets.forEach(function(planet) { planetURLs += "<a href='index.php/Story:"+planet+"'>"+planet+"</a> "; }); html += "<tr>"; html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>"; html += "<td>"+mob["hp"]+"</td>"; html += "<td>"+mob["min_damage"]+" - "+mob["max_damage"]+"</td>"; html += "<td>"+mob["maturity"]+"</td>"; html += "<td>"+planetURLs+"</td>"; html += "</tr>" }); html += "</table>"; output.html(html); } $(document).ready(function() { if ($("#creatures-list") != null) { $("#loader-creatures-list").show(); $.ajax({ type: "GET", dataType: "json", url: "/vv-api/get-creatures.php", success: function(data) { $("#loader-creatures-list").hide(); drawTable(data.result); }, error: function(status, exec) { $("#loader-creatures-list").hide(); $("#creatures-list").html("<i>Error retrieving mob data!</i>"); } }); } });