1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 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, 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 revoke share dialog. 30 * @class 31 * This class represents a revoke share dialog. 32 * 33 * @param {DwtComposite} parent the parent 34 * @param {String} className the class name 35 * 36 * @extends DwtDialog 37 */ 38 ZmRevokeShareDialog = function(parent, className) { 39 className = className || "ZmRevokeShareDialog"; 40 var title = ZmMsg.revokeShare; 41 var buttons = [ DwtDialog.YES_BUTTON, DwtDialog.NO_BUTTON ]; 42 DwtDialog.call(this, {parent:parent, className:className, title:title, standardButtons:buttons}); 43 this.setButtonListener(DwtDialog.YES_BUTTON, new AjxListener(this, this._handleYesButton)); 44 45 var view = this._createView(); 46 this.setView(view); 47 48 // create formatters 49 this._formatter = new AjxMessageFormat(ZmMsg.revokeShareConfirm); 50 }; 51 52 ZmRevokeShareDialog.prototype = new DwtDialog; 53 ZmRevokeShareDialog.prototype.constructor = ZmRevokeShareDialog; 54 55 // Public methods 56 57 ZmRevokeShareDialog.prototype.toString = 58 function() { 59 return "ZmRevokeShareDialog"; 60 }; 61 62 /** 63 * Pops-up the dialog. 64 * 65 * @param {ZmShare} share the share 66 */ 67 ZmRevokeShareDialog.prototype.popup = 68 function(share) { 69 this._share = share; 70 71 var isPubShare = share.isPublic(); 72 var isGuestShare = share.isGuest(); 73 var isAllShare = share.grantee && (share.grantee.type == ZmShare.TYPE_ALL); 74 75 var params = isPubShare ? ZmMsg.shareWithPublic : isGuestShare ? share.grantee.id : isAllShare ? ZmMsg.shareWithAll : 76 (share.grantee.name || ZmMsg.userUnknown); 77 this._confirmMsgEl.innerHTML = this._formatter.format(params); 78 79 this._reply.setReplyType(ZmShareReply.STANDARD); 80 this._reply.setReplyNote(""); 81 this._reply.setVisible(!isPubShare && !isAllShare); 82 83 if (isGuestShare) { 84 this._reply.setReplyOptions(ZmShareReply.EXTERNAL_USER_OPTIONS); 85 } 86 else { 87 this._reply.setReplyOptions(ZmShareReply.DEFAULT_OPTIONS); 88 } 89 90 DwtDialog.prototype.popup.call(this); 91 this.setButtonEnabled(DwtDialog.YES_BUTTON, true); 92 }; 93 94 // Protected methods 95 96 ZmRevokeShareDialog.prototype._handleYesButton = 97 function() { 98 var callback = new AjxCallback(this, this._yesButtonCallback); 99 this._share.revoke(callback); 100 }; 101 102 ZmRevokeShareDialog.prototype._yesButtonCallback = 103 function() { 104 var share = this._share; 105 var replyType = this._reply.getReplyType(); 106 var sendMail = !(share.isAll() || share.isPublic() || share.invalid); 107 if (replyType != ZmShareReply.NONE && sendMail) { 108 // initialize rest of share information 109 share.grantee.email = share.grantee.name || share.grantee.id; 110 share.grantor.id = appCtxt.get(ZmSetting.USERID); 111 share.grantor.email = appCtxt.get(ZmSetting.USERNAME); 112 share.grantor.name = appCtxt.get(ZmSetting.DISPLAY_NAME) || share.grantor.email; 113 share.link.id = share.object.id; 114 share.link.name = share.object.name; 115 share.link.view = ZmOrganizer.getViewName(share.object.type); 116 117 share.notes = (replyType == ZmShareReply.QUICK) ? this._reply.getReplyNote() : ""; 118 119 share.sendMessage(ZmShare.DELETE); 120 } 121 122 this.popdown(); 123 }; 124 125 ZmRevokeShareDialog.prototype._createView = 126 function() { 127 this._confirmMsgEl = document.createElement("DIV"); 128 this._confirmMsgEl.style.fontWeight = "bold"; 129 this._confirmMsgEl.style.marginBottom = "0.25em"; 130 131 var view = new DwtComposite(this); 132 this._reply = new ZmShareReply(view); 133 134 var element = view.getHtmlElement(); 135 element.appendChild(this._confirmMsgEl); 136 element.appendChild(this._reply.getHtmlElement()); 137 138 this._tabGroup.addMember(this._reply.getTabGroupMember()); 139 return view; 140 }; 141 142 ZmRevokeShareDialog.prototype._getSeparatorTemplate = 143 function() { 144 return ""; 145 }; 146