-
Notifications
You must be signed in to change notification settings - Fork 1
/
selectTime.html
377 lines (338 loc) · 19.1 KB
/
selectTime.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>selectTime</title>
<link rel="stylesheet" href="css/selectTime.css" />
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
/*
여기에는 배열들이 들어가있다
selectedArray는 2차원 배열로 왼쪽에 내가 선택하는 표를 만든다
0은 선택안된거 1은 선택된거
resultArray는 2차원 배열로 오른쪽에 다른사람들이 선택한걸 종합해서 결과를 보여준다
0은 아무도 시간안되는거 1~인원수 는 그만큼 인원이 선택한거
headcount는 총 인원수이다
*/
var teamLeader=1; //0이면 리더 아님, 아니면 리더
var timeNum=7; //시간 개수 백에서 받아와야함.....
var dayNum=6; //날짜 개수
var selectedArray=new Array(timeNum);
for(var i=0;i<timeNum;i++) {
selectedArray[i]=new Array(dayNum);
for(var j=0;j<dayNum;j++) {
selectedArray[i][j]=0; //일단 다 0으로 초기화
}
}
selectedArray[2][2]=1; //테스트용으로 넣어둔거
var headcount=4; //인원수 백에서 받아와야..
var resultArray=new Array(timeNum);
for(var a=0;a<timeNum;a++) {
resultArray[a]=new Array(dayNum);
for(var b=0;b<dayNum;b++) {
resultArray[a][b]=0; //일단 다 0으로 초기화
}
}
resultArray[3][2]=1; //테스트용으로 넣어둔거
resultArray[3][3]=3; //테스트용으로 넣어둔거
///////////날짜 받아오기
var startDate="11/22/2021"; //시작하는 날짜 월/일/년도************이거만넣어주시면 감사할것같습니다
var startTime=7; //***********************시작시간! 이거만 넣어주시면 감사할것같습니당
var endTime=startTime+timeNum;
var arr=startDate.split("/");
var sDate=new Date(arr[2]+"-"+arr[0]+"-"+arr[1]); //프론트에서 처리한 시작하는날
var tempDate=new Date(arr[2]+"-"+arr[0]+"-"+arr[1]);
var eDate=new Date(tempDate.setDate(tempDate.getDate()+dayNum)); //프론트에서 만든 끝나는날
var dates = []; //날짜들 쭉 들어가는 배열
var confirmDates=[];
var days=[];
var ss_day = new Date(sDate);
var ee_day = new Date(eDate);
while (ss_day.getTime() <= ee_day.getTime()) {
var _mon_ = (ss_day.getMonth() + 1);
_mon_ = _mon_ < 10 ? '0' + _mon_ : _mon_;
var _day_ = ss_day.getDate();
_day_ = _day_ < 10 ? '0' + _day_ : _day_;
dates.push( _mon_ + '-' + _day_);
confirmDates.push(ss_day.getFullYear()+'-'+_mon_ + '-' + _day_);
var dayday; //요일
switch(ss_day.getDay()) {
case 0:dayday="일";break;
case 1:dayday="월";break;
case 2:dayday="화";break;
case 3:dayday="수";break;
case 4:dayday="목";break;
case 5:dayday="금";break;
case 6:dayday="토";break;
}
days.push(dayday);
ss_day.setDate(ss_day.getDate() + 1);
}
var times=[];
for(var i=startTime;i<startTime+timeNum;i++) {
times.push(i);
}
function clip() {
var url = '';
var textarea = document.createElement("textarea");
document.body.appendChild(textarea);
url = window.document.location.href;
textarea.value = url;
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
alert("URL이 복사되었습니다.")
}
</script>
</head>
<body>
<div class="inner">
<div class="titleBox" style="display: flex; flex-direction: column;text-align: center;">
<h1>이게 제목입니다</h1>
<span class="button gray medium" style="margin-left:700px"><a href="#" onclick="clip(); return false;" style="text-decoration: none; color:inherit; border:solid 2px #c4c4c4; border-radius: 20px; padding:5px;">URL주소복사</a></span>
</div>
<div class="timeBox">
<div class="leftTimeBox">
<div class="leftTimeHeader">
<p>안채완's Availability</p>
<div class="leftColorInfo">
<p style="background-color: #FFF7BA; margin-right:20px;">불가능한 시간</p>
<p style="background-color: #A0CD63; margin-left:20px;">가능한 시간</p>
</div>
</div>
<div id="setLeftTable"></div>
<script type="text/javascript">
/*
여기에는 왼쪽 표를 js로 그린다
신경안써도 되는파트..
*/
//테이블 생성시작
var tableAddr=new Array(timeNum+1);
var table=document.createElement("table");
table.setAttribute("id","leftTable");
table.setAttribute("border",1);
for(var i=0;i<timeNum+1;i++) {
var trString="tr";
tableAddr[i]=new Array(dayNum+1);
tableAddr[i]=document.createElement("tr");
tableAddr[i].setAttribute("id",trString+=i.toString());
for(var j=0;j<dayNum+1;j++) {
if(i==0) { //날짜넣는 맨위파트
tableAddr[0][j]=document.createElement("th");
if(j!=0) { //제일 윗줄에 날짜넣음
var tempDateText=document.createTextNode(dates[j-1]);
var tempDateText2=document.createTextNode(days[j-1]);
var dateBox=document.createElement("p");
var dateBox2=document.createElement("p");
dateBox.style.fontSize="10px";
dateBox2.style.fontSize="14px";
dateBox.appendChild(tempDateText);
dateBox2.appendChild(tempDateText2);
tableAddr[0][j].appendChild(dateBox);
tableAddr[0][j].appendChild(dateBox2);
}
} else {
if(j==0) { //시간넣는 맨왼쪽파트
tableAddr[i][0]=document.createElement("th");
if(i!=0) { //제일 왼쪽줄에 시간넣음
var tempTimeText=document.createTextNode(times[i-1]);
var timeBox=document.createElement("p");
timeBox.style.fontSize="15px";
timeBox.appendChild(tempTimeText);
tableAddr[i][0].appendChild(timeBox);
}
} else {
tableAddr[i][j]=document.createElement("td");
if(i!=0 && selectedArray[i-1][j-1]==0) { //선택안된거
tableAddr[i][j].style.backgroundColor="#FFF7BA"; //선택안한거 색상
} else {
tableAddr[i][j].style.backgroundColor="#A0CD63"; //선택한거 색상
}
tableAddr[i][j].setAttribute("id",(i-1)+" "+(j-1)); //각 칸마다 id=0 1이런식
}
}
tableAddr[i][j].setAttribute("width",40);
tableAddr[i][j].setAttribute("height",30);
tableAddr[i].appendChild(tableAddr[i][j]);
}
table.appendChild(tableAddr[i]);
}
document.getElementById("setLeftTable").appendChild(table);
//테이블 생성 완료
//클릭, 드래그로 선택 시작
$(function () {
var isMouseDown = false;
$("td").mousedown(function () {
isMouseDown = true;
//document.getElementById($(this).attr("id")).style.backgroundColor="#A0CD63";
})/*
.mouseover(function () {
if (isMouseDown) { //드래그는 시간되면 만들자......ㅠ
$(this).toggleClass("highlighted");
}
})*/
.click(function() { //일단 클릭만 만들었따..
var idString=$(this).attr("id");
var tempID=idString.split(" ");
if(selectedArray[tempID[0]][tempID[1]]==1) {
selectedArray[tempID[0]][tempID[1]]=0;
document.getElementById($(this).attr("id")).style.backgroundColor="#FFF7BA";
} else {
selectedArray[tempID[0]][tempID[1]]=1;
document.getElementById($(this).attr("id")).style.backgroundColor="#A0CD63";
}
})
/* $(document).mouseup(function () {
isMouseDown = false;
});*/
});
//클릭, 드래그로 선택 완료
</script>
</div>
<div class="rightTimeBox">
<div class="rightTimeHeader">
<p>Group's Availability</p>
<div class="colorInfoBox">
<p style="margin-right:10px;">불가능</p>
<div id="colorChart" style=" border:solid; border-width: 2px; padding:0px"></div>
<script type="text/javascript">
var colorArray=document.createElement("table");
var colorRow=document.createElement("tr");
var colorMini=new Array(headcount+1);
for(var i=0;i<headcount+1;i++) {
colorMini[i]=document.createElement("td");
colorMini[i].style.backgroundColor='rgba('+51+','+153+','+0+','+i/headcount+')';
colorMini[i].setAttribute("width",25);
colorMini[i].setAttribute("height",25);
colorRow.appendChild(colorMini[i]);
}
colorArray.appendChild(colorRow);
document.getElementById("colorChart").appendChild(colorArray);
</script>
<p style="margin-left:10px;">가능</p>
</div>
</div>
<div id="setRightTable"></div>
<script type="text/javascript">
/*
여기에는 오른쪽에 보여줄 표를 js로 그린다
신경안써도 되지않을까..
*/
//테이블 생성시작
var RtableAddr=new Array(timeNum+1);
var Rtable=document.createElement("table");
Rtable.setAttribute("id","rightTable");
Rtable.setAttribute("border",1);
for(var i=0;i<timeNum+1;i++) {
var RtrString="tr";
RtableAddr[i]=new Array(dayNum+1);
RtableAddr[i]=document.createElement("tr");
for(var j=0;j<dayNum+1;j++) {
if(i==0) { //날짜넣는 맨위파트
RtableAddr[0][j]=document.createElement("th");
if(j!=0) { //제일 윗줄에 날짜넣음
var tempDateText=document.createTextNode(dates[j-1]);
var tempDateText2=document.createTextNode(days[j-1]);
var dateBox=document.createElement("p");
var dateBox2=document.createElement("p");
dateBox.style.fontSize="10px";
dateBox2.style.fontSize="14px";
dateBox.appendChild(tempDateText);
dateBox2.appendChild(tempDateText2);
RtableAddr[0][j].appendChild(dateBox);
RtableAddr[0][j].appendChild(dateBox2);
}
} else {
if(j==0) { //시간넣는 맨왼쪽파트
RtableAddr[i][0]=document.createElement("th");
if(i!=0) { //제일 왼쪽줄에 시간넣음
var tempTimeText=document.createTextNode(times[i-1]);
var timeBox=document.createElement("p");
timeBox.style.fontSize="15px";
timeBox.appendChild(tempTimeText);
RtableAddr[i][0].appendChild(timeBox);
}
} else {
RtableAddr[i][j]=document.createElement("td");
if(resultArray[i-1][j-1]==0) {
RtableAddr[i][j].style.backgroundColor="white";
} else {
var f=resultArray[i-1][j-1]/headcount;
RtableAddr[i][j].style.backgroundColor='rgba('+51+','+153+','+0+','+f+')';
}
RtableAddr[i][j].setAttribute("id","R"+(i-1)+" "+(j-1)); //각 칸마다 id=R0 1이런식
}
}
RtableAddr[i][j].setAttribute("width",40);
RtableAddr[i][j].setAttribute("height",30);
RtableAddr[i].appendChild(RtableAddr[i][j]);
}
Rtable.appendChild(RtableAddr[i]);
}
document.getElementById("setRightTable").appendChild(Rtable);
//테이블 생성 완료
$(function () {
$("td").mouseover(function () {
var howmanyOK=$(this).attr("id").toString();
var howmany=howmanyOK.substring(1,howmanyOK.length);
var idnums=howmany.split(" ");
$(this).text(resultArray[idnums[0]][idnums[1]]).css('textAlign','center');
})
$("td").mouseout(function() {
$(this).text("");
})
});
</script>
</div>
</div>
<button type="submit" id="submit-test">선택완료</button>
<div id="onlyLeader" style="display:flex; flex-direction: row; margin-top:20px">
</div>
<script>
if(teamLeader!=0) {
var teamLeaderHTML="<form action='' style='display:flex; flex-direction: row;'><div><label for='dateConfirm'>날짜</label><select id='dateConfirm' style='margin-right:10px;'></select><label for='timeStartConfirm'>시작시간</label><select id='timeStartConfirm'></select><label for='timeStartConfirmMinute'>:</label><select id='timeStartConfirmMinute' style='margin-right:10px;'></select><label for='timeEndConfirm'>끝나는시간</label><select id='timeEndConfirm'></select><label for='timeEndConfirmMinute'>:</label><select id='timeEndConfirmMinute' style='margin-right:10px;'></select></div><div><input type='submit' value='확정하기' id='confirmButton'></div></form>";
document.getElementById("onlyLeader").innerHTML=teamLeaderHTML;
}
</script>
</div>
<script type="text/javascript">
for (var i = 0; i < confirmDates.length - 1; i++) {
var dateConfirmOps = document.createElement('option');
dateConfirmOps.innerHTML = confirmDates[i];
dateConfirmOps.value = confirmDates[i];
document.getElementById('dateConfirm').appendChild(dateConfirmOps);
}
for (var i = 0; i < times.length; i++) {
var dateConfirmOps = document.createElement('option');
dateConfirmOps.innerHTML = times[i];
dateConfirmOps.value = times[i];
document.getElementById('timeStartConfirm').appendChild(dateConfirmOps);
}
for (var i = 0; i < 61; i++) {
var dateConfirmOps = document.createElement('option');
dateConfirmOps.innerHTML = i;;
dateConfirmOps.value = i;
document.getElementById('timeStartConfirmMinute').appendChild(dateConfirmOps);
}
for (var i = 0; i < times.length; i++) {
var dateConfirmOps = document.createElement('option');
dateConfirmOps.innerHTML = times[i];
dateConfirmOps.value = times[i];
document.getElementById('timeEndConfirm').appendChild(dateConfirmOps);
}
for (var i = 0; i < 61; i++) {
var dateConfirmOps = document.createElement('option');
dateConfirmOps.innerHTML = i;
dateConfirmOps.value = i;
document.getElementById('timeEndConfirmMinute').appendChild(dateConfirmOps);
}
</script>
</body>
</html>