LoginSignup
1
0

M5_1.html

Last updated at Posted at 2024-03-15
M5_1.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>入力フォーム</title>
    <style>
        label {
            display: block;
            margin-bottom: 8px;
            white-space: nowrap;
        }

        textarea {
            width: 500px;
            height: 800px;
            margin-bottom: 16px;
        }

        li {
            float: left;
            list-style: none;
            padding: 8px;
        }

        /* #display_block {
            display: block;
        } */
    </style>
</head>
<body>
    <div>
        <label for="inputText">【JNDI名】</label>
    </div>
    <div>
        &nbsp;jdbc/<input id="inputText">
    </div>
    <div>
        <br>
        <div>【DBスキーマ名】</div>
        <label for="Schema">スキーマを入力or選択</label>
        <input list="SchemaList" id="Schema" name="Schema" />
        <datalist id="SchemaList">
            <option value="BUNSHO"></option>
            <option value="DOC_MANAGER"></option>
            <option value="EG_USER"></option>
            <option value="ACCMGR"></option>
            <option value="DP_USER"></option>
        </datalist>
    </div>
    <div>
        <div>
            <p id="checkList">【追加項目】</p>
        </div>
        <form name="'checkboxForm">
          <div>
            <input type="checkbox" name="btn" id="maxTotal" onclick="btnClick2(this)" checked>maxTotal<label for="maxTotal"></label>
          </div>
           <div>
             <input type="checkbox" name="btn" id="initalSize" onclick="btnClick2(this)" checked>initalSize<label for="initalSize"></label>
          </div>
          <div>
            <input type="checkbox" name="btn" id="validationQuery" onclick="btnClick2(this)" checked>validationQuery<label for="validationQuery"></label>
          </div>
          <div>
            <input type="checkbox" name="btn" id="testOnBorrow" onclick="btnClick2(this)" checked>testOnBorrow<label for="testOnBorrow"></label>
          </div>
          <p id="checkList">【共通リソース】</p>
            <div>
              <input type="checkbox" name="btn" id="Intra_authDS" onclick="btnClick()">Intra_authDS<label for="Intra_authDS"></label>
            </div>
            <div>
              <input type="checkbox" name="btn" id="OaUtilDS" onclick="btnClick()">OaUtilDS<label for="OaUtilDS"></label>
            </div>
        </form>
    </div>
    <br>
    <button type="button" onclick="showOutput()">出力</button>
    <div>
    <button type="button" onclick="clearTextarea()">クリア</button>
    </div>
    <label for="outputText">cntext.xml</label>
    <textarea id="outputText">Resource</textarea>

    <script>
        // クラスを表すオブジェクト
        class MyClass {
            constructor(firstName, jdbcName, schemaName, endName) {
                this.firstName = firstName;
                this.jdbcName = jdbcName;
                this.schemaName = schemaName;
                this.endName = endName;
                this.maxTotal = "8";
                this.initalSize = "10";
                this.validationQuery = "select 1";
                this.testOnBorrow = "true";
                // this.buttonValues = []; // チェックボックスの値を格納するプロパティを追加
            }
            
            // 文字列を返すメソッド
            getInfo() {
                return this.firstName + '\n' + 'name="jdbc/' + this.jdbcName + '"\n' + 'type="javax.sql.DataSource"\n' + 'url="${URL};queryTimeout=90"\n' + 'driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"\n' + 'username="${USER_' + this.schemaName + '}"\n' + 'password="${PASS_' + this.schemaName + '}"\n' + 'maxTotal="' + this.maxTotal + '"\n' + 'initialSize="' + this.initalSize + '"\n' + 'validationQuery="' + this.validationQuery + '"\n' + 'testOnBorrow="' + this.testOnBorrow + '"\n' + this.endName;
            }
        }



    let classesArray = [];
    const selectedClass = new MyClass('<Resource', 'Intra_authDS', 'Intra_authDS', '/>');
    const selectedClass2 = new MyClass('<Resource', 'OaUtilDS', 'OaUtilDS', '/>');

        
        function showOutput() {
            // 入力された input【JNDI名】を取得
            var inputTextValue = document.getElementById('inputText').value;
            
            // 入力 or 選択されたスキーマを取得
            var inputSchema = document.getElementById('Schema').value;
            
            // インスタンスのjdbcNameとschemaNameに適用
            const selectedClass = new MyClass('<Resource', inputTextValue, inputSchema, '/>');
            // インスタンスを配列の頭に追加
            classesArray.unshift(selectedClass);
            
            // 出力用の文字列を作成
            var outputValue = "";
            for (const classInstance of classesArray) {
                    outputValue += classInstance.getInfo() + '\n\n';
                    
                    // 出力
                    document.getElementById('outputText').value = outputValue;
                }           
            }
            
            function btnClick(){
                classesArray.length = 0; // 配列をリセット
             if (document.getElementById('Intra_authDS').checked) {
                 classesArray.push(selectedClass);
                 
                } if (document.getElementById('OaUtilDS').checked) {
                    classesArray.push(selectedClass2);
                    
                }
            }  

            function btnClick2(checkbox){
            if (!checkbox.checked) {
                alert('aaa');
                // チェックが外れた場合は削除
                for(let i = 0; i < classesArray.length; i++) {
                    if(classesArray[i].jdbcName === checkbox.id) {
                        classesArray.splice(i, 1);
                        // break;
                    }
                }
            // }else {
            //     alert('zzz');
            }
        }     
                //クリアボタンのメソッド
                function clearTextarea() {
                    var textareaForm = document.getElementById('outputText');
                    textareaForm.value = '';
            }
        </script>
    </body>
    </html>


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0