summaryrefslogtreecommitdiff
path: root/day9/task5/index.html
blob: 20e2a3dde7718d0f72df29c091366340b5b7fdc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<html lang="ru">

<head>
    <meta charset="utf-8">
    <title>"table_task1" table view</title>
    <style type="text/css">
        table {
            border-spacing: 0;
            padding: 0;
            border: 1px solid black;
        }

        thead > tr > th {
            padding: 10px;
            font-size: 20px;
            background-color: #6f6f6f;
        }

        td {
            padding: 5px;
            font-size: 17px;
        }

        input[type="date"], input[type="time"] {
            padding: 7px;
            font-size: 1.3em;
        }

        input {
            margin: 3px 0;
        }

        #table_operations {
            margin: 30px;
            font-size: 20px;
        }

        .odd { background-color: #dedede; }
        .even { background-color: #c5c5c5; }
        .keyword { color: blue; }

    </style>
</head>

<body onload="loadDefaultOperation()">

    <div id="table_operations">
        <select onchange="typeChanged()" id="operation">
            <option>UPDATE</option>
            <option>DELETE FROM</option>
            <option>INSERT INTO</option>
        </select> `table_task1`<br>

        <form method="post" action="/update" id="operation_form">
            <div id="query"></div>
            <button type="submit">Выполнить запрос</button>
        </form>
    </div>

    <div>
        <form action="/update">
            <label> service_id <input type="text" name="service_id" disabled></label> <br>
            <label> servtype <input type="text" name="servtype"></label> <br>
            <label> subtype <input type="text" name="subtype"></label> <br>
            <label> user_id <input type="text" name="user_id"></label> <br>
            <label> referrer_user_id <input type="text" name="referrer_user_id"></label> <br>
            <label>
                state
                <select name="state">
                    <option>N</option>
                    <option>A</option>
                    <option>S</option>
                    <option>D</option>
                    <option>O</option>
                </select>
            </label><br>
            <label> creation_date <input type="date" name="creation_date"></label> <br>
            <label> creation_time <input type="time" name="creation_time"></label> <br>
            <label>
                creation_request_sent_date
                <input type="date" name="creation_request_sent_date">
                <input type="time" name="creation_request_sent_time">
            </label> <br>
            <label> notified_about_expiration <input type="text" name="notified_about_expiration"></label> <br>

            <button type="submit">Submit</button>
        </form>
    </div>

    <table>
        %%heading%%

        %%body%%
    </table>

    <script>
        let queryHTMLElements = {
            'UPDATE': `
                <span class="keyword">SET</span><br>

                <div id="update_set"></div>
                <button type="button" onclick="addUpdateSet()">Добавить выражение</button><br>

                <span class="keyword">WHERE</span><br>

                <div id="conditions"></div>
                <button type="button" onclick="addCondition()">Добавить условие</button>
            `,

            'DELETE FROM': `
                <span class="keyword">WHERE</span><br>

                <div id="conditions"></div>
                <button type="button" onclick="addCondition()">Добавить условие</button>
            `,

            'INSERT INTO': `
                <span class="keyword">VALUES</span><br>
            `
        };

        const DEFAULT_OPERATION = 'UPDATE';

        let expressionsCount = 0;
        let conditionsCount = 0;

        function loadDefaultOperation() {
            let query = document.getElementById('query');
            query.innerHTML = queryHTMLElements[DEFAULT_OPERATION];
        }

        function addUpdateSet() {
            let element = document.createElement('div');

            const keyName = `expression${expressionsCount}_key`;
            const valueName = `expression${expressionsCount}_value`;
            element.innerHTML = `<input type="text" name="${keyName}"> = <input type="text" name="${valueName}">,`;

            document.getElementById('update_set').appendChild(element);

            expressionsCount++;
        }

        function addCondition() {
            let element = document.createElement('div');

            const keyName = `condition${conditionsCount}_key`;
            const valueName = `condition${conditionsCount}_value`;
            element.innerHTML = `<input type="text" name="${keyName}">
                                    = <input type="text" name="${valueName}">
                                     <span class="keyword">AND</span>`;

            document.getElementById('conditions').appendChild(element);

            conditionsCount++;
        }

        function typeChanged() {
            let query = document.getElementById('query');
            let text = document.getElementById('operation').value;
            query.innerHTML = queryHTMLElements[text];

            let operationForm = document.getElementById('operation_form');
            switch (text) {
                case 'UPDATE':
                    operationForm.method = 'POST';
                    operationForm.action = '/update';
                    break;
                case 'DELETE FROM':
                    operationForm.method = 'POST';
                    operationForm.action = '/delete';
                    break;
                case 'INSERT INTO':
                    operationForm.method = 'POST';
                    operationForm.action = 'add';
                    break;
            }

            expressionsCount = 0;
            conditionsCount = 0;
        }
    </script>
</body>

</html>