Do not add duplicate headers, and clear table for append

Instead of appending the API results non-stop, we clear the table first so that it's fresh data loaded into the table.

In addition, I added a class to the "To" `tr` and jQuery will look for this class. If it doesn't exist then it'll add that `tr`. Otherwise it won't continue to stack it.

Fixes https://github.com/HaschekSolutions/opentrashmail/issues/2
This commit is contained in:
Pat O'Brien 2019-10-03 09:54:16 -04:00
parent 53e6c8dba2
commit 8e362bec24

View file

@ -91,9 +91,14 @@ function updateEmailTable()
{
clearInterval(timer);
admin = true;
$('#tableheader').children(':eq(1)').after('<th scope="col">To</th>');
// Do not add the To header if one with the "to" class already exists
if ( $('#tableheader').children(':eq(2)').hasClass("to") === false )
{
$('#tableheader').children(':eq(1)').after('<th scope="col" class="to">To</th>');
}
}
$("#emailtable tr").remove(); // Empty all <tr> from the table so we don't stack
if(Object.keys(data.emails).length>0)
for(em in data.emails)
{