From a8f9f6c913b29aaff8384cc0025d216c26447791 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 23 Jun 2017 12:47:58 +0200 Subject: [PATCH] IT IS ALIVE --- _src/_assets/javascripts/page-getstarted.js | 32 +++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/_src/_assets/javascripts/page-getstarted.js b/_src/_assets/javascripts/page-getstarted.js index d23f797..4476840 100644 --- a/_src/_assets/javascripts/page-getstarted.js +++ b/_src/_assets/javascripts/page-getstarted.js @@ -9,7 +9,7 @@ jQuery(function($) { Newsletter.init() }) -//=include bigchaindb-driver/dist/browser/bundle.window.min.js +//=include bigchaindb-driver/dist/browser/bigchaindb-driver.window.min.js window.addEventListener('DOMContentLoaded', function domload(event){ window.removeEventListener('DOMContentLoaded', domload, false) @@ -21,16 +21,28 @@ window.addEventListener('DOMContentLoaded', function domload(event){ const form = document.getElementById('form-transaction') const postButton = document.getElementById('post') + const messageInput = document.getElementById('message') + + // quick form validation + postButton.classList.add('disabled') + + messageInput.addEventListener('input', function() { + if (messageInput.value === '') { + postButton.classList.add('disabled') + } else { + postButton.classList.remove('disabled') + } + }) postButton.addEventListener('click', function(e) { e.preventDefault() - const message = document.getElementById('message').value + const message = messageInput.value const alice = new driver.Ed25519Keypair() const tx = driver.Transaction.makeCreateTransaction( { assetMessage: message }, - { metaDataMessage: 'hello' }, + { metaDataMessage: message }, [ driver.Transaction.makeOutput( driver.Transaction.makeEd25519Condition(alice.publicKey)) ], @@ -44,23 +56,27 @@ window.addEventListener('DOMContentLoaded', function domload(event){ }) const waiting = document.getElementsByClassName('waiting')[0] - const response = document.getElementsByClassName('response')[0] + const responseArea = document.getElementsByClassName('response')[0] const output = document.getElementsByClassName('output')[0] const messageSuccess = document.getElementsByClassName('message--success')[0] const messageFail = document.getElementsByClassName('message--fail')[0] conn.postTransaction(txSigned) - .then(() => { + .then((response) => { waiting.classList.add('hide') - response.classList.remove('hide') + responseArea.classList.remove('hide') + messageSuccess.classList.remove('hide') - const outputContent = conn.getStatus(txSigned.id) + console.log(response) + + const outputContent = JSON.stringify(response, null, 4) // indented with 4 spaces output.textContent = outputContent + }, reason => { // Error! console.log(reason) waiting.classList.add('hide') - response.classList.remove('hide') + responseArea.classList.remove('hide') messageFail.classList.remove('hide') const outputContent = reason.status + ' ' + reason.statusText