civ/resources/spawn/progress-table.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

window.onload = function(){
2017-06-18 21:12:56 +00:00
const addRow = function(building){
2017-06-18 21:21:33 +00:00
//Populate First table cell: Building Name
$nameElement = $("<td></td>")
2017-06-18 21:12:56 +00:00
.attr("id", `${building.id}-progress.name`)
.append(building.name);
2017-06-18 21:21:33 +00:00
//Populate table cell: Use
2017-06-18 21:12:56 +00:00
$useElement = $("<td></td>")
.attr("id", `${building.id}-progress.use`)
.append(building.use)
2017-06-18 21:21:33 +00:00
//Populate table cell: Designed
2017-06-18 21:12:56 +00:00
$designedElement = $("<td></td>")
.attr("id", `${building.id}-progress.designed`)
.addClass("checkboxCell")
.append($("<input>")
.attr("type", "checkbox")
2017-06-18 21:12:56 +00:00
.attr("id", `${building.id}.designed?`)
.attr("checked", building.designed));
2017-06-18 21:21:33 +00:00
//Populate table cell: Started
2017-06-18 21:12:56 +00:00
$startedElement = $("<td></td>")
.attr("id", `${building.id}-progress.stated`)
.addClass("checkboxCell")
.append($("<input>")
.attr("type", "checkbox")
2017-06-18 21:12:56 +00:00
.attr("id", `${building.id}.started?`)
.attr("checked", building.started));
2017-06-18 21:21:33 +00:00
//Populate table cell: Completed
2017-06-18 21:12:56 +00:00
$completedElement = $("<td></td>")
.attr("id", `${building.id}-progress.completed`)
.addClass("checkboxCell")
.append($("<input>")
.attr("type", "checkbox")
2017-06-18 21:12:56 +00:00
.attr("id", `${building.id}.completed?`)
.attr("checked", building.completed));
2017-06-18 21:21:33 +00:00
//Populate table cell: Populated
2017-06-18 21:12:56 +00:00
$populatedElement = $("<td></td>")
.attr("id", `${building.id}-progress.populated`)
.addClass("checkboxCell")
.append($("<input>")
.attr("type", "checkbox")
2017-06-18 21:12:56 +00:00
.attr("id", `${building.id}.populated?`)
.attr("checked", building.populated));
2017-06-18 21:21:33 +00:00
//Create entire row, appending all elements
2017-06-18 21:12:56 +00:00
$outputRow = $("<tr></tr>")
.attr("id", `${building.id}-progress`)
.append($nameElement)
.append($useElement)
.append($designedElement)
.append($startedElement)
.append($completedElement)
.append($populatedElement);
2017-06-18 21:21:33 +00:00
//return the entire row
return $outputRow;
}
console.info("loading");
$.getJSON("./resources/spawn/buildings.json", "", function(file){
for(const buildingName in file.buildings){
$("#progress-table").append(addRow(file.buildings[buildingName]));
}
});
}