1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2006, 2007, 2009, 2010, 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) 2006, 2007, 2009, 2010, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 * This file defines a mountpoint organizer class. 27 */ 28 29 /** 30 * Creates a mountpoint organizer. 31 * @class 32 * This class represents a mountpoint organizer. This class can be used to represent generic 33 * mountpoints in an overview tree but is mostly used as a utility to create mountpoints. 34 * 35 * @param {Hash} params a hash of parameters 36 * 37 * @extends ZmOrganizer 38 */ 39 ZmMountpoint = function(params) { 40 params.type = ZmOrganizer.MOUNTPOINT; 41 ZmOrganizer.call(this, params); 42 this.view = params.view; 43 } 44 45 ZmMountpoint.prototype = new ZmOrganizer; 46 ZmMountpoint.prototype.constructor = ZmMountpoint; 47 48 // Constants 49 ZmMountpoint.__CREATE_PARAMS = AjxUtil.arrayAsHash(["l", "name", "zid", "rid", "owner", "path", "view", "color", "rgb", "f"]); 50 51 52 // Public Methods 53 54 /** 55 * Returns a string representation of the object. 56 * 57 * @return {String} a string representation of the object 58 */ 59 ZmMountpoint.prototype.toString = 60 function() { 61 return "ZmMountpoint"; 62 }; 63 64 /** 65 * Creates the mountpoint. 66 * 67 * @param {Hash} params a hash of parameters 68 * @param {String} params.name the name 69 */ 70 ZmMountpoint.create = 71 function(params, callback) { 72 var soapDoc = AjxSoapDoc.create("CreateMountpointRequest", "urn:zimbraMail"); 73 74 var linkNode = soapDoc.set("link"); 75 for (var p in params) { 76 if (!(p in ZmMountpoint.__CREATE_PARAMS)) continue; 77 linkNode.setAttribute(p, params[p]); 78 } 79 80 var errorCallback = new AjxCallback(null, ZmMountpoint._handleCreateError, params.name); 81 appCtxt.getAppController().sendRequest({soapDoc:soapDoc, 82 asyncMode:true, 83 callback:callback, 84 errorCallback:errorCallback}); 85 }; 86 87 /** 88 * @private 89 */ 90 ZmMountpoint._handleCreateError = 91 function(name, response) { 92 93 var msg; 94 if (response.code == ZmCsfeException.SVC_PERM_DENIED || response.code == ZmCsfeException.MAIL_NO_SUCH_FOLDER) { 95 msg = ZmCsfeException.getErrorMsg(response.code); 96 } else if (response.code == ZmCsfeException.MAIL_ALREADY_EXISTS) { 97 var type = appCtxt.getFolderTree(appCtxt.getActiveAccount()).getFolderTypeByName(name); 98 msg = AjxMessageFormat.format(ZmMsg.errorAlreadyExists, [name,type.toLowerCase()]); 99 } 100 if (msg) { 101 appCtxt.getAppController().popupErrorDialog(msg, null, null, true); 102 return true; 103 } 104 }; 105