1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011, 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) 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 */ 27 28 /** 29 * Creates a rename tag dialog. 30 * @class 31 * This class represents a rename tag dialog. 32 * 33 * @param {DwtComposite} parent the parent 34 * @param {String} className the class name 35 * 36 * @extends ZmDialog 37 */ 38 ZmRenameTagDialog = function(parent, className) { 39 40 ZmDialog.call(this, {parent:parent, className:className, title:ZmMsg.renameTag, id:"RenameTagDialog"}); 41 42 this._setNameField(this._nameFieldId); 43 }; 44 45 ZmRenameTagDialog.prototype = new ZmDialog; 46 ZmRenameTagDialog.prototype.constructor = ZmRenameTagDialog; 47 48 ZmRenameTagDialog.prototype.toString = 49 function() { 50 return "ZmRenameTagDialog"; 51 }; 52 53 /** 54 * Pops-up the dialog. 55 * 56 * @param {ZmTag} tag the tag 57 * @param {Object} [source] (not used) 58 */ 59 ZmRenameTagDialog.prototype.popup = 60 function(tag, source) { 61 ZmDialog.prototype.popup.call(this); 62 this.setTitle(ZmMsg.renameTag + ': ' + tag.getName(false, ZmOrganizer.MAX_DISPLAY_NAME_LENGTH)); 63 this._nameField.value = tag.getName(false, null, true); 64 this._tag = tag; 65 }; 66 67 ZmRenameTagDialog.prototype._contentHtml = 68 function() { 69 this._nameFieldId = this._htmlElId + "_name"; 70 var subs = {id:this._htmlElId, newLabel:ZmMsg.newTagName}; 71 return AjxTemplate.expand("share.Dialogs#ZmRenameDialog", subs); 72 }; 73 74 ZmRenameTagDialog.prototype._okButtonListener = 75 function(ev) { 76 var results = this._getTagData(); 77 if (results) { 78 DwtDialog.prototype._buttonListener.call(this, ev, results); 79 } 80 }; 81 82 ZmRenameTagDialog.prototype._getTagData = 83 function() { 84 // check name for presence and validity 85 var name = AjxStringUtil.trim(this._nameField.value); 86 var msg = ZmTag.checkName(name); 87 88 // make sure tag name doesn't already exist 89 if (!msg) { 90 var tagTree = appCtxt.getTagTree(); 91 if (tagTree) { 92 var t = tagTree.getByName(name); 93 if (t && (t.id != this._tag.id)) { 94 msg = ZmMsg.tagNameExists; 95 } 96 } 97 } 98 99 return (msg ? this._showError(msg) : [this._tag, name]); 100 }; 101 102 ZmRenameTagDialog.prototype._enterListener = 103 function(ev) { 104 var results = this._getTagData(); 105 if (results) { 106 this._runEnterCallback(results); 107 } 108 }; 109