This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_subject.html
179 lines (152 loc) · 4.75 KB
/
add_subject.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Add new subject</title>
<style>
@import url(https://cdn.rawgit.com/rastikerdar/vazir-font/v21.0.1/dist/font-face.css);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'vazir', 'Times New Roman', Times, serif
}
body {
height: 100vh;
padding: 30px;
width: 100%;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.hide {
visibility: hidden;
}
#container {
display: flex;
flex-direction: column;
width: 80%;
direction: rtl;
align-items: center;
justify-content: center;
max-width: 700px;
}
#wrapper {
width: 100%;
height: 40px;
border-radius: 5px;
display: flex;
/* flex-direction: row-reverse; */
align-items: center;
justify-content: center;
}
label {
width: 80%;
font-weight: bold;
margin-bottom: 10px;
}
#subject {
outline: none;
border: 2px solid black;
border-radius: 9px;
height: 100%;
width: 100%;
direction: rtl;
padding-right: 20px;
}
#details-wrapper {
display: flex;
flex-direction: column;
width: 80%;
margin-top: 5px;
}
#details-wrapper div {
height: 16px;
}
#details-wrapper label {
font-weight: lighter;
font-size: x-small;
}
#details-wrapper input {
outline: none;
border: none;
height: 100%;
direction: rtl;
padding-right: 10px;
font-weight: normal;
font-size: x-small;
}
#add {
outline: none;
font-size: xx-large;
background: none;
cursor: pointer;
display: flex;
transform: rotate(45deg);
border-style: solid;
border-width: 18px 18px 5px 5px;
border-color: transparent transparent black black;
}
#add:disabled {
opacity: .5;
}
</style>
</head>
<body>
<div class="preloader"></div>
<div id="container" class="hide">
<label for="subject">اضافهکردن موضوع</label>
<div id="wrapper">
<input type="text" name="subject" id="subject">
<!-- <button id="add" disabled>◀️</button> -->
<button id="add" disabled></button>
</div>
<div id="details-wrapper">
<div id="details-suggester">
<label for="suggester">پیشنهاد از:</label>
<input type="text" name="suggester" id="suggester">
</div>
<div id="details-resources">
<label for="resources">منابع مطالعاتی پیشنهادی:</label>
<input type="text" name="resources" id="resources">
</div>
</div>
</div>
</body>
<script>
window.onload = function () {
const $ = document.querySelectorAll.bind(document);
const container = $('#container')[0],
subjectInput = $('#subject')[0],
suggesterInput = $('#suggester')[0],
resourcesInput = $('#resources')[0],
addButton = $('#add')[0];
// show elements when page is done loading
container.classList.remove('hide');
// enable the add button
subjectInput.addEventListener('keyup', () => {
if (subjectInput.value.length == 0)
addButton.disabled = 'disabled'
else
addButton.disabled = ''
});
// add subject to DB
function addNewSubject(event) {
var data = new FormData();
data.append('subject', subjectInput.value);
data.append('suggester', suggesterInput.value);
data.append('resources', resourcesInput.value);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/subject/add', true);
xhr.onload = function () {
window.location.replace('/' + this.responseText);
};
xhr.send(data);
}
document.querySelector('#add').addEventListener('click', addNewSubject);
}
</script>
</html>