-
Notifications
You must be signed in to change notification settings - Fork 3
/
join.js
192 lines (187 loc) · 8.94 KB
/
join.js
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
186
187
188
189
190
191
192
let p = document.getElementById("pp");
let cancel = document.getElementById("cancel");
let join = document.getElementById("join");
function click_cancel() {
// open("./index.html");
close();
}
function click_join() {
let teacher_id = localStorage.getItem("teacher_id");
let id = localStorage.getItem("id"); //로그인한 학생의
let timestamp = localStorage.getItem("timestamp");
let userName = localStorage.getItem("name");
let classfication = localStorage.getItem("classfication");
let flag = false;
db.collection("teachers")
.doc(teacher_id)
.collection("teaching")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
if (doc.id == id) {
flag = true; //이미 신청 했었음.
}
});
})
.then(() => {
if (flag) {
alert(`이미 신청 했습니다.`);
} else
db.collection("board")
.doc(teacher_id)
.collection("register_board")
.get()
.then((querySnapshot) => {
// console.log(`1`);
querySnapshot.forEach((doc) => {
if (doc.id == timestamp) {
console.log(`matched : ${timestamp}`);
let cnt = doc.data().count;
let max = doc.data().recruitment_number;
if (cnt >= max) {
alert(
`모집인원${max}명이 충족되었습니다. 신청 불가합니다.`
);
} else {
cnt++;
// $($tr).append($text);
db.collection("board")
.doc(teacher_id)
.collection("register_board")
.doc(doc.id)
.update({
count: cnt,
});
// alert("complete");
}
}
});
})
.then(() => {
let img_update = false;
// console.log(`2`);
db.collection("board")
.doc("main")
.collection("boards")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
if (doc.id == timestamp) {
// console.log(`matched : ${timestamp}`);
let cnt = doc.data().count;
let max = doc.data().recruitment_number;
if (cnt >= max) {
// img_update = true;
} else {
cnt++;
if (cnt >= max) img_update = true;
db.collection("board")
.doc("main")
.collection("boards")
.doc(doc.id)
.update({
count: cnt,
})
.then(() => {
db.collection("teachers")
.doc(teacher_id)
.collection("teaching")
.doc(id)
.set({
name: userName,
star_check: false,
report_check: false,
});
})
.then(() => {
// console.log("3");
alert("신청되었습니다.");
db.collection("students")
.doc(id)
.collection("join")
.doc(teacher_id)
.set({
timestamp:
timestamp,
})
.then(() => {
opener.document.location.reload();
console.log(
`reload`
);
close();
});
// open("./index.html");
});
}
}
});
})
.then(() => {
console.log("mmm1");
localStorage.setItem("alert", true);
opener.document.getElementById(
"alert_icon"
).src = "./images/is_notification.png";
});
});
});
}
function init() {
$(document).ready(function () {
let classfication = localStorage.getItem("classfication");
if (classfication == "teacher") {
join.style.display = "none";
} else {
}
let teacher_id = localStorage.getItem("teacher_id");
let timestamp = localStorage.getItem("timestamp");
let name = localStorage.getItem("name");
console.log(timestamp);
p.innerHTML = timestamp;
db.collection("board")
.doc(teacher_id)
.collection("register_board")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
if (doc.id == timestamp) {
// console.log(`matched : ${timestamp}`);
$tr = $(`<tr class="tr"></tr>`);
$("tbody").append($tr);
$title = $(
`<td id="${
doc.id
}" class="join_title" style="color : blue">${
doc.data().title
}</td>`
);
$count = doc.data().count;
$recruitment = $(
`<td>${$count}/${
doc.data().recruitment_number
}</td>`
);
// $recruitment = $(
// `<td>${doc.data().recruitment_number}</td>`
// );
$author = $(`<td>${doc.data().author}</td>`);
$date = $(`<td>${doc.data().date}</td>`);
$term = $(`<td>${doc.data().term}</td>`);
// $text = $(`<td>${doc.data().text}</td>`);
$($tr).append($title);
$($tr).append($recruitment);
$($tr).append($author);
$($tr).append($date);
$($tr).append($term);
let text = document.getElementById("text");
text.innerHTML = `${doc.data().text}`;
// $($tr).append($text);
}
});
});
});
}
init();
cancel.addEventListener("click", click_cancel);
join.addEventListener("click", click_join);