Cleaned stuff up a bit

This commit is contained in:
alisolarflare 2017-06-18 17:21:33 -04:00
parent cfe5deabfa
commit f4c17e5b53
2 changed files with 35 additions and 22 deletions

View file

@ -2,45 +2,48 @@
window.onload = function(){ window.onload = function(){
makeScenario = function(scenario){ makeScenario = function(scenario){
//output element, that other elements are attached to //Create output Element
let $trueOutputElement = $("<li></li>") let $trueOutputElement = $("<li></li>")
$trueOutputElement.attr("id", `scenarios-${scenario.name}`); $trueOutputElement.attr("id", `scenarios-${scenario.name}`);
let $outputElement = $("<div class=\"accordion-panel\"></div>") let $outputElement = $("<div class=\"accordion-panel\"></div>")
//Determines whether this is a jQuery Accordion
//Create Control Element
const isAccordion = true; const isAccordion = true;
if(isAccordion){ if(isAccordion){
$controlElement = $("<button></button>"); $controlElement = $("<button></button>");
$controlElement.addClass("accordion-control"); .addClass("accordion-control");
$controlElement.append(scenario.name); .append(scenario.name);
$trueOutputElement.append($controlElement); $trueOutputElement.append($controlElement);
} }
//Mature Content rating //Mature Content rating
if(scenario.adult == true){ if(scenario.adult == true){
$adultText = $("<p>(question for those over the age of 18... or those mature enough)</p>"); $adultText = $("<p>)</p>");
$adultText.addClass("adult"); .addClass("adult");
.append(`(question for those over the age of 18... or those mature enough)`)
$outputElement.append($adultText); $outputElement.append($adultText);
$outputElement.addClass("adult-scenario"); $outputElement.addClass("adult-scenario");
} }
//description //description
$descriptionElement = $("<p>" + scenario.description +"</p>"); $descriptionElement = $(`<p>${scenario.description}</p>`);
//option list //option list
$optionElement = $("<ul></ul>"); $optionElement = $("<ul></ul>");
for(option of scenario.options){ for(option of scenario.options){
//Create radio button //Create radio button
$inputTag = $("<input>"); $inputTag = $("<input>")
$inputTag.attr("type", "radio"); .attr("type", "radio")
$inputTag.attr("name", `radio-${scenario.name}`); .attr("name", `radio-${scenario.name}`);
//Populate list element //Populate list element
$newOption = $("<li></li>"); $newOption = $("<li></li>")
$newOption.append($inputTag); .append($inputTag)
$newOption.append(option); .append(option)
$optionElement.append($newOption); .append($newOption);
} }
//Other Question //Other Question
@ -64,18 +67,19 @@ window.onload = function(){
//Extra Question //Extra Question
if(scenario.question){ if(scenario.question){
$question = $("<p>" + scenario.question + "</p>"); $question = $("<p>" + scenario.question + "</p>")
$questionResponse = $("<textArea></textArea>"); .append($("<textArea></textArea>")
$questionResponse.attr("placeholder", "Enter response here"); .attr("placeholder", "Enter response here"));
$outputElement.append($question); $outputElement.append($question);
$outputElement.append($questionResponse); $outputElement.append($questionResponse);
} }
//Submission button //Submission button
$submitElement = $("<input>"); $submitElement = $("<input>")
$submitElement.attr("type", "submit"); .attr("type", "submit")
$submitElement.append("Submit"); .append("Submit");
$outputElement.append($("<br /><br />")); $outputElement.append($("<br /><br />"));
$outputElement.append($submitElement); $outputElement.append($submitElement);

View file

@ -1,13 +1,17 @@
window.onload = function(){ window.onload = function(){
const addRow = function(building){ const addRow = function(building){
//Populate First table cell: Building Name
$nameElement = $("<td></td>") $nameElement = $("<td></td>")
.attr("id", `${building.id}-progress.name`) .attr("id", `${building.id}-progress.name`)
.append(building.name); .append(building.name);
//Populate table cell: Use
$useElement = $("<td></td>") $useElement = $("<td></td>")
.attr("id", `${building.id}-progress.use`) .attr("id", `${building.id}-progress.use`)
.append(building.use) .append(building.use)
//Populate table cell: Designed
$designedElement = $("<td></td>") $designedElement = $("<td></td>")
.attr("id", `${building.id}-progress.designed`) .attr("id", `${building.id}-progress.designed`)
.addClass("checkboxCell") .addClass("checkboxCell")
@ -16,6 +20,7 @@ window.onload = function(){
.attr("id", `${building.id}.designed?`) .attr("id", `${building.id}.designed?`)
.attr("checked", building.designed)); .attr("checked", building.designed));
//Populate table cell: Started
$startedElement = $("<td></td>") $startedElement = $("<td></td>")
.attr("id", `${building.id}-progress.stated`) .attr("id", `${building.id}-progress.stated`)
.addClass("checkboxCell") .addClass("checkboxCell")
@ -24,6 +29,7 @@ window.onload = function(){
.attr("id", `${building.id}.started?`) .attr("id", `${building.id}.started?`)
.attr("checked", building.started)); .attr("checked", building.started));
//Populate table cell: Completed
$completedElement = $("<td></td>") $completedElement = $("<td></td>")
.attr("id", `${building.id}-progress.completed`) .attr("id", `${building.id}-progress.completed`)
.addClass("checkboxCell") .addClass("checkboxCell")
@ -32,6 +38,7 @@ window.onload = function(){
.attr("id", `${building.id}.completed?`) .attr("id", `${building.id}.completed?`)
.attr("checked", building.completed)); .attr("checked", building.completed));
//Populate table cell: Populated
$populatedElement = $("<td></td>") $populatedElement = $("<td></td>")
.attr("id", `${building.id}-progress.populated`) .attr("id", `${building.id}-progress.populated`)
.addClass("checkboxCell") .addClass("checkboxCell")
@ -40,7 +47,7 @@ window.onload = function(){
.attr("id", `${building.id}.populated?`) .attr("id", `${building.id}.populated?`)
.attr("checked", building.populated)); .attr("checked", building.populated));
//Create entire row, appending all elements
$outputRow = $("<tr></tr>") $outputRow = $("<tr></tr>")
.attr("id", `${building.id}-progress`) .attr("id", `${building.id}-progress`)
.append($nameElement) .append($nameElement)
@ -49,6 +56,8 @@ window.onload = function(){
.append($startedElement) .append($startedElement)
.append($completedElement) .append($completedElement)
.append($populatedElement); .append($populatedElement);
//return the entire row
return $outputRow; return $outputRow;
} }
console.info("loading"); console.info("loading");