/** * サブミット **/ // ネームスペースを設定 window.CmnLib = {}; // HTMLエスケープ CmnLib.escapeHtml = function (str) { if (typeof str !== 'string') { return str; } // エスケープ文字 var escChars = { '&': '&', '"': '"', "'": ''', '<': '<', '>': '>' }; return str.replace(/[&"'<>]/g, function (match) { return escChars[match]; }); }; CmnLib.isSubmit = false; // 2重クリック防止用サブミット(id属性指定) CmnLib.doubleClickSubmit = function (formId) { if(!CmnLib.isSubmit) { CmnLib.isSubmit = true; $('#' + formId).submit(); } } // 画面表示が完了したタイミングで必ず2重クリック防止フラグを戻す。 window.onpageshow = function() { CmnLib.isSubmit = false; } // サブミット(id属性指定) CmnLib.submit = function (formId) { $('#' + formId).submit(); } // CSVダウンロード(id属性指定) CmnLib.csvDownload = function (formId) { $('#' + formId).submit(); } //ファイルダウンロード(ウイルスチェックなし) CmnLib.fileDownload = function (downloadUrl, bucket, filepath, filename) { var _params = $.param({bucket:bucket, filepath:filepath, filename:filename}); $.ajax({ type: 'POST', url: downloadUrl, data: _params, beforeSend: function(request) { request.setRequestHeader($('meta[name="_csrf_token_header"]').attr('content'), $('meta[name="_csrf_token"]').attr('content')); } }).done(function (res, status, xhr) { // ダウンロード用URLにアクセス window.location.href = res.url; }).fail(function (xhr, status, error) { }); } // ファイルダウンロード(ウイルスチェックあり) CmnLib.fileDownloadVirusCheck = function (downloadUrl, bucket, filepath, filename, table) { // バケット/ファイルパス/ファイル名をURLパラメータ化 var _params = $.param({bucket:bucket, filepath:filepath, filename:filename, table:table}); // ダウンロード中表示On処理 $('[data-remodal-id=virusCheckModal]').remodal().open(); $.ajax({ type: 'POST', url: downloadUrl, data: _params, beforeSend: function(request) { request.setRequestHeader($('meta[name="_csrf_token_header"]').attr('content'), $('meta[name="_csrf_token"]').attr('content')); } }).done(function (res, status, xhr) { CmnLib._virusCheckModalClose(); // ダウンロード用URLにアクセス window.location.href = res.url; }).fail(function (xhr, status, error) { CmnLib._virusCheckModalClose(); }); } CmnLib._virusCheckModalClose = function () { var timerid = setInterval(function(){ clearInterval(timerid); // ダウンロード中表示Off処理 $('[data-remodal-id=virusCheckModal]').remodal().close(); }, 300); } // 帳票ダウンロード CmnLib.reportDownload = function (downloadUrl, id) { var _form = $('#' + id).serialize(); $.ajax({ type: 'POST', url: downloadUrl, data: _form, beforeSend: function(request) { request.setRequestHeader($('meta[name="_csrf_token_header"]').attr('content'), $('meta[name="_csrf_token"]').attr('content')); } }).done(function (res, status, xhr) { window.location.href = res.url; }).fail(function (xhr, status, error) { }); } // ファイルアップロード CmnLib.fileUpload = function (uploadUrl) { $.ajax({ type: 'POST', url: uploadUrl, beforeSend: function(request) { request.setRequestHeader($('meta[name="_csrf_token_header"]').attr('content'), $('meta[name="_csrf_token"]').attr('content')); } }).done(function (res, status, xhr) { // 遷移先 window.location.href = res.url; }).fail(function (xhr, status, error) { }); } /** * モーダル **/ // モダール生成 CmnLib.modalCreate = function(id, title, content) { jQuery(function($) { $("." + id).attr("href", "#"); $("." + id).attr("id", ""); $("." + id).attr("onclick", "CmnLib.modalOpen('"+id+"')"); }); document.write( '
' + title + '
' + 'メンバー閲覧機能制限
' + '