1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc.
  5  *
  6  * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at: https://www.zimbra.com/license
  9  * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15
 10  * have been added to cover use of software over a computer network and provide for limited attribution
 11  * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
 12  *
 13  * Software distributed under the License is distributed on an "AS IS" basis,
 14  * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing rights and limitations under the License.
 16  * The Original Code is Zimbra Open Source Web Client.
 17  * The Initial Developer of the Original Code is Zimbra, Inc.  All rights to the Original Code were
 18  * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015.
 19  *
 20  * All portions of the code are Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * @overview
 26  * This file contains the address book class.
 27  */
 28 
 29 /**
 30  * Creates an address book.
 31  * @constructor
 32  * @class
 33  * This class represents an address book.
 34  * 
 35  * @author Parag Shah
 36  *
 37  * @param	{Hash}	params		a hash of parameters
 38  * @param {int}	params.id			a numeric ID
 39  * @param {String}	params.name		[string]	the name
 40  * @param {ZmOrganizer}	params.parent		the parent organizer
 41  * @param {ZmTree}	params.tree		a tree model that contains this organizer
 42  * @param {int}	params.color		the color of this address book
 43  * @param {String}	params.owner	the owner of the address book (if shared)
 44  * @param {String}	params.zid 		the the share ID of a shared address book
 45  * @param {String}	params.rid		the the remote folder id of a shared address book
 46  * @param {String}	params.restUrl	the REST URL of this organizer
 47  * 
 48  * @extends		ZmFolder
 49  */
 50 ZmAddrBook = function(params) {
 51 	params.type = ZmOrganizer.ADDRBOOK;
 52 	ZmFolder.call(this, params);
 53 };
 54 
 55 ZmAddrBook.prototype = new ZmFolder;
 56 ZmAddrBook.prototype.constructor = ZmAddrBook;
 57 
 58 ZmAddrBook.prototype.isZmAddrBook = true;
 59 ZmAddrBook.prototype.toString = function() { return "ZmAddrBook"; };
 60 
 61 
 62 // Consts
 63 
 64 ZmAddrBook.ID_ADDRESSBOOK = ZmOrganizer.ID_ADDRBOOK; 							// XXX: may not be necessary
 65 
 66 // Public methods
 67 
 68 ZmAddrBook.prototype.getIcon =
 69 function() {
 70 	if (this.nId == ZmFolder.ID_ROOT)			{ return null; }
 71 	if (this.nId == ZmFolder.ID_TRASH)			{ return "Trash"; }
 72 	if (this.link || this.isRemote())			{ return "SharedContactsFolder"; }
 73 	if (this.nId == ZmFolder.ID_AUTO_ADDED)		{ return "EmailedContacts"; }
 74 	return "ContactsFolder";
 75 };
 76 
 77 /**
 78  * Checks if the address book supports public access.
 79  * 
 80  * @return	{Boolean}		always returns <code>true</code>
 81  */
 82 ZmAddrBook.prototype.supportsPublicAccess =
 83 function() {
 84 	// AddrBook's can be accessed outside of ZCS (i.e. REST)
 85 	return true;
 86 };
 87 
 88 /**
 89  * @private
 90  */
 91 ZmAddrBook.prototype.mayContain = function(what) {
 92 
 93 	if (!what) {
 94 		return true;
 95 	}
 96 
 97 	// Distribution Lists is a system-generated folder
 98 	if (this.id == ZmOrganizer.ID_DLS) {
 99 		return false;
100 	}
101 
102 	if (what.isZmAddrBook) {
103 		return ZmFolder.prototype.mayContain.apply(this, arguments);
104 	}
105 
106 	// An item or an array of items is being moved
107 	var items = AjxUtil.toArray(what);
108 	for (var i = 0; i < items.length; i++) {
109 		var item = items[i];
110 		if (item.type !== ZmItem.CONTACT && item.type !== ZmItem.GROUP) {
111 			// only contacts are valid for addr books.
112 			return false;
113 		}
114 	}
115 
116 	return ZmFolder.prototype.mayContain.apply(this, arguments);
117 };
118