1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2011, 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, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 /** 24 * From Group divides messages into sort by sender. 25 */ 26 ZmMailListFromGroup = function() { 27 this.id = ZmId.GROUPBY_FROM; 28 this.field = ZmItem.F_FROM; 29 ZmMailListGroup.call(this); 30 31 }; 32 33 ZmMailListFromGroup.prototype = new ZmMailListGroup; 34 ZmMailListFromGroup.prototype.constructor = ZmMailListFromGroup; 35 36 /** 37 * returns HTML string for all sections. 38 * @return {String} HTML for all sections including section header 39 */ 40 ZmMailListFromGroup.prototype.getAllSections = 41 function() { 42 var htmlArr = []; 43 var sections = this._sectionList; 44 45 for (var i = 0; i < sections.length; i++) { 46 var section = sections[i]; 47 htmlArr.push(this.getSectionHeader(section)); 48 htmlArr.push(this._section[section].join("")); 49 } 50 51 return htmlArr.join(""); 52 }; 53 54 /** 55 * Adds item to section 56 * @param {ZmMailMsg} msg mail message 57 * @param {String} itemHtml HTML to add to section 58 * @return {String} section returns section if successfully added, else returns null 59 */ 60 ZmMailListFromGroup.prototype.addMsgToSection = 61 function(msg, itemHtml){ 62 var fromParticipant = msg.getAddress(AjxEmailAddress.FROM); 63 if (!fromParticipant) { 64 return null; 65 } 66 var section = fromParticipant.getText(); 67 if (!this._section.hasOwnProperty(section)) { 68 this._section[section] = []; 69 this._sectionList.push(section); 70 } 71 this._section[section].push(itemHtml); 72 return section; 73 }; 74 75 /** 76 * Returns the sort by (ZmSearch.NAME_ASC or ZmSearch.NAME_DESC) 77 * @param {boolean} sortAsc 78 * @return {String} sortBy 79 */ 80 ZmMailListFromGroup.prototype.getSortBy = 81 function(sortAsc) { 82 return sortAsc ? ZmSearch.NAME_ASC : ZmSearch.NAME_DESC; 83 }; 84 85 ZmMailListFromGroup.prototype._init = 86 function() { 87 this._section = {}; 88 this._sectionList = []; 89 }; 90 91 ZmMailListFromGroup.prototype._getSectionHeaderTitle = 92 function(section) { 93 return section; 94 };