1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2011, 2012, 2013, 2014, 2015, 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) 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 /** 24 * ZmMailListGroup is the base class for creating a mail group to be displayed by the ListView. A mail group consists of sections and a section header. 25 * Each section is an array of HTML strings that divide the group. For example, ZmMailListSizeGroup has sections to divide 26 * the group based on size: Enormous, Huge, Very Large, etc. Each section consists of an HTML representation of the 27 * message and a section header. 28 */ 29 ZmMailListGroup = function(){ 30 this._showEmptySectionHeader = false; 31 this._sectionHeaders = []; 32 this._init(); 33 }; 34 35 36 /** 37 * Overload method; return HTML string for all sections. 38 * @param {boolean} sortAsc true/false if sort ascending 39 * @return {String} HTML for all sections including section header 40 */ 41 ZmMailListGroup.prototype.getAllSections = 42 function(sortAsc) { 43 44 }; 45 46 /** 47 * Adds item to section; Groups should overload 48 * @param {ZmMailMsg} msg mail message 49 * @param {String} item HTML to add to section 50 * @return {String} section returns section if successfully added, else returns null 51 */ 52 ZmMailListGroup.prototype.addMsgToSection = 53 function(msg, item) { 54 55 }; 56 57 /** 58 * Determines if message is in section/subgroup; Groups should overload 59 * @param {String} section ID of section 60 * @param {ZmMailMsg} msg 61 * @return {boolean} true/false 62 */ 63 ZmMailListGroup.prototype.isMsgInSection = 64 function(section, msg) { 65 66 }; 67 68 /** 69 * Clears all sections 70 */ 71 ZmMailListGroup.prototype.clearSections = 72 function() { 73 this._init(); 74 }; 75 76 /** 77 * return the section size 78 * @param {String} section id 79 */ 80 ZmMailListGroup.prototype.getSectionSize = 81 function(section) { 82 if (this._section[section]){ 83 return this._section[section].length; 84 } 85 return -1; 86 }; 87 88 /** 89 * Returns section title 90 * @param {String} section 91 */ 92 ZmMailListGroup.prototype.getSectionTitle = 93 function(section) { 94 return this._getSectionHeaderTitle(section); 95 }; 96 97 ZmMailListGroup.prototype.getSectionHeader = 98 function(headerTitle) { 99 var header = new ZmMailListSectionHeader(this, {headerTitle : headerTitle}); 100 this._sectionHeaders.push(header); 101 return header.getHeaderHtml(); 102 }; 103 104 ZmMailListGroup.prototype.resetSectionHeaders = 105 function() { 106 for (var i = 0; i < this._sectionHeaders.length; i++) { 107 var el = this._sectionHeaders[i].getHtmlElement(); 108 el.parentNode.removeChild(el); 109 } 110 111 this._sectionHeaders = []; 112 }; 113 114 /** 115 * Returns the sort by for the Group. For example size would be ZmSearch.SIZE_ASC or ZmSearch.SIZE_DESC 116 * Groups should overload 117 * @param {boolean} sortAsc 118 * @return {String} sortBy 119 */ 120 ZmMailListGroup.prototype.getSortBy = 121 function(sortAsc) { 122 return null; 123 }; 124 125 /** 126 * Returns the section headers for the group 127 * @return {array} array of section headers 128 */ 129 ZmMailListGroup.prototype.getAllSectionHeaders = 130 function() { 131 return this._sectionHeaders; 132 }; 133 134 //PROTECTED METHODs 135 136 /** 137 * initialize sections 138 */ 139 ZmMailListGroup.prototype._init = 140 function() { 141 this._section = {}; 142 }; 143 144 /** 145 * Groups should overload 146 * @param {String} section 147 * @return {String} section title 148 */ 149 ZmMailListGroup.prototype._getSectionHeaderTitle = 150 function(section) { 151 return ""; 152 }; 153 154 //STATIC methods 155 156 /** 157 * Return Group object based on groupId 158 * @param {String} groupId 159 * @return {ZmMailListGroup} group object 160 */ 161 ZmMailListGroup.getGroup = 162 function(groupId) { 163 164 switch (groupId){ 165 case ZmId.GROUPBY_DATE: 166 return new ZmMailListDateGroup(); 167 168 case ZmId.GROUPBY_SIZE: 169 return new ZmMailListSizeGroup(); 170 171 case ZmId.GROUPBY_PRIORITY: 172 return new ZmMailListPriorityGroup(); 173 174 case ZmId.GROUPBY_FROM: 175 return new ZmMailListFromGroup(); 176 177 default: 178 return null; 179 } 180 181 }; 182 183 /** 184 * Return the header field based on groupId 185 * @param {String} groupId 186 * @param {boolean} isMultiColumn 187 */ 188 ZmMailListGroup.getHeaderField = 189 function(groupId, isMultiColumn) { 190 191 if (isMultiColumn == false) { 192 return ZmId.FLD_SORTED_BY; 193 } 194 195 switch (groupId) { 196 case ZmId.GROUPBY_SIZE: 197 return ZmId.FLD_SIZE; 198 199 case ZmId.GROUPBY_FROM: 200 return ZmId.FLD_FROM; 201 202 case ZmId.GROUPBY_DATE: 203 return ZmId.FLD_DATE; 204 205 default: 206 return null; 207 } 208 209 }; 210 211 /** 212 * Return the group Id based on the sort field 213 * @param {String} sortField 214 */ 215 ZmMailListGroup.getGroupIdFromSortField = 216 function(sortField, type) { 217 switch (sortField) { 218 case ZmId.FLD_FROM: 219 if (type === ZmItem.CONV) { 220 return ZmId.GROUPBY_NONE; 221 } 222 return ZmId.GROUPBY_FROM; 223 224 case ZmId.FLD_SIZE: 225 return ZmId.GROUPBY_SIZE; 226 227 case ZmId.FLD_DATE: 228 return ZmId.GROUPBY_DATE; 229 230 default: 231 return ZmId.GROUPBY_NONE; 232 } 233 }; 234