File size: 8,722 Bytes
8e11898
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Duty Roster Calendar</title>
<style>

  body {

    font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;

    background: linear-gradient(35deg, rgb(4, 0, 0), #00ddff);

    padding: 0;

    margin: 0;

    color: #fff;

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

    height: 100vh;

    overflow: hidden;

  }



  h1 {

    text-align: center;

    margin: 20px 0;

    color: #fff;

    font-size: 48px;

    font-weight: bold;

    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);

  }



  #calendar-controls {

    display: flex;

    justify-content: center;

    align-items: center;

    margin: 20px 0;

    gap: 10px;

  }



  #calendar-controls select {

    padding: 15px;

    font-size: 18px;

    background-color: #171818;

    border: none;

    border-radius: 5px;

    color: #fdfbfb;

    font-weight: bold;

    width: 500px;

  }



  #calendar {

    display: grid;

    grid-template-columns: repeat(7, 1fr);

    gap: 5px;

    padding: 10px;

    background-color: rgba(0, 0, 0, 0.7);

    border-radius: 10px;

    width: 95%;

    height: 75vh;

    overflow-y: auto;

  }



  .calendar-day {

    padding: 40px;

    background-color: rgba(255, 255, 255, 0.1);

    border-radius: 10px;

    position: relative;

    text-align: center;

    font-size: 24px;

    font-weight: bold;

    cursor: pointer;

    transition: transform 0.3s, box-shadow 0.3s;

    color: #05d9ff;

  }



  .calendar-day:hover {

    transform: scale(1.05);

    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);

  }



  .calendar-day.duty {

    background-color: rgba(0, 0, 0, 0.5);

  }



  .calendar-day .duty-text {

    margin-top: 20px;

    background-color: rgba(255, 255, 255, 0.2);

    padding: 10px;

    border-radius: 5px;

    font-size: 24px;

    color: #05d9ff;

    font-weight: bold;

  }



  .day-header {

    background-color: rgba(0, 0, 0, 0.3);

    font-weight: bold;

  }



  .modal {

    display: none;

    position: fixed;

    top: 50%;

    left: 50%;

    transform: translate(-50%, -50%);

    background-color: rgba(7, 3, 0, 0.9);

    padding: 30px;

    border-radius: 10px;

    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);

    z-index: 1000;

    width: 300px;

    text-align: center;

  }



  .modal.show {

    display: block;

  }



  .modal h2 {

    margin-bottom: 20px;

    color: #fbf7f7;

  }



  .modal input[type="text"] {

    width: calc(100% - 20px);

    padding: 10px;

    margin-bottom: 20px;

    border-radius: 5px;

    border: 1px solid #ccc;

    font-size: 16px;

  }



  .modal button {

    padding: 12px 24px;

    background-color: #3498db;

    color: #fff;

    border: none;

    border-radius: 5px;

    cursor: pointer;

    transition: background-color 0.3s;

    font-size: 18px;

    font-weight: bold;

  }



  .modal button:hover {

    background-color: #2980b9;

  }



  .modal-close {

    position: absolute;

    top: 10px;

    right: 10px;

    cursor: pointer;

    font-size: 20px;

    color: #333;

  }

</style>
</head>
<body>

<h1>Duty Allocation</h1>

<div id="calendar-controls">
  <select id="year-select"></select>
  <select id="month-select"></select>
</div>

<div id="calendar"></div>

<div id="dutyModal" class="modal">
  <span class="modal-close" onclick="closeModal()">&times;</span>
  <h2>Enter Duty</h2>
  <input type="text" id="dutyInput" placeholder="Enter duty">
  <button onclick="saveDuty()">Save</button>
</div>

<script>

  // Get current date

  const today = new Date();

  let currentMonth = today.getMonth();

  let currentYear = today.getFullYear();

  let activeDayElement = null;



  const monthNames = ["January", "February", "March", "April", "May", "June", 

                      "July", "August", "September", "October", "November", "December"];



  // Populate year and month dropdowns

  function populateYearMonthSelectors() {

    const yearSelect = document.getElementById('year-select');

    const monthSelect = document.getElementById('month-select');



    for (let year = currentYear - 10; year <= currentYear + 10; year++) {

      const option = document.createElement('option');

      option.value = year;

      option.textContent = year;

      if (year === currentYear) option.selected = true;

      yearSelect.appendChild(option);

    }



    monthNames.forEach((month, index) => {

      const option = document.createElement('option');

      option.value = index;

      option.textContent = month;

      if (index === currentMonth) option.selected = true;

      monthSelect.appendChild(option);

    });

  }



  // Render the calendar

  function renderCalendar(month, year) {

    const calendar = document.getElementById('calendar');

    calendar.innerHTML = ''; // Clear previous calendar



    const firstDay = new Date(year, month).getDay();

    const daysInMonth = 32 - new Date(year, month, 32).getDate();



    // Days of the week

    const daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

    daysOfWeek.forEach(day => {

      const dayElement = document.createElement('div');

      dayElement.textContent = day;

      dayElement.classList.add('calendar-day', 'day-header');

      calendar.appendChild(dayElement);

    });



    // Add empty cells for days of the previous month

    for (let i = 0; i < firstDay; i++) {

      const emptyCell = document.createElement('div');

      emptyCell.classList.add('calendar-day');

      emptyCell.style.backgroundColor = 'transparent';

      calendar.appendChild(emptyCell);

    }



    // Add the days of the current month

    for (let day = 1; day <= daysInMonth; day++) {

      const dayElement = document.createElement('div');

      dayElement.classList.add('calendar-day');

      dayElement.textContent = day;

      dayElement.addEventListener('click', () => openModal(dayElement));

      calendar.appendChild(dayElement);

    }



    // Check if there are duties for the current day and alert

    checkTodayDuty();

  }



  // Open modal to enter duty

  function openModal(dayElement) {

    activeDayElement = dayElement;

    const modal = document.getElementById('dutyModal');

    modal.classList.add('show');

  }



  // Close modal

  function closeModal() {

    const modal = document.getElementById('dutyModal');

    modal.classList.remove('show');

  }



  // Save duty

  function saveDuty() {

    const dutyInput = document.getElementById('dutyInput');

    const dutyText = dutyInput.value.trim();

    if (dutyText !== '') {

      activeDayElement.classList.add('duty');

      const dutyElement = document.createElement('p');

      dutyElement.classList.add('duty-text');

      dutyElement.textContent = dutyText;

      activeDayElement.innerHTML = activeDayElement.textContent.split('\n')[0]; // Keep only the day number

      activeDayElement.appendChild(dutyElement);

      dutyInput.value = '';

      closeModal();

      saveDutyToLocal(activeDayElement.dataset.date, dutyText); // Saving duty to local storage

    } else {

      alert('Please enter a duty.');

    }

  }



  // Save duty to local storage

  function saveDutyToLocal(date, duty) {

    // You can customize this function to save duty details to local storage

    const dutyData = {

      date: date,

      duty: duty

    };

    localStorage.setItem('dutyData', JSON.stringify(dutyData));

  }



  // Check if there are duties for the current day and alert

  function checkTodayDuty() {

    const today = new Date();

    const currentDay = today.getDate();

    const currentMonth = today.getMonth();

    const currentYear = today.getFullYear();

    const activeDay = document.querySelector(`.calendar-day:not(.day-header)[data-date="${currentYear}-${currentMonth + 1}-${currentDay}"]`);

    if (activeDay && activeDay.querySelector('.duty-text')) {

      alert(`You have a duty today:\n${activeDay.querySelector('.duty-text').textContent}`);

    }

  }



  // Handle month and year change

  document.getElementById('year-select').addEventListener('change', (e) => {

    currentYear = parseInt(e.target.value);

    renderCalendar(currentMonth, currentYear);

  });



  document.getElementById('month-select').addEventListener('change', (e) => {

    currentMonth = parseInt(e.target.value);

    renderCalendar(currentMonth, currentYear);

  });



  // Initial setup

  populateYearMonthSelectors();

  renderCalendar(currentMonth, currentYear);

</script>

</body>
</html>