var WAITING_TIME_BETWEEN_CHECKING = 10000; var waitForDataLoading = function(show){ if(show){ $('.waitScreen').jqmShow(); }else{ $('.waitScreen').jqmHide(); } }; var getQuerystring = function(key) { key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regex = new RegExp("[\\?&]" + key + "=([^&#]*)"); var qs = regex.exec(window.location.href); if(qs == null) return ''; else return qs[1].replace(/%20/g," "); }; var onlyNumberDigit = function(control, e){ var keynum; var keychar; var numcheck; if(window.event) // IE { keynum = e.keyCode; } else if(e.which) // Netscape/Firefox/Opera { keynum = e.which; } if(keynum == undefined){ if(e.keyCode == 9){ return true; } } if(keynum == 13){ return true; } if(keynum == 8){ return true; } if(keynum == undefined){ return true; } if(keynum == 45){ return false; } keychar = String.fromCharCode(keynum); numcheck = /\d/; return numcheck.test(keychar); }; var init = function(){ // Register "Open my message" event $("#btnOpenMessage").unbind().click(function(){ // Validate form data if(validateData() >= 0){ $('#tblRowMsg').css('display', ''); return; } else{ $('#tblRowMsg').css('display', 'none'); } waitForDataLoading(true); $.ajax({ url: '/secureretrieve', dataType: 'json', type: 'Post', data: {id: getQuerystring('id') ,name: $('#txtName').val() ,code: $('#txtCode').val()}, cache: false, complete: function() { //$('#messageForm').find('input[type=text]').val(''); //waitForDataLoading(false); }, success: function(response, status) { // Secure Email if(response.taskInfoKey != undefined && response.taskInfoKey != ''){ $('#messageForm').css('display', 'none'); $('.serviceTerms').css('display', 'none'); $('#pdfDownload').css('display', '') processCheckingFileAndDownloadInBE(response.taskInfoKey); } // Secure Forward else if(response.forwardLink != undefined && response.forwardLink != ''){ //$('#messageForm').css('display', 'none'); //$('.serviceTerms').css('display', 'none'); //waitForDataLoading(false); window.location.href = response.forwardLink; } // Daily Report with Secure (CO-2092) else if(response.dailyReportLink != undefined && response.dailyReportLink != ''){ $('#messageForm').css('display', 'none'); $('.serviceTerms').css('display', 'none'); $('#pdfDownload').css('display', '') // process download daily report if('pdf' == response.dailyReportExtension){ PDFObject.embed(response.dailyReportLink + '&secure=1'); } else{ window.open(response.dailyReportLink); } } else{ $('#tblRowMsg').css('display', ''); $('#validateMsg').html(response.error); waitForDataLoading(false); } }, error: function(request, status, error) { jAlert(msg_unknown_error); waitForDataLoading(false); } }); }); // Register event handler for validating Code format $('#txtCode') .keypress(function(event){ if(!onlyNumberDigit(this, event)){ event.preventDefault(); } }) .keyup(function(event){ var ret = $(this).val().replace(/[^0-9]/gi, ''); if(ret.length > 3){ $(this).val(ret.substring(0,3) + '-' + ret.substring(3,ret.length)); } }); // Register term of services event $('.styleLink').unbind().click(function() { if($('.serviceTerms').css('display') == 'none'){ $('.serviceTerms').css('display', ''); } else{ $('.serviceTerms').css('display', 'none'); } }); }; var validateData = function(){ var result = -1; if($('#txtName').val() == ''){ $('#txtName').focus(); $('#validateMsg').html(error_secure_email_name_empty); result = 0; } else if($('#txtCode').val() == ''){ $('#txtCode').focus(); $('#validateMsg').html(error_secure_email_code_empty); result = 1; } else if(!$('#chk_serviceTerms').prop('checked')){ $('#validateMsg').html(error_secure_email_term_uncheck); result = 2; } else{ $('#validateMsg').html(''); } return result; }; /** * Process check finish progress and download file (Excel/PDF/Convert PDF) * @param taskInfoKey */ function processCheckingFileAndDownloadInBE(taskInfoKey) { // Check dummy processing ExcelTemplate $.ajax({ url : '/PrintRPHandlerServlet', dataType : 'json', type : 'POST', data : { action : 'check_finish_task' ,taskInfoKey : taskInfoKey }, cache : false, complete: function() { waitForDataLoading(false); }, success : function(response, status) { // Check result download if (response.isFinish === true) { // Get link download. // Redirect into download page (using iframe) var linkDownload = response.downloadLink; if (linkDownload.indexOf('http://') === 0 || linkDownload.indexOf('https://') === 0) { // Link of Aspose's PDF // => DO NOTHING } else { var fullUrl = window.location.href; var domain = /:\/\/([^\/]+)/.exec(fullUrl)[1]; var url_server = ''; if (fullUrl.indexOf('https://') == 0) { url_server = 'https://' + domain; } else { // Default case url_server = 'http://' + domain; } linkDownload = url_server + linkDownload; } // Check if the task okie or not if (response.isErrorTaskInfo === true) { // Error occur, we will show error information $('.waiting').empty().append(response.errorMessage); return; } // Process view pdf if(response.extension == 'pdf'){ PDFObject.embed(linkDownload + '&secure=1'); // CO-1773 } else{ //$('body').empty().append(''); window.open(linkDownload); } return; } // Loop process checking finish task and download file setTimeout('processCheckingFileAndDownloadInBE("' + taskInfoKey + '")' , WAITING_TIME_BETWEEN_CHECKING); },error : function() { $('#pdfDownload').css('display', '').empty().append(msg_unknown_error); } }); };