"use strict"; $h(startDoc) var LambdaCounts = null var LambdaActions = null var UpdateCounter = 0 function startDoc() { const home = document.getElementById('page-home') if (home !== null) { $h('.committed-button').on('click', countCommits) fetchAndUpdateCount() setTimeout(delayedCounterUpdate, 1000) } const countmeX = document.getElementById('page-countme') if (countmeX !== null) { // connect a click event on the button // $h('.count-me-button').on('click', countme) const hereBefore = localStorage.getItem('hereBefore') if (hereBefore !== null) { const sparams = new URLSearchParams(window.location.search) const nodup = sparams.get('nodup') if (nodup === null) { const confirmTitle = document.getElementById('text-05').innerHTML const confirmText = document.getElementById('text-06').innerHTML showConfirmModal(confirmTitle, confirmText, confirmModalDone) } } } const admin = document.getElementById('page-admin') if (admin !== null) { startAdmin() } } function startAdmin() { ajaxPost({ url : 'https://4s302aalg2.execute-api.us-east-2.amazonaws.com/production?offset=0&count=1', method: 'GET', success : function(result) { const pageCount = document.getElementById('page-count') const itemsPerPage = parseInt(pageCount.value) pageCount.addEventListener("change", populateActions) let pages = result.total_items / itemsPerPage if ((result.total_items % itemsPerPage) === 0) { pages += 1 } const pageSelect = document.getElementById('page-offset') pageSelect.innerHTML = "" let sel = " selected" for(let ix = 0; ix !== pages; ix++) { const html = '' pageSelect.innerHTML += html sel = '' } pageSelect.addEventListener("change", populateActions) populateActions() }, error: function(xhr, status, error) { showModal("Woops", 'Something bad happened fetching actions but not sure what.', null) } }) ajaxPost({ url : 'https://jkilsncuo6.execute-api.us-east-2.amazonaws.com/production', method: 'GET', success : function(result) { LambdaCounts = result.result populateCounts(LambdaCounts) }, error: function(xhr, status, error) { showModal("Woops", 'Something bad happened fetching counts but not sure what.', null) } }) } function populateActions(actions, total_items) { const pageCountElem = document.getElementById('page-count') const itemsPerPage = parseInt(pageCountElem.value) const pageSelectElem = document.getElementById('page-offset') const pageSelect = parseInt(pageSelectElem.value) const offset = pageSelect * itemsPerPage ajaxPost({ url : 'https://4s302aalg2.execute-api.us-east-2.amazonaws.com/production?offset=' + offset + '&count=' + itemsPerPage, method: 'GET', success : function(result) { LambdaActions = result.items const resDiv = document.getElementById('actions-go-here') resDiv.innerHTML = "" for (let iy = 0; iy !== LambdaActions.length; iy++) { const action = LambdaActions[iy] let name = '' if (typeof action.name !== 'undefined') name = action.name let email = '' if (typeof action.email !== 'undefined') email = action.email let age = '' if (typeof action.age !== 'undefined') age = action.age let zip = '' if (typeof action.zip !== 'undefined') zip = action.zip let votes = '' if (typeof action.votes !== 'undefined') votes = action.votes let text = '' if (typeof action.text !== 'undefined') text = action.text resDiv.innerHTML += '' + name + '' + email + '' + age + '' + zip + '' + votes + '' + text + '' } }, error: function(xhr, status, error) { showModal("Woops", 'Something bad happened fetching actions but not sure what.', null) } }) } function getNameForSelection(id) { let selectionName = null if (!Number.isNaN(parseInt(id))) { const nameOfSelections = document.querySelectorAll('.name-of-selection') for(let ix = 0; ix !== nameOfSelections.length; ix++) { const selNum = nameOfSelections[ix].getAttribute('for-selection') if (selNum == id) { selectionName = nameOfSelections[ix].innerHTML } } } if (selectionName === null) selectionName = id return selectionName } function populateCounts(counts) { const resDiv = document.getElementById('counts-go-here') for (let [key, value] of Object.entries(counts)) { const key_i = parseInt(key) if (Number.isNaN(key_i) ) continue const selectionName = getNameForSelection(key) resDiv.innerHTML += '

' + selectionName + ': ' + value + '

' } } function confirmModalDone(e) { if (e.toLowerCase() === 'no') { window.location.href = 'index.html' } } function delayedCounterUpdate() { fetchAndUpdateCount() UpdateCounter += 1 if (UpdateCounter < 5) { setTimeout(delayedCounterUpdate, 1000) } } function fetchAndUpdateCount() { // get the count from s3 and poke into the counter $ajax({ url : 'count.json', method: 'GET', success : function(result) { updateCount(result.count) }, error: function(xhr, status, error) { updateCount(0) } }) } function updateCount(v) { const counter = $h('#counter') if (counter.length !== 0) counter[0].innerText = v.toLocaleString() } function countCommits() { window.location.href = "countme.html" } function countme() { const cbs = $h('.collab-checkbox') let ids_selected = [] for(let ix = 0; ix !== cbs.length; ix++) { if (cbs[ix].checked) { const id_ = cbs[ix].id.split('_') ids_selected.push(id_[1]) } } const name = $h('#contact-name').val() const age = $h('#contact-age').val() const zip = $h('#contact-zip').val() const email = $h('#contact-email').val() const txt = $h('#contact-actions').val() const org = $h('#contact-org').val() let errors = false if (name.length === 0) { errors = true $h('#error-name').show() } else { $h('#error-name').hide() } if (!IsValidZip(zip)) { errors = true $h('#error-zip').show() } else { $h('#error-zip').hide() } if ((email.length !== 0) && !IsValidEmail(email)) { errors = true $h('#error-email').show() } else { $h('#error-email').hide() } if (errors) return if (ids_selected.length === 0) { const tbc = document.getElementById('text-00').innerHTML const aoi = document.getElementById('text-01').innerHTML showModal(tbc, aoi, null) return } const button = document.getElementById('count-me-button') button.setAttribute('disabled', '') let body = { 'body' : { 'name' : name, 'age' : age, 'zip' : zip, 'email' : email, 'org' : org, 'text' : txt, 'votes_for' : ids_selected, 'token' : RecaptchaToken, } } // do the api call ajaxPost({ url : 'https://0qz74mt9wk.execute-api.us-east-2.amazonaws.com/production/', method: 'POST', data: JSON.stringify(body), success : function(result) { localStorage.setItem('hereBefore', "true") const ybc = document.getElementById('text-02').innerHTML let tx = document.getElementById('text-03').innerHTML // there may be additional items to include in the message box const ids = ids_selected const addItems = document.querySelectorAll('.info-for-selection') for(let ix = 0; ix !== addItems.length; ix++) { const elem = addItems[ix] const forSel = elem.getAttribute('for-selection') if ((forSel !== null) && (ids.includes(forSel))) { tx += elem.innerHTML } } showModal(ybc, tx, modalAllDone) }, error: function(xhr, status, error) { showModal("Woops", 'Something bad happened but not sure what.', modalAllDone) } }) } function ajaxPost(options) { let httpRequest = new XMLHttpRequest(); if (httpRequest) { httpRequest.onreadystatechange = function(e) { if (e.target.readyState === XMLHttpRequest.DONE) { if (e.target.status === 200) { const apiResults = JSON.parse(e.target.responseText); options['success'](apiResults, e.target.status); } else { options['error'](null, e.target.status, ""); } } }; httpRequest.open(options['method'], options['url']); httpRequest.setRequestHeader('Content-Type', 'application/json;charset=UTF-8') httpRequest.send(options['data']); } } function modalAllDone() { window.location.href = 'index.html' } /** * @return {boolean} */ function IsValidEmail(email_) { const email = email_.trim(); const ix_at = email.indexOf('@'); const ix_dot = email.lastIndexOf('.'); const ix_space = email.indexOf(' '); return (ix_at > 0) && (ix_at < ix_dot) && ((ix_at+1) < ix_dot) && ((ix_dot+1) < email.length) && (ix_space === -1); } /** * @return {boolean} */ function IsValidZip(zip) { if (zip.length !== 5) return false const z = parseInt(zip) if (isNaN(z)) return false return true } var CompletionModalElem = null var CompletionModal = null function showModal(title, text, func) { document.getElementById('modal-title').innerHTML = title document.getElementById('modal-text').innerHTML = text CompletionModalElem = document.getElementById('modal-completion') CompletionModal = new bootstrap.Modal(CompletionModalElem, { keyboard: false, backdrop: 'static', }) if (func !== null) { CompletionModalElem.addEventListener('hidden.bs.modal', func) } document.getElementById('modal-ok').addEventListener('click', completionModalOK) CompletionModal.show() } function completionModalOK() { CompletionModal.hide() } function completionModalOK() { CompletionModal.hide() } var ConfirmModalElem = null var ConfirmModal = null var ConfirmModalCallback = null function showConfirmModal(title, text, func) { document.getElementById('modal-confirm-title').innerHTML = title document.getElementById('modal-confirm-text').innerHTML = text ConfirmModalElem = document.getElementById('modal-confirm') ConfirmModal = new bootstrap.Modal(ConfirmModalElem, { keyboard: false, backdrop: 'static', }) if (func !== null) { ConfirmModalCallback = func } document.getElementById('modal-confirm-no').addEventListener('click', confirmModalClick) document.getElementById('modal-confirm-yes').addEventListener('click', confirmModalClick) ConfirmModal.show() } function confirmModalClick(e) { if (ConfirmModalCallback === null) retrurn const id_ = e.currentTarget.id.split('-') ConfirmModalCallback(id_[2]) } var RecaptchaToken = null function onRecaptchaSubmit(token) { RecaptchaToken = token countme() }