Skip to content

Commit

Permalink
Submission button linking to google form
Browse files Browse the repository at this point in the history
  • Loading branch information
atlleung committed Sep 6, 2024
1 parent cc3249c commit 31e2878
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
48 changes: 45 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ if (VERSION != 'adult' && VERSION != 'youth') {
VERSION = 'masterlife';
}

const open_link_window = (url) => {
// Open a new tab with the concatenated string as a data URL
const dataUrl = 'data:text/plain;charset=utf-8,' + encodeURIComponent(url);
console.log(dataUrl)
window.open(url, '_blank');
};

const submit_results_button = (url) => {
// Function to handle button click
return `
<div>
<a class="btn btn-primary btnSubmit" href="${url} target="_blank"">Submit Your Top 5 Gifts</a>
</div>
`
}


const question_component = (question, category, index) => {
let radiobuttons = Array(10).fill(1).map((_, i) => `<input type="radio" class="btn-check" name="question${index}" autocomplete="off" value="${i}" id="c${index}-${i}" data-category="${category}"><label class="btn btn-outline-secondary btn-sm" for="c${index}-${i}">${i + 1}</label>`).join('');

Expand Down Expand Up @@ -117,29 +134,54 @@ const score_quiz = () => {
let value = parseInt(q.value);
score += value;
});

// store the score
scores[category] = score;

// console.log(category,scores[category])
});

// write scores to screen
let max_score = Object.keys(scores).reduce((max, category) => Math.max(max, scores[category]), 0);
let html_scores = Object.keys(scores).map((category) => {
let width = scores[category] / max_score * 100;
return [width, progress_component(width, category + ': ' + scores[category], category)];
console.log(category)
return [width, progress_component(width, category + ': ' + scores[category], category),CATEGORY[VERSION][category]["resp"]];
});

// sort by width
html_scores.sort((a, b) => b[0] - a[0]);

// get max array
let max_resps = html_scores.slice(0,5).map((s) => s[2])
console.log(max_resps)

const labels = ["1st", "2nd", "3rd", "4th", "5th"];
const baseurl = 'https://docs.google.com/forms/d/e/1FAIpQLScqn67keX2ubHdtRVsMfhe5r0D_OeYP2Prn-FAafZiJsGQqRw/viewform?usp=pp_url'

// Combine both arrays into a new string
const prefill_str = max_resps.map((id, index) =>
`&entry.${id}=${labels[index]}`
);

// Add the new entry at the start of the array
prefill_str.unshift(baseurl)

const final_url = prefill_str.join('');

console.log(final_url)

// remove width
html_scores = html_scores.map((s) => s[1]).join('');

//button
let submit_button = submit_results_button(final_url)

const resultsdiv = document.getElementById('results');
resultsdiv.innerHTML = `<h3 class="mt-5 mb-4">Your personal spiritual gifts inventory </h3>
<p><b>(Click to see definitions)</b></p>` + html_scores;
<p><b>(Click to see definitions)</b></p>` + html_scores + submit_button;
resultsdiv.scrollIntoView({ behavior: 'smooth', block: 'start' });


// biblegateway reftagger
BGLinks.linkVerses();
};
Expand Down
18 changes: 18 additions & 0 deletions survey_categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,114 @@ const CATEGORY = {
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"1888054660"
},
"Mercy": {
"Blurb": "Mercy (Serving Gift) - the ability to feel sympathy and compassion for and to meet the needs of persons who suffer distress and crisis from physical, mental, or emotional problems",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"151657800"
},
"Giving": {
"Blurb": "Giving (Serving Gift) - the special ability and desire to contribute material resources to others and the Lord's work with liberality and cheerfulness",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"546481533"
},
"Healing": {
"Blurb": "Healing (Serving Gift) - the God-given ability to help others regain physical, mental, or spiritual health through the direct action of God",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"437278966"
},
"Wisdom": {
"Blurb": "Wisdom (Teaching Gift) - the ability to gain insight into the practical application of God's truths to specific situations",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"141581951"
},
"Knowledge": {
"Blurb": "Knowledge (Teaching Gift) - the ability to discover, understand, clarify, and communicate information that relates to the life, growth, and well-being of the church",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp": "1264814599"
},
"Teaching": {
"Blurb": "Teaching (Teaching Gift) - the special ability to study God's Word and to communicate spiritual truths in such a way that they are relevant to the church's health and ministry and in such a way that others will learn",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp": "777438159"
},
"Leadership": {
"Blurb": "Leadership (Teaching Gift) - the special ability to set goals in accordance with God's will, to communicate those goals to others, and to motivate others to work together to achieve those goals",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp": "70368253"
},
"Prophecy": {
"Blurb": "Prophecy (Worshiping Gift) - the special ability to receive a message from God and then to communicate that message toothers through a divinely anointed utterance",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"762570468"
},
"Discernment": {
"Blurb": "Spiritual discernment (Worshiping Gift) - the ability to know which actions and teachings that are claimed to be of God are actually of God rather than human or satanic",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"2124218295"
},
"Exhortation": {
"Blurb": "Exhortation (Worshiping Gift) - the special ability to comfort and encourage others as well as to motivate others to right actions",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp": "515457841"
},
"Shepherding": {
"Blurb": "Shepherding (Worshiping Gift) - the ability to build up, equip, and guide Christians in spiritual growth and maturity",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"1736554945"

},
"Faith": {
"Blurb": "Faith (Witnessing Gift) - the special ability to affirm God's power to intervene in the world today and to be a part of this intervention through prayer and the Holy Spirit's power",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"1541904179"
},
"Evangelism": {
"Blurb": "Evangelism (Witnessing Gift) - the ability to comprehend the lost condition of people in the world and to present Christ effectively so that persons will accept salvation in Jesus",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"1882308817"
},
"Apostleship": {
"Blurb": "Apostleship (Witnessing Gift) - the ability to share God's message of reconciliation; to start new Bible-study groups and churches; or to cross cultural, language, or racial barriers to present the gospel",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"2032165540"
},
"Miracles": {
"Blurb": "Miracles (Witnessing Gift) - the special ability to serve as a human intermediary through whom God works to bring about events that cannot be explained by natural law",
"Attributes": [],
"References": [],
"SeeAlso": [],
"resp":"1124159722"

},

},
Expand Down

0 comments on commit 31e2878

Please sign in to comment.