vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | gCalendarEventViewer_ShowScheduleEditor = false; |
2 | gCalendarEventViewer_Active = false; |
||
3 | |||
4 | gCalendarEventViewer_Database = nil; |
||
5 | gCalendarEventViewer_Event = nil; |
||
6 | gCalendarEventViewer_SelectedPlayerDatabase = nil; |
||
7 | |||
8 | gCalendarEventViewer_PanelFrames = |
||
9 | { |
||
10 | "CalendarEventViewerEventFrame", |
||
11 | "CalendarEventViewerAttendanceFrame", |
||
12 | }; |
||
13 | |||
14 | gCalendarEventViewer_CurrentPanel = 1; |
||
15 | |||
16 | function CalendarEventViewer_ViewEvent(pDatabase, pEvent) |
||
17 | gCalendarEventViewer_Database = pDatabase; |
||
18 | gCalendarEventViewer_Event = pEvent; |
||
19 | gCalendarEventViewer_SelectedPlayerDatabase = gGroupCalendar_UserDatabase; |
||
20 | |||
21 | CalendarAttendanceList_SetEvent(CalendarEventViewerAttendance, pDatabase, pEvent); |
||
22 | CalendarEventViewer_UpdateControlsFromEvent(gCalendarEventViewer_Event, false); |
||
23 | |||
24 | ShowUIPanel(CalendarEventViewerFrame); |
||
25 | |||
26 | CalendarEventTitle:SetFocus(); |
||
27 | CalendarEventTitle:HighlightText(0, 100); |
||
28 | |||
29 | gCalendarEventViewer_ShowScheduleEditor = false; |
||
30 | gCalendarEventViewer_Active = true; |
||
31 | end |
||
32 | |||
33 | function CalendarEventViewer_DoneViewing() |
||
34 | if not gCalendarEventViewer_Active then |
||
35 | return; |
||
36 | end |
||
37 | |||
38 | CalendarEventViewer_Close(true); |
||
39 | end |
||
40 | |||
41 | function CalendarEventViewer_ScheduleChanged(pDate) |
||
42 | if gCalendarEventViewer_Active |
||
43 | and gCalendarEventViewer_Event.mDate == pDate then |
||
44 | CalendarAttendanceList_EventChanged(CalendarEventViewerAttendance, gCalendarEventViewer_Database, gCalendarEventViewer_Event); |
||
45 | CalendarEventViewer_UpdateControlsFromEvent(gCalendarEventViewer_Event, true); |
||
46 | end |
||
47 | end |
||
48 | |||
49 | function CalendarEventViewer_MajorDatabaseChange() |
||
50 | if gCalendarEventViewer_Active then |
||
51 | CalendarAttendanceList_EventChanged(CalendarEventViewerAttendance, gCalendarEventViewer_Database, gCalendarEventViewer_Event); |
||
52 | CalendarEventViewer_UpdateControlsFromEvent(gCalendarEventViewer_Event, true); |
||
53 | end |
||
54 | end |
||
55 | |||
56 | function CalendarEventViewer_Save() |
||
57 | -- Save attendance feedback |
||
58 | |||
59 | if EventDatabase_EventTypeUsesAttendance(gCalendarEventViewer_Event.mType) |
||
60 | and EventDatabase_PlayerIsQualifiedForEvent(gCalendarEventViewer_Event, gCalendarEventViewer_SelectedPlayerDatabase.PlayerLevel) then |
||
61 | local vPendingRSVP = EventDatabase_FindRSVPRequestData(gCalendarEventViewer_SelectedPlayerDatabase, gCalendarEventViewer_Database.UserName, gCalendarEventViewer_Event.mID); |
||
62 | local vEventRSVP = EventDatabase_FindEventRSVP(gCalendarEventViewer_Database.UserName, gCalendarEventViewer_Event, gCalendarEventViewer_SelectedPlayerDatabase.UserName); |
||
63 | local vChanged = false; |
||
64 | local vHasResponse = false; |
||
65 | local vStatus; |
||
66 | local vComment; |
||
67 | |||
68 | if not vPendingRSVP then |
||
69 | if vEventRSVP then |
||
70 | vStatus = vEventRSVP.mStatus; |
||
71 | vComment = vEventRSVP.mComment; |
||
72 | else |
||
73 | vStatus = nil; |
||
74 | vComment = ""; |
||
75 | end |
||
76 | else |
||
77 | vStatus = vPendingRSVP.mStatus; |
||
78 | vComment = vPendingRSVP.mComment; |
||
79 | end |
||
80 | |||
81 | if not vComment then |
||
82 | vComment = ""; |
||
83 | end |
||
84 | |||
85 | -- Update the status |
||
86 | |||
87 | if CalendarEventViewerYes:GetChecked() then |
||
88 | vHasResponse = true; |
||
89 | |||
90 | if vStatus ~= "Y" then |
||
91 | vStatus = "Y"; |
||
92 | vChanged = true; |
||
93 | end |
||
94 | elseif CalendarEventViewerNo:GetChecked() then |
||
95 | vHasResponse = true; |
||
96 | |||
97 | if vStatus ~= "N" then |
||
98 | vStatus = "N"; |
||
99 | vChanged = true; |
||
100 | end |
||
101 | --[[ |
||
102 | elseif vStatus ~= nil |
||
103 | and vStatus ~= "-" then |
||
104 | vStatus = "-"; |
||
105 | vChanged = true; |
||
106 | ]] |
||
107 | end |
||
108 | |||
109 | -- Update the comment |
||
110 | |||
111 | if vHasResponse then |
||
112 | local vNewComment = Calendar_EscapeString(CalendarEventViewerComment:GetText()); |
||
113 | |||
114 | if vComment ~= vNewComment then |
||
115 | vComment = vNewComment; |
||
116 | vChanged = true; |
||
117 | end |
||
118 | end |
||
119 | |||
120 | -- Add a new RSVP if it's changed |
||
121 | |||
122 | if vChanged then |
||
123 | local vRSVP = EventDatabase_CreatePlayerRSVP( |
||
124 | gCalendarEventViewer_Database, |
||
125 | gCalendarEventViewer_Event, |
||
126 | gCalendarEventViewer_SelectedPlayerDatabase.UserName, |
||
127 | gCalendarEventViewer_SelectedPlayerDatabase.PlayerRaceCode, |
||
128 | gCalendarEventViewer_SelectedPlayerDatabase.PlayerClassCode, |
||
129 | gCalendarEventViewer_SelectedPlayerDatabase.PlayerLevel, |
||
130 | vStatus, |
||
131 | vComment, |
||
132 | gGroupCalendar_PlayerGuild, |
||
133 | gGroupCalendar_PlayerGuildRank, |
||
134 | gGroupCalendar_PlayerCharacters); |
||
135 | |||
136 | EventDatabase_AddRSVP(gCalendarEventViewer_SelectedPlayerDatabase, vRSVP); |
||
137 | |||
138 | -- Update the UI |
||
139 | |||
140 | CalendarAttendanceList_EventChanged(CalendarEventViewerAttendance, gCalendarEventViewer_Database, gCalendarEventViewer_Event); |
||
141 | CalendarEventViewer_UpdateControlsFromEvent(gCalendarEventViewer_Event, false); |
||
142 | end |
||
143 | end |
||
144 | end |
||
145 | |||
146 | function CalendarEventViewer_Close(pShowScheduleEditor) |
||
147 | gCalendarEventViewer_ShowScheduleEditor = pShowScheduleEditor; |
||
148 | HideUIPanel(CalendarEventViewerFrame); |
||
149 | end |
||
150 | |||
151 | function CalendarEventViewer_OnLoad() |
||
152 | -- Tabs |
||
153 | |||
154 | PanelTemplates_SetNumTabs(this, table.getn(gCalendarEventViewer_PanelFrames)); |
||
155 | CalendarEventViewerFrame.selectedTab = gCalendarEventViewer_CurrentPanel; |
||
156 | PanelTemplates_UpdateTabs(this); |
||
157 | |||
158 | CalendarEventViewerCharacterMenu.ChangedValueFunc = CalendarEventViewer_SelectedCharacterChanged; |
||
159 | end |
||
160 | |||
161 | function CalendarEventViewer_OnShow() |
||
162 | PlaySound("igCharacterInfoOpen"); |
||
163 | |||
164 | CalendarEventViewer_ShowPanel(1); -- Always switch to the event view when showing the window |
||
165 | end |
||
166 | |||
167 | function CalendarEventViewer_OnHide() |
||
168 | PlaySound("igCharacterInfoClose"); |
||
169 | |||
170 | CalendarEventViewer_Save(); |
||
171 | |||
172 | if not gCalendarEventViewer_ShowScheduleEditor then |
||
173 | HideUIPanel(CalendarEditorFrame); |
||
174 | end |
||
175 | |||
176 | gCalendarEventViewer_Database = nil; |
||
177 | gCalendarEventViewer_Event = nil; |
||
178 | |||
179 | gCalendarEventViewer_Active = false; |
||
180 | end |
||
181 | |||
182 | function CalendarEventViewer_SelectedCharacterChanged(pMenuFrame, pValue) |
||
183 | gCalendarEventViewer_SelectedPlayerDatabase = EventDatabase_GetDatabase(pValue, false); |
||
184 | CalendarEventViewer_UpdateControlsFromEvent(gCalendarEventViewer_Event, false); |
||
185 | end |
||
186 | |||
187 | function CalendarEventViewer_UpdateControlsFromEvent(pEvent, pSkipAttendanceFields) |
||
188 | -- Update the title |
||
189 | |||
190 | CalendarEventViewerEventFrameEventTitle:SetText(EventDatabase_GetEventDisplayName(pEvent)); |
||
191 | |||
192 | -- Update the date and time |
||
193 | |||
194 | if pEvent.mTime ~= nil then |
||
195 | local vTime; |
||
196 | local vDate = pEvent.mDate; |
||
197 | |||
198 | if gGroupCalendar_Settings.ShowEventsInLocalTime then |
||
199 | vDate, vTime = Calendar_GetLocalDateTimeFromServerDateTime(pEvent.mDate, pEvent.mTime); |
||
200 | else |
||
201 | vTime = pEvent.mTime; |
||
202 | end |
||
203 | |||
204 | -- Set the date |
||
205 | |||
206 | CalendarEventViewerEventFrameDate:SetText(Calendar_GetLongDateString(vDate)); |
||
207 | |||
208 | -- |
||
209 | |||
210 | local vTimeString; |
||
211 | |||
212 | if pEvent.mDuration ~= nil |
||
213 | and pEvent.mDuration ~= 0 then |
||
214 | local vEndTime = math.mod(vTime + pEvent.mDuration, 1440); |
||
215 | |||
216 | vTimeString = string.format( |
||
217 | GroupCalendar_cTimeRangeFormat, |
||
218 | Calendar_GetShortTimeString(vTime), |
||
219 | Calendar_GetShortTimeString(vEndTime)); |
||
220 | |||
221 | else |
||
222 | vTimeString = Calendar_GetShortTimeString(vTime); |
||
223 | end |
||
224 | |||
225 | CalendarEventViewerEventFrameTime:SetText(vTimeString); |
||
226 | CalendarEventViewerEventFrameTime:Show(); |
||
227 | else |
||
228 | CalendarEventViewerEventFrameDate:SetText(Calendar_GetLongDateString(pEvent.mDate)); |
||
229 | CalendarEventViewerEventFrameTime:Hide(); |
||
230 | end |
||
231 | |||
232 | -- Update the level range |
||
233 | |||
234 | if EventDatabase_EventTypeUsesLevelLimits(pEvent.mType) then |
||
235 | if pEvent.mMinLevel ~= nil then |
||
236 | if pEvent.mMaxLevel ~= nil then |
||
237 | if pEvent.mMinLevel == pEvent.mMaxLevel then |
||
238 | CalendarEventViewerEventFrameLevels:SetText(string.format(CalendarEventViewer_cSingleLevel, pEvent.mMinLevel)); |
||
239 | else |
||
240 | CalendarEventViewerEventFrameLevels:SetText(string.format(CalendarEventViewer_cLevelRangeFormat, pEvent.mMinLevel, pEvent.mMaxLevel)); |
||
241 | end |
||
242 | else |
||
243 | if pEvent.mMinLevel == 60 then |
||
244 | CalendarEventViewerEventFrameLevels:SetText(string.format(CalendarEventViewer_cSingleLevel, pEvent.mMinLevel)); |
||
245 | else |
||
246 | CalendarEventViewerEventFrameLevels:SetText(string.format(CalendarEventViewer_cMinLevelFormat, pEvent.mMinLevel)); |
||
247 | end |
||
248 | end |
||
249 | |||
250 | CalendarEventViewerEventFrameLevels:Show(); |
||
251 | else |
||
252 | if pEvent.mMaxLevel ~= nil then |
||
253 | CalendarEventViewerEventFrameLevels:SetText(string.format(CalendarEventViewer_cMaxLevelFormat, pEvent.mMaxLevel)); |
||
254 | else |
||
255 | CalendarEventViewerEventFrameLevels:SetText(CalendarEventViewer_cAllLevels); |
||
256 | end |
||
257 | |||
258 | CalendarEventViewerEventFrameLevels:Show(); |
||
259 | end |
||
260 | |||
261 | if EventDatabase_PlayerIsQualifiedForEvent(gCalendarEventViewer_Event, gCalendarEventViewer_SelectedPlayerDatabase.PlayerLevel) then |
||
262 | CalendarEventViewerEventFrameLevels:SetTextColor(1.0, 0.82, 0); |
||
263 | else |
||
264 | CalendarEventViewerEventFrameLevels:SetTextColor(1.0, 0.2, 0.2); |
||
265 | end |
||
266 | else |
||
267 | CalendarEventViewerEventFrameLevels:Hide(); |
||
268 | end |
||
269 | |||
270 | -- Update the description |
||
271 | |||
272 | if pEvent.mDescription then |
||
273 | CalendarEventViewerDescText:SetText(Calendar_UnescapeString(pEvent.mDescription)); |
||
274 | CalendarEventViewerDescText:Show(); |
||
275 | else |
||
276 | CalendarEventViewerDescText:Hide(); |
||
277 | end |
||
278 | |||
279 | -- Update the attendance |
||
280 | |||
281 | if EventDatabase_EventTypeUsesAttendance(pEvent.mType) then |
||
282 | local vIsAttending = false; |
||
283 | local vIsNotAttending = false; |
||
284 | local vAttendanceComment = ""; |
||
285 | |||
286 | CalendarEventViewer_SetAttendanceVisible(true); |
||
287 | |||
288 | if not pSkipAttendanceFields then |
||
289 | CalendarDropDown_SetSelectedValue(CalendarEventViewerCharacterMenu, gCalendarEventViewer_SelectedPlayerDatabase.UserName); |
||
290 | |||
291 | if EventDatabase_PlayerIsQualifiedForEvent(gCalendarEventViewer_Event, gCalendarEventViewer_SelectedPlayerDatabase.PlayerLevel) then |
||
292 | CalendarEventViewer_SetAttendanceEnabled(true); |
||
293 | |||
294 | local vPendingRSVP = EventDatabase_FindRSVPRequestData(gCalendarEventViewer_SelectedPlayerDatabase, gCalendarEventViewer_Database.UserName, gCalendarEventViewer_Event.mID); |
||
295 | local vEventRSVP = EventDatabase_FindEventRSVP(gCalendarEventViewer_Database.UserName, gCalendarEventViewer_Event, gCalendarEventViewer_SelectedPlayerDatabase.UserName); |
||
296 | local vRSVP; |
||
297 | |||
298 | if vPendingRSVP then |
||
299 | vRSVP = vPendingRSVP; |
||
300 | else |
||
301 | vRSVP = vEventRSVP; |
||
302 | end |
||
303 | |||
304 | if vRSVP then |
||
305 | vIsAttending = vRSVP.mStatus == "Y" or vRSVP.mStatus == "S"; |
||
306 | vIsNotAttending = vRSVP.mStatus == "N"; |
||
307 | |||
308 | if vRSVP.mComment then |
||
309 | vAttendanceComment = Calendar_UnescapeString(vRSVP.mComment); |
||
310 | end |
||
311 | end |
||
312 | |||
313 | CalendarEventViewer_SetResponseStatus(vPendingRSVP, vEventRSVP); |
||
314 | else |
||
315 | CalendarEventViewer_SetAttendanceEnabled(false); |
||
316 | end |
||
317 | |||
318 | CalendarEventViewerYes:SetChecked(vIsAttending); |
||
319 | CalendarEventViewerNo:SetChecked(vIsNotAttending); |
||
320 | CalendarEventViewerComment:SetText(vAttendanceComment); |
||
321 | |||
322 | CalendarEventViewer_UpdateCommentEnable(); |
||
323 | end -- if not skipAttendance |
||
324 | else |
||
325 | CalendarEventViewer_SetAttendanceVisible(false); |
||
326 | end |
||
327 | |||
328 | if pEvent.mType ~= nil then |
||
329 | CalendarEventViewerEventBackground:SetTexture(Calendar_GetEventTypeIconPath(pEvent.mType)); |
||
330 | if pEvent.mType == "Birth" then |
||
331 | CalendarEventViewerEventBackground:SetVertexColor(1, 1, 1, 0.8); |
||
332 | else |
||
333 | CalendarEventViewerEventBackground:SetVertexColor(1, 1, 1, 0.19); |
||
334 | end |
||
335 | else |
||
336 | CalendarEventViewerEventBackground:SetTexture(""); |
||
337 | end |
||
338 | end |
||
339 | |||
340 | function CalendarEventViewer_UpdateCommentEnable() |
||
341 | local vEnable = CalendarEventViewerYes:GetChecked() or CalendarEventViewerNo:GetChecked(); |
||
342 | |||
343 | Calendar_SetEditBoxEnable(CalendarEventViewerComment, vEnable); |
||
344 | end |
||
345 | |||
346 | function CalendarEventViewer_SetAttendanceEnabled(pEnable) |
||
347 | Calendar_SetCheckButtonEnable(CalendarEventViewerYes, pEnable); |
||
348 | Calendar_SetCheckButtonEnable(CalendarEventViewerNo, pEnable); |
||
349 | Calendar_SetEditBoxEnable(CalendarEventViewerComment, pEnable); |
||
350 | |||
351 | if pEnable then |
||
352 | CalendarEventViewerEventFrameStatus:Show(); |
||
353 | else |
||
354 | CalendarEventViewerEventFrameStatus:Hide(); |
||
355 | end |
||
356 | end |
||
357 | |||
358 | function CalendarEventViewer_SetAttendanceVisible(pVisible) |
||
359 | if pVisible then |
||
360 | CalendarEventViewerCharacter:Show(); |
||
361 | CalendarEventViewerYes:Show(); |
||
362 | CalendarEventViewerNo:Show(); |
||
363 | CalendarEventViewerComment:Show(); |
||
364 | CalendarEventViewerEventFrameStatus:Show(); |
||
365 | CalendarEventViewerFrameTab2:Show(); |
||
366 | else |
||
367 | CalendarEventViewerCharacter:Hide(); |
||
368 | CalendarEventViewerYes:Hide(); |
||
369 | CalendarEventViewerNo:Hide(); |
||
370 | CalendarEventViewerComment:Hide(); |
||
371 | CalendarEventViewerEventFrameStatus:Hide(); |
||
372 | CalendarEventViewerFrameTab2:Hide(); |
||
373 | end |
||
374 | end |
||
375 | |||
376 | function CalendarEventViewer_CalculateResponseStatus(pPendingRSVP, pEventRSVP) |
||
377 | if pPendingRSVP then |
||
378 | return 2; |
||
379 | elseif pEventRSVP then |
||
380 | return 3; |
||
381 | else |
||
382 | return 1; |
||
383 | end |
||
384 | end |
||
385 | |||
386 | function CalendarEventViewer_SetResponseStatus(pPendingRSVP, pEventRSVP) |
||
387 | local vStatus = CalendarEventViewer_CalculateResponseStatus(pPendingRSVP, pEventRSVP); |
||
388 | CalendarEventViewerEventFrameStatus:SetText(CalendarEventViewer_cResponseMessage[vStatus]); |
||
389 | end |
||
390 | |||
391 | function CalendarEventViewer_ShowPanel(pPanelIndex) |
||
392 | if gCalendarEventViewer_CurrentPanel > 0 |
||
393 | and gCalendarEventViewer_CurrentPanel ~= pPanelIndex then |
||
394 | CalendarEventViewer_HidePanel(gCalendarEventViewer_CurrentPanel); |
||
395 | end |
||
396 | |||
397 | -- NOTE: Don't check for redundant calls since this function |
||
398 | -- will be called to reset the field values as well as to |
||
399 | -- actuall show the panel when it's hidden |
||
400 | |||
401 | gCalendarEventViewer_CurrentPanel = pPanelIndex; |
||
402 | |||
403 | -- Update the control values |
||
404 | |||
405 | if pPanelIndex == 1 then |
||
406 | -- Event panel |
||
407 | |||
408 | CalendarEventViewerParchment:Show(); |
||
409 | |||
410 | elseif pPanelIndex == 2 then |
||
411 | -- Attendance panel |
||
412 | |||
413 | CalendarEventViewerParchment:Hide(); |
||
414 | |||
415 | if EventDatabase_IsQuestingEventType(gCalendarEventViewer_Event.mType) then |
||
416 | CalendarAttendanceList_SetClassTotalsVisible(CalendarEventViewerAttendance, true, false); |
||
417 | else |
||
418 | CalendarAttendanceList_SetClassTotalsVisible(CalendarEventViewerAttendance, false, false); |
||
419 | end |
||
420 | else |
||
421 | Calendar_DebugMessage("CalendarEventViewer_ShowPanel: Unknown index ("..pPanelIndex..")"); |
||
422 | end |
||
423 | |||
424 | getglobal(gCalendarEventViewer_PanelFrames[pPanelIndex]):Show(); |
||
425 | |||
426 | PanelTemplates_SetTab(CalendarEventViewerFrame, pPanelIndex); |
||
427 | end |
||
428 | |||
429 | function CalendarEventViewer_HidePanel(pFrameIndex) |
||
430 | if gCalendarEventViewer_CurrentPanel ~= pFrameIndex then |
||
431 | return; |
||
432 | end |
||
433 | |||
434 | CalendarEventViewer_Save(); |
||
435 | |||
436 | getglobal(gCalendarEventViewer_PanelFrames[pFrameIndex]):Hide(); |
||
437 | gCalendarEventViewer_CurrentPanel = 0; |
||
438 | end |
||
439 |