forked from I2P_Developers/i2p.i2p
SusiMail: Replace onclick and onload, part 1
Don't reload page after mark-all and clear-all
This commit is contained in:
@@ -1,2 +1,22 @@
|
||||
let beforePopup = true;
|
||||
window.addEventListener('beforeunload', (e)=>{if (beforePopup) e.returnValue=true;} );
|
||||
|
||||
function initPopup() {
|
||||
var buttons = document.getElementsByClassName("beforePopup");
|
||||
for(index = 0; index < buttons.length; index++)
|
||||
{
|
||||
var button = buttons[index];
|
||||
addClickHandler5(button);
|
||||
}
|
||||
}
|
||||
|
||||
function addClickHandler5(elem)
|
||||
{
|
||||
elem.addEventListener("click", function() {
|
||||
beforePopup = false;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
initPopup();
|
||||
}, true);
|
||||
|
||||
@@ -1,3 +1,66 @@
|
||||
function initButtons() {
|
||||
var buttons = document.getElementsByClassName("delete1");
|
||||
for(index = 0; index < buttons.length; index++)
|
||||
{
|
||||
var button = buttons[index];
|
||||
addClickHandler1(button);
|
||||
}
|
||||
buttons = document.getElementsByClassName("markall");
|
||||
for(index = 0; index < buttons.length; index++)
|
||||
{
|
||||
var button = buttons[index];
|
||||
addClickHandler2(button);
|
||||
}
|
||||
buttons = document.getElementsByClassName("clearselection");
|
||||
for(index = 0; index < buttons.length; index++)
|
||||
{
|
||||
var button = buttons[index];
|
||||
addClickHandler3(button);
|
||||
}
|
||||
// TODO delete button, to show really-delete section or popup
|
||||
}
|
||||
|
||||
function addClickHandler1(elem)
|
||||
{
|
||||
elem.addEventListener("click", function() {
|
||||
deleteboxclicked();
|
||||
});
|
||||
}
|
||||
|
||||
function addClickHandler2(elem)
|
||||
{
|
||||
elem.addEventListener("click", function() {
|
||||
var form = document.forms[0];
|
||||
form.delete.disabled = false;
|
||||
form.markall.disabled = true;
|
||||
form.clearselection.disabled = true;
|
||||
var buttons = document.getElementsByClassName("delete1");
|
||||
for(index = 0; index < buttons.length; index++)
|
||||
{
|
||||
var button = buttons[index];
|
||||
button.checked = true;
|
||||
}
|
||||
event.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
function addClickHandler3(elem)
|
||||
{
|
||||
elem.addEventListener("click", function() {
|
||||
var form = document.forms[0];
|
||||
form.delete.disabled = true;
|
||||
form.markall.disabled = false;
|
||||
form.clearselection.disabled = false;
|
||||
var buttons = document.getElementsByClassName("delete1");
|
||||
for(index = 0; index < buttons.length; index++)
|
||||
{
|
||||
var button = buttons[index];
|
||||
button.checked = false;
|
||||
}
|
||||
event.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
function deleteboxclicked() {
|
||||
var hasOne = false;
|
||||
var hasAll = true;
|
||||
@@ -18,3 +81,8 @@ function deleteboxclicked() {
|
||||
form.markall.disabled = hasAll;
|
||||
form.clearselection.disabled = hasNone;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
initButtons();
|
||||
deleteboxclicked();
|
||||
}, true);
|
||||
|
||||
19
apps/susimail/src/js/notifications.js
Normal file
19
apps/susimail/src/js/notifications.js
Normal file
@@ -0,0 +1,19 @@
|
||||
function initNotifications() {
|
||||
var buttons = document.getElementsByClassName("notifications");
|
||||
for(index = 0; index < buttons.length; index++)
|
||||
{
|
||||
var button = buttons[index];
|
||||
addClickHandler6(button);
|
||||
}
|
||||
}
|
||||
|
||||
function addClickHandler6(elem)
|
||||
{
|
||||
elem.addEventListener("click", function() {
|
||||
elem.remove();
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
initNotifications();
|
||||
}, true);
|
||||
@@ -391,12 +391,15 @@ public class WebMail extends HttpServlet
|
||||
private static String button( String name, String label )
|
||||
{
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("<input type=\"submit\" class=\"").append(name).append("\" name=\"")
|
||||
buf.append("<input type=\"submit\" name=\"")
|
||||
.append(name).append("\" value=\"").append(label).append('"');
|
||||
buf.append(" class=\"").append(name);
|
||||
if (name.equals(SEND) || name.equals(CANCEL) || name.equals(DELETE_ATTACHMENT) ||
|
||||
name.equals(NEW_UPLOAD) || name.equals(SAVE_AS_DRAFT) || // compose page
|
||||
name.equals(SETPAGESIZE) || name.equals(SAVE)) // config page
|
||||
buf.append(" onclick=\"beforePopup=false;\"");
|
||||
buf.append(" beforePopup\"");
|
||||
else
|
||||
buf.append('"');
|
||||
// These are icons only now, via the CSS, so add a tooltip
|
||||
if (name.equals(FIRSTPAGE) || name.equals(PREVPAGE) || name.equals(NEXTPAGE) || name.equals(LASTPAGE) ||
|
||||
name.equals(PREV) || name.equals(LIST) || name.equals(NEXT))
|
||||
@@ -2348,7 +2351,8 @@ public class WebMail extends HttpServlet
|
||||
out.println("<meta http-equiv=\"refresh\" content=\"5;url=" + myself + "\">");
|
||||
// TODO we don't need the form below
|
||||
}
|
||||
out.print("</head>\n<body" + (state == State.LIST ? " onload=\"deleteboxclicked()\">" : ">"));
|
||||
out.println("<script src=\"/susimail/js/notifications.js?" + CoreVersion.VERSION + "\" type=\"text/javascript\"></script>");
|
||||
out.print("</head>\n<body>");
|
||||
String nonce = state == State.AUTH ? LOGIN_NONCE :
|
||||
Long.toString(ctx.random().nextLong());
|
||||
sessionObject.addNonce(nonce);
|
||||
@@ -2414,7 +2418,7 @@ public class WebMail extends HttpServlet
|
||||
}
|
||||
}
|
||||
if (showRefresh || sessionObject.error.length() > 0 || sessionObject.info.length() > 0) {
|
||||
out.println("<div class=\"notifications\" onclick=\"this.remove()\">");
|
||||
out.println("<div class=\"notifications\">");
|
||||
if (sessionObject.error.length() > 0)
|
||||
out.println("<p class=\"error\">" + quoteHTML(sessionObject.error).replace("\n", "<br>") + "</p>");
|
||||
if (sessionObject.info.length() > 0 || showRefresh) {
|
||||
@@ -3221,8 +3225,7 @@ public class WebMail extends HttpServlet
|
||||
if (subj.length() <= 0)
|
||||
subj = "<i>" + _t("no subject") + "</i>";
|
||||
out.println( "<tr class=\"list" + bg + "\">" +
|
||||
"<td><input type=\"checkbox\" class=\"optbox\" name=\"check" + b64UIDL + "\" value=\"1\"" +
|
||||
" onclick=\"deleteboxclicked();\" " +
|
||||
"<td><input type=\"checkbox\" class=\"optbox delete1\" name=\"check" + b64UIDL + "\" value=\"1\"" +
|
||||
( idChecked ? "checked" : "" ) + ">" + "</td><td " + jslink + ">" +
|
||||
(mail.isNew() ? "<img src=\"/susimail/icons/flag_green.png\" alt=\"\" title=\"" + _t("Message is new") + "\">" : " ") + "</td><td " + jslink + ">");
|
||||
// mail.shortSender and mail.shortSubject already html encoded
|
||||
@@ -3271,6 +3274,7 @@ public class WebMail extends HttpServlet
|
||||
}
|
||||
out.println("<tr class=\"bottombuttons\"><td colspan=\"5\" align=\"left\">");
|
||||
if (i > 0) {
|
||||
// TODO do this in js
|
||||
if( sessionObject.reallyDelete ) {
|
||||
// TODO ngettext
|
||||
out.println("<p class=\"error\">" + _t("Really delete the marked messages?") +
|
||||
|
||||
Reference in New Issue
Block a user