fixed UI sentbox

This commit is contained in:
Kevin Froman 2019-03-04 21:16:33 -06:00
parent 9b6553511b
commit c262b67626
3 changed files with 19 additions and 9 deletions

View File

@ -20,6 +20,7 @@
import sys, os, json import sys, os, json
from flask import Response, request, redirect, Blueprint, abort from flask import Response, request, redirect, Blueprint, abort
import core import core
from onionrusers import contactmanager
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import loadinbox, sentboxdb import loadinbox, sentboxdb
@ -54,5 +55,7 @@ def list_sentbox():
if sentbox_list_copy[x]['hash'] in deleted: if sentbox_list_copy[x]['hash'] in deleted:
x -= 1 x -= 1
sentbox_list.pop(x) sentbox_list.pop(x)
else:
sentbox_list[x]['name'] = contactmanager.ContactManager(c, sentbox_list[x]['peer'], saveUser=False).get_info('name')
return json.dumps(sentbox_list) return json.dumps(sentbox_list)

View File

@ -191,36 +191,41 @@ function getSentbox(){
.then(function(resp) { .then(function(resp) {
var keys = []; var keys = [];
var entry = document.createElement('div') var entry = document.createElement('div')
var entryUsed;
for(var k in resp) keys.push(k); for(var k in resp) keys.push(k);
if (keys.length == 0){ if (keys.length == 0){
threadPart.innerHTML = "nothing to show here yet." threadPart.innerHTML = "nothing to show here yet."
} }
for (var i = 0; i < keys.length; i++){ for (var i = 0; i < keys.length; i++){
var entry = document.createElement('div') var entry = document.createElement('div')
var obj = resp[i]; var obj = resp[i]
var toLabel = document.createElement('span') var toLabel = document.createElement('span')
toLabel.innerText = 'To: ' toLabel.innerText = 'To: '
var toEl = document.createElement('input') var toEl = document.createElement('input')
var preview = document.createElement('span') var preview = document.createElement('span')
var deleteBtn = document.createElement('button') var deleteBtn = document.createElement('button')
var message = resp[i]['message']
deleteBtn.classList.add('deleteBtn', 'dangerBtn') deleteBtn.classList.add('deleteBtn', 'dangerBtn')
deleteBtn.innerText = 'X' deleteBtn.innerText = 'X'
toEl.readOnly = true toEl.readOnly = true
if (resp[i]['name'] == null){
toEl.value = resp[i]['peer'] toEl.value = resp[i]['peer']
}
else{
toEl.value = resp[i]['name']
}
preview.innerText = '(' + resp[i]['subject'] + ')' preview.innerText = '(' + resp[i]['subject'] + ')'
entry.setAttribute('data-hash', resp[i]['hash']) entry.setAttribute('data-hash', resp[i]['hash'])
entry.appendChild(deleteBtn) entry.appendChild(deleteBtn)
entry.appendChild(toLabel) entry.appendChild(toLabel)
entry.appendChild(toEl) entry.appendChild(toEl)
entry.appendChild(preview) entry.appendChild(preview)
entryUsed = resp[i]['message'] entry.onclick = (function(tree, el, msg) {return function() {
entry.onclick = function(){
console.log(resp) console.log(resp)
if (! entry.target.classList.contains('deleteBtn')){ if (! entry.classList.contains('deleteBtn')){
showSentboxWindow(toEl.value, entryUsed) showSentboxWindow(el.value, msg)
}
} }
};})(entry, toEl, message);
deleteBtn.onclick = function(){ deleteBtn.onclick = function(){
entry.parentNode.removeChild(entry); entry.parentNode.removeChild(entry);
deleteMessage(entry.getAttribute('data-hash')) deleteMessage(entry.getAttribute('data-hash'))

View File

@ -27,6 +27,7 @@ function sendMail(to, message, subject){
//postData = {"postData": '{"to": "' + to + '", "message": "' + message + '"}'} // galaxy brain //postData = {"postData": '{"to": "' + to + '", "message": "' + message + '"}'} // galaxy brain
postData = {'message': message, 'to': to, 'type': 'pm', 'encrypt': true, 'meta': JSON.stringify({'subject': subject})} postData = {'message': message, 'to': to, 'type': 'pm', 'encrypt': true, 'meta': JSON.stringify({'subject': subject})}
postData = JSON.stringify(postData) postData = JSON.stringify(postData)
sendForm.style.display = 'none'
fetch('/insertblock', { fetch('/insertblock', {
method: 'POST', method: 'POST',
body: postData, body: postData,
@ -36,6 +37,8 @@ function sendMail(to, message, subject){
}}) }})
.then((resp) => resp.text()) // Transform the data into json .then((resp) => resp.text()) // Transform the data into json
.then(function(data) { .then(function(data) {
sendForm.style.display = 'block'
alert('Queued for sending!')
}) })
} }
@ -51,7 +54,6 @@ sendForm.onsubmit = function(){
return false return false
} }
} }
sendMail(to.value, messageContent.value, subject.value) sendMail(to.value, messageContent.value, subject.value)
return false return false
} }