1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 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) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 */ 27 28 /** 29 * Creates a share reply widget. 30 * @class 31 * This class implements a share reply query box and additional input 32 * controls to allow the user to specify the reply type and quick reply 33 * note, if wanted. This control can be used from within the various 34 * share dialogs to add reply capabilities. 35 * 36 * @param {DwtControl} parent the parent 37 * @param {String} className the class name 38 * @param {Array} options an array of options 39 * @extends DwtComposite 40 */ 41 ZmShareReply = function(params) { 42 43 params = Dwt.getParams(arguments, ZmShareReply.PARAMS); 44 45 params.className = params.className || "ZmShareReply"; 46 params.id = "ZmShareReply"; 47 DwtComposite.call(this, params); 48 this._tabGroup = new DwtTabGroup(this.toString()); 49 this._initControl(params); 50 }; 51 52 ZmShareReply.PARAMS = [ 'parent', 'className', 'options' ]; 53 54 ZmShareReply.prototype = new DwtComposite; 55 ZmShareReply.prototype.constructor = ZmShareReply; 56 //ZmShareReply.prototype.isFocusable = true; 57 58 // Constants 59 /** 60 * Defines the "none" reply type. 61 */ 62 ZmShareReply.NONE = 0; 63 /** 64 * Defines the "standard" reply type. 65 */ 66 ZmShareReply.STANDARD = 1; 67 /** 68 * Defines the "quick" reply type. 69 */ 70 ZmShareReply.QUICK = 2; 71 72 ZmShareReply.DEFAULT_OPTIONS = [ 73 ZmShareReply.NONE, ZmShareReply.STANDARD, ZmShareReply.QUICK 74 ]; 75 76 ZmShareReply.EXTERNAL_USER_OPTIONS = [ 77 ZmShareReply.STANDARD, ZmShareReply.QUICK 78 ]; 79 80 ZmShareReply._LABELS = {}; 81 ZmShareReply._LABELS[ZmShareReply.NONE] = ZmMsg.sendNoMailAboutShare; 82 ZmShareReply._LABELS[ZmShareReply.STANDARD] = ZmMsg.sendStandardMailAboutShare; 83 ZmShareReply._LABELS[ZmShareReply.QUICK] = ZmMsg.sendStandardMailAboutSharePlusNote; 84 85 // Public methods 86 87 /** 88 * Sets the reply type. 89 * 90 * @param {constant} type the type 91 */ 92 ZmShareReply.prototype.setReplyType = 93 function(type) { 94 this._replyType.setSelectedValue(type); 95 Dwt.setVisible(this._replyStandardMailNoteEl, type == ZmShareReply.STANDARD || type == ZmShareReply.QUICK); 96 Dwt.setVisible(this._replyNoteEl, type == ZmShareReply.QUICK); 97 }; 98 99 /** 100 * Gets the reply type. 101 * 102 * @return {constant} the reply type 103 */ 104 ZmShareReply.prototype.getReplyType = 105 function() { 106 return this._replyType.getValue(); 107 }; 108 109 /** 110 * Sets the reply note. 111 * 112 * @param {String} note the note 113 */ 114 ZmShareReply.prototype.setReplyNote = 115 function(note) { 116 this._replyNoteEl.value = note; 117 }; 118 119 /** 120 * Gets the reply note. 121 * 122 * @return {String} the reply note 123 */ 124 ZmShareReply.prototype.getReplyNote = 125 function() { 126 return this._replyNoteEl.value; 127 }; 128 129 /** 130 * Sets the reply options. 131 * 132 * @param {Array} options an array of options 133 */ 134 ZmShareReply.prototype.setReplyOptions = 135 function(options) { 136 if (this._replyOptions == options) return; 137 138 this._replyOptions = options; 139 this._replyType.clearOptions(); 140 141 for (var i = 0; i < options.length; i++) { 142 var value = options[i]; 143 this._replyType.addOption(ZmShareReply._LABELS[value], false, value); 144 } 145 }; 146 147 /** 148 * Gets the reply options. 149 * 150 * @return {Array} an array of options 151 */ 152 ZmShareReply.prototype.getReplyOptions = 153 function() { 154 return this._replyOptions; 155 }; 156 157 // Protected methods 158 159 ZmShareReply.prototype._handleReplyType = 160 function(event) { 161 var type = this._replyType.getValue(); 162 this.setReplyType(type); 163 }; 164 165 ZmShareReply.prototype._initControl = function(params) { 166 167 this._replyType = new DwtSelect({ 168 parent: this, 169 id: "ZmShareReplySelect", 170 legendId: params.legendId 171 }); 172 var options = params.options || ZmShareReply.DEFAULT_OPTIONS; 173 this.setReplyOptions(options); 174 this._replyType.addChangeListener(this._handleReplyType.bind(this)); 175 176 var doc = document; 177 this._replyTypeEl = doc.createElement("DIV"); 178 this._replyTypeEl.style.paddingBottom = "0.5em"; 179 this._replyTypeEl.appendChild(this._replyType.getHtmlElement()); 180 181 this._replyStandardMailNoteEl = doc.createElement("DIV"); 182 this._replyStandardMailNoteEl.style.paddingBottom = "0.125em"; 183 this._replyStandardMailNoteEl.style.width = "30em"; 184 this._makeFocusable(this._replyStandardMailNoteEl); 185 this._replyStandardMailNoteEl.innerHTML = ZmMsg.sendMailAboutShareNote; 186 187 var div = doc.createElement("DIV"); 188 this._replyNoteEl = doc.createElement("TEXTAREA"); 189 this._replyNoteEl.cols = 50; 190 this._replyNoteEl.rows = 4; 191 div.appendChild(this._replyNoteEl); 192 193 this._replyControlsEl = doc.createElement("DIV"); 194 this._replyControlsEl.style.marginLeft = "1.5em"; 195 this._replyControlsEl.appendChild(this._replyTypeEl); 196 this._replyControlsEl.appendChild(this._replyStandardMailNoteEl); 197 this._replyControlsEl.appendChild(div); 198 199 // append controls 200 var element = this.getHtmlElement(); 201 element.appendChild(this._replyControlsEl); 202 this._tabGroup.addMember(this._replyType); 203 this._tabGroup.addMember(this._replyStandardMailNoteEl); 204 this._tabGroup.addMember(this._replyNoteEl); 205 }; 206 207 ZmShareReply.prototype.getTabGroupMember = function(){ 208 return this._tabGroup; 209 }; 210