Created
July 4, 2020 02:42
-
-
Save simonho288/abbd30efa8b4e52f1ca9a24d7fdcd115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var _account; | |
| ///////////////////////////////////////////// | |
| // Internal Functions | |
| ///////////////////////////////////////////// | |
| // Call server-side script unlockWalletRestApi() | |
| function callServerUnlockWallet_(callback) { | |
| var status = app.pages.ElectionPage.descendants.ConnectionStatus; // the status label | |
| google.script.run.withFailureHandler(function(error) { | |
| // An error occurred, so display an error message. | |
| status.text = error.message; | |
| }).withSuccessHandler(function(result) { | |
| callback(); | |
| }).unlockWalletRestApi(); | |
| } | |
| // Call server-side script createAccountRestApi() | |
| function callServerCreateAccount_(callback) { | |
| var status = app.pages.ElectionPage.descendants.SubmitStatus; // the status label | |
| google.script.run.withFailureHandler(function(error) { | |
| // An error occurred, so display an error message. | |
| status.text = error.message; | |
| }).withSuccessHandler(function(result) { | |
| // Store the account and show the panelVote | |
| _account = JSON.parse(result).account; | |
| callback(true); // return a true result to callback | |
| }).createAccountRestApi(); | |
| } | |
| // Call server-side script voteCandidateRestApi() | |
| function callServerVoteCandidate_(candidateKey) { | |
| var status = app.pages.ElectionPage.descendants.SubmitStatus; // the status label | |
| google.script.run.withFailureHandler(function(error) { | |
| // An error occurred, so display an error message. | |
| status.text = error.message; | |
| }).withSuccessHandler(function(result) { | |
| }).voteCandidateRestApi(_account, candidateKey); | |
| } | |
| ///////////////////////////////////////////// | |
| // Functions availiable for pages | |
| ///////////////////////////////////////////// | |
| function onFormLoad() { | |
| app.pages.ElectionPage.descendants.panelVote.visible = false; | |
| app.pages.ElectionPage.descendants.panelVoteResult.visible = false; | |
| } | |
| function onInputNameSubmitClicked(submitButton) { | |
| var props = submitButton.root.properties; | |
| if (submitButton.root.descendants.panelInputName.validate()) { | |
| props.CreatingAccount = true; | |
| callServerUnlockWallet_(function() { | |
| callServerCreateAccount_(function(result) { | |
| props.CreatingAccount = false; | |
| if (result) { | |
| // Show next panel if success | |
| app.currentPage.root.descendants.panelVote.visible = true; | |
| } | |
| }); | |
| }); | |
| } | |
| } | |
| function onVoteButtonClicked(voteButton) { | |
| var selected = voteButton.root.descendants.dropdownCandidate.value; | |
| console.log('dropdownCandidate: ' + selected); | |
| var props = voteButton.root.properties; | |
| props.VotingCandidate = true; | |
| var candidateKey = null; | |
| for (var i = 0; i < app.datasources.ElectionData.items.length; ++i) { | |
| var candidate = app.datasources.ElectionData.items[i]; | |
| if (candidate.Name == selected) { | |
| candidateKey = candidate.Key; | |
| } | |
| } | |
| console.log('candidateKey=' + candidateKey); | |
| callServerVoteCandidate_(candidateKey); | |
| app.datasources.ElectionData.load(function() { | |
| app.currentPage.root.descendants.panelVoteResult.visible = true; | |
| props.VotingCandidate = false; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment