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