// Upload Document Activity const DOCUMENT_UPLOAD_URL = `${base_url}document-activity/upload`; const DOCUMENT_DOWNLOAD_URL = (id) => `${base_url}document-activity/download/${id}/${company_id}`; const DOCUMENT_SEARCH_URL = `${base_url}document-activity/search`; const DOCUMENT_DELETE_URL = (id, company_id) => `${base_url}document-activity/delete/${id}/${company_id}`; var fileToUpload = null; $(document).ready(function() { $(".modal_add_btn_doc").on('click', function() { console.log('onclick add document'); addDocuments(); }); $("#btn_doc_submit").on('click', function() { submitDocuments(); }); $("#dokumen").on('change', function(e) { fileToUpload = e.target.files[0]; }); // $("#add_doc_form").on('submit', function(e) { // // submitDocuments(); // e.preventDefault(); // console.log(this); // var formData = new FormData(this); // console.log('formData', formData); // $.ajax({ // method: "POST", // url: DOCUMENT_UPLOAD_URL, // data: formData, // processData: false, // contentType: false, // cache: false, // success: function(msg) { // console.log('done submit comment', msg) // $("#add_doc_form").trigger("reset"); // searchDocuments(activity_id); // reload the contents // }, // error: function(xhr, status, error) { // // error handling // console.log('error document upload', xhr, status, error); // } // }); // }); $("#btn_doc_reset").on('click', function() { // $("#add_doc_form").trigger("reset"); }) $('#modal_upload_doc').on('hidden.bs.modal', function () { $("#add_doc_form").trigger('reset'); }); }); // show comments modal function showDocuments(id) { var task = gantt.getTaskBy('id', id); console.log('showComments', task); var activity = task && task.length > 0 ? task[0].text : ''; $("#activity_id").val(id); $("#upload_doc_title").text(activity); searchDocuments(id); $("#modal_upload_doc").modal('show'); } function addDocuments() { // toggle input form if ($('#add_doc_form').css("display") === 'block') { $("#add_doc_form").css({ display: "none" }); $(".modal_add_btn_doc").html('
'); } else if ($('#add_doc_form').css("display") === 'none') { $("#add_doc_form").css({ display: "block" }); $(".modal_add_btn_doc").html(' '); } } // pressing submit button (add comment) async function submitDocuments() { var activity_id = $("#activity_id").val(); var files = $("#dokumen")[0].files[0]; $('#btn_doc_submit').html('Uploading...'); $('#btn_doc_submit').prop("disabled",true); if (!files) { gantt.alert("Please insert the document file"); $('#btn_doc_submit').html('Upload'); $('#btn_doc_submit').prop("disabled",false); return; } console.log('fileToUpload', fileToUpload); var formData = new FormData; formData.append('activity_id', activity_id); formData.append('dokumen', files); formData.append('company_id',company_id); if (activity_id !== '' && dokumen !== '') { const result = await axiosInstance .post(DOCUMENT_UPLOAD_URL, formData) .then(res => res) .catch((error) => error.response); if(result && result.status==200){ console.log('done upload doc', result) gantt.alert("Upload Success"); $("#add_doc_form").trigger("reset"); $('#btn_doc_submit').html('Upload'); $('#btn_doc_submit').prop("disabled",false); searchDocuments(activity_id); // reload the contents }else{ console.log('failed upload'); gantt.alert({type: "error", text: "Upload Failed"}); $('#btn_doc_submit').html('Upload'); $('#btn_doc_submit').prop("disabled",false); } } else { gantt.alert("Please insert the document file"); $('#btn_doc_submit').html('Upload'); $('#btn_doc_submit').prop("disabled",false); } } // generate comment list function searchDocuments(activity_id) { var payload = { "paging": { "start": 0, "length": 10 }, "columns": [ { "name": "activity_id", "logic_operator": "=", "value": activity_id, "operator": "AND" } ], // "joins": [{ "name": "m_proyek", "column_join": "proyek_id", "column_results": ["kode_sortname", "nama"] }], "orders": { "columns": [ "id" ], "ascending": false } } $.ajax({ method: "POST", url: DOCUMENT_SEARCH_URL, dataType: "json", data: JSON.stringify(payload) }) .done(function( msg ) { console.log('done search documents', msg) var documents = msg && msg.data; // var contents = ''; // if (documents.length > 0) { // contents += '