function setWhite(acl) { acl == 'custom' ? $('#whitelistBox').removeClass('hidden') : $('#whitelistBox').addClass('hidden'); } function switchStatus(projectID, status) { if(status) location.href = createLink('project', 'task', 'project=' + projectID + '&type=' + status); } function switchGroup(projectID, groupBy) { link = createLink('project', 'groupTask', 'project=' + projectID + '&groupBy=' + groupBy); location.href=link; } /** * Convert a date string like 2011-11-11 to date object in js. * * @param string $date * @access public * @return date */ function convertStringToDate(dateString) { dateString = dateString.split('-'); dateString = dateString[1] + '/' + dateString[2] + '/' + dateString[0]; return Date.parse(dateString); } /** * Compute delta of two days. * * @param string $date1 * @param string $date1 * @access public * @return int */ function computeDaysDelta(date1, date2) { date1 = convertStringToDate(date1); date2 = convertStringToDate(date2); delta = (date2 - date1) / (1000 * 60 * 60 * 24) + 1; weekEnds = 0; for(i = 0; i < delta; i++) { if(date1.getDay() == 0 || date1.getDay() == 6) weekEnds ++; date1 = date1.valueOf(); date1 += 1000 * 60 * 60 * 24; date1 = new Date(date1); } return delta - weekEnds; } /** * Compute work days. * * @access public * @return void */ function computeWorkDays() { beginDate = $('#begin').val(); endDate = $('#end').val(); if(beginDate && endDate) { $('#days').val(computeDaysDelta(beginDate, endDate)); } else if($('input[checked="true"]').val()) { computeEndDate(); } } /** * Compute the end date for project. * * @param int $delta * @access public * @return void */ function computeEndDate(delta) { beginDate = $('#begin').val(); if(!beginDate) return; endDate = convertStringToDate(beginDate).addDays(parseInt(delta)); endDate = endDate.toString('yyyy-M-dd'); $('#end').val(endDate); computeWorkDays(); } /* Auto compute the work days. */ $(function() { $(".date").bind('dateSelected', function() { computeWorkDays(); }) });