From b7fb1d46365d6bfa49d92fabb5341f0e68bf9852 Mon Sep 17 00:00:00 2001 From: jngrt Date: Tue, 19 May 2015 21:36:23 +0200 Subject: [PATCH] submit message return to overview --- web/main.js | 57 ++++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/web/main.js b/web/main.js index d099aa0..24d5ca0 100644 --- a/web/main.js +++ b/web/main.js @@ -25,7 +25,6 @@ document.addEventListener('DOMContentLoaded', function(){ //update everything to initialize updateInboxView(); - updateOutboxView(); update(); //check for new messages every 7 seconds @@ -39,29 +38,27 @@ document.addEventListener('DOMContentLoaded', function(){ */ function initState(){ - document.getElementById('photo-page').style.display = "none"; - document.getElementById('overview-page').style.display = "block"; - document.getElementById('message-page').style.display = "none"; + showOverview(); - document.getElementById('new-photo').onclick = onNewPhoto; - document.getElementById('new-message').onclick = onNewMessage; - document.getElementById('message-back').onclick = onBack; - document.getElementById('photo-back').onclick = onBack; + document.getElementById('new-photo').onclick = showNewPhoto; + document.getElementById('new-message').onclick = showNewMessage; + document.getElementById('message-back').onclick = showOverview; + document.getElementById('photo-back').onclick = showOverview; } -function onNewPhoto(){ +function showNewPhoto(){ document.getElementById('photo-page').style.display = "block"; document.getElementById('overview-page').style.display = "none"; document.getElementById('message-page').style.display = "none"; } -function onNewMessage(){ +function showNewMessage(){ document.getElementById('photo-page').style.display = "none"; document.getElementById('overview-page').style.display = "none"; document.getElementById('message-page').style.display = "block"; } -function onBack(){ +function showOverview(){ document.getElementById('photo-page').style.display = "none"; document.getElementById('overview-page').style.display = "block"; document.getElementById('message-page').style.display = "none"; @@ -72,33 +69,27 @@ function onBack(){ */ document.getElementById('message-form').onsubmit = function(){ var outStr = localStorage.getItem( 'outbox' ) || ''; - - if (document.getElementById('name').value == ""){ - var namm = "anonymous"; - } - else{ - var namm = document.getElementById('name').value; - } - var mess = document.getElementById('message').value.replace(/\r?\n/g, "
"); + var namm = document.getElementById('name').value || "anonymous"; + var mess = document.getElementById('message').value.replace(/\r?\n/g, "
"); var newMsgs = {}; var ddata = new Date().getTime(); - var alias = ownAlias //to do: build a check to see if ownAlias == ownId, if so, alias should become 'local' + var alias = ownAlias;//to do: build a check to see if ownAlias == ownId, if so, alias should become 'local' var contento = { "time" : ddata, "message" : mess, "name" : namm, "node" : alias, "hops" : "0" - } + }; newMsgs.message = contento; - localStorage.setItem( 'outbox', JSON.stringify(newMsgs) ); - updateOutboxView(); + localStorage.setItem( 'outbox', JSON.stringify(newMsgs) ); checkOutbox(); document.getElementById('message').value = ''; + showOverview(); return false; -} +}; function checkOutbox() { var outStr = localStorage.getItem( 'outbox' ); @@ -148,24 +139,6 @@ function removeOutboxItem( timestamp ) { } var newOutStr = lines.join('\n'); localStorage.setItem('outbox', newOutStr); - updateOutboxView(); -} -function updateOutboxView() { - var contentString = ''; - var outStr = localStorage.getItem( 'outbox' ) || ''; - var lines = outStr.split( /\n/ ); - for ( var i in lines ) { - if ( lines[ i ].length === 0 ) { - continue; - } - var obj = JSON.parse(lines[i]); - var ts = obj.message.time; - delete obj.message.time; - var msg = JSON.stringify(obj.message); - - contentString += '
  • ' + ts + ' ' + msg + '
  • '; - } - document.getElementById( 'outbox' ).innerHTML = contentString; } /*