File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
var _fileIdx = 0;
var testInterval;
//파일업로드 드래그앤 드롭
var objDragAndDrop = $("#upload_area");
$(document).on("dragenter","#upload_area",function(e){
e.stopPropagation();
e.preventDefault();
//$(this).css('border', '2px solid #0B85A1');
});
$(document).on("dragover","#upload_area",function(e){
e.stopPropagation();
e.preventDefault();
});
/**
* @description 해당 영역에 file drop 했을 시 이벤트 발생
*/
$(document).on("drop","#upload_area",function(e){
//$(this).css('border', '2px dotted #0B85A1');
e.preventDefault();
var files = e.originalEvent.dataTransfer.files;
handleFileUpload(files,objDragAndDrop); //파일업로드
});
$(document).on('dragenter', function (e){
e.stopPropagation();
e.preventDefault();
});
$(document).on('dragover', function (e){
e.stopPropagation();
e.preventDefault();
//objDragAndDrop.css('border', '2px dotted #0B85A1');
});
$(document).on('drop', function (e){
e.stopPropagation();
e.preventDefault();
});
//파일 드래그앤드롭 종료
//단일 파일업로드
$(function(){
$('#realFileUploadButton').change(function(e){
var objUpload = $(".upload_area");
var files = $('#realFileUploadButton')[0].files;
handleFileUpload(files,objUpload); //파일업로드
if($("#realFileUploadButton").length > 0){
$("#realFileUploadButton").val(""); //파일지우기
}
});
});
//단일 파일업로드 끝
function handleFileUpload(files,obj) //업로드 function
{
//팩스 파일업로드는 1개의 파일만 가능
if($('#tbody_fiielist tr').length > 0){
alert('첨부파일은 하나만 등록 가능합니다.');
return false;
}
_fileForm2 = []; //form file data 초기화
var limitsize = 50*1024*1024; //파일 제한 체크(50개, 50MB)
var limitcount = 1;//$("input[name=limitcount]").val()*1 ;
var fileNece = true; //첨부파일필수
if($('#fileNece').length > 0){
if('N'==$('#fileNece').val()){
fileNece = false;
}
}
//엑셀 및 TXT 파일만 업로드 할수 있도록 체크하기
var fileNm = files[0].name;
fileExt = fileNm.split('.').pop().toLowerCase();
// if($.inArray(fileExt, ['txt','xls','xlsx']) == -1) {
if($.inArray(fileExt, ['hwp', 'hwpml', 'doc', 'xls', 'ppt', 'pdf', 'txt', 'docx', 'xlsx', 'pptx', 'tif', 'htm', 'html', 'jpg', 'jpeg', 'gif', 'bmp', 'gul']) == -1) {
alert('등록할 수 없는 파일입니다.');
return;
}
for (var i = 0; i < files.length; i++)
{
var fd = new FormData();
fd.append('file', files[i]);
var tmpObj = new Object();
tmpObj.name = "file_" + _fileIdx;
tmpObj.fileObj = files[i];
_fileForm2.push(tmpObj);
sendFileToServer(fd, obj, files[i], _fileIdx);
_fileIdx++;
// var totalfileSize = 0;
// $('.totalfileCount').text($('.item_file_size').length) ;
// $('.item_file_size').each(function(){
// totalfileSize += $(this).val()*1 ;
// });
// $('.totalfileSize').text(getStrFileSize(totalfileSize)) ;
}
}
/**
*
* @param {*} formData
* @param {*} obj
* @param {*} fileObj
* @param {*} _fileIdx
* @description 드래그앤 드롭 엑셀 및 텍스트 파일 서버 전송 함수
*/
function sendFileToServer(formData, obj , fileObj, _fileIdx)
{
var data = new FormData();
_fileForm2.forEach(function(obj, idx) {
if (obj) data.append("file0", obj.fileObj);
});
var url = "/web/mjon/fax/faxFileConvertAjax.do";
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: url,
data: data,
dataType:'json',
async: true,
processData: false,
contentType: false,
cache: false,
//timeout: 600000,
success: function (data) {
console.log('data : ', data);
if(data.status=="OK"){
$('#convertForm #faxConvertSeq').val(data.object.faxConvertSeq);
testInterval = setInterval(function()
{
convertChk(formData, obj , fileObj, _fileIdx);
}, 2000 );
}else{
alert(data.message);
$('.loading_layer').removeClass('active');
$('#fileUploadButton').attr('disabled',false);
}
},
error: function (e) {
alert("변환에 실패하였습니다. 확장자를 확인해 주세요.");
console.log("ERROR : ", e);
},
beforeSend : function(xmlHttpRequest) {
//로딩창 show
$('.loading_layer').addClass('active');
$('#fileUploadButton').attr('disabled',true);
},
complete : function(xhr, textStatus) {
}
});
}
/* 파일사이즈 가져오기 */
function getStrFileSize(filesize){
var sizeStr="";
var sizeKB = filesize/1024;
if(parseInt(sizeKB) > 1024){
var sizeMB = sizeKB/1024;
sizeStr = sizeMB.toFixed(2)+" MB";
}else{
sizeStr = sizeKB.toFixed(2)+" KB";
}
return sizeStr;
}
/**
* @description 파일 변환 확인
*/
function convertChk(formData, obj , fileObj, _fileIdx){
var data = new FormData(document.convertForm);
$.ajax({
type: "POST"
, url: '/web/mjon/fax/findByConvertTbStatus.do'
, data: data
, dataType: 'json'
, async: false
, processData: false
, contentType: false
, cache: false
, success: function (data) {
console.log('data : ', data);
var object = data.object
if(object.status === 3){
/**
* :: resResult ::
* 0:변환 성공
* 1:요청 파일 없음
* 2:전송 중 오류
* 3:변환 중 오류
* 4:변환 문서 내려 받기 실패
* 5:내려 받은 문서 없음
*/
if(object.resResult === 0){
$('#fileChk').val('Y');
$('#convertForm #faxConvertFilePath').val(object.faxConvertFilePath);
$('#resPage').text(object.resPage);
$('#totalEa').val(object.resPage);
alert("변환이 정상적으로 처리되었습니다.");
try{
fileUploadAreaShow(formData, obj , fileObj, _fileIdx);
}
catch(error){
console.error(error);
}
}else{
alert("변환 중 오류가 발생하였습니다. \n파일 확인 후 다시 시도해주세요.");
}
clearInterval(testInterval);
// 로딩창 제거
$('.loading_layer').removeClass('active');
$('#fileUploadButton').removeAttr('disabled');
}
}
,error: function (e) {
console.log("ERROR : ", e);
alert("관리자에게 문의해 주세요");
}
});
}
/**
* @description 팩스 발송 function
*/
function fn_faxSendData(){
var data = new FormData(document.faxSendForm);
$.ajax({
type: "POST"
, url: '/web/mjon/fax/sendData.do'
, data: data
, dataType: 'json'
, async: false
, processData: false
, contentType: false
, cache: false
, success: function (data) {
console.log('data : ', data);
if(data.status == "OK"){
$('.pop_msg_success').css({'display':'block','opacity':'1','left':'50%','top':'50%','transform':'translate(-50%,-50%)'});
$('.pop_msg_success .msg_text').html("발송 성공 : <strong>"+ tableL.getRows().length + "</strong>건의<br>팩스가 발송 되었습니다.");
}else{
alert(data.message);
}
}
,error: function (e) {
console.log("ERROR : ", e);
alert("관리자에게 문의해 주세요");
}
});
}
//파일 업로드 후 리스트에 노출
function fileUploadAreaShow(formData, obj , fileObj, _fileIdx){
$('#upload_area').hide(); //list 박스 형식 변경
$('#upload_area_list').show();
var list_html = "";
var tt = "";
list_html += '<tr class="item_'+tt+' uploaded_obj">';
list_html += '<td class="file_name"><span class="file_name_text">'+fileObj.name+'</span></td>';
list_html += '<td class="file_size"><span class="file_size_text" value='+fileObj.size+'>'+getStrFileSize(fileObj.size)+'</span></td>';
list_html += '<td class="file_date">'+getDate()+'</td>';
list_html += '<td class="file_del"><button type="button" class="btn_file_del" onclick="delete_item(this, '+_fileIdx+')" ><img src="/publish/images/content/del_img.png" alt="" /></button></td>';
list_html += '</tr>';
$('#tbody_fiielist').append(list_html);
}
//리스트에 파일이 없을 경우
function fileUploadAreaHide(){
if( $("#tbody_fiielist > [class^=item]").length == 0 ){
$('#upload_area').show();
$('#upload_area_list').hide();
}
}
/*등록 시간 가져오기 */
function getDate(){
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1 ; month.toString().length < 2 ? month = "0"+month : month;
var date = d.getDate() ; date.toString().length < 2 ? date = "0"+date : date;
var currentDate = year+"-"+month+"-"+date+" ";
var hour = d.getHours(); hour.toString().length < 2 ? hour = "0"+hour : hour;
var minutes = d.getMinutes() ; minutes.toString().length < 2 ? minutes = "0"+minutes : minutes;
var seconds = d.getSeconds() ; seconds.toString().length < 2 ? seconds = "0"+seconds : hour;
currentTime = hour+":"+minutes+":"+seconds ;
return currentDate + currentTime ;
}
/* 임시파일 삭제버튼 클릭시 */
function delete_item(obj, fileIdx){
_fileForm2.forEach(function(fobj, idx) {
_fileForm2[idx] = "";
});
$(obj).closest("tr").remove();
$('#fileChk').val('N');
$('#previewChk').val('N');
$('#convertForm #faxConvertFilePath').val('');
$('#resPage').text('0');
$('#totalEa').val('');
$('#upload_area').show();
$('#upload_area_list').hide();
}