home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / mail.xpi / bin / chrome / messenger.jar / content / messenger / threadPane.js < prev    next >
Text File  |  2001-08-22  |  8KB  |  309 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  */
  20.  
  21. var gLastMessageUriToLoad = null;
  22. var gThreadPaneCommandUpdater = null;
  23.  
  24. function ThreadPaneOnClick(event)
  25. {
  26.     // we only care about button 0 (left click) events
  27.     if (event.button != 0) return;
  28.  
  29.     // we are already handling marking as read and flagging
  30.     // in nsMsgDBView.cpp
  31.     // so all we need to worry about here is double clicks
  32.     // and column header.
  33.     //
  34.     // we get in here for clicks on the "outlinercol" (headers)
  35.     // and the "scrollbarbutton" (scrollbar buttons)
  36.     // we don't want those events to cause a "double click"
  37.  
  38.     var t = event.originalTarget;
  39.  
  40.     if (t.localName == "outlinercol") {
  41.        HandleColumnClick(t.id);
  42.     }
  43.     else if (event.detail == 2 && t.localName == "outlinerbody") {
  44.        var row = new Object;
  45.        var colID = new Object;
  46.        var childElt = new Object;
  47.  
  48.        var outliner = GetThreadOutliner();
  49.        // figure out what cell the click was in
  50.        outliner.boxObject.QueryInterface(Components.interfaces.nsIOutlinerBoxObject).getCellAt(event.clientX, event.clientY, row, colID, childElt);
  51.  
  52.        // if the cell is in a "cycler" column
  53.        // or if the user double clicked on the twisty,
  54.        // don't open the message in a new window
  55.        var col = document.getElementById(colID.value);
  56.        if (col && col.getAttribute("cycler") != "true" && (childElt.value != "twisty")) {
  57.          ThreadPaneDoubleClick();
  58.          // double clicking should not toggle the open / close state of the 
  59.          // thread.  this will happen if we don't prevent the event from
  60.          // bubbling to the default handler in outliner.xml
  61.      event.preventBubble();
  62.        }
  63.     }
  64. }
  65.  
  66. function nsMsgDBViewCommandUpdater()
  67. {}
  68.  
  69. nsMsgDBViewCommandUpdater.prototype = 
  70. {
  71.   updateCommandStatus : function()
  72.     {
  73.       // the back end is smart and is only telling us to update command status
  74.       // when the # of items in the selection has actually changed.
  75.           document.commandDispatcher.updateCommands('mail-toolbar');
  76.     },
  77.  
  78.   displayMessageChanged : function(aFolder, aSubject)
  79.   {
  80.     setTitleFromFolder(aFolder, aSubject);
  81.     gHaveLoadedMessage = true;
  82.   },
  83.  
  84.   QueryInterface : function(iid)
  85.    {
  86.      if(iid.equals(Components.interfaces.nsIMsgDBViewCommandUpdater))
  87.         return this;
  88.       
  89.      throw Components.results.NS_NOINTERFACE;
  90.      return null;
  91.     }
  92. }
  93.  
  94. function HandleColumnClick(columnID)
  95. {
  96.   var sortType = ConvertColumnIDToSortType(columnID);
  97.  
  98.   // if sortType is 0, this is an unsupported sort type
  99.   // return, since we can't sort by that column.
  100.   if (sortType == 0) {
  101.     return;
  102.   }
  103.  
  104.   var dbview = GetDBView();
  105.   if (dbview.sortType == sortType) {
  106.     MsgReverseSortThreadPane();
  107.   }
  108.   else {
  109.     MsgSortThreadPane(sortType);
  110.   }
  111. }
  112.  
  113. function MsgComposeDraftMessage()
  114. {
  115.     var loadedFolder = GetLoadedMsgFolder();
  116.     var messageArray = GetSelectedMessages();
  117.  
  118.     ComposeMessage(msgComposeType.Draft, msgComposeFormat.Default, loadedFolder, messageArray);
  119. }
  120.  
  121. function ThreadPaneDoubleClick()
  122. {
  123.   if (IsSpecialFolderSelected(MSG_FOLDER_FLAG_DRAFTS)) {
  124.     MsgComposeDraftMessage();
  125.   }
  126.   else if(IsSpecialFolderSelected(MSG_FOLDER_FLAG_TEMPLATES)) {
  127.     var loadedFolder = GetLoadedMsgFolder();
  128.     var messageArray = GetSelectedMessages();
  129.     ComposeMessage(msgComposeType.Template, msgComposeFormat.Default, loadedFolder, messageArray);
  130.   }
  131.   else {
  132.     MsgOpenSelectedMessages();
  133.   }
  134. }
  135.  
  136. function ThreadPaneKeyPress(event)
  137. {
  138.     if (event.keyCode == 13)
  139.       ThreadPaneDoubleClick();
  140. }
  141.  
  142. function MsgSortByDate()
  143. {
  144.     MsgSortThreadPane(nsMsgViewSortType.byDate);
  145. }
  146.  
  147. function MsgSortBySenderOrRecipient()
  148. {
  149.     if (IsSpecialFolderSelected(MSG_FOLDER_FLAG_SENTMAIL | MSG_FOLDER_FLAG_DRAFTS | MSG_FOLDER_FLAG_QUEUE)) {
  150.       MsgSortThreadPane(nsMsgViewSortType.byRecipient);
  151.     }
  152.     else {
  153.       MsgSortThreadPane(nsMsgViewSortType.byAuthor);
  154.     }
  155. }
  156.  
  157. function MsgSortByStatus()
  158. {
  159.     MsgSortThreadPane(nsMsgViewSortType.byStatus);
  160. }
  161.  
  162. function MsgSortBySubject()
  163. {
  164.     MsgSortThreadPane(nsMsgViewSortType.bySubject);
  165. }
  166.  
  167. function MsgSortByLocation()
  168. {
  169.     MsgSortThreadPane(nsMsgViewSortType.byLocation);
  170. }
  171.  
  172.  
  173. function MsgSortByFlagged() 
  174. {
  175.     MsgSortThreadPane(nsMsgViewSortType.byFlagged);
  176. }
  177.  
  178. function MsgSortByPriority()
  179. {
  180.     MsgSortThreadPane(nsMsgViewSortType.byPriority);
  181. }
  182.  
  183. function MsgSortBySize() 
  184. {
  185.     MsgSortThreadPane(nsMsgViewSortType.bySize);
  186. }
  187.  
  188. function MsgSortByUnread()
  189. {
  190.     MsgSortThreadPane(nsMsgViewSortType.byUnread);
  191. }
  192.  
  193. function MsgSortByOrderReceived()
  194. {
  195.     MsgSortThreadPane(nsMsgViewSortType.byId);
  196. }
  197.  
  198. function MsgSortByTotal()
  199. {
  200.     dump("XXX fix MsgSortByTotal\n");
  201.     //MsgSortThreadPane(nsMsgViewSortType.byTotal);
  202. }
  203.  
  204. function MsgSortByThread()
  205. {
  206.     MsgSortThreadPane(nsMsgViewSortType.byThread);
  207. }
  208.  
  209. function MsgSortThreadPane(sortType)
  210. {
  211.     var dbview = GetDBView();
  212.     dbview.sort(sortType, nsMsgViewSortOrder.ascending);
  213.     UpdateSortIndicators(sortType, nsMsgViewSortOrder.ascending);
  214. }
  215.  
  216. function MsgReverseSortThreadPane()
  217. {
  218.   var dbview = GetDBView();
  219.   if (dbview.sortOrder == nsMsgViewSortOrder.ascending) {
  220.     MsgSortDescending();
  221.   }
  222.   else {
  223.     MsgSortAscending();
  224.   }
  225. }
  226.  
  227. function MsgSortAscending()
  228. {
  229.   var dbview = GetDBView();
  230.   dbview.sort(dbview.sortType, nsMsgViewSortOrder.ascending);
  231.   UpdateSortIndicators(dbview.sortType, nsMsgViewSortOrder.ascending);
  232. }
  233.  
  234. function MsgSortDescending()
  235. {
  236.   var dbview = GetDBView();
  237.   dbview.sort(dbview.sortType, nsMsgViewSortOrder.descending);
  238.   UpdateSortIndicators(dbview.sortType, nsMsgViewSortOrder.descending);
  239. }
  240.  
  241. function UpdateSortIndicators(sortType, sortOrder)
  242. {
  243.   var colID = ConvertSortTypeToColumnID(sortType);
  244.   var sortedColumn;
  245.  
  246.   // set the sort indicator on the column we are sorted by
  247.   if (colID) {
  248.     sortedColumn = document.getElementById(colID);
  249.     if (sortedColumn) {
  250.       if (sortOrder == nsMsgViewSortOrder.ascending) {
  251.         sortedColumn.setAttribute("sortDirection","ascending");
  252.       }
  253.       else {
  254.         sortedColumn.setAttribute("sortDirection","descending");
  255.       }
  256.     }
  257.   }
  258.  
  259.   // remove the sort indicator from all the columns
  260.   // except the one we are sorted by
  261.   var currCol = GetThreadOutliner().firstChild;
  262.   while (currCol) {
  263.     while (currCol && currCol.localName != "outlinercol")
  264.       currCol = currCol.nextSibling;
  265.     if (currCol && (currCol != sortedColumn)) {
  266.       currCol.removeAttribute("sortDirection");
  267.     }
  268.     if (currCol) 
  269.       currCol = currCol.nextSibling;
  270.   }
  271. }
  272.  
  273. function IsSpecialFolderSelected(flags)
  274. {
  275.   var selectedFolder = GetThreadPaneFolder();
  276.   return IsSpecialFolder(selectedFolder, flags);
  277. }
  278.  
  279. function GetThreadOutliner()
  280. {
  281.   if (gThreadOutliner) return gThreadOutliner;
  282.     gThreadOutliner = document.getElementById('threadOutliner');
  283.     return gThreadOutliner;
  284. }
  285.  
  286. function GetThreadPaneFolder()
  287. {
  288.   try {
  289.     return gDBView.msgFolder;
  290.   }
  291.   catch (ex) {
  292.     return null;
  293.   }
  294. }
  295.  
  296. function EnsureRowInThreadOutlinerIsVisible(index)
  297. {
  298.   var outliner = GetThreadOutliner();
  299.   outliner.boxObject.QueryInterface(Components.interfaces.nsIOutlinerBoxObject).ensureRowIsVisible(index); 
  300. }
  301.  
  302. function ThreadPaneOnLoad()
  303. {
  304.   var outliner = GetThreadOutliner();
  305.   outliner.addEventListener("click",ThreadPaneOnClick,true);
  306. }
  307.  
  308. addEventListener("load",ThreadPaneOnLoad,true);
  309.