var projectTable;
var projectRowID;
var projectPos;
$(document).ready(function () {
deptList();
companyList();
loadyearmonth();
var actualDate = new Date(); // convert to actual date
var prevDate = new Date(actualDate.getFullYear(), actualDate.getMonth() - 13, actualDate.getDate());
var startTxt = prevDate.getFullYear().toString() + "/" + padding(prevDate.getMonth() + 1, 2);
var endTxt = actualDate.getFullYear().toString() + "/" + padding(actualDate.getMonth() + 1, 2);
const fpStart = flatpickr("#dateStart", {
"locale": "zh_tw",
"plugins": [
new monthSelectPlugin({
shorthand: true, //defaults to false
dateFormat: "Y/m", //defaults to "F Y"
altFormat: "Y M", //defaults to "F Y"
theme: "light" // defaults to "light"
})
]
});
const fpEnd = flatpickr("#dateEnd", {
"locale": "zh_tw",
"plugins": [
new monthSelectPlugin({
shorthand: true, //defaults to false
dateFormat: "Y/m", //defaults to "F Y"
altFormat: "Y M", //defaults to "F Y"
theme: "light" // defaults to "light"
})
]
});
fpStart.setDate(new Date(startTxt + '/1'))
fpEnd.setDate(new Date(endTxt + '/1'))
$('#projectSaveBtn').on('click', function () {
var company_uid = $('#company_select').val();
var project_name = $('#project_name').val();
var project_ps = $('#project_ps').val();
var project_uid = $('#project_uid').val();
var mehtod = $('#project_method').val();
var msg = '';
if (company_uid == "") {
msg += '請選擇客戶公司!\n';
}
if (project_name == '') {
msg += '請輸入專案名稱!\n';
}
if (msg != '') {
alert(msg);
return;
}
var formData = {
method: method,
project_uid: project_uid,
project_name: project_name,
company_uid: company_uid,
project_ps: project_ps
}
});
$('#projectNewBtn').on('click', function () {
$('#prjoect_method').val('add');
$('#clientProjectModal').modal("toggle");
});
function loadyearmonth() {
var actualDate = new Date(); // convert to actual date
var nowYear = actualDate.getFullYear();
for (tmpY = nowYear; tmpY >= 2019; tmpY--) {
$("#project_year").append($("").attr("value", tmpY).text(tmpY + " 年度"));
}
for (tmpM = 1; tmpM <= 12; tmpM++) {
$("#project_month").append($("").attr("value", tmpM).text(tmpM + " 月"));
}
}
});
function loadDataTable() {
var dataTables = {
init: function init() {
this.bindUIActions();
},
bindUIActions: function bindUIActions() {
// event handlers
this.table = this.handleDataTables();
// add buttons
//this.table.buttons().container().appendTo('#dt-buttons').unwrap();
},
handleDataTables: function handleDataTables() {
//$('#myTable').append("
| | | | | | |
");
return $('#dt-responsive').DataTable({
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
lengthChange: true,
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
pageLength: 50,
buttons: [
//{
// text: '休假設定',
// action: function (e, dt, node, config) {
// vacationBtnFun();
// }
//},
//'excelHtml5'
],
language: {
paginate: {
previous: '',
next: ''
},
buttons: {
copyTitle: 'Data copied',
copyKeys: 'Use your keyboard or menu to select the copy command'
}
},
autoWidth: false,
ajax: {
url: '/Api/projectViewList',
type: 'POST',
data: function (d) {
Object.assign(d, {
dept_uid: $('#dept_select').val(),
start_txt: $('#dateStart').val(),
end_txt: $('#dateEnd').val()
});
return d;
},
dataSrc: 'projectViews'
},
rowId: 'project_uid',
deferRender: true,
initComplete: function () {
projectTable = $('#dt-responsive').dataTable();
$('#dt-responsive').on('click', 'a', function () {
buttonClick(this);
});
$('#dt-responsive').on('click', 'button', function () {
buttonClick(this);
});
},
order: [[0, 'desc']],
info: true,
search: "搜尋:",
searching: true,
columns: [
{ data: 'project_datetime', className: 'align-top text-left', orderable: true, searchable: true },
{ data: 'project_name', className: 'align-top text-left', orderable: false, searchable: true },
{ data: 'company_name', className: 'align-top text-left', orderable: false, searchable: true },
{ data: 'project_ps', className: 'align-top text-left', orderable: false, searchable: false },
{ data: 'project_uid', className: 'align-top text-center', orderable: false, searchable: false }
],
columnDefs: [
{
targets: 1,
className: 'align-middle text-left',
orderable: false,
searchable: true,
render: function render(data, type, row, meta) {
return '' + row.project_name + '';
}
},
{
targets: 4,
orderable: false,
searchable: false,
render: function render(data, type, row, meta) {
var ret = '';
ret += '';
ret += '';
return ret;
}
}
],
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.childRowImmediate,
type: ''
}
}
});
},
handleSearchRecords: function handleSearchRecords() {
var self = this;
$('#table-search, #filterBy').on('keyup change focus', function (e) {
var filterBy = $('#filterBy').val();
var hasFilter = filterBy !== '';
var value = $('#table-search').val();
self.table.search('').columns().search('').draw();
if (hasFilter) {
self.table.columns(filterBy).search(value).draw();
} else {
self.table.search(value).draw();
}
});
}
}
dataTables.init();
}
function companyList() {
$.ajax({
url: "/Api/companyList",
type: "post",
data: null,
success: function (data, textStatus, jqXHR) {
if (data.ret == "yes") {
var obj = data.companys;
var items = "";
$("#company_select").append($("