[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/templates/mailbox/ -> javascript.inc (source)

   1  <script type="text/javascript">
   2  <!--
   3  
   4  // Set up left (37) and right (39) arrows to go to the previous/next page.
   5  setKeybinding(37, 'arrowHandler');
   6  setKeybinding(39, 'arrowHandler');
   7  
   8  function arrowHandler(e, key)
   9  {
  10      if (!document.getElementById || e.altKey || e.shiftKey || e.ctrlKey) {
  11          return false;
  12      }
  13  
  14      var loc;
  15      if (key == 37) {
  16          loc = document.getElementById('prev');
  17      } else if (key == 39) {
  18          loc = document.getElementById('next');
  19      }
  20  
  21      if (loc) {
  22          document.location.href = loc.href;
  23      }
  24      return true;
  25  }
  26  
  27  function AnySelected()
  28  {
  29      for (i = 0; i < document.messages.elements.length; i++) {
  30          if (document.messages.elements[i].checked) return true;
  31      }
  32      return false;
  33  }
  34  
  35  var rowColors = new Array();
  36  function selectRow(rowId)
  37  {
  38      rowOb = document.getElementById('row' + rowId);
  39      if (!rowOb) {
  40          return;
  41      }
  42  
  43      if (rowOb.className.indexOf('selectedRow') != -1) {
  44          rowOb.className = rowColors[rowId];
  45      } else {
  46          rowColors[rowId] = rowOb.className;
  47          rowOb.className = 'selectedRow';
  48      }
  49  }
  50  
  51  function getIndexByElement(elem)
  52  {
  53      for (var i = 0; i < elem.form.elements.length; i++) {
  54          if (elem == elem.form.elements[i]) return i;
  55      }
  56      return null;
  57  }
  58  
  59  function Submit(actID)
  60  {
  61      if (!AnySelected()) {
  62          window.alert('<?php echo addslashes(_("You must select at least one message first.")) ?>');
  63          return;
  64      }
  65  
  66  <?php if ($_SESSION['imp']['base_protocol'] == 'pop3'): ?>
  67      if (actID == 'delete_messages') {
  68          if (!window.confirm('<?php echo addslashes(_("Are you sure you wish to PERMANENTLY delete these messages?")) ?>')) {
  69              return;
  70          }
  71      }
  72  <?php endif; ?>
  73      if (actID == 'spam_report') {
  74          if (!window.confirm('<?php echo addslashes(_("Are you sure you wish to report this message as spam?")) ?>')) {
  75              return;
  76          }
  77      }
  78      if (actID == 'notspam_report') {
  79          if (!window.confirm('<?php echo addslashes(_("Are you sure you wish to report this message as innocent?")) ?>')) {
  80              return;
  81          }
  82      }
  83      document.messages.actionID.value = actID;
  84      document.messages.submit();
  85  }
  86  
  87  function makeSelection(whichForm)
  88  {
  89      switch (parseInt(whichForm)) {
  90      case -1:
  91          if (document.messages.checkAll.checked) {
  92              flag = "!<?php echo IMP_ALL ?>";
  93          } else {
  94              flag = "<?php echo IMP_ALL ?>";
  95          }
  96          break;
  97  
  98      case 1:
  99          flag = document.select1.filter.options[document.select1.filter.selectedIndex].value;
 100          break;
 101  
 102      default:
 103          flag = document.select2.filter.options[document.select2.filter.selectedIndex].value;
 104      }
 105  
 106      if (flag.substring(0, 1) == "!") {
 107          selectFlagged(parseInt(flag.substring(1)), false);
 108      } else if (flag.substring(0, 1) == "+") {
 109          selectFlagged(flag.substring(0,1), null);
 110      } else {
 111          selectFlagged(parseInt(flag), true);
 112      }
 113  
 114      // Reset the form.
 115      switch (parseInt(whichForm)) {
 116      case -1:
 117          break;
 118  
 119      case 1:
 120          document.select1.reset();
 121          break;
 122  
 123      default:
 124          document.select2.reset();
 125      }
 126  }
 127  
 128  var startrange = -1;
 129  
 130  function selectRange(e)
 131  {
 132      var checkBox = (e.srcElement || e.target);
 133      var endrange = getIndexByElement(checkBox);
 134  
 135      if (startrange >= 0 && e.shiftKey) {
 136          if (document.messages.elements[startrange].checked == document.messages.elements[endrange].checked) {
 137              if (startrange > endrange) {
 138                  var tmp = endrange;
 139                  endrange = startrange;
 140                  startrange = tmp;
 141              }
 142              for (var i = startrange + 1; i < endrange; i++) {
 143                  document.messages.elements[i].checked = document.messages.elements[startrange].checked;
 144                  selectRow(document.messages.elements[i].id.replace(/check/, ''));
 145              }
 146          }
 147          startrange = -1;
 148      } else {
 149          startrange = getIndexByElement(checkBox);
 150      }
 151  }
 152  
 153  function onClickHandler(e)
 154  {
 155      var e = e || window.event;
 156      var elem = (e.srcElement || e.target);
 157  
 158      // Range selection/deselection.
 159      if (elem.name == "indices[]") {
 160          selectRange(e);
 161      }
 162  }
 163  
 164  document.onclick = onClickHandler;
 165  
 166  <?php if (!empty($GLOBALS['conf']['user']['allow_folders'])): ?>
 167  function updateFolders(whichForm)
 168  {
 169      if (document.copymove2) {
 170          if ((whichForm == 1 && document.copymove1.targetMailbox.options[document.copymove1.targetMailbox.selectedIndex].value != "") ||
 171              (whichForm == 2 && document.copymove2.targetMailbox.options[document.copymove2.targetMailbox.selectedIndex].value != "")) {
 172              if (whichForm == 1) {
 173                  document.copymove2.targetMailbox.selectedIndex = document.copymove1.targetMailbox.selectedIndex;
 174              } else {
 175                  document.copymove1.targetMailbox.selectedIndex = document.copymove2.targetMailbox.selectedIndex;
 176              }
 177          }
 178      }
 179  }
 180  
 181  function Transfer(actID, whichForm)
 182  {
 183      if (AnySelected()) {
 184          if (whichForm == 1) {
 185              document.messages.targetMbox.value = document.copymove1.targetMailbox.options[document.copymove1.targetMailbox.selectedIndex].value;
 186          } else {
 187              document.messages.targetMbox.value = document.copymove2.targetMailbox.options[document.copymove2.targetMailbox.selectedIndex].value;
 188          }
 189  
 190          // Check for a mailbox actually being selected.
 191          if (document.messages.targetMbox.value == '*new*') {
 192              var newFolder = window.prompt('<?php echo addslashes(_("You are copying/moving to a new folder.")) . '\n' . addslashes(_("Please enter a name for the new folder:")) ?>\n', '');
 193              if (newFolder != null && newFolder != '') {
 194                  document.messages.newMbox.value = 1;
 195                  document.messages.targetMbox.value = newFolder;
 196                  document.messages.actionID.value = actID;
 197                  document.messages.submit();
 198              }
 199          } else {
 200              if (document.messages.targetMbox.value == '') {
 201                  window.alert('<?php echo addslashes(_("You must select a target mailbox first.")) ?>');
 202              } else {
 203                  document.messages.actionID.value = actID;
 204                  document.messages.submit();
 205              }
 206          }
 207      } else {
 208          window.alert('<?php echo addslashes(_("You must select at least one message first.")) ?>');
 209      }
 210  }
 211  <?php endif; ?>
 212  
 213  // Put everything reliant on IMAP flags in this section.
 214  var Flags;
 215  
 216  function selectFlagged(flag, val)
 217  {
 218      shift = 0;
 219      for (var i = 0; i < document.messages.elements.length; i++) {
 220          while (document.messages.elements[i].name != "indices[]") {
 221              i++;
 222              shift++;
 223              if (!document.messages.elements[i]) {
 224                  return;
 225              }
 226          }
 227  
 228          if (flag == '+') {
 229              check = !document.messages.elements[i].checked;
 230          } else if (flag & Flags[i - shift]) {
 231              check = val;
 232          } else {
 233              check = !val;
 234          }
 235  
 236          if (document.messages.elements[i].checked != check) {
 237              document.messages.elements[i].checked = check;
 238              selectRow(document.messages.elements[i].id.replace(/check/, ''));
 239          }
 240      }
 241  }
 242  
 243  <?php if ($_SESSION['imp']['base_protocol'] != 'pop3'): ?>
 244  function flagMessages(whichForm)
 245  {
 246      if ((whichForm == 1 && document.select1.flag.options[document.select1.flag.selectedIndex].value != "") ||
 247          (whichForm == 2 && document.select2.flag.options[document.select2.flag.selectedIndex].value != "")) {
 248          if (AnySelected()) {
 249              if (whichForm == 1) {
 250                  document.messages.flag.value = document.select1.flag.options[document.select1.flag.selectedIndex].value;
 251              } else {
 252                  document.messages.flag.value = document.select2.flag.options[document.select2.flag.selectedIndex].value;
 253              }
 254  
 255              document.messages.actionID.value = 'flag_messages';
 256              document.messages.submit();
 257          } else {
 258              if (whichForm == 1) {
 259                  document.select1.flag.selectedIndex = 0;
 260              } else {
 261                  document.select2.flag.selectedIndex = 0;
 262              }
 263              window.alert('<?php echo addslashes(_("You must select at least one message first.")) ?>');
 264          }
 265      }
 266  }
 267  <?php endif; ?>
 268  
 269  <?php if ($GLOBALS['browser']->hasFeature('dom')): ?>
 270  function getMessage(id, offset, index)
 271  {
 272      for (i = 0; i < messagelist.length; i++) {
 273          if (messagelist[i] == id) {
 274              j = i + offset;
 275              if (j >= 0 && j < messagelist.length) {
 276                  if (index) {
 277                      return j;
 278                  } else {
 279                      return messagelist[j];
 280                  }
 281              }
 282          }
 283      }
 284      return '';
 285  }
 286  
 287  function onKeyDownHandler(e)
 288  {
 289      var e = e || window.event;
 290      var o = (e.srcElement || e.target);
 291      var next;
 292      var old;
 293      var id;
 294  
 295      if (e.altKey || e.ctrlKey) {
 296          switch (e.keyCode) {
 297          // Up
 298          case 38:
 299              if (o.id.substr(0, 5) == 'check' && o.tagName == 'INPUT') {
 300                  old = o.id.substr(5, o.id.length - 5);
 301                  id = getMessage(old, -1);
 302                  next = document.getElementById('check' + id);
 303              } else if (o.id.substr(0, 7) == 'subject' && o.tagName == 'A') {
 304                  if (e.altKey) {
 305                      return;
 306                  }
 307                  old = o.id.substr(7, o.id.length - 7);
 308                  id = getMessage(old, -1);
 309                  next = document.getElementById('subject' + id);
 310              } else {
 311                  id = messagelist[messagelist.length - 1];
 312                  if (e.altKey) {
 313                      next = document.getElementById('check' + id);
 314                  } else {
 315                      next = document.getElementById('subject' + id);
 316                  }
 317              }
 318              break;
 319          // Down
 320          case 40:
 321              if (o.id.substr(0, 5) == 'check' && o.tagName == 'INPUT') {
 322                  old = o.id.substr(5, o.id.length - 5);
 323                  id = getMessage(old, 1);
 324                  next = document.getElementById('check' + id);
 325              } else if (o.id.substr(0, 7) == 'subject' && o.tagName == 'A') {
 326                  if (e.altKey) {
 327                      return;
 328                  }
 329                  old = o.id.substr(7, o.id.length - 7);
 330                  id = getMessage(old, 1);
 331                  next = document.getElementById('subject' + id);
 332              } else {
 333                  id = messagelist[0];
 334                  if (e.altKey) {
 335                      next = document.getElementById('check' + id);
 336                  } else {
 337                      next = document.getElementById('subject' + id);
 338                  }
 339              }
 340              break;
 341          // Left
 342          case 37:
 343              if (e.altKey) {
 344                  return;
 345              }
 346              if (o.id.substr(0, 5) == 'check' && o.tagName == 'INPUT') {
 347                  old = o.id.substr(5, o.id.length - 5);
 348                  id = getMessage(old, -1);
 349                  next = document.getElementById('subject' + id);
 350              } else if (o.id.substr(0, 7) == 'subject' && o.tagName == 'A') {
 351                  id = o.id.substr(7, o.id.length - 7);
 352                  next = document.getElementById('check' + id);
 353              } else {
 354                  id = messagelist[messagelist.length - 1];
 355                  next = document.getElementById('subject' + id);
 356              }
 357              break;
 358          // Right
 359          case 39:
 360              if (e.altKey) {
 361                  return;
 362              }
 363              if (o.id.substr(0, 5) == 'check' && o.tagName == 'INPUT') {
 364                  id = o.id.substr(5, o.id.length - 5);
 365                  next = document.getElementById('subject' + id);
 366              } else if (o.id.substr(0, 7) == 'subject' && o.tagName == 'A') {
 367                  old = o.id.substr(7, o.id.length - 7);
 368                  id = getMessage(old, 1);
 369                  next = document.getElementById('check' + id);
 370              } else {
 371                  id = messagelist[0];
 372                  next = document.getElementById('check' + id);
 373              }
 374              break;
 375          default:
 376              return;
 377          }
 378      } else if (e.keyCode == 32 && o.id.substr(0, 7) == 'subject' && o.tagName == 'A') {
 379          id = o.id.substr(7, o.id.length - 7);
 380          var checkbox = document.getElementById('check' + id);
 381          checkbox.checked = !checkbox.checked;
 382          selectRow(id);
 383      } else {
 384          return;
 385      }
 386  
 387      if (next) {
 388          next.focus();
 389          var row = document.getElementById('row' + id);
 390          if (e.altKey && next.tagName == 'INPUT') {
 391              next.checked = !next.checked;
 392              selectRow(next.id.replace(/check/, ''));
 393          } else if (old != next && row.className.indexOf('-over') == -1) {
 394              row.className = row.className + '-over';
 395          }
 396          var index = getMessage(id, 0, true);
 397          if (old) {
 398              row = document.getElementById('row' + old);
 399              if (old != next) {
 400                  row.className = row.className.replace(/-over/, '');
 401              }
 402              index = getMessage(old, 0, true);
 403          }
 404      }
 405  
 406      e.returnValue = false;
 407  <?php if ($GLOBALS['browser']->isBrowser('mozilla')): ?>
 408      e.preventDefault();
 409  <?php endif; ?>
 410  }
 411  
 412  document.onkeydown = onKeyDownHandler;
 413  <?php endif; ?>
 414  
 415  //-->
 416  </script>


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics