1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2005, 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) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 ZmCalWorkWeekView = function(parent, posStyle, controller, dropTgt) {
 25     var workingDays = ZmCalBaseView.parseWorkingHours(ZmCalBaseView.getWorkingHours()),
 26         numOfWorkingDays = 0,
 27         i;
 28     for(i=0; i<workingDays.length; i++) {
 29         if(workingDays[i].isWorkingDay) {
 30             numOfWorkingDays++;    
 31         }
 32     }
 33 	ZmCalColView.call(this, parent, posStyle, controller, dropTgt, ZmId.VIEW_CAL_WORK_WEEK, numOfWorkingDays, false);
 34 }
 35 
 36 ZmCalWorkWeekView.prototype = new ZmCalColView;
 37 ZmCalWorkWeekView.prototype.constructor = ZmCalWorkWeekView;
 38 
 39 ZmCalWorkWeekView.prototype.toString = 
 40 function() {
 41 	return "ZmCalWorkWeekView";
 42 }
 43 
 44 /**
 45  * Returns the available start time in work week view
 46  *
 47  * @param   {ZmAppt} appt
 48  *
 49  * @return	{Time} or <code>null</code> if start time is not available
 50  */
 51 ZmCalWorkWeekView.prototype.getAvailableStartTime = function(appt) {
 52 	// If appointment start date is available in the view then just return start time
 53 	if (this._getDayForDate(appt.startDate)) {
 54 		return appt.getStartTime();
 55 	}
 56 	if (appt.isMultiDay()) {
 57 		//If multi-day appointment start date is not available in the view then try to find the next available day by rolling the start date to next day.
 58 		var startTime = Math.max(appt.getStartTime(), this._timeRangeStart);
 59 		var endTime = Math.min(appt.getEndTime(), this._timeRangeEnd);
 60 		while (startTime < endTime) {
 61 			var startDate = new Date(startTime);
 62 			if (this._getDayForDate(startDate)) {
 63 				return startTime;
 64 			}
 65 			AjxDateUtil.rollToNextDay(startDate);
 66 			startTime = startDate.getTime();
 67 		}
 68 	}
 69 	return null;
 70 };
 71