Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv26835

Modified Files:
        Pending.py 
Log Message:
Added Javascript confirmation on delete or blacklist if
Defaults.CGI_USE_JS_CONFIRM is set.

Bugfix:

Moved Count incremement to end of loop to avoid off by one error.


Index: Pending.py
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/cgi/Pending.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Pending.py  26 Nov 2002 19:42:20 -0000      1.2
+++ Pending.py  29 Nov 2002 18:46:00 -0000      1.3
@@ -147,11 +147,41 @@
 <head>
 <title>Pending E-mails for %s</title>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<link href="display/styles.css" rel="stylesheet" type="text/css">
-</head>
+<link href="display/styles.css" rel="stylesheet" type="text/css">""" % 
+Defaults.FULLNAME
+  
+  if Defaults.CGI_USE_JS_CONFIRM:
+    print """<script>
+function TestConfirm()
+{
+  ToBlacklist = 0
+  ToDelete = 0
+  for (i = 0; i < %s; i++)
+  {
+    action = document.forms.actions["a" + i]
+    if (action)
+      for (j = 0; j < action.length; j++)
+      {
+        if (action[j].checked && (action[j].value == "blacklist")) ToBlacklist++
+        if (action[j].checked && (action[j].value == "delete")) ToDelete++
+      }
+  }
+  if (ToDelete)
+    if (ToBlacklist) Msg = "Permanently delete and blacklist"
+    else Msg = "Permanently delete"
+  else
+    if (ToBlacklist) Msg = "Permanently blacklist"
+    else return true
+  if ((ToDelete + ToBlacklist) == 1) Msg += " this pending message?"
+  else Msg += " these pending messages?"
+  if (ToDelete) Msg += "\\nAny confirmation that follows will fail."
+  return confirm(Msg)
+}
+</script>""" % Defaults.CGI_PAGER_SIZE
+
+  print """</head>
 
 <body class="PendingPage">
-<table>""" % Defaults.FULLNAME
+<table>"""
   
   if len(Msgs): print """%s
   <tr>
@@ -167,8 +197,13 @@
   
   if len(Msgs):
     # Display pending messages if there are any
-    print  """  <form method="post" action="%s" name="actions">
-    <tr>
+    if Defaults.CGI_USE_JS_CONFIRM:
+      print "  <form method=post action=%s name=actions onSubmit='return 
+TestConfirm()'> " \
+        % os.environ["SCRIPT_NAME"]
+    else:
+      print "  <form method=post action=%s name=actions>" % os.environ["SCRIPT_NAME"]
+      
+    print """    <tr>
       <td colspan="4">
         <table class="MailList">
           <tr> 
@@ -182,14 +217,13 @@
           <tr bgcolor="#CCCCCC"> 
             <td colspan="5" class="Spacer"></td>
           </tr>
-""" % (os.environ["SCRIPT_NAME"], IconWidth, ExtraIcons, 
-      os.environ["SCRIPT_NAME"], ToggleSort, PVars.SID, SortIcon)
+""" % (IconWidth, ExtraIcons, os.environ["SCRIPT_NAME"], ToggleSort, PVars.SID, 
+      SortIcon)
 
     Count = 0
     InProcMsg = ""
     for Msg in Msgs[FirstMsg:LastMsg]:
       # Print a single message record inside list loop
-      Count = Count + 1
       try:
         MsgObj = Pending.Message(Msg)
       except:
@@ -254,6 +288,7 @@
           <tr bgcolor="#CCCCCC"> 
             <td colspan="5" class="Spacer"></td>
           </tr>""" % (Date, MsgSize)
+      Count = Count + 1
       # (end of) Print a single message record inside list loop
 
     print """          <tr> 

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs

Reply via email to