!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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 * Mark Banner <mark@standard8.demon.co.uk>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 var abResultsPaneObserver = {
onDragStart
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
41 onDragStart: function (aEvent, aXferData, aDragAction)
42 {
43 var selectedRows = GetSelectedRows();
44
45 if (!selectedRows)
46 return;
47
48 var selectedAddresses = GetSelectedAddresses();
49
50 aXferData.data = new TransferData();
51 aXferData.data.addDataForFlavour("moz/abcard", selectedRows);
52 aXferData.data.addDataForFlavour("text/x-moz-address", selectedAddresses);
53 aXferData.data.addDataForFlavour("text/unicode", selectedAddresses);
54
55 var srcDirectory = GetDirectoryFromURI(GetSelectedDirectory());
56 // The default allowable actions are copy, move and link, so we need
57 // to restrict them here.
58 if ((srcDirectory.operations & srcDirectory.opWrite))
59 // Only allow copy & move from read-write directories.
60 aDragAction.action = Components.interfaces.
61 nsIDragService.DRAGDROP_ACTION_COPY |
62 Components.interfaces.
63 nsIDragService.DRAGDROP_ACTION_MOVE;
64 else
65 // Only allow copy from read-only directories.
66 aDragAction.action = Components.interfaces.
67 nsIDragService.DRAGDROP_ACTION_COPY;
68 },
69
onDrop
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
70 onDrop: function (aEvent, aXferData, aDragSession)
71 {
72 },
73
onDragExit
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
74 onDragExit: function (aEvent, aDragSession)
75 {
76 },
77
onDragOver
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
78 onDragOver: function (aEvent, aFlavour, aDragSession)
79 {
80 },
81
getSupportedFlavours
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
82 getSupportedFlavours: function ()
83 {
84 return null;
85 }
86 };
87
88
89 var dragService = Components.classes["@mozilla.org/widget/dragservice;1"].getService().QueryInterface(Components.interfaces.nsIDragService);
90
91 var abDirTreeObserver = {
92 /**
93 * canDrop - determine if the tree will accept the dropping of a item
94 * onto it.
95 *
96 * Note 1: We don't allow duplicate mailing list names, therefore copy
97 * is not allowed for mailing lists.
98 * Note 2: Mailing lists currently really need a card in the parent
99 * address book, therefore only moving to an address book is allowed.
100 *
101 * The possibilities:
102 *
103 * anything -> same place = Not allowed
104 * anything -> read only directory = Not allowed
105 * mailing list -> mailing list = Not allowed
106 * (we currently do not support recursive lists)
107 * address book card -> different address book = MOVE or COPY
108 * address book card -> mailing list = COPY only
109 * (cards currently have to exist outside list for list to work correctly)
110 * mailing list -> different address book = MOVE only
111 * (lists currently need to have unique names)
112 * card in mailing list -> parent mailing list = Not allowed
113 * card in mailing list -> other mailing list = MOVE or COPY
114 * card in mailing list -> other address book = MOVE or COPY
115 * read only directory item -> anywhere = COPY only
116 */
canDrop
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
117 canDrop: function(index, orientation)
118 {
119 if (orientation != Components.interfaces.nsITreeView.DROP_ON)
120 return false;
121
122 var targetResource = dirTree.builderView.getResourceAtIndex(index);
123 var targetURI = targetResource.Value;
124
125 var srcURI = GetSelectedDirectory();
126
127 // The same place case
128 if (targetURI == srcURI)
129 return false;
130
131 // determine if we dragging from a mailing list on a directory x to the parent (directory x).
132 // if so, don't allow the drop
133 if (srcURI.substring(0, targetURI.length) == targetURI)
134 return false
135
136 // check if we can write to the target directory
137 // e.g. LDAP is readonly currently
138 var targetDirectory = GetDirectoryFromURI(targetURI);
139
140 if (!(targetDirectory.operations & targetDirectory.opWrite))
141 return false;
142
143 var dragSession = dragService.getCurrentSession();
144 if (!dragSession)
145 return false;
146
147 // XXX Due to bug 373125/bug 349044 we can't specify a default action,
148 // so we default to move and this means that the user would have to press
149 // ctrl to copy which most users don't realise.
150 //
151 // If target directory is a mailing list, then only allow copies.
152 // if (targetDirectory.isMailList &&
153 // dragSession.dragAction != Components.interfaces.
154 // nsIDragService.DRAGDROP_ACTION_COPY)
155 //return false;
156
157 var srcDirectory = GetDirectoryFromURI(srcURI);
158
159 // Only allow copy from read-only directories.
160 if (!(srcDirectory.operations & srcDirectory.opWrite) &&
161 dragSession.dragAction != Components.interfaces.
162 nsIDragService.DRAGDROP_ACTION_COPY)
163 return false;
164
165 // Go through the cards checking to see if one of them is a mailing list
166 // (if we are attempting a copy) - we can't copy mailing lists as
167 // that would give us duplicate names which isn't allowed at the
168 // moment.
169 var draggingMailList = false;
170 var abView = GetAbView();
171 var trans = Components.classes["@mozilla.org/widget/transferable;1"].
172 createInstance(Components.interfaces.nsITransferable);
173
174 trans.addDataFlavor("moz/abcard");
175
176 for (var i = 0; i < dragSession.numDropItems && !draggingMailList; i++)
177 {
178 dragSession.getData(trans, i);
179
180 var dataObj = new Object();
181 var flavor = new Object();
182 var len = new Object();
183 try {
184 trans.getAnyTransferData(flavor, dataObj, len);
185 }
186 catch (ex) {
187 dragSession.canDrop = false;
188 return false;
189 }
190
191 dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
192
193 var transData = dataObj.data.split("\n");
194 var rows = transData[0].split(",");
195
196 for (var j = 0; j < rows.length; j++)
197 {
198 if (abView.getCardFromRow(rows[j]).isMailList)
199 {
200 draggingMailList = true;
201 break;
202 }
203 }
204 }
205
206 // The rest of the cases - allow cards for copy or move, but only allow
207 // move of mailing lists if we're not going into another mailing list.
208 if (draggingMailList &&
209 (targetDirectory.isMailList ||
210 dragSession.dragAction == Components.interfaces.
211 nsIDragService.DRAGDROP_ACTION_COPY))
212 {
213 return false;
214 }
215
216 dragSession.canDrop = true;
217 return true;
218 },
219
220 /**
221 * onDrop - we don't need to check again for correctness as the
222 * tree view calls canDrop just before calling onDrop.
223 *
224 */
onDrop
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
225 onDrop: function(row, orientation)
226 {
227 var dragSession = dragService.getCurrentSession();
228 if (!dragSession)
229 return;
230
231 var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
232 trans.addDataFlavor("moz/abcard");
233
234 var targetResource = dirTree.builderView.getResourceAtIndex(row);
235
236 var targetURI = targetResource.Value;
237 var srcURI = GetSelectedDirectory();
238
239 for (var i = 0; i < dragSession.numDropItems; i++) {
240 dragSession.getData(trans, i);
241 var dataObj = new Object();
242 var flavor = new Object();
243 var len = new Object();
244 try {
245 trans.getAnyTransferData(flavor, dataObj, len);
246 dataObj =
247 dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
248 }
249 catch (ex) {
250 continue;
251 }
252
253 var transData = dataObj.data.split("\n");
254 var rows = transData[0].split(",");
255 var numrows = rows.length;
256
257 var result;
258 // needToCopyCard is used for whether or not we should be creating
259 // copies of the cards in a mailing list in a different address book
260 // - it's not for if we are moving or not.
261 var needToCopyCard = true;
262 if (srcURI.length > targetURI.length) {
263 result = srcURI.split(targetURI);
264 if (result[0] != srcURI) {
265 // src directory is a mailing list on target directory, no need to copy card
266 needToCopyCard = false;
267 }
268 }
269 else {
270 result = targetURI.split(srcURI);
271 if (result[0] != targetURI) {
272 // target directory is a mailing list on src directory, no need to copy card
273 needToCopyCard = false;
274 }
275 }
276
277 // if we still think we have to copy the card,
278 // check if srcURI and targetURI are mailing lists on same directory
279 // if so, we don't have to copy the card
280 if (needToCopyCard) {
281 var targetParentURI = GetParentDirectoryFromMailingListURI(targetURI);
282 if (targetParentURI && (targetParentURI == GetParentDirectoryFromMailingListURI(srcURI)))
283 needToCopyCard = false;
284 }
285
286 var abView = GetAbView();
287 var directory = GetDirectoryFromURI(targetURI);
288
289 // Only move if we are not transferring to a mail list
290 var actionIsMoving = (dragSession.dragAction & dragSession.DRAGDROP_ACTION_MOVE) && !directory.isMailList;
291
292 for (j = 0; j < numrows; j++) {
293 var card = abView.getCardFromRow(rows[j]);
294 if (card.isMailList) {
295 // This check ensures we haven't slipped through by mistake
296 if (needToCopyCard && actionIsMoving) {
297 directory.addMailList(GetDirectoryFromURI(card.mailListURI));
298 }
299 } else {
300 directory.dropCard(card, needToCopyCard);
301 }
302 }
303
304 var cardsTransferredText;
305
306 // If we are moving, but not moving to a directory, then delete the
307 // selected cards and display the appropriate text
308 if (actionIsMoving) {
309 // If we have moved the cards, then delete them as well.
310 abView.deleteSelectedCards();
311 cardsTransferredText = (numrows == 1 ? gAddressBookBundle.getString("cardMoved")
312 : gAddressBookBundle.getFormattedString("cardsMoved", [numrows]));
313 } else {
314 cardsTransferredText = (numrows == 1 ? gAddressBookBundle.getString("cardCopied")
315 : gAddressBookBundle.getFormattedString("cardsCopied", [numrows]));
316 }
317
318 document.getElementById("statusText").label = cardsTransferredText;
319 }
320 },
321
onToggleOpenState
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
322 onToggleOpenState: function()
323 {
324 },
325
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
326 onCycleHeader: function(colID, elt)
327 {
328 },
329
onCycleCell
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
330 onCycleCell: function(row, colID)
331 {
332 },
333
onSelectionChanged
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
334 onSelectionChanged: function()
335 {
336 },
337
onPerformAction
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
338 onPerformAction: function(action)
339 {
340 },
341
onPerformActionOnRow
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
342 onPerformActionOnRow: function(action, row)
343 {
344 },
345
onPerformActionOnCell
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
346 onPerformActionOnCell: function(action, row, colID)
347 {
348 }
349 }
350
DragAddressOverTargetControl
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
351 function DragAddressOverTargetControl(event)
352 {
353 var dragSession = gDragService.getCurrentSession();
354
355 if (!dragSession.isDataFlavorSupported("text/x-moz-address"))
356 return;
357
358 var trans = Components.classes["@mozilla.org/widget/transferable;1"]
359 .createInstance(Components.interfaces.nsITransferable);
360 trans.addDataFlavor("text/x-moz-address");
361
362 var canDrop = true;
363
364 for ( var i = 0; i < dragSession.numDropItems; ++i )
365 {
366 dragSession.getData ( trans, i );
367 var dataObj = new Object();
368 var bestFlavor = new Object();
369 var len = new Object();
370 try
371 {
372 trans.getAnyTransferData ( bestFlavor, dataObj, len );
373 }
374 catch (ex)
375 {
376 canDrop = false;
377 break;
378 }
379 }
380 dragSession.canDrop = canDrop;
381 }
382
DropAddressOverTargetControl
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
383 function DropAddressOverTargetControl(event)
384 {
385 var dragSession = gDragService.getCurrentSession();
386
387 var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
388 trans.addDataFlavor("text/x-moz-address");
389
390 for ( var i = 0; i < dragSession.numDropItems; ++i )
391 {
392 dragSession.getData ( trans, i );
393 var dataObj = new Object();
394 var bestFlavor = new Object();
395 var len = new Object();
396
397 // Ensure we catch any empty data that may have slipped through
398 try
399 {
400 trans.getAnyTransferData ( bestFlavor, dataObj, len);
401 }
402 catch (ex)
403 {
404 continue;
405 }
406
407 if ( dataObj )
408 dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsString);
409 if ( !dataObj )
410 continue;
411
412 // pull the address out of the data object
413 var address = dataObj.data.substring(0, len.value);
414 if (!address)
415 continue;
416
417 DropRecipient(address);
418 }
419 }