1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 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, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 * This file contains the task folder class. 27 */ 28 29 /** 30 * Creates the task folder. 31 * @class 32 * This class represents a task folder. 33 * 34 * @author Parag Shah 35 * 36 * @param {Hash} params a hash of parameters 37 * @param {int} params.id the numeric ID 38 * @param {String} params.name the name 39 * @param {ZmOrganizer} params.parent the parent organizer 40 * @param {ZmTree} params.tree the tree model that contains this organizer 41 * @param {String} params.color the color 42 * @param {String} params.url the URL for this organizer's feed 43 * @param {String} params.owner the owner 44 * @param {String} params.zid the Zimbra id of owner, if remote share 45 * @param {String} params.rid the remote id of organizer, if remote share 46 * @param {String} params.restUrl [the REST URL of this organizer. 47 * 48 * @extends ZmFolder 49 */ 50 ZmTaskFolder = function(params) { 51 params.type = ZmOrganizer.TASKS; 52 ZmFolder.call(this, params); 53 } 54 55 ZmTaskFolder.prototype = new ZmFolder; 56 ZmTaskFolder.prototype.constructor = ZmTaskFolder; 57 58 // Public methods 59 60 /** 61 * Returns a string representation of the object. 62 * 63 * @return {String} a string representation of the object 64 */ 65 ZmTaskFolder.prototype.toString = 66 function() { 67 return "ZmTaskFolder"; 68 }; 69 70 ZmTaskFolder.prototype.getIcon = 71 function() { 72 if (this.id == ZmFolder.ID_ROOT) { return null; } 73 if (this.link) { return "SharedTaskList"; } 74 return "TaskList"; 75 }; 76 77 ZmTaskFolder.prototype.supportsPublicAccess = 78 function() { 79 // Task's can be accessed outside of ZCS (i.e. REST) 80 return true; 81 }; 82 83 /** 84 * Sets the free/busy. 85 * 86 * @param {AjxCallback} callback the callback 87 * @param {AjxCallback} errorCallback the error callback 88 * @param {Boolean} exclude checks to exclose free busy 89 */ 90 ZmTaskFolder.prototype.setFreeBusy = 91 function(exclude, callback, errorCallback) { 92 if (this.excludeFreeBusy == exclude) return; 93 // NOTE: Don't need to store the value since the response will 94 // report that the object was modified. 95 this._organizerAction({action: "fb", attrs: {excludeFreeBusy: exclude ? "1" : "0"}, callback: callback, errorCallback: errorCallback}); 96 }; 97 98 ZmTaskFolder.prototype.mayContain = 99 function(what) { 100 if (!what) return true; 101 102 var invalid = false; 103 104 if (this.id == ZmFolder.ID_ROOT) { 105 // cannot drag anything onto root folder 106 invalid = true; 107 } else if (this.link) { 108 // cannot drop anything onto a read-only task folder 109 invalid = this.isReadOnly(); 110 } 111 112 if (!invalid) { 113 // An item or an array of items is being moved 114 var items = (what instanceof Array) ? what : [what]; 115 var item = items[0]; 116 117 if (item.type != ZmItem.TASK) { 118 // only tasks are valid for task folders 119 invalid = true; 120 } else { 121 // can't move items to folder they're already in; we're okay if 122 // we have one item from another folder 123 if (!invalid && item.folderId) { 124 invalid = true; 125 for (var i = 0; i < items.length; i++) { 126 var item = items[i]; 127 var folder = appCtxt.getById(item.folderId); 128 if (folder != this) { 129 invalid = false; 130 break; 131 } 132 } 133 } 134 } 135 } 136 137 return !invalid; 138 }; 139 140 141 // Callbacks 142 143 ZmTaskFolder.prototype.notifyCreate = 144 function(obj) { 145 var t = ZmFolderTree.createFromJs(this, obj, this.tree); 146 var i = ZmOrganizer.getSortIndex(t, ZmFolder.sortCompareNonMail); 147 this.children.add(t, i); 148 t._notify(ZmEvent.E_CREATE); 149 }; 150 151 ZmTaskFolder.prototype.notifyModify = 152 function(obj) { 153 ZmFolder.prototype.notifyModify.call(this, obj); 154 155 if (obj.f != null && !obj._isRemote) { 156 this._parseFlags(obj.f); 157 // TODO: Should a F_EXCLUDE_FB property be added to ZmOrganizer? 158 // It doesn't make sense to require the base class to know about 159 // all the possible fields in sub-classes. So I'm just using the 160 // modified property name as the key. 161 var fields = {}; 162 fields["excludeFreeBusy"] = true; 163 this._notify(ZmEvent.E_MODIFY, {fields: fields}); 164 } 165 }; 166 167 168 // Static methods 169 170 /** 171 * Checks the name for validity 172 * 173 * @return {String} an error message if the name is invalid; <code>null</code> if the name is valid. 174 */ 175 ZmTaskFolder.checkName = 176 function(name) { 177 return ZmFolder.checkName(name); 178 }; 179 180