NB. create_response_message_to_GET_method_jconsole.ijs
NB. making_of_app_def_file_jconsole_2023_08_01_english
NB. making of definition file for adding web GUI to your J function
NB. (c)2023 Yuji Suda


NB. create_response_message_to_GET_method_part_1_jconsole.ijs

NB. fixed part 1 start

NB. クライアントからのHTTPリクエスト GET method に応答するHTTPレスポンスメッセージを用意する

NB. クライアントのGET methodへの応答として HTTP レスポンスメッセージを作成する
NB. ---------------------------------------------------------------------------------
prepare_http_response_message_to_GET_method =: 3 : 0

NB. HTTPのステータスラインとレスポンスヘッダーフィールドを作る

http_response_status_and_header_field =. prepare_http_response_status_and_header_field 0

NB. HTTPのボディをhtml form documentとして用意する

NB. fixed part 1 end

TEXTBOX_90_VALUE =: 'test_app'
TEXTBOX_91_VALUE =: 'Your HTML Title'
TEXTBOX_92_VALUE =: 'Describe what this document is here'
CHECKBOX_00_VALUE =: ''
DROPDOWN_00_VALUE =: 'VERTICAL'
TEXTBOX_00_VALUE =: '20'
TEXTBOX_01_VALUE =: 'txt00Label '
TEXTBOX_02_VALUE =: 'txt00Value'
CHECKBOX_10_VALUE =: ''
DROPDOWN_10_VALUE =: 'VERTICAL'
TEXTBOX_10_VALUE =: '20'
TEXTBOX_11_VALUE =: 'txt01Label '
TEXTBOX_12_VALUE =: 'txt01Value'
CHECKBOX_20_VALUE =: ''
DROPDOWN_20_VALUE =: 'VERTICAL'
TEXTBOX_20_VALUE =: '20'
TEXTBOX_21_VALUE =: 'txt02Label '
TEXTBOX_22_VALUE =: 'tzt02Value'
CHECKBOX_30_VALUE =: ''
DROPDOWN_30_VALUE =: 'VERTICAL'
TEXTBOX_30_VALUE =: '150'
TEXTBOX_31_VALUE =: '20'
TEXTBOX_32_VALUE =: 'txa00Label '
TEXTBOX_33_VALUE =: 'txa00Value'
CHECKBOX_40_VALUE =: ''
DROPDOWN_40_VALUE =: 'VERTICAL'
TEXTBOX_40_VALUE =: 'chk00Label '
TEXTBOX_41_VALUE =: 'chk00Value'
CHECKBOX_50_VALUE =: ''
DROPDOWN_50_VALUE =: 'VERTICAL'
TEXTBOX_50_VALUE =: 'chk01Label '
TEXTBOX_51_VALUE =: 'chk01Value'
CHECKBOX_60_VALUE =: ''
DROPDOWN_60_VALUE =: 'VERTICAL'
TEXTBOX_60_VALUE =: 'drp00ControlLabel '
TEXTBOX_61_VALUE =: 'drp001ItemLabel'
TEXTBOX_62_VALUE =: 'drp001Value'
TEXTBOX_63_VALUE =: 'drp002ItemLabel'
TEXTBOX_64_VALUE =: 'drp002Value'
TEXTBOX_65_VALUE =: 'drp003ItemLabel'
TEXTBOX_66_VALUE =: 'drp003Value'
CHECKBOX_70_VALUE =: ''
DROPDOWN_70_VALUE =: 'VERTICAL'
TEXTBOX_70_VALUE =: '3'
TEXTBOX_71_VALUE =: 'chl00ControlLabel '
TEXTBOX_72_VALUE =: 'chl001ItemLabel'
TEXTBOX_73_VALUE =: 'chl001Value'
TEXTBOX_74_VALUE =: 'chl002ItemLabel'
TEXTBOX_75_VALUE =: 'chl002Value'
TEXTBOX_76_VALUE =: 'chl003ItemLabel'
TEXTBOX_77_VALUE =: 'chl003Value'
CHECKBOX_80_VALUE =: ''
DROPDOWN_80_VALUE =: 'HORIZONTAL'
TEXTBOX_80_VALUE =: 'rad00ControlLabel '
TEXTBOX_81_VALUE =: 'rad001ItemLabel'
TEXTBOX_82_VALUE =: 'rad001Value'
TEXTBOX_83_VALUE =: 'rad002ItemLabel'
TEXTBOX_84_VALUE =: 'rad002Value'
TEXTBOX_85_VALUE =: 'rad003ItemLabel'
TEXTBOX_86_VALUE =: 'rad003Value'
TEXTAREA_00_VALUE =: 'NB.define your J function(s) which will be used in YOUR_JOB function'
TEXTAREA_01_VALUE =: 'NB. contents of this textarea will be saved in try. block of YOUR_JOB function'

NB. create_response_message_to_GET_method_part_2_jconsole.ijs

NB. fixed part 2 start

NB.MSG_FROM_SERVER =: '漢字コード(Kanji code) ->', ENCODING_CODE, ' '
MSG_FROM_SERVER =: 'character encoding code: ', ENCODING_CODE, ' '

html_form_doc =. make_html_form_doc 0

NB. 完成した html_docのバイト数を数える
byteCount =. $ html_form_doc

NB. クライントへ送信するレスポンスhttpメッセージを完成させる
NB. HTTPプロトコル上、html_docの前に空行が必要
http_response_status_and_header_field, (":byteCount), CRLF, CRLF, html_form_doc
)

NB. httpメッセージに添付するhtml_form_docの作成
NB. この関数をコールする前に、テキストボックス、テキストエリアの値の設定は必須
NB. ---------------------------------------------------------------------------------
make_html_form_doc =: 3 : 0

NB. まずHTMLのヘッダー部分 HTML_HEADER_PART を作成
make_html_header_part 0

NB. フォーム部品を記述

NB. fixed part 2 end


NB. create_response_message_to_GET_method_part_3_jconsole.ijs

NB. fixed part 3 start

NB. 以上でフォーム部品の定義完了

NB. html_docの生成

html_doc =. ''
html_doc =. html_doc, HTML_HEADER_PART

define_html_code_for_controls_based_on_plan_ijs 0

NB. fixed part 3 end
html_doc =. html_doc, rff NEW_APP_DIR, '/', 'auto_written_html_src_jconsole.ijs'
NB. create_response_message_to_GET_method_part_4_jconsole.ijs

NB. fixed part 4 start

NB. add response_image.bmp link ... for possible expressiion of form result as bmp image
NB. default response_image.bmp is always initialized as orange dot at the beginning of execute_your_job function

if. RESPONSE_IMG_FLG = 1 do.
     IMAGE_BMP =: '<hr>server response image display region<br><iframe id="iftest" title="img" width="', IFRAME_SIZE_W, '" height="', IFRAME_SIZE_H, '" frameborder="', IFRAME_BORDER, '" src="response_image.bmp" ></iframe>', CRLF
     NB. IMAGE_BMP =: '<hr>サーバー応答イメージ表示エリア<br><iframe id="iftest" title="img" width="', IFRAME_SIZE_W, '" height="', IFRAME_SIZE_H, '" frameborder="', IFRAME_BORDER, '" src="response_image.bmp" ></iframe>', CRLF
     NB. IMAGE_BMP =: '<img src="response_image.bmp" border="2" alt="Response_Image"><hr>', CRLF
     NB. IMAGE_BMP =: '<img src="response_image.bmp" width="1000" height="1000" border="2" alt="Response_Image"><hr>', CRLF
     NB. IMAGE_BMP =: IMAGE_BMP, '<a href="/response_image.bmp" target="_blank">別タブで表示</a>',CRLF
else.
     IMAGE_BMP =: ''
end.

TXA_99 =: '<hr>server reply message display region<hr><textarea name="textarea99" cols="100" rows="5">'
NB. TXA_99 =: '<hr>サーバーメッセージ表示エリア<hr><textarea name="textarea99" cols="100" rows="5">'
TXA_99 =: TXA_99, MSG_FROM_SERVER, '</textarea>', CRLF

NB.PRE_00 =: '<hr><PRE>サーバーメッセージ表示エリア', CRLF, CRLF, MSG_FROM_SERVER, '</PRE><hr>', CRLF
PRE_00 =: '<hr><PRE>server reply message display region', CRLF, CRLF, MSG_FROM_SERVER, '</PRE><hr>', CRLF

if. MSG_FROM_SERVER_FLG -: 'TXA_99' do.
    html_doc =. html_doc, IMAGE_BMP, RADIO_99, SEND_BUTTON, TXA_99
    NB. html_doc =. html_doc, TXA_99, RADIO_99, SEND_BUTTON, IMAGE_BMP
    NB. html_doc =. html_doc, TXA_99, IMAGE_BMP, RADIO_99, SEND_BUTTON
    NB. html_doc =. html_doc, TXA_99, RADIO_99, SEND_BUTTON
end.
if. MSG_FROM_SERVER_FLG -: 'PRE_00' do.
    html_doc =. html_doc, IMAGE_BMP, RADIO_99, SEND_BUTTON, PRE_00
    NB. html_doc =. html_doc, PRE_00, RADIO_99, SEND_BUTTON, IMAGE_BMP
    NB. html_doc =. html_doc, PRE_00, IMAGE_BMP, RADIO_99, SEND_BUTTON
    NB. html_doc =. html_doc, PRE_00, RADIO_99, SEND_BUTTON
end.

NB. 合体時は、RADIO_99(サーバー制御用ラジオボタン)とSEND_BUTTON(送信ボタン)は必須

html_doc =. html_doc, FORM_END, BODY_END, HTML_END
)

NB. End of file

NB. fixed part 4 end
