118 lines
4.8 KiB
JavaScript
118 lines
4.8 KiB
JavaScript
(function ($) {
|
|
$.fn.nonProjectTimeGrid = function (options) {
|
|
// plugin settings
|
|
this.$settings = $.extend({
|
|
// These are the defaults.
|
|
read: "false",
|
|
write: "false",
|
|
permanent: "false",
|
|
ishistory: "false"
|
|
}, options);
|
|
|
|
// methods
|
|
this.formatFDDate = function (jsonDate) {
|
|
if (!jsonDate)
|
|
return "";
|
|
|
|
var ms = parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10);
|
|
if (isNaN(ms) || ms <= 0)
|
|
return "";
|
|
|
|
var dt = new Date(ms);
|
|
return (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear();
|
|
};
|
|
|
|
this.initPlugin = function () {
|
|
var ctr = 0;
|
|
var th = this;
|
|
console.log(this.$settings.write);
|
|
this.$container = this.find('table');
|
|
this.$container.dataTable({
|
|
"bProcessing": true,
|
|
"bFilter": false,
|
|
"dom": 't<"bottom table-footer clearfix"irpl>',
|
|
"bServerSide": true,
|
|
"bAutoWidth": false,
|
|
"sAjaxSource": this.$settings.url + '&permanent=' + this.$settings.permanent + ('&ishistory=' + (this.$settings.ishistory || false)),
|
|
"sServerMethod": "POST",
|
|
"aoColumns": [
|
|
{
|
|
"mData": function (data, type, full) {
|
|
if (th.$settings.write == 'True')
|
|
return '<a href="#" onclick="return editNonProjectTime(\'aEditNPTime_' + data.Id + '\', \'' + data.Id + '\', \'' + data.ResourceId + '\')">' + data.Name + '</a>';
|
|
else return data.Name;
|
|
}, "bSortable": false, "aTargets": [ 0 ]
|
|
},
|
|
{ "mDataProp": "CategoryName", "bSortable": false },
|
|
{
|
|
"mData": function (data, type, full) { return th.formatFDDate(data.StartDate) + ' - ' + th.formatFDDate(data.EndDate) }, "bSortable": false
|
|
}
|
|
,
|
|
{ "mDataProp": "Duration", "bSortable": false },
|
|
{ "mDataProp": "CostFormatted", "bSortable": false },
|
|
{
|
|
"mData": function (data, type, full) {
|
|
var result = '';
|
|
if (!data.IsInvalid) {
|
|
if (data.IsPercentMode) {
|
|
if (data.Permanent) {
|
|
result = (data.ActualPercents4Today || 0) + '% weekly';
|
|
} else {
|
|
if (data.ApproximatePercents) {
|
|
result = (data.MinPercents || 0) + '% to ' + (data.MaxPercents || 0) + '% weekly';
|
|
}
|
|
else {
|
|
result = (data.TotalPercents || 0) + '% weekly';
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if (data.Permanent) {
|
|
result = (data.ActualHours4Today || 0) + ' hours weekly';
|
|
}
|
|
else {
|
|
result = (data.TotalHours || 0) + ' hours';
|
|
}
|
|
}
|
|
}
|
|
else
|
|
// Invalid NPT record
|
|
result = '-';
|
|
|
|
return result;
|
|
}, "bSortable": false
|
|
},
|
|
{ "mDataProp": "Details", "bSortable": false },
|
|
{
|
|
"visible": !(this.$settings.ishistory != null && this.$settings.ishistory),
|
|
"mData": function (data, type, full) {
|
|
|
|
if (th.$settings.write == 'True') {
|
|
|
|
ctr++;
|
|
return ('<a href="#" id="aDeleteNPTime__rplcmnt_" onclick="return deleteNonProjectTime(this.id, \'_rplcmnt_\')" data-placement="left" class="btn-xs btn-danger popover-warning popover-dark"><i class="fa fa-trash-o"></i> Delete</a>')
|
|
.replace(/_rplcmnt_/g, data.Id);
|
|
}
|
|
else {
|
|
return "";
|
|
}
|
|
}, "bSortable": false
|
|
}],
|
|
"order": []
|
|
});
|
|
// if (this.$settings.write)
|
|
//{
|
|
// $('#glAccount_wrapper .table-caption').html('<a class="btn btn-primary" href="@Url.Action("Edit", "GLAccount")"><i class="fa fa-plus"></i> Add GL Account</a>');
|
|
//}
|
|
//$('#glAccount_wrapper .dataTables_filter input').attr('placeholder', 'Search...');
|
|
//$('#glAccount_wrapper .dataTables_processing').addClass("table-caption");
|
|
//$('#glAccount_wrapper .dataTables_processing').html('<span class="h3"><img class="valign-middle" src="../Content/images/loadFA.gif"/></span>');
|
|
return this;
|
|
};
|
|
|
|
// init plugin
|
|
this.initPlugin();
|
|
// return plugin object
|
|
return this;
|
|
};
|
|
}(jQuery)); |