1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 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) 2004, 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 * This file contains the tag tree class. 27 */ 28 29 /** 30 * Creates the tag tree 31 * @class 32 * This class represents the tag tree. 33 * 34 * @param {ZmZimbraAccount} account the account 35 * @extends ZmTree 36 */ 37 ZmTagTree = function(account) { 38 ZmTree.call(this, ZmOrganizer.TAG); 39 var id = (account) 40 ? ([account.id, ZmTag.ID_ROOT].join(":")) 41 : ZmTag.ID_ROOT; 42 this.root = new ZmTag({ id:id, tree:this }); 43 }; 44 45 ZmTagTree.prototype = new ZmTree; 46 ZmTagTree.prototype.constructor = ZmTagTree; 47 48 // ordered list of colors 49 ZmTagTree.COLOR_LIST = [ 50 ZmOrganizer.C_BLUE, 51 ZmOrganizer.C_CYAN, 52 ZmOrganizer.C_GREEN, 53 ZmOrganizer.C_PURPLE, 54 ZmOrganizer.C_RED, 55 ZmOrganizer.C_YELLOW, 56 ZmOrganizer.C_PINK, 57 ZmOrganizer.C_GRAY, 58 ZmOrganizer.C_ORANGE 59 ]; 60 61 /** 62 * Returns a string representation of the object. 63 * 64 * @return {String} a string representation of the object 65 */ 66 ZmTagTree.prototype.toString = 67 function() { 68 return "ZmTagTree"; 69 }; 70 71 /** 72 * @private 73 */ 74 ZmTagTree.prototype.loadFromJs = 75 function(tagsObj, type, account) { 76 if (!tagsObj || !tagsObj.tag || !tagsObj.tag.length) { return; } 77 78 for (var i = 0; i < tagsObj.tag.length; i++) { 79 ZmTag.createFromJs(this.root, tagsObj.tag[i], this, null, account); 80 } 81 var children = this.root.children.getArray(); 82 if (children.length) { 83 children.sort(ZmTag.sortCompare); 84 } 85 }; 86 87 /** 88 * Gets the tag by index. 89 * 90 * @param {int} idx the index 91 * @return {ZmTag} the tag 92 */ 93 ZmTagTree.prototype.getByIndex = 94 function(idx) { 95 var list = this.asList(); // tag at index 0 is root 96 if (list && list.length && (idx < list.length)) { 97 return list[idx]; 98 } 99 }; 100 101 /** 102 * Resets the tree. 103 */ 104 ZmTagTree.prototype.reset = 105 function() { 106 this.root = new ZmTag({id: ZmTag.ID_ROOT, tree: this}); 107 }; 108