var g_ajax_post_url='/abin4/alib_server.php'; var g_alib_skey='1976'; //******************************************************************************************** //[isJSON] // // // // // // // // // first 20040915-01 // last 20040915-01 // //******************************************************************************************** function isJSON(str) { try { JSON.parse(str); } catch (e) { return false; } return true; } (function ($) { $.isJSON = function (json) { json = json.replace(/\\["\\\/bfnrtu]/g, '@'); json = json.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'); json = json.replace(/(?:^|:|,)(?:\s*\[)+/g, ''); return (/^[\],:{}\s]*$/.test(json)) } $.fn.isJSON = function () { var json = this; if (jQuery(json).is(":input")) { json = jQuery(json).val(); json = new String(json); return jQuery.isJSON(json) } else { throw new SyntaxError("$(object).isJSON only accepts fields!"); } } String.prototype.isJSON = function () { var y = this; return jQuery.isJSON(y); } }) ( jQuery ); //******************************************************************************************** //[ALIB AJAX CLASS] // // // // // // // // // first 20040915-01 // last 20040915-01 // //******************************************************************************************** /* * * */ function c_ajax() { return this; } /* * init Javascript パラメータ * */ c_ajax.prototype.java_init = function() { return alib_call('java_init'); } /* * 標準的な送信処理 * */ c_ajax.prototype.call = function(strRoute,objForm) { return new Promise((resolve,reject) => { alib_call('call',strRoute,objForm).then(function(response){ resolve(response); }); }); } /* * XMLHttpRequest * */ c_ajax.prototype.call_xhr = function(strRoute,objForm,blFormData,strTitle,callback) { if(blFormData == undefined) blFormData = false; if(strTitle == undefined) strTitle='処理実行中'; alib_xhr('call',strRoute,objForm,blFormData,strTitle,callback); /* return new Promise((resolve,reject) => { alib_xhr('call',strRoute,objForm,blFormData,strTitle).then(function(response){ resolve(response); }); }); */ } /* * 非同期サーバ長時間実行 * */ c_ajax.prototype.async = function(strRoute,objForm) { return new Promise((resolve,reject) => { alib_call('async',strRoute,objForm).then(function(response){ resolve(response); }); }); } /* * * */ c_ajax.prototype.async_status = function(async_id) { return new Promise((resolve,reject) => { alib_call('async_status',async_id).then(function(response){ resolve(response); }); }); } /* * * */ c_ajax.prototype.async_progress = function(async_id) { return new Promise((resolve,reject) => { alib_call('async_progress',async_id).then(function(response){ resolve(response); }); }); } /* * 長時間によるサーバ処理用 * ブラウザが閉じられても処理を継続 */ c_ajax.prototype.term = function(strRoute,objForm) { return new Promise((resolve,reject) => { alib_term('term',strRoute,objForm).then(function(response){ resolve(response); }); }); } /* * * */ c_ajax.prototype.check = function(strRoute,objForm,strField) { return new Promise((resolve,reject) => { alib_call('check',strRoute,objForm,strField).then(function(response){ resolve(response); }); }); }; /* * * */ /* c_ajax.prototype.check_all = function(strRoute,objForm) { //return alib_call('check_all',strAction,strExec,options,objForm); }; */ //******************************************************************************************** //実際のデータをサーバに投げる // //フォームのデータをjavascriptの配列にセットする。 //ajaxで送信する際にこの配列のデータを利用する。 // // // // // // // // // // //******************************************************************************************** function alib_call(method,strRoute,objForm) { //フォームの対応コードを入れる var fetch_method='get'; var objType = typeOf(objForm); //送信先URLの生成 var url = alib_create_url(method,strRoute); //console.log(url); switch(objType){ case 'htmlformelement': fetch_method='post'; break; case 'string': fetch_method='get'; url += "¶m=" + objForm; break; case 'object': fetch_method='get'; url += "¶m=" + JSON.stringify(objForm); break; } //send return new Promise((resolve,reject) => { if(fetch_method == 'post'){ fetch(url,{ method: 'POST', headers: {'Accept': 'application/json'}, body: new FormData(objForm), credentials: "same-origin" }).then(function(res) { return res.text(); }).then(function(text) { //テキストデータがJSONなら if(text.length > 0 && $.isJSON(text)){ var json = $.parseJSON(text); resolve(json); }else { resolve(text); } }); }else{ fetch(url,{ method: 'GET' }).then(function(res) { return res.text(); }).then(function(text) { //テキストデータがJSONなら if(text.length > 0 && $.isJSON(text)){ var json = $.parseJSON(text); resolve(json); }else { resolve(text); } }); } }); } //******************************************************************************************** //XMLHttpRequest // // // // // // // // // // // // // //******************************************************************************************** function alib_xhr(method,strRoute,objForm,blFormData,strTitle,callback) { let xhr = new XMLHttpRequest(); let fd; var url = alib_create_url(method,strRoute); if(blFormData == undefined) blFormData = false; if(blFormData){ fd = objForm; }else{ fd = new FormData(objForm); } //========================= //非同期 //========================= xhr.open("POST", url,true); //========================= //処理が完全に終了 //========================= xhr.addEventListener('load', (evt) => { console.log('** xhr: load'); let objData; let rtnData; if(isJSON(evt.target.response)){ objData = JSON.parse(evt.target.response); rtnData = evt.target.response; } if(objData != undefined){ if(objData["success"] == false){ let msg = 'ERR_CODE:' + objData["error"]["code"] + '
'; msg += objData["error"]["msg"] + '
'; objModal.changeTitle('エラーが発生しました'); objModal.changeMessage(msg); objModal.showBtnOK(); objModal.hideBtnCancel(); }else{ setTimeout(function (){ if(objModal.isOpen()){ objModal.close(); } },800); } }else{ setTimeout(function (){ if(objModal.isOpen()){ objModal.close(); } },800); } if(callback != undefined){ callback(rtnData); } }); //========================= // //========================= //xhr.addEventListener('progress', (evt) => { // console.log('** xhr: progress'); //}); //========================= //Upload Events //========================= xhr.upload.addEventListener('loadstart', (evt) => { console.log('++ xhr.upload: loadstart'); progressBar(xhr,0,strTitle); }); //========================= // //========================= xhr.upload.addEventListener('progress', (evt) => { const percent = ((evt.loaded / evt.total) * 100).toFixed(1); console.log(`++ xhr.upload: progress ${percent}%`); progressBar(xhr,percent,strTitle); }); //========================= // //========================= xhr.upload.addEventListener('abort', (evt) => { console.log('++ xhr.upload: abort (Upload aborted)'); }); //========================= // //========================= xhr.upload.addEventListener('error', (evt) => { console.log('++ xhr.upload: error (Upload failed)'); }); //========================= // //========================= xhr.upload.addEventListener('load', (evt) => { console.log('++ xhr.upload: load (Upload Completed Successfully)'); }); //========================= // //========================= xhr.upload.addEventListener('timeout', (evt) => { console.log('++ xhr.upload: timeout'); }); //========================= // //========================= xhr.upload.addEventListener('loadend', (evt) => { console.log('++ xhr.upload: loadend (Upload Finished)'); }); //========================= // //========================= xhr.send(fd); } //******************************************************************************************** //HTTPDのタイムアウトを超える時間の処理を要する実行はこちらを使用 // // // // // // // // // // // // // //******************************************************************************************** function alib_term(method,strRoute,objForm) { //送信先URLの生成 var url = alib_create_url(method,strRoute); //send return new Promise((resolve,reject) => { fetch(url,{ method: 'POST', body: new FormData(objForm), credentials: "same-origin" }).then(function(res) { // foo.txt の全体サイズ //const total = res.headers.get('content-length'); // body の reader を取得する //let reader = res.body.getReader(); //let chunk = 0; return res.text(); }); }); } //******************************************************************************************** // // // // // // // // // // // // // // //******************************************************************************************** function progressBar(xhr,percent,strTitle) { let msg = '
0%
'; if(!objModal.isOpen()){ objModal.open({ title:strTitle, message:msg, autoclose_ok:false, disp_ok:false, bgclose_lock:true, cancel:function(){ xhr.abort(); }, ok:function(){ objModal.close(); } }); }else{ let bar = document.getElementById('alib-progress-bar'); let msg = document.getElementById('alib-progress-message'); if(bar != undefined){ bar.style.width = percent + '%'; msg.innerHTML = percent + '%'; if(percent > 50){ msg.classList.add('color-percent-50'); }else{ msg.classList.add('color-percent-0'); } } } } //******************************************************************************************** //ajaxで投げる送信先のURLを生成する。 // //フォームのデータをjavascriptの配列にセットする。 //ajaxで送信する際にこの配列のデータを利用する。 // // // // // // // // // // //******************************************************************************************** function alib_create_url(method,strRoute) { if(strRoute == undefined) strRoute=''; //====================================== // //====================================== if(method == 'java_init') { val = "?skey=" + g_alib_skey; val += "&method=" + method; }else if(method == 'async_status' || method == 'async_progress') { val = "?skey=" + g_alib_skey; val += "&method=" + method; val += "&async_id=" + strRoute; }else{ val = "?skey=" + g_alib_skey; val += "&method=" + method; val += '&var=' + strRoute; } return g_ajax_post_url + val; } //******************************************************************************************** // // // // // // // // // // // // // // //******************************************************************************************** var toString = Object.prototype.toString; function typeOf(obj) { return toString.call(obj).slice(8, -1).toLowerCase(); } //******************************************************************************************** // // // // // // // // // // // // // // //******************************************************************************************** function isNumber(val){ var regexp = new RegExp(/^[0-9]+(\.[0-9]+)?$/); return regexp.test(val); } //******************************************************************************************** //ロケーション移動 // // // // // // // // // // // // // //******************************************************************************************** function jump(url){ window.location = url; } //********************************************************************************************* // 1.ajax.base.class.jsの関数を呼び出し // 2.ajax.base.class.jsにskeyを付加して送信 // 3.返信された値を戻す。 // // HTML5でのみ動作可能 // // // // // // // // // // //********************************************************************************************* //import {isObject} from "../monaco-editor-0.22.3/esm/vs/base/common/types"; var alibSite = new Object(); var formFiles = new Array(); //ファイルオブジェクト var ERROR_TITLE='[ALIB4] Error'; //エラーダイヤログのタイトル var ca = new c_ajax(); var alibReturnCallback; //呼び出し元のコールバック関数を記録する。 var stack_async_id=null; /********************************************************/ // // // // // /********************************************************/ function CALIB(skey) { //HTML5対応 if(!(window.File && window.FileReader && window.FileList && window.Blob)) { return false; } alibSite = ca.java_init(); return this; } /********************************************************/ //呼び出し、コールバックからHTMLへの反映 //帰り値はALIB依存 // // // /********************************************************/ CALIB.prototype.call = function(strRoute,objParam,beforeCallback,afterCallback) { //========================= //実行 //========================= CALIB.prototype.call_raw(strRoute,objParam,function(response){ if(beforeCallback != undefined){ beforeCallback(response); } if(response != undefined && response != null){ if(typeOf(response) == "object") { let objElem = ""; let success = response["success"]; let error = response["error"]; let element_ids = response["element_ids"]; let data = response["data"]; let ec = ""; let em = ""; //===================== //望まれる帰り値でない //===================== if (typeof success == undefined || typeof data == undefined) { return false; } //===================== //エラー判定 //===================== if (success === false) { if(response['error'] != undefined){ ec = error["code"]; em = error["msg"]; } if (!alibModalOpen) { objModal.open({ title: "エラーコード:" + ec, message: em, disp_cancel: false, ok: function () { if (afterCallback != undefined) afterCallback(response); } }); } else { alibModal.prototype.changeTitle("エラーコード:" + ec); alibModal.prototype.changeMessage(em); alibModal.prototype.hideBtnCancel(); alibModal.prototype.hideBtnYes(); alibModal.prototype.showBtnOK(); alibModal.prototype.changeCallbackOK(function(){ alibModal.prototype.close(); }); alibReturnCallback(response); } return false; } //===================== //成功(処理継続) //===================== //element_ids が存在する場合 //HTMLに帰り直のHTMLを入れる。 //HTMLにデータを反映させる if (element_ids != null) { Object.keys(element_ids).forEach(function (key) { objElem = document.getElementById(key); if (objElem != undefined) { objElem.innerHTML = element_ids[key]; //HTMLを反映 } }); } } } if(afterCallback != undefined){ afterCallback(response); } }); } /********************************************************/ //呼び出し 送信確認なし // // // // /********************************************************/ CALIB.prototype.call_raw = function(strRoute,objForm,callback) { var objPro = new Promise((resolve,reject) => { ca.call(strRoute,objForm).then(text => { resolve(text); if(callback != undefined){ callback(text); } }).catch(function (error) { reject(ERROR_TITLE + error); }); }); }; /********************************************************/ //呼び出し 旧形式 //XMLHtmlRequest // // // /********************************************************/ CALIB.prototype.call_xhr = function(strRoute,objForm,blFormData,strTitle,callback) { ca.call_xhr(strRoute,objForm,blFormData,strTitle,callback); //ca.call_xhr(strRoute,objForm,blFormData,strTitle,function(rtnData){ //console.log(rtnData); //callback(rtnData); //}); }; /********************************************************/ //呼び出し 送信確認あり // // // // /********************************************************/ CALIB.prototype.confirm = function(strRoute,objForm,callback,strMessage,strTitle) { //========================= // //========================= strMessage = (strMessage == undefined || strMessage.length == 0) ? '処理を実行します。よろしいですか?' : strMessage; strTitle = (strTitle == undefined || strTitle.length == 0) ? '処理実行確認' : strTitle; //========================= //ダイヤログ表示、動作確認 //========================= alibReturnCallback=callback; //========================= //実行 //========================= objModal.open({ title:strTitle, message:strMessage, autoclose_ok:false, ok:function(){ //========================= //実行 //========================= CALIB.prototype.call(strRoute,objForm,function(){},function(response){ alibModal.prototype.close(); alibReturnCallback(response); }); } }); }; /********************************************************/ /*保存*/ // // // // /********************************************************/ CALIB.prototype.exec = function(strRoute,objForm,callback,strMessage,strTitle) { //========================= // //========================= strMessage = (strMessage == undefined || strMessage.length == 0) ? '処理を実行します。よろしいですか?' : strMessage; strTitle = (strTitle == undefined || strTitle.length == 0) ? '処理実行' : strTitle; //========================= //データチェック //========================= //console.log("route:" + strRoute); /* CALIB.prototype.check(strRoute,objForm,'',function(res) { if (res != true) { objModal.open({title:strTitle}); //メッセージをエラーに変更 alibModal.prototype.changeCallbackOK(function () { alibModal.prototype.close(); }); alibModal.prototype.hideBtnCancel(); alibModal.prototype.hideBtnYes(); alibModal.prototype.showBtnOK(); var msg = 'route: ' + strRoute + "
\n"; msg += 'response: ' + res + "
\n"; alibModal.prototype.changeTitle(ERROR_TITLE + "(フォームデータチェック)"); alibModal.prototype.changeMessage(msg); return; } }); */ alibReturnCallback=callback; //========================= //実行 //========================= objModal.open({ title:strTitle, message:strMessage, autoclose_ok:false, ok:function(){ //========================= //実行 //========================= CALIB.prototype.call(strRoute,objForm,function(){},function(response){ alibModal.prototype.close(); alibReturnCallback(response); }); } }); }; /********************************************************/ /**/ // // // // /********************************************************/ CALIB.prototype.form = function(strRoute,objForm,callback,strMessage,strTitle) { //========================= // //========================= strMessage = (strMessage == undefined || strMessage.length == 0) ? '処理を実行します。よろしいですか?' : strMessage; strTitle = (strTitle == undefined || strTitle.length == 0) ? '処理実行確認' : strTitle; //========================= //ダイヤログ表示、動作確認 //========================= objModal.open({ title:strTitle, message:strMessage, ok:function(){ return CALIB.prototype.call_raw(strRoute,objForm,callback); } }); }; /********************************************************/ /*非同期呼び出し*/ // // // // /********************************************************/ //objALIB.async(route,param,function(){},function(){},msg,title); CALIB.prototype.async = function(strRoute,objParam,beforeCallback,afterCallback,strMessage,strTitle) { //========================= //実行 //========================= strMessage = (strMessage == undefined || strMessage.length == 0) ? '非同期処理を実行します。よろしいですか?' : strMessage; strTitle = (strTitle == undefined || strTitle.length == 0) ? '非同期処理実行確認' : strTitle; let html = '
' + '' + '
'; html = strMessage + html; //========================= //ダイヤログ表示、動作確認 //========================= objModal.open({ title:strTitle, message:html, autoclose_ok:false, ok:function(){ CALIB.prototype.async_raw(strRoute,objParam,function(res){ if(beforeCallback != undefined) beforeCallback(res); let async_id = res; if(isNumber(async_id)){ stack_async_id = async_id; document.cookie = "stack_async_id=" + async_id; let objResult = document.getElementById('alib_async_result'); if(objResult){ objResult.innerText=''; } //動作の確認処理 clearTimeout(timea); var timea = setTimeout("CALIB.prototype.async_result()",1000); } if(afterCallback != undefined) afterCallback(res); }); } }); } /********************************************************/ /**/ // // // // /********************************************************/ CALIB.prototype.async_raw = function(strRoute,objForm,callback) { var objPro = new Promise((resolve,reject) => { ca.async(strRoute,objForm).then(text => { resolve(text); if(callback != undefined) {callback(text);} }).catch(function (error) { reject(ERROR_TITLE + error); }); }); }; /********************************************************/ /**/ // // // // /********************************************************/ CALIB.prototype.async_status = function(async_id,callback) { var objPro = new Promise((resolve,reject) => { if (isNumber(async_id)) { ca.async_status(async_id).then(text => { resolve(text); //DIVには入れず単に処理をする。 if (callback != undefined) { callback(text); } }).catch(function (error) { reject(ERROR_TITLE + error); }); } }); } /********************************************************/ /**/ // // // // /********************************************************/ CALIB.prototype.async_progress = function(async_id,callback) { var objPro = new Promise((resolve,reject) => { if (isNumber(async_id)) { ca.async_progress(async_id).then(text => { resolve(text); //DIVには入れず単に処理をする。 if (callback != undefined) { callback(text); } }).catch(function (error) { reject(ERROR_TITLE + error); }); } }); } /********************************************************/ /*非同期呼び出し*/ // // // // /********************************************************/ CALIB.prototype.async_raw1 = function(act,strRoute,objForm,callback) { var blDiv=false; var objDiv=null; //============================== // //============================== var objPro = new Promise((resolve,reject) => { let async_id = strRoute; //status and progress if(act == 'status'){ if(isNumber(async_id)) { ca.async_status(async_id).then(text => { resolve(text); //DIVには入れず単に処理をする。 if (callback != undefined) { callback(text); } }).catch(function (error) { reject(ERROR_TITLE + error); }); } }else if(act == 'progress'){ if(isNumber(async_id)) { ca.async_progress(async_id).then(text => { resolve(text); //DIVには入れず単に処理をする。 if (callback != undefined) { callback(text); } }).catch(function (error) { reject(ERROR_TITLE + error); }); } }else{ //標準 ca.async(strRoute,'').then(text => { resolve(text); //DIVには入れず単に処理をする。 if(callback != undefined) {callback(text);} }).catch(function (error) { reject(ERROR_TITLE + error); }); } }); } /********************************************************/ /* Async Check Status and Progress*/ // // // // /********************************************************/ CALIB.prototype.async_result = function() { var end_flag = false; let objResult = document.getElementById('alib_async_result'); let async_id = stack_async_id; if(async_id == undefined || async_id == null) { //stack_async_id = get_cookie("stack_async_id"); } if(async_id.length == 0) return true; if(!end_flag) objResult.value = ""; CALIB.prototype.async_status(async_id,function(res){ if(res["end_ymds"] != null){ end_flag = true; } else { clearTimeout(timea); var timea = setTimeout("CALIB.prototype.async_result()",1000); } if(objResult){ //console.log(end_flag + "AAAAA"); CALIB.prototype.async_progress(async_id,function(res){ let msg=""; if(end_flag){ clearTimeout(timea); msg += "================= 処理終了 =================\n"; end_flag=false; } if(res){ if (res instanceof Array) { for(var i=0;i { ca.check(strRoute,objForm,strField).then(res => { resolve(res); if(callback != undefined){ callback(res); } }).catch(function (error) { reject(ERROR_TITLE + error); }); }); };