LoginSignup
1
0

M4.html 個人用

Last updated at Posted at 2024-03-11
M4.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;
        }
    </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="btnClick()" checked>maxTotal<label for="maxTotal"></label>
          </div>
           <div>
             <input type="checkbox" name="btn" id="initalSize" onclick="btnClick()" checked>initalSize<label for="initalSize"></label>
          </div>
          <div>
            <input type="checkbox" name="btn" id="validationQuery" onclick="btnClick()" checked>validationQuery<label for="validationQuery"></label>
          </div>
          <div>
            <input type="checkbox" name="btn" id="testOnBorrow" onclick="btnClick()" 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>
    <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 = "";
                this.initalSize = "";
                this.validationQuery = "";
                this.testOnBorrow = "";
                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;
            }
        }

        // インスタンスを生成
        const CLASS1 = new MyClass('<Resource','', '', '/>');

        function showOutput() {
            // 入力された input【JNDI名】を取得
            var inputTextValue = document.getElementById('inputText').value;
            alert(inputTextValue);

            // 入力 or 選択されたスキーマを取得
            var inputSchema = document.getElementById('Schema').value;
            alert(inputSchema);

            // インスタンスのjdbcNameとschemaNameに適用
            CLASS1.jdbcName = inputTextValue;
            CLASS1.schemaName = inputSchema;

            // 選択されたクラスのインスタンスを取得
            let selectedValue = CLASS1;

            if (selectedValue) {
                // チェックボックスの値をインスタンスに設定
                selectedValue.buttonValues = getCheckedValues();
                // 追加の属性をインスタンスに設定
                selectedValue.maxTotal = "30";
                selectedValue.initalSize = "1";
                selectedValue.validationQuery = "select 1";
                selectedValue.testOnBorrow = "true";
                // インスタンスの情報を取得し、結果をテキストエリアに表示
                var outputValue = selectedValue.getInfo();
                document.getElementById('outputText').value = outputValue;
            } else {
                document.getElementById('outputText').value = '対応する値が見つかりませんでした。';
            }
        }

        function btnClick() {
            var checkboxes = document.getElementsByName('btn');
            checkboxes.forEach(function (checkbox) {
                if (checkbox.checked) {
                    var checkedId = checkbox.id;
                    updateCheckedValues(checkedId);
                }
            });
        }

        function updateCheckedValues(checkedId) {
            // 選択されたチェックボックスの値をbuttonValuesに追加
            CLASS1.buttonValues.push(checkedId);
        }

        function getCheckedValues() {
            // チェックされたチェックボックスの値を取得
            var checkedValues = [];
            var checkboxes = document.getElementsByName('btn');
            checkboxes.forEach(function (checkbox) {
                if (checkbox.checked) {
                    checkedValues.push(checkbox.id);
                }
            });
            return checkedValues;
        }
    </script>
</body>
</html>


1
0
1

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