(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 '' + data.Name + '';
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 (' Delete')
.replace(/_rplcmnt_/g, data.Id);
}
else {
return "";
}
}, "bSortable": false
}],
"order": []
});
// if (this.$settings.write)
//{
// $('#glAccount_wrapper .table-caption').html(' Add GL Account');
//}
//$('#glAccount_wrapper .dataTables_filter input').attr('placeholder', 'Search...');
//$('#glAccount_wrapper .dataTables_processing').addClass("table-caption");
//$('#glAccount_wrapper .dataTables_processing').html('
');
return this;
};
// init plugin
this.initPlugin();
// return plugin object
return this;
};
}(jQuery));