1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 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) 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates a list view for time or location suggestions 26 * @constructor 27 * @class 28 * 29 * @author Vince Bellows 30 * 31 * @param parent [ZmScheduleAssistantView] the smart scheduler view 32 * @param controller [ZmApptComposeController] the appt compose controller 33 * @param apptEditView [ZmApptEditView] the appt edit view 34 */ 35 ZmSuggestionsView = function(parent, controller, apptEditView, id, showHeaders, className) { 36 if (arguments.length == 0) { return; } 37 38 var params = {parent: parent, posStyle: DwtControl.RELATIVE_STYLE, view: id}; 39 if (className) { 40 params.className = className; 41 } 42 ZmListView.call(this, params); 43 44 this._controller = controller; 45 this._editView = apptEditView; 46 47 this._rendered = false; 48 this._kbMgr = appCtxt.getKeyboardMgr(); 49 this._normalClass = DwtListView.ROW_CLASS; 50 this._selectedClass = [DwtListView.ROW_CLASS, DwtCssStyle.SELECTED].join("-"); 51 this.setMultiSelect(false); 52 53 this._showHeaders = showHeaders; 54 }; 55 56 ZmSuggestionsView.prototype = new ZmListView; 57 ZmSuggestionsView.prototype.constructor = ZmSuggestionsView; 58 59 ZmSuggestionsView.prototype.toString = 60 function() { 61 return "ZmSuggestionsView"; 62 } 63 64 ZmSuggestionsView.prototype.set = 65 function(params) { 66 this._items = params.items; 67 this._itemIndex = params.itemIndex; 68 ZmListView.prototype.set.call(this, params.list); 69 }; 70 71 ZmSuggestionsView.prototype._setNoResultsHtml = 72 function() {}; 73 74 ZmSuggestionsView.prototype.setShowSuggestionsHTML = 75 function(date) {}; 76 77 ZmSuggestionsView.prototype.setLoadingHtml = 78 function() { 79 this.removeAll(); 80 var div = document.createElement("div"); 81 div.innerHTML = AjxTemplate.expand("calendar.Appointment#TimeSuggestion-Loading"); 82 this._addRow(div); 83 }; 84 85 ZmSuggestionsView.prototype._getHeaderKey = 86 function(item) { 87 return ''; 88 } 89 90 ZmSuggestionsView.prototype._renderList = 91 function(list, noResultsOk, doAdd, prefixHtml) { 92 if (list instanceof AjxVector && list.size()) { 93 var now = new Date(); 94 var size = list.size(); 95 var htmlArr = [], hdrKey, hdrListed = {}; 96 if (prefixHtml) { 97 htmlArr.push(prefixHtml); 98 } 99 var nonZeroAvailableFound = false; 100 for (var i = 0; i < size; i++) { 101 var item = list.get(i); 102 nonZeroAvailableFound = nonZeroAvailableFound || item.availableUsers > 0; 103 //Note that this works since it's sorted from higher available down, so first we'll get the non zero. 104 if (item.availableUsers === 0 && nonZeroAvailableFound) { 105 break; //ignore 0 available if we got items with more than 0 available. 106 } 107 108 if (this._showHeaders) { 109 hdrKey = this._getHeaderKey(item); 110 if(!hdrListed[hdrKey]) { 111 var sectionHeaderHtml = this._renderListSectionHdr(hdrKey, item); 112 if(sectionHeaderHtml) htmlArr.push(sectionHeaderHtml); 113 hdrListed[hdrKey] = true; 114 } 115 } 116 117 var div = this._createItemHtml(item, {now:now}, !doAdd, i); 118 if (div) { 119 if (div instanceof Array) { 120 for (var j = 0; j < div.length; j++){ 121 this._addRow(div[j]); 122 } 123 } else if (div.tagName || doAdd) { 124 this._addRow(div); 125 } else { 126 htmlArr.push(div); 127 } 128 } 129 } 130 if (htmlArr.length) { 131 this._parentEl.innerHTML = htmlArr.join(""); 132 } 133 } else if (!noResultsOk) { 134 this._setNoResultsHtml(); 135 } 136 }; 137 138 139 140