|
|
|
var toolsModal = $('#modal-tools > .modal-dialog > .modal-content');
|
|
|
|
|
|
|
|
function resetFormAssignTools() {
|
|
|
|
$('#select-tools').val(null).trigger("change");
|
|
|
|
$('#select-tools').find('option').remove();
|
|
|
|
$('#select-tools').val("");
|
|
|
|
// $("#form-assign-tools").hide();
|
|
|
|
$('#form-assign-tools').trigger("reset");
|
|
|
|
$('#btn-assign-tools').html('Assign');
|
|
|
|
$('#btn-assign-tools').prop("disabled",false);
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
var tableTools = $("#table-tools").DataTable({
|
|
|
|
"processing": true,
|
|
|
|
"serverSide": true,
|
|
|
|
"ajax": {
|
|
|
|
"url": `${base_url}assign-tools/datatables`,
|
|
|
|
"data": function ( d ) {
|
|
|
|
d.idact = activityId;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"columns": [
|
|
|
|
{data: 'tools_name', name: 'tools_name'},
|
|
|
|
{data: 'qty_planning', name: 'qty_planning'},
|
|
|
|
{data: 'uom', name: 'uom'},
|
|
|
|
{
|
|
|
|
data: 'action',
|
|
|
|
name: 'action',
|
|
|
|
orderable: true,
|
|
|
|
searchable: true
|
|
|
|
},
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
function deleteToolsAssign(id)
|
|
|
|
{
|
|
|
|
$.ajax({
|
|
|
|
url: `${base_url}assign-tools/delete/${id}`,
|
|
|
|
type:"DELETE",
|
|
|
|
success: function (data) {
|
|
|
|
actionHappen = true;
|
|
|
|
gantt.alert("Delete Tools Assign Success!");
|
|
|
|
tableTools.draw();
|
|
|
|
},
|
|
|
|
error: function (data) {
|
|
|
|
gantt.alert("Delete Tools Assign Failed, try again later!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#modal-tools").on("click", "#show-form-tools", function(){
|
|
|
|
$(this).hide();
|
|
|
|
$("#hide-form-tools").show();
|
|
|
|
$("#form-assign-tools").show();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#modal-tools").on("click", "#hide-form-tools", function(){
|
|
|
|
$(this).hide();
|
|
|
|
resetFormAssignTools()
|
|
|
|
$("#show-form-tools").show();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#modal-tools').on('show.bs.modal', function (event) {
|
|
|
|
$('#modal-tools-title').html("Tools Resource " + activityName);
|
|
|
|
$('#modal-tools-sub-title').html(`<p style="font-size: 12px; color: #747474">Plan Date ${moment(activityEarlyStart).format('MM-DD-YYYY')} - ${moment(activityEarlyFinish).format('MM-DD-YYYY')}</p>`);
|
|
|
|
tableTools.draw();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#modal-tools').on('hide.bs.modal', function (event) {
|
|
|
|
$("#hide-form-tools").hide();
|
|
|
|
$("#show-form-tools").show();
|
|
|
|
if(actionHappen){
|
|
|
|
updateActivity(activityId);
|
|
|
|
}
|
|
|
|
resetFormAssignTools();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#select-tools').select2({
|
|
|
|
dropdownParent: toolsModal,
|
|
|
|
placeholder: 'Pilih tools resource',
|
|
|
|
allowClear:true,
|
|
|
|
ajax: {
|
|
|
|
url: `${base_url}tools-resource/select`,
|
|
|
|
dataType: 'json',
|
|
|
|
data: function (params) {
|
|
|
|
var query = {
|
|
|
|
search: params.term,
|
|
|
|
type: 'public',
|
|
|
|
idact:activityId
|
|
|
|
}
|
|
|
|
return query;
|
|
|
|
},
|
|
|
|
processResults: function (result) {
|
|
|
|
return {
|
|
|
|
results: $.map(result, function (item) {
|
|
|
|
// console.log("cek item", item)
|
|
|
|
return {
|
|
|
|
text: item.name,
|
|
|
|
id: item.id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
},
|
|
|
|
cache: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// click submit to add
|
|
|
|
$("#form-assign-tools").on('submit', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$('#btn-assign-tools').html('Assign...');
|
|
|
|
$('#btn-assign-tools').prop("disabled",true);
|
|
|
|
|
|
|
|
let tools_id = $("#select-tools").val();
|
|
|
|
let qty_planning = $("#select-tools-qty").val();
|
|
|
|
|
|
|
|
if(!tools_id || tools_id < 0){
|
|
|
|
gantt.alert("Please choose tools to assign!");
|
|
|
|
$('#btn-assign-tools').html('Assign');
|
|
|
|
$('#btn-assign-tools').prop("disabled",false);
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!qty_planning || qty_planning < 0){
|
|
|
|
gantt.alert("Please input qty tools!");
|
|
|
|
$('#btn-assign-tools').html('Assign');
|
|
|
|
$('#btn-assign-tools').prop("disabled",false);
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let payload = {
|
|
|
|
proyek_id: proyekId,
|
|
|
|
activity_id: activityId,
|
|
|
|
tools_id: tools_id,
|
|
|
|
qty_planning: qty_planning
|
|
|
|
}
|
|
|
|
$.ajax({
|
|
|
|
data: JSON.stringify(payload),
|
|
|
|
url: `${base_url}assign-tools/add`,
|
|
|
|
type: "POST",
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
success: function (data) {
|
|
|
|
console.log('response data', data);
|
|
|
|
if (data && data.code === 200) {
|
|
|
|
actionHappen = true;
|
|
|
|
gantt.alert("Tools Assign Success!");
|
|
|
|
tableTools.draw();
|
|
|
|
resetFormAssignTools();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gantt.alert({type: "error", text: data.message});
|
|
|
|
$('#btn-assign-tools').html('Assign');
|
|
|
|
$('#btn-assign-tools').prop("disabled",false);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFormAssignTools();
|
|
|
|
},
|
|
|
|
error: function (data) {
|
|
|
|
gantt.alert("Tools Assign Failed, try again later!");
|
|
|
|
resetFormAssignTools();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// delete from row
|
|
|
|
$("#table-tools").on("click", ".btn-tools-delete", function() {
|
|
|
|
let id = $(this).data('id');
|
|
|
|
var box = gantt.confirm({
|
|
|
|
text: "Tools resource will be deleted from activity, continue?",
|
|
|
|
ok:"Delete",
|
|
|
|
cancel:"Cancel",
|
|
|
|
callback: function(result){
|
|
|
|
if(result){
|
|
|
|
deleteToolsAssign(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|