1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2011, 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, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates a password update dialog. 26 * @class 27 * This class represents a password update dialog. 28 * 29 * @param {DwtComposite} parent the parent 30 * @param {String} className the class name 31 * 32 * @extends ZmDialog 33 */ 34 ZmPasswordUpdateDialog = function(parent, className) { 35 36 ZmDialog.call(this, {parent:parent, className:className, title:ZmMsg.changePassword, id:"PasswdChangeDialog"}); 37 this._setNameField(this._nameFieldId); 38 this._createControls(); 39 }; 40 41 ZmPasswordUpdateDialog.prototype = new ZmDialog; 42 ZmPasswordUpdateDialog.prototype.constructor = ZmPasswordUpdateDialog; 43 44 ZmPasswordUpdateDialog.prototype.toString = 45 function() { 46 return "ZmPasswordUpdateDialog"; 47 }; 48 49 /** 50 * Pops-up the dialog. 51 */ 52 ZmPasswordUpdateDialog.prototype.popup = 53 function(acct) { 54 ZmDialog.prototype.popup.call(this); 55 this.acct = acct; 56 var desc = document.getElementById(this._htmlElId + "_desc"); 57 this._toggleOKButton(false); 58 desc.innerHTML = AjxMessageFormat.format(ZmMsg.offlinePasswordUpdate, this.acct.name); 59 var acctTd = document.getElementById(this._htmlElId + "_acct"); 60 acctTd.innerHTML = this.acct.name; 61 this._nameField.value = ""; 62 }; 63 64 ZmPasswordUpdateDialog.prototype._createControls = 65 function() { 66 this.setTitle(ZmMsg.offlineAccountAuth); 67 this._toggleOKButton(false); 68 var cancelBtn = this.getButton(DwtDialog.CANCEL_BUTTON); 69 cancelBtn.setText(ZmMsg.dismiss); 70 var okBtn = this.getButton(DwtDialog.OK_BUTTON); 71 okBtn.setText(ZmMsg.save); 72 this._nameField._dlgEl = this._htmlElId; 73 Dwt.setHandler(this._nameField, DwtEvent.ONKEYUP, this._handleKeyUp); 74 75 }; 76 77 78 ZmPasswordUpdateDialog.prototype._contentHtml = 79 function() { 80 this._nameFieldId = this._htmlElId + "_name"; 81 var subs = {id:this._htmlElId, labelAcct:ZmMsg.account, labelPasswd:ZmMsg.password}; 82 return AjxTemplate.expand("share.Dialogs#ZmPasswordUpdateDialog", subs); 83 }; 84 85 ZmPasswordUpdateDialog.prototype._okButtonListener = 86 function(ev) { 87 var pwd = AjxStringUtil.trim(this._nameField.value); 88 if (pwd && pwd.length > 0 ) { 89 var soapDoc = AjxSoapDoc.create("ChangePasswordRequest", "urn:zimbraOffline"); 90 soapDoc.setMethodAttribute("id", this.acct.id); 91 soapDoc.set("password", pwd); 92 93 appCtxt.getAppController().sendRequest({ 94 soapDoc:soapDoc, 95 asyncMode:true, 96 noBusyOverlay:true, 97 callback: new AjxCallback(this, this._handlePasswordUpdateResult), 98 accountName:this.name 99 }); 100 } 101 }; 102 103 104 /** 105 * Updates password for specified account 106 * 107 */ 108 109 ZmPasswordUpdateDialog.prototype._handlePasswordUpdateResult = 110 function(result) { 111 var resp = result.getResponse(); 112 resp = resp.ChangePasswordResponse; 113 if (resp && resp.status == "success") { 114 this.popdown(); 115 var msg = AjxMessageFormat.format(ZmMsg.offlinePasswordUpdateSuccess, this.acct.name); 116 appCtxt.setStatusMsg(msg, ZmStatusView.LEVEL_INFO); 117 } else { 118 appCtxt.setStatusMsg(ZmMsg.offlinePasswordUpdateFailure, ZmStatusView.LEVEL_WARNING); 119 this._nameField.value = ""; 120 this._toggleOKButton(false); 121 } 122 }; 123 124 ZmPasswordUpdateDialog.prototype._enterListener = 125 function(ev) { 126 var pwd = AjxStringUtil.trim(this._nameField.value); 127 if (pwd && pwd.length > 0 ) { 128 this._okButtonListener(); 129 } 130 }; 131 132 ZmPasswordUpdateDialog.prototype._handleKeyUp = 133 function(ev) { 134 135 var key = DwtKeyEvent.getCharCode(ev); 136 if (key === DwtKeyEvent.KEY_TAB) { 137 return; 138 } 139 var el = DwtUiEvent.getTarget(ev); 140 var val = el && el.value; 141 var dlgEl = el && el._dlgEl && DwtControl.ALL_BY_ID[el._dlgEl]; 142 dlgEl._toggleOKButton(val.length > 0); 143 }; 144 145 ZmPasswordUpdateDialog.prototype._toggleOKButton = 146 function(enable) { 147 var okBtn = this.getButton(DwtDialog.OK_BUTTON); 148 okBtn.setEnabled(enable); 149 }; 150