window.ignoreTips = { 'beyondBudgetTip' : false, 'dateTip' : false }; /** * Access rights are equal to private, and the white list settings are displayed. * * @param string acl * @access public * @return void */ function setWhite(acl) { acl != 'open' ? $('#whitelistBox').removeClass('hidden') : $('#whitelistBox').addClass('hidden'); } /** * Convert a date string like 2011-11-11 to date object in js. * * @param string dateString * @access public * @return date */ function convertStringToDate(dateString) { dateString = dateString.split('-'); return new Date(dateString[0], dateString[1] - 1, dateString[2]); } /** * Compute delta of two days. * * @param string date1 * @param string date2 * @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((weekend == 2 && date1.getDay() == 6) || date1.getDay() == 0) weekEnds ++; date1 = date1.valueOf(); date1 += 1000 * 60 * 60 * 24; date1 = new Date(date1); } return delta - weekEnds; } /** * Compute work days. * * @param string currentID * @access public * @return void */ function computeWorkDays(currentID) { isBactchEdit = false; if(currentID) { index = currentID.replace('begins[', ''); index = index.replace('ends[', ''); index = index.replace(']', ''); if(!isNaN(index)) isBactchEdit = true; } if(isBactchEdit) { beginDate = $('#begins\\[' + index + '\\]').val(); endDate = $('#ends\\[' + index + '\\]').val(); } else { beginDate = $('#begin').val(); endDate = $('#end').val(); var begin = new Date(beginDate.replace(/-/g,"/")); var end = new Date(endDate.replace(/-/g,"/")); var time = end.getTime() - begin.getTime(); var days = parseInt(time / (1000 * 60 * 60 * 24)) + 1; if(days != $("input:radio[name='delta']:checked").val()) $("input:radio[name='delta']:checked").attr('checked', false); if(endDate == longTime) $("#delta999").prop('checked', true); } if(beginDate && endDate) { if(isBactchEdit) $('#dayses\\[' + index + '\\]').val(computeDaysDelta(beginDate, endDate)); if(!isBactchEdit) $('#days').val(computeDaysDelta(beginDate, endDate)); } else if($('input[checked="true"]').val()) { computeEndDate(); } outOfDateTip(); } /** * Compute the end date for project. * * @param int $delta * @access public * @return void */ function computeEndDate(delta) { beginDate = $('#begin').val(); if(!beginDate) return; delta = parseInt(delta); if(delta == 999) { $('#end').val(longTime); outOfDateTip(); return false; } beginDate = convertStringToDate(beginDate); if((delta == 7 || delta == 14) && (beginDate.getDay() == 1)) { delta = (weekend == 2) ? (delta - 2) : (delta - 1); } endDate = $.zui.formatDate(beginDate.addDays(delta - 1), 'yyyy-MM-dd'); $('#end').val(endDate).datetimepicker('update'); computeWorkDays(); } /** * Load branches. * * @param object product * @access public * @return void */ function loadBranches(product) { /* When selecting a product, delete a plan that is empty by default. */ $("#planDefault").remove(); $('#productsBox select').each(function() { var $product = $(product); if($product.val() != 0 && $product.val() == $(this).val() && $product.attr('id') != $(this).attr('id')) { alert(errorSameProducts); $product.val(0); $product.trigger("chosen:updated"); return false; } }); if($('#productsBox .input-group:last select:first').val() != 0) { var length = $('#productsBox .input-group').size(); $('#productsBox .row').append('
" + beginGreateChild + childInfo.minChildBegin + "
" + ignore + "
"; } else if(programEnd < childEnd && programBegin <= childBegin) { dateTip = "" + endLetterChild + childInfo.maxChildEnd + "
" + ignore + "
"; } else { dateTip = "" + dateExceedChild + childInfo.minChildBegin + "~" + childInfo.maxChildEnd + "
" + ignore + "
"; } $('#dateBox').after(dateTip); }); } } /** * The date is out of the range of the parent project set, and a prompt is given. * * @access public * @return void */ function outOfDateTip() { if(window.ignoreTips['dateTip']) return; var end = $('#end').val(); var begin = $('#begin').val(); if($('#dateTip').length > 0) $('#dateTip').remove(); if(end == longTime) end = LONG_TIME; if(end.length > 0 && begin.length > 0) { var selectedProgramID = $('#parent').val(); var programEnd = new Date(end); var programBegin = new Date(begin); if(selectedProgramID == 0) { compareChildDate(); return; } if(typeof(programID) == 'undefined') programID = 0; $.get(createLink('project', 'ajaxGetObjectInfo', 'objectType=program&objectID=' + programID + "&selectedProgramID=" + selectedProgramID), function(data) { var dateTip = ''; var data = JSON.parse(data); var parentEnd = new Date(data.selectedProgramEnd); var parentBegin = new Date(data.selectedProgramBegin); if(programBegin >= parentBegin && programEnd <= parentEnd) { compareChildDate(); return; } if(programBegin < parentBegin && programEnd <= parentEnd && programEnd >= parentBegin) { dateTip = "" + beginLetterParent + data.selectedProgramBegin + "
" + ignore + "
"; } else if(programEnd > parentEnd && programBegin >= parentBegin && programBegin <= parentEnd) { dateTip = "" + endGreaterParent + data.selectedProgramEnd + "
" + ignore + "
"; } else { dateTip = "" + dateExceedParent + data.selectedProgramBegin + "~" + data.selectedProgramEnd + "
" + ignore + "
"; } $('#dateBox').after(dateTip); }); } } /** * Append prompt when the budget exceeds the parent project set. * * @access public * @return void */ function budgetOverrunTips() { if(window.ignoreTips['beyondBudgetTip']) return; var selectedProgramID = $('#parent').val(); var budget = $('#budget').val(); if(selectedProgramID == 0) { if($('#beyondBudgetTip').length > 0) $('#beyondBudgetTip').remove(); return false; } if(typeof(programID) == 'undefined') programID = 0; $.get(createLink('project', 'ajaxGetObjectInfo', 'objectType=program&objectID=' + programID + "&selectedProgramID=" + selectedProgramID), function(data) { var data = JSON.parse(data); var tip = ""; if(budget !=0 && budget !== null && budget > data.availableBudget) var tip = "" + budgetOverrun + currencySymbol[data.budgetUnit] + data.availableBudget + "
" + ignore + "
" if($('#beyondBudgetTip').length > 0) $('#beyondBudgetTip').remove(); $('#budgetBox').after(tip); }); } /** * Make this prompt no longer appear. * * @param string $obj * @access public * @return void */ function ignoreTip(obj) { var parentID = obj.parentNode.id; $('#' + parentID).addClass('hidden'); if(parentID == 'dateTip') window.ignoreTips['dateTip'] = true; if(parentID == 'beyondBudgetTip') window.ignoreTips['beyondBudgetTip'] = true; }