home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / messenger.jar / content / messenger / addressbook / abDragDrop.js < prev    next >
Text File  |  2005-07-29  |  7KB  |  209 lines

  1. /* -*- Mode: Java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Seth Spitzer <sspitzer@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the NPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the NPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var abResultsPaneObserver = {
  40.   onDragStart: function (aEvent, aXferData, aDragAction)
  41. {
  42.       aXferData.data = new TransferData();
  43.       var selectedRows = GetSelectedRows();
  44.       var selectedAddresses = GetSelectedAddresses();
  45.  
  46.       aXferData.data.addDataForFlavour("moz/abcard", selectedRows);
  47.       aXferData.data.addDataForFlavour("text/x-moz-address", selectedAddresses);
  48.     },
  49.  
  50.   onDrop: function (aEvent, aXferData, aDragSession)
  51.     {
  52.     },
  53.  
  54.   onDragExit: function (aEvent, aDragSession)
  55.     {
  56.     },
  57.  
  58.   onDragOver: function (aEvent, aFlavour, aDragSession)
  59.     {
  60.     },
  61.  
  62.   getSupportedFlavours: function ()
  63.     {
  64.      return null;
  65.   }
  66. };
  67.  
  68.  
  69. var dragService = Components.classes["@mozilla.org/widget/dragservice;1"].getService().QueryInterface(Components.interfaces.nsIDragService);
  70.  
  71. var abDirTreeObserver = {
  72.     canDropOn: function(index)
  73.     {
  74.       var targetResource = dirTree.builderView.getResourceAtIndex(index);
  75.       var targetURI = targetResource.Value;
  76.  
  77.       var srcURI = GetSelectedDirectory();
  78.  
  79.       if (targetURI == srcURI)
  80.         return false;
  81.  
  82.       // determine if we dragging from a mailing list on a directory x to the parent (directory x).
  83.       // if so, don't allow the drop
  84.       var result = srcURI.split(targetURI);
  85.       if (result != srcURI) 
  86.         return false;
  87.  
  88.       // check if we can write to the target directory 
  89.       // LDAP is readonly
  90.       var targetDirectory = GetDirectoryFromURI(targetURI);
  91.       return (targetDirectory.isMailList ||
  92.               (targetDirectory.operations & targetDirectory.opWrite));
  93.     },
  94.  
  95.     canDropBeforeAfter: function(index, before)
  96.     {
  97.     },
  98.  
  99.     onDrop: function(row, orientation)
  100.     {
  101.       var dragSession = dragService.getCurrentSession();
  102.       if (!dragSession)
  103.         return;
  104.       
  105.       var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
  106.       trans.addDataFlavor("moz/abcard");
  107.  
  108.       for (var i = 0; i < dragSession.numDropItems; i++) {
  109.         dragSession.getData(trans, i);
  110.         var dataObj = new Object();
  111.         var flavor = new Object();
  112.         var len = new Object();
  113.         trans.getAnyTransferData(flavor, dataObj, len);
  114.         if (dataObj)
  115.           dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
  116.         else
  117.           continue;
  118.         
  119.         var transData = dataObj.data.split("\n");
  120.         var rows = transData[0].split(",");
  121.       var numrows = rows.length;
  122.  
  123.         var targetResource = dirTree.builderView.getResourceAtIndex(row);
  124.         var targetURI = targetResource.Value;
  125.  
  126.         var srcURI = GetSelectedDirectory();
  127.  
  128.         if (srcURI == targetURI)
  129.           return; // should not be here
  130.  
  131.       var result;
  132.       var needToCopyCard = true;
  133.       if (srcURI.length > targetURI.length) {
  134.         result = srcURI.split(targetURI);
  135.         if (result[0] != srcURI) {
  136.           // src directory is a mailing list on target directory, no need to copy card
  137.           needToCopyCard = false;
  138.         }
  139.       }
  140.       else {
  141.         result = targetURI.split(srcURI);
  142.         if (result[0] != targetURI) {
  143.           // target directory is a mailing list on src directory, no need to copy card
  144.           needToCopyCard = false;
  145.         }
  146.       }
  147.  
  148.       // if we still think we have to copy the card,
  149.       // check if srcURI and targetURI are mailing lists on same directory
  150.       // if so, we don't have to copy the card
  151.       if (needToCopyCard) {
  152.         var targetParentURI = GetParentDirectoryFromMailingListURI(targetURI);
  153.         if (targetParentURI && (targetParentURI == GetParentDirectoryFromMailingListURI(srcURI)))
  154.           needToCopyCard = false;
  155.       }
  156.  
  157.         var abView = GetAbView();
  158.         var directory = GetDirectoryFromURI(targetURI);
  159.  
  160.       for (var j = 0; j < numrows; j++) {
  161.         var card = abView.getCardFromRow(rows[j]);
  162.         directory.dropCard(card, needToCopyCard);
  163.       }
  164.  
  165.         var cardsCopiedText = numrows == 1 ? gAddressBookBundle.getString("cardCopied")
  166.                                            : gAddressBookBundle.getFormattedString("cardsCopied", [numrows]);
  167.  
  168.         var statusText = document.getElementById("statusText");
  169.         statusText.setAttribute("label", cardsCopiedText);        
  170.       }
  171.     },
  172.  
  173.     onToggleOpenState: function()
  174.     {
  175.     },
  176.  
  177.     onCycleHeader: function(colID, elt)
  178.     {
  179.     },
  180.       
  181.     onCycleCell: function(row, colID)
  182.     {
  183.     },
  184.       
  185.     onSelectionChanged: function()
  186.     {
  187.     },
  188.  
  189.     isEditable: function(row, colID)
  190.     {        
  191.     },
  192.  
  193.     onSetCellText: function(row, colID, value)
  194.     {
  195.     },
  196.  
  197.     onPerformAction: function(action)
  198.     {
  199.     },
  200.  
  201.     onPerformActionOnRow: function(action, row)
  202.     {
  203.     },
  204.  
  205.     onPerformActionOnCell: function(action, row, colID)
  206.   {
  207.   }
  208. }
  209.