203 lines
5.6 KiB
JavaScript
203 lines
5.6 KiB
JavaScript
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('-');
|
|
return new Date(dateString[0], dateString[1] - 1, dateString[2]);
|
|
}
|
|
|
|
/**
|
|
* 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((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.
|
|
*
|
|
* @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();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
beginDate = convertStringToDate(beginDate);
|
|
if((delta == 7 || delta == 14) && (beginDate.getDay() == 1))
|
|
{
|
|
delta = (weekend == 2) ? (delta - 2) : (delta - 1);
|
|
}
|
|
|
|
endDate = beginDate.addDays(delta - 1).toString('yyyy-MM-dd');
|
|
$('#end').val(endDate).datetimepicker('update');
|
|
computeWorkDays();
|
|
}
|
|
|
|
/**
|
|
* Load branches.
|
|
*
|
|
* @param int $product
|
|
* @access public
|
|
* @return void
|
|
*/
|
|
function loadBranches(product)
|
|
{
|
|
$('#productsBox select').each(function()
|
|
{
|
|
var $product = $(product);
|
|
if($product.val() != 0 && $product.val() == $(this).val() && $product.attr('id') != $(this).attr('id'))
|
|
{
|
|
bootbox.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('<div class="col-sm-3">' + $('#productsBox .col-sm-3:last').html() + '</div>');
|
|
if($('#productsBox .input-group:last select').size() >= 2)$('#productsBox .input-group:last select:last').remove();
|
|
$('#productsBox .input-group:last .chosen-container').remove();
|
|
$('#productsBox .input-group:last select:first').attr('name', 'products[' + length + ']').attr('id', 'products' + length);
|
|
$('#productsBox .input-group:last .chosen').chosen(defaultChosenOptions);
|
|
}
|
|
|
|
var $inputgroup = $(product).closest('.input-group');
|
|
if($inputgroup.find('select').size() >= 2)$inputgroup.find('select:last').remove();
|
|
var index = $inputgroup.find('select:first').attr('id').replace('products' , '');
|
|
$.get(createLink('branch', 'ajaxGetBranches', "productID=" + $(product).val()), function(data)
|
|
{
|
|
if(data)
|
|
{
|
|
$inputgroup.append(data);
|
|
$inputgroup.find('select:last').attr('name', 'branch[' + index + ']').attr('id', 'branch' + index).css('width', '80px');
|
|
}
|
|
})
|
|
}
|
|
function loadBranch(){}
|
|
|
|
/* Auto compute the work days. */
|
|
$(function()
|
|
{
|
|
if(typeof(replaceID) != 'undefined')
|
|
{
|
|
setModal4List('iframe', replaceID, function($list)
|
|
{
|
|
$list.find('.progress-pie:visible').progressPie();
|
|
var datatable = $list.data('zui.datatable');
|
|
if(datatable) datatable.$datatable.find('.progress-pie:visible').progressPie();
|
|
});
|
|
}
|
|
$(".date").bind('dateSelected', function()
|
|
{
|
|
computeWorkDays(this.id);
|
|
})
|
|
});
|
|
|
|
$(function()
|
|
{
|
|
$(document).on('click', '.task-toggle', function(e)
|
|
{
|
|
var $toggleIcon = $(this).find('i');
|
|
var id = $(this).data('id');
|
|
|
|
if($toggleIcon.hasClass('icon-double-angle-down'))
|
|
{
|
|
$('tr.parent-'+id).show();
|
|
$toggleIcon.removeClass('icon-double-angle-down').addClass('icon-double-angle-up');
|
|
}
|
|
else if($toggleIcon.hasClass('icon-double-angle-up'))
|
|
{
|
|
$('tr.parent-'+id).hide();
|
|
$toggleIcon.removeClass('icon-double-angle-up').addClass('icon-double-angle-down');
|
|
}
|
|
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
});
|
|
})
|