submit message return to overview
This commit is contained in:
parent
5de5ed9f1a
commit
b7fb1d4636
57
web/main.js
57
web/main.js
@ -25,7 +25,6 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||||||
|
|
||||||
//update everything to initialize
|
//update everything to initialize
|
||||||
updateInboxView();
|
updateInboxView();
|
||||||
updateOutboxView();
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
//check for new messages every 7 seconds
|
//check for new messages every 7 seconds
|
||||||
@ -39,29 +38,27 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function initState(){
|
function initState(){
|
||||||
document.getElementById('photo-page').style.display = "none";
|
showOverview();
|
||||||
document.getElementById('overview-page').style.display = "block";
|
|
||||||
document.getElementById('message-page').style.display = "none";
|
|
||||||
|
|
||||||
document.getElementById('new-photo').onclick = onNewPhoto;
|
document.getElementById('new-photo').onclick = showNewPhoto;
|
||||||
document.getElementById('new-message').onclick = onNewMessage;
|
document.getElementById('new-message').onclick = showNewMessage;
|
||||||
document.getElementById('message-back').onclick = onBack;
|
document.getElementById('message-back').onclick = showOverview;
|
||||||
document.getElementById('photo-back').onclick = onBack;
|
document.getElementById('photo-back').onclick = showOverview;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onNewPhoto(){
|
function showNewPhoto(){
|
||||||
document.getElementById('photo-page').style.display = "block";
|
document.getElementById('photo-page').style.display = "block";
|
||||||
document.getElementById('overview-page').style.display = "none";
|
document.getElementById('overview-page').style.display = "none";
|
||||||
document.getElementById('message-page').style.display = "none";
|
document.getElementById('message-page').style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function onNewMessage(){
|
function showNewMessage(){
|
||||||
document.getElementById('photo-page').style.display = "none";
|
document.getElementById('photo-page').style.display = "none";
|
||||||
document.getElementById('overview-page').style.display = "none";
|
document.getElementById('overview-page').style.display = "none";
|
||||||
document.getElementById('message-page').style.display = "block";
|
document.getElementById('message-page').style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
function onBack(){
|
function showOverview(){
|
||||||
document.getElementById('photo-page').style.display = "none";
|
document.getElementById('photo-page').style.display = "none";
|
||||||
document.getElementById('overview-page').style.display = "block";
|
document.getElementById('overview-page').style.display = "block";
|
||||||
document.getElementById('message-page').style.display = "none";
|
document.getElementById('message-page').style.display = "none";
|
||||||
@ -72,33 +69,27 @@ function onBack(){
|
|||||||
*/
|
*/
|
||||||
document.getElementById('message-form').onsubmit = function(){
|
document.getElementById('message-form').onsubmit = function(){
|
||||||
var outStr = localStorage.getItem( 'outbox' ) || '';
|
var outStr = localStorage.getItem( 'outbox' ) || '';
|
||||||
|
var namm = document.getElementById('name').value || "anonymous";
|
||||||
if (document.getElementById('name').value == ""){
|
var mess = document.getElementById('message').value.replace(/\r?\n/g, "<br />");
|
||||||
var namm = "anonymous";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
var namm = document.getElementById('name').value;
|
|
||||||
}
|
|
||||||
var mess = document.getElementById('message').value.replace(/\r?\n/g, "<br />");
|
|
||||||
var newMsgs = {};
|
var newMsgs = {};
|
||||||
var ddata = new Date().getTime();
|
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 = {
|
var contento = {
|
||||||
"time" : ddata,
|
"time" : ddata,
|
||||||
"message" : mess,
|
"message" : mess,
|
||||||
"name" : namm,
|
"name" : namm,
|
||||||
"node" : alias,
|
"node" : alias,
|
||||||
"hops" : "0"
|
"hops" : "0"
|
||||||
}
|
};
|
||||||
newMsgs.message = contento;
|
newMsgs.message = contento;
|
||||||
|
|
||||||
localStorage.setItem( 'outbox', JSON.stringify(newMsgs) );
|
localStorage.setItem( 'outbox', JSON.stringify(newMsgs) );
|
||||||
updateOutboxView();
|
|
||||||
checkOutbox();
|
checkOutbox();
|
||||||
document.getElementById('message').value = '';
|
document.getElementById('message').value = '';
|
||||||
|
|
||||||
|
showOverview();
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
|
|
||||||
function checkOutbox() {
|
function checkOutbox() {
|
||||||
var outStr = localStorage.getItem( 'outbox' );
|
var outStr = localStorage.getItem( 'outbox' );
|
||||||
@ -148,24 +139,6 @@ function removeOutboxItem( timestamp ) {
|
|||||||
}
|
}
|
||||||
var newOutStr = lines.join('\n');
|
var newOutStr = lines.join('\n');
|
||||||
localStorage.setItem('outbox', newOutStr);
|
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 += '<li><b>' + ts + ' </b>' + msg + '</li>';
|
|
||||||
}
|
|
||||||
document.getElementById( 'outbox' ).innerHTML = contentString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user