vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 gCalendarEventEditor_ShowScheduleEditor = false;
2 gCalendarEventEditor_Active = false;
3  
4 gCalendarEventEditor_Database = nil;
5 gCalendarEventEditor_Event = nil;
6 gCalendarEventEditor_IsNewEvent = false;
7 gCalendarEventEditor_NewClassLimits = nil;
8  
9 gCalendarEventEditor_PreviousEventType = nil;
10  
11 gCalendarEventEditor_CurrentPanel = 1;
12 gCalendarEventEditor_UsingLocalTime = false;
13 gCalendarEventEditor_EventDate = nil;
14 gCalendarEventEditor_EventTime = nil;
15 gCalendarEventEditor_EventDateIsLocal = false;
16  
17 gGroupCalendar_cNumAttendanceItems = 12;
18 gGroupCalendar_cNumAutoConfirmAttendanceItems = 11;
19 gGroupCalendar_cNumPlainAttendanceItems = 16;
20 gGroupCalendar_cAttendanceItemHeight = 16;
21  
22 gCalendarEventEditor_PanelFrames =
23 {
24 "CalendarEventEditorEventFrame",
25 "CalendarEventEditorAttendanceFrame",
26 };
27  
28 StaticPopupDialogs["CONFIRM_CALENDAR_EVENT_DELETE"] = {
29 text = TEXT(CalendarEventEditor_cConfirmDeleteMsg),
30 button1 = TEXT(CalendarEventEditor_cDelete),
31 button2 = TEXT(CANCEL),
32 OnAccept = function() CalendarEventEditor_DeleteEvent(); end,
33 timeout = 0,
34 whileDead = 1,
35 hideOnEscape = 1
36 };
37  
38 StaticPopupDialogs["CONFIRM_CALENDAR_RSVP_DELETE"] = {
39 text = TEXT(GroupCalendar_cConfrimDeleteRSVP),
40 button1 = TEXT(CalendarEventEditor_cDelete),
41 button2 = TEXT(CANCEL),
42 OnAccept = function() CalendarEventEditor_DeleteRSVP(); end,
43 timeout = 0,
44 whileDead = 1,
45 hideOnEscape = 1
46 };
47  
48 StaticPopupDialogs["CONFIRM_CALENDAR_CLEAR_WHISPERS"] = {
49 text = TEXT(GroupCalendar_cConfirmClearWhispers),
50 button1 = TEXT(GroupCalendar_cClear),
51 button2 = TEXT(CANCEL),
52 OnAccept = function() CalendarWhisperLog_Clear(); end,
53 timeout = 0,
54 whileDead = 1,
55 hideOnEscape = 1
56 };
57  
58 function CalendarEventEditor_EditEvent(pDatabase, pEvent, pIsNewEvent)
59 gCalendarEventEditor_Database = pDatabase;
60 gCalendarEventEditor_Event = pEvent;
61 gCalendarEventEditor_IsNewEvent = pIsNewEvent;
62 gCalendarEventEditor_UsingLocalTime = gGroupCalendar_Settings.ShowEventsInLocalTime;
63 gCalendarEventEditor_NewClassLimits = nil;
64  
65 CalendarAttendanceList_SetEvent(CalendarEventEditorAttendance, pDatabase, pEvent);
66  
67 gCalendarEventEditor_EventDateIsLocal = gCalendarEventEditor_UsingLocalTime;
68  
69 if pIsNewEvent then
70 -- New events have their date in whatever time zone is
71 -- selected for display
72  
73 gCalendarEventEditor_EventDate = pEvent.mDate;
74 gCalendarEventEditor_EventTime = pEvent.mTime;
75 else
76 -- Existing events have their date in server time so
77 -- convert to a local date if necessary
78  
79 if gCalendarEventEditor_EventDateIsLocal then
80 gCalendarEventEditor_EventDate, gCalendarEventEditor_EventTime = Calendar_GetLocalDateTimeFromServerDateTime(pEvent.mDate, pEvent.mTime);
81 else
82 gCalendarEventEditor_EventDate = pEvent.mDate;
83 gCalendarEventEditor_EventTime = pEvent.mTime;
84 end
85 end
86  
87 CalendarEventEditorFrameSubTitle:SetText(Calendar_GetLongDateString(gCalendarEventEditor_EventDate));
88  
89 CalendarEventEditor_UpdateControlsFromEvent(pEvent);
90  
91 ShowUIPanel(CalendarEventEditorFrame);
92  
93 if pIsNewEvent then
94 CalendarEventTitle:SetFocus();
95 CalendarEventTitle:HighlightText();
96 else
97 CalendarEventTitle:HighlightText(0, 0);
98 end
99  
100 gCalendarEventEditor_ShowScheduleEditor = false;
101 gCalendarEventEditor_Active = true;
102 end
103  
104 function CalendarEventEditor_MajorDatabaseChange()
105 if not gCalendarEventEditor_Active then
106 return;
107 end
108  
109 if gCalendarEventEditor_UsingLocalTime ~= gGroupCalendar_Settings.ShowEventsInLocalTime then
110 gCalendarEventEditor_UsingLocalTime = gGroupCalendar_Settings.ShowEventsInLocalTime;
111  
112 gCalendarEventEditor_EventTime = CalendarEventEditor_GetTimeControlValue(CalendarEventEditorTime);
113  
114 if gCalendarEventEditor_UsingLocalTime then
115 gCalendarEventEditor_EventDate, gCalendarEventEditor_EventTime = Calendar_GetLocalDateTimeFromServerDateTime(gCalendarEventEditor_EventDate, gCalendarEventEditor_EventTime);
116 else
117 gCalendarEventEditor_EventDate, gCalendarEventEditor_EventTime = Calendar_GetServerDateTimeFromLocalDateTime(gCalendarEventEditor_EventDate, gCalendarEventEditor_EventTime);
118 end
119  
120 CalendarEventEditor_SetTimeControlValue(CalendarEventEditorTime, gCalendarEventEditor_EventTime);
121 end
122 end
123  
124 function CalendarEventEditor_EventChanged(pEvent)
125 if pEvent == gCalendarEventEditor_Event then
126 CalendarAttendanceList_EventChanged(CalendarEventEditorAttendance, gCalendarEventEditor_Database, pEvent);
127  
128 -- Don't update the control values since that'll overwrite whatever
129 -- is currently being set up
130 -- CalendarEventEditor_UpdateControlsFromEvent(pEvent);
131  
132 CalendarGroupInvites_EventChanged(pEvent);
133 end
134 end
135  
136 function CalendarEventEditor_OnLoad()
137 -- Tabs
138  
139 PanelTemplates_SetNumTabs(this, table.getn(gCalendarEventEditor_PanelFrames));
140 CalendarEventEditorFrame.selectedTab = gCalendarEventEditor_CurrentPanel;
141 PanelTemplates_UpdateTabs(this);
142 end
143  
144 function CalendarEventEditor_OnShow()
145 PlaySound("igCharacterInfoOpen");
146  
147 CalendarEventTypeEventType.ChangedValueFunc = CalendarEventEditor_EventTypeChanged;
148  
149 CalendarEventEditor_ShowPanel(1); -- Always switch to the event view when showing the window
150 end
151  
152 function CalendarEventEditor_OnHide()
153 PlaySound("igCharacterInfoClose");
154  
155 CalendarAddPlayer_Cancel(); -- Force the dialog to close if it's open
156  
157 if not gCalendarEventEditor_ShowScheduleEditor then
158 CalendarEventEditor_SaveEvent();
159 HideUIPanel(CalendarEditorFrame);
160 end
161  
162 gCalendarEventEditor_Database = nil;
163 gCalendarEventEditor_Event = nil;
164 gCalendarEventEditor_Active = false;
165 end
166  
167 function CalendarEventEditor_DoneEditing()
168 if not gCalendarEventEditor_Active then
169 return;
170 end
171  
172 CalendarEventEditor_SaveEvent();
173 CalendarEventEditor_CloseEditor(true);
174 end
175  
176 function CalendarEventEditor_UpdateControlsFromEvent(pEvent, pExistingValuesOnly)
177 if not pExistingValuesOnly
178 or pEvent.mType then
179 CalendarDropDown_SetSelectedValue(CalendarEventTypeEventType, pEvent.mType);
180 end
181  
182 if pEvent.mTitle and pEvent.mTitle ~= "" then
183 CalendarEventTitle:SetText(Calendar_UnescapeString(pEvent.mTitle));
184 elseif not pExistingValuesOnly
185 or pEvent.mType then
186 local vEventName = EventDatabase_GetEventNameByID(pEvent.mType);
187  
188 if vEventName ~= nil then
189 CalendarEventTitle:SetText(vEventName);
190 else
191 CalendarEventTitle:SetText("");
192 end
193 end
194  
195 if not pExistingValuesOnly
196 or gCalendarEventEditor_EventTime then
197 CalendarEventEditor_SetTimeControlValue(CalendarEventEditorTime, gCalendarEventEditor_EventTime);
198 end
199  
200 if not pExistingValuesOnly
201 or pEvent.mDuration then
202 CalendarDropDown_SetSelectedValue(CalendarEventEditorDurationDuration, pEvent.mDuration);
203 end
204  
205 if pEvent.mDescription then
206 CalendarEventDescription:SetText(Calendar_UnescapeString(pEvent.mDescription));
207 elseif not pExistingValuesOnly then
208 CalendarEventDescription:SetText("");
209 end
210  
211 if pEvent.mMinLevel then
212 CalendarEventMinLevel:SetText(pEvent.mMinLevel);
213 elseif not pExistingValuesOnly then
214 CalendarEventMinLevel:SetText("");
215 end
216  
217 if pEvent.mMaxLevel then
218 CalendarEventMaxLevel:SetText(pEvent.mMaxLevel);
219 elseif not pExistingValuesOnly then
220 CalendarEventMaxLevel:SetText("");
221 end
222  
223 if not pExistingValuesOnly
224 or pEvent.mType then
225 gCalendarEventEditor_PreviousEventType = pEvent.mType;
226 CalendarEventEditor_SetEventType(pEvent.mType);
227 end
228 end
229  
230 function CalendarEventEditor_SaveClassLimits(pLimits)
231 gCalendarEventEditor_NewClassLimits = pLimits;
232 end
233  
234 function CalendarEventEditor_UpdateEventFromControls(rEvent, rChangedFields)
235 local vChanged = false;
236 local vValue;
237  
238 -- Type
239  
240 vValue = UIDropDownMenu_GetSelectedValue(CalendarEventTypeEventType);
241  
242 if rEvent.mType ~= vValue then
243 rEvent.mType = vValue;
244 rChangedFields.mType = {op = "UPD", val = vValue};
245 vChanged = true;
246 end
247  
248 -- Title
249  
250 vValue = CalendarEventTitle:GetText();
251  
252 if vValue == EventDatabase_GetEventNameByID(rEvent.mType)
253 or vValue == "" then
254 vValue = nil;
255 else
256 vValue = Calendar_EscapeString(vValue);
257 end
258  
259 if rEvent.mTitle ~= vValue then
260 rEvent.mTitle = vValue;
261 rChangedFields.mTitle = "UPD";
262 vChanged = true;
263 end
264  
265 -- Time
266  
267 local vDate, vTime = nil, nil;
268  
269 if EventDatabase_EventTypeUsesTime(rEvent.mType) then
270 vDate, vTime = gCalendarEventEditor_EventDate, CalendarEventEditor_GetTimeControlValue(CalendarEventEditorTime);
271  
272 if gCalendarEventEditor_UsingLocalTime then
273 vDate, vTime = Calendar_GetServerDateTimeFromLocalDateTime(vDate, vTime);
274 end
275 else
276 vDate = gCalendarEventEditor_EventDate;
277 end
278  
279 if rEvent.mDate ~= vDate then
280 rEvent.mDate = vDate;
281 rChangedFields.mDate = "UPD";
282 vChanged = true;
283 end
284  
285 if rEvent.mTime ~= vTime then
286 rEvent.mTime = vTime;
287 rChangedFields.mTime = "UPD";
288 vChanged = true;
289 end
290  
291 -- Duration
292  
293 if EventDatabase_EventTypeUsesTime(rEvent.mType) then
294 vValue = UIDropDownMenu_GetSelectedValue(CalendarEventEditorDurationDuration);
295 else
296 vValue = nil;
297 end
298  
299 if vValue == 0 then
300 vValue = nil;
301 end
302  
303 if rEvent.mDuration ~= vValue then
304 rEvent.mDuration = vValue;
305 rChangedFields.mDuration = "UPD";
306 vChanged = true;
307 end
308  
309 -- Description
310  
311 vValue = CalendarEventDescription:GetText();
312  
313 if vValue == "" then
314 vValue = nil;
315 else
316 vValue = Calendar_EscapeString(vValue);
317 end
318  
319 if rEvent.mDescription ~= vValue then
320 rEvent.mDescription = vValue;
321 rChangedFields.mDescription = "UPD";
322 vChanged = true;
323 end
324  
325 -- MinLevel
326  
327 if EventDatabase_EventTypeUsesLevelLimits(rEvent.mType) then
328 vValue = CalendarEventMinLevel:GetText();
329 else
330 vValue = nil;
331 end
332  
333 if vValue and vValue ~= "" then
334 vValue = tonumber(vValue);
335  
336 if vValue == 0 then
337 vValue = nil;
338 end
339 else
340 vValue = nil;
341 end
342  
343 if rEvent.mMinLevel ~= vValue then
344 rEvent.mMinLevel = vValue;
345 rChangedFields.mMinLevel = "UPD";
346 vChanged = true;
347 end
348  
349 -- MaxLevel
350  
351 if EventDatabase_EventTypeUsesTime(rEvent.mType) then
352 vValue = CalendarEventMaxLevel:GetText();
353 else
354 vValue = nil;
355 end
356  
357 if vValue and vValue ~= "" then
358 vValue = tonumber(vValue);
359  
360 if vValue == 0 then
361 vValue = nil;
362 end
363 else
364 vValue = nil;
365 end
366  
367 if rEvent.mMaxLevel ~= vValue then
368 rEvent.mMaxLevel = vValue;
369 rChangedFields.mMaxLevel = "UPD";
370 vChanged = true;
371 end
372  
373 -- Automatic confirmations
374  
375 local vManualConfirm;
376  
377 if EventDatabase_IsQuestingEventType(rEvent.mType) then
378 vManualConfirm = CalendarAttendanceList_GetManualConfirmEnable(CalendarEventEditorAttendance);
379 else
380 -- Non-questing events are always auto-confirm (ie meetings)
381  
382 vManualConfirm = nil;
383 end
384  
385 if vManualConfirm ~= rEvent.mManualConfirm then
386 rEvent.mManualConfirm = vManualConfirm;
387 rChangedFields.mManualConfirm = {op = "UPD", val = vManualConfirm};
388 end
389  
390 if EventDatabase_IsQuestingEventType(rEvent.mType) then
391 if gCalendarEventEditor_NewClassLimits
392 and CalendarClassLimits_ClassLimitsChanged(rEvent.mLimits, gCalendarEventEditor_NewClassLimits) then
393 rEvent.mLimits = gCalendarEventEditor_NewClassLimits;
394 rChangedFields.mLimits = {op = "UPD", val = rEvent.mLimits};
395 end
396 else
397 -- No limits on non-questing event types (ie, meetings)
398  
399 if rEvent.mLimits then
400 rEvent.mLimits = nil;
401 rChangedFields.mLimits = {op = "UPD", val = rEvent.mLimits};
402 end
403 end
404  
405 -- Done
406  
407 return vChanged;
408 end
409  
410 function CalendarEventEditor_SetEventType(pEventType)
411 -- CalendarEventTypeEventType:Show();
412 -- CalendarEventTitle:Show();
413 -- CalendarEventDescription:Show();
414  
415 local vTitleText = CalendarEventTitle:GetText();
416 local vEventName = EventDatabase_GetEventNameByID(gCalendarEventEditor_PreviousEventType);
417 local vTitleWasEventName = vTitleText == vEventName;
418  
419 if EventDatabase_EventTypeUsesTime(pEventType) then
420 CalendarEventEditorTime:Show();
421 CalendarEventEditorDuration:Show();
422 else
423 CalendarEventEditorTime:Hide();
424 CalendarEventEditorDuration:Hide();
425 end
426  
427 if EventDatabase_EventTypeUsesLevelLimits(pEventType) then
428 CalendarEventMinLevel:Show();
429 CalendarEventMaxLevel:Show();
430 else
431 CalendarEventMinLevel:Hide();
432 CalendarEventMaxLevel:Hide();
433 end
434  
435 if EventDatabase_EventTypeUsesAttendance(pEventType) then
436 CalendarEventEditorFrameTab2:Show();
437 CalendarEventEditorSelfAttend:Show();
438 else
439 CalendarEventEditorFrameTab2:Hide();
440 CalendarEventEditorSelfAttend:Hide();
441 end
442  
443 if vTitleWasEventName then
444 CalendarEventTitle:SetText(EventDatabase_GetEventNameByID(pEventType));
445 CalendarEventTitle:SetFocus();
446 CalendarEventTitle:HighlightText();
447 end
448  
449 -- Update the sample icon
450  
451 CalendarEventEditorEventBackground:SetTexture(Calendar_GetEventTypeIconPath(pEventType));
452 if pEventType == "Birth" then
453 CalendarEventEditorEventBackground:SetVertexColor(1, 1, 1, 0.4);
454 else
455 CalendarEventEditorEventBackground:SetVertexColor(1, 1, 1, 0.19);
456 end
457  
458 --
459  
460 gCalendarEventEditor_PreviousEventType = pEventType;
461 end
462  
463 function CalendarEventEditor_DeleteEvent()
464 if not gCalendarEventEditor_IsNewEvent then
465 EventDatabase_DeleteEvent(gCalendarEventEditor_Database, gCalendarEventEditor_Event);
466 end
467  
468 CalendarEventEditor_CloseEditor(true);
469 end
470  
471 function CalendarEventEditor_DeleteRSVP()
472 if not gGroupCalendar_RSVPToDelete then
473 return;
474 end
475  
476 gGroupCalendar_RSVPToDelete.mStatus = "-";
477  
478 EventDatabase_AddEventRSVP(
479 gCalendarEventEditor_Database,
480 gCalendarEventEditor_Event,
481 gGroupCalendar_RSVPToDelete.mName,
482 gGroupCalendar_RSVPToDelete);
483  
484 gGroupCalendar_RSVPToDelete = nil;
485 end
486  
487 function CalendarEventEditor_CloseEditor(pShowScheduleEditor)
488 gCalendarEventEditor_Active = false;
489  
490 gCalendarEventEditor_ShowScheduleEditor = pShowScheduleEditor;
491 HideUIPanel(CalendarEventEditorFrame);
492 end
493  
494 function CalendarEventEditor_CopyTemplateFields(pFromEvent, rToEvent)
495 rToEvent.mTitle = pFromEvent.mTitle;
496 rToEvent.mDescription = pFromEvent.mDescription;
497 rToEvent.mTime = pFromEvent.mTime;
498 rToEvent.mDuration = pFromEvent.mDuration;
499 rToEvent.mMinLevel = pFromEvent.mMinLevel;
500 rToEvent.mMaxLevel = pFromEvent.mMaxLevel;
501  
502 rToEvent.mManualConfirm = pFromEvent.mManualConfirm;
503 rToEvent.mLimits = pFromEvent.mLimits;
504 end
505  
506 function CalendarEventEditor_SaveEvent()
507 -- Update the event
508  
509 local vChangedFields = {};
510  
511 CalendarEventEditor_UpdateEventFromControls(gCalendarEventEditor_Event, vChangedFields);
512  
513 if Calendar_ArrayIsEmpty(vChangedFields) then
514 return;
515 end
516  
517 -- Save the event if it's new
518  
519 if gCalendarEventEditor_IsNewEvent then
520 if (gCalendarEventEditor_Event.mTitle ~= nil and gCalendarEventEditor_Event.mTitle ~= "")
521 or gCalendarEventEditor_Event.mType ~= nil then
522 EventDatabase_AddEvent(gCalendarEventEditor_Database, gCalendarEventEditor_Event);
523 end
524 else
525 EventDatabase_EventChanged(gCalendarEventEditor_Database, gCalendarEventEditor_Event, vChangedFields);
526 end
527  
528 -- Save a template for the event
529  
530 if gCalendarEventEditor_Event.mType
531 and gCalendarEventEditor_Event.mType ~= "Birth" then
532 if not gGroupCalendar_PlayerSettings.EventTemplates then
533 gGroupCalendar_PlayerSettings.EventTemplates = {};
534 end
535  
536 local vEventTemplate = {};
537  
538 CalendarEventEditor_CopyTemplateFields(gCalendarEventEditor_Event, vEventTemplate);
539 vEventTemplate.mSelfAttend = CalendarEventEditor_GetSelfAttend();
540  
541 gGroupCalendar_PlayerSettings.EventTemplates[gCalendarEventEditor_Event.mType] = vEventTemplate;
542 end
543 end
544  
545 function CalendarEventEditor_SetTimeControlValue(pFrame, pTime)
546 if pTime == nil then
547 return;
548 end
549  
550 local vFrameName = pFrame:GetName();
551  
552 local vHourFrame = getglobal(vFrameName.."Hour");
553 local vMinuteFrame = getglobal(vFrameName.."Minute");
554 local vAMPMFrame = getglobal(vFrameName.."AMPM");
555  
556 if TwentyFourHourTime then
557 local vHour, vMinute = Calendar_ConvertTimeToHM(pTime);
558  
559 CalendarDropDown_SetSelectedValue(vHourFrame, vHour);
560 CalendarDropDown_SetSelectedValue(vMinuteFrame, vMinute);
561 vAMPMFrame:Hide();
562 else
563 local vHour, vMinute, vAMPM = Calendar_ConvertTimeToHMAMPM(pTime);
564  
565 CalendarDropDown_SetSelectedValue(vHourFrame, vHour);
566 CalendarDropDown_SetSelectedValue(vMinuteFrame, vMinute);
567  
568 vAMPMFrame:Show();
569 CalendarDropDown_SetSelectedValue(vAMPMFrame, vAMPM);
570 end
571 end
572  
573 function CalendarEventEditor_GetTimeControlValue(pFrame)
574 local vFrameName = pFrame:GetName();
575  
576 local vHourFrame = getglobal(vFrameName.."Hour");
577 local vMinuteFrame = getglobal(vFrameName.."Minute");
578 local vAMPMFrame = getglobal(vFrameName.."AMPM");
579  
580 local vHour = UIDropDownMenu_GetSelectedValue(vHourFrame);
581 local vMinute = UIDropDownMenu_GetSelectedValue(vMinuteFrame);
582  
583 if TwentyFourHourTime then
584 return Calendar_ConvertHMToTime(vHour, vMinute);
585 else
586 local vAMPM = UIDropDownMenu_GetSelectedValue(vAMPMFrame);
587  
588 return Calendar_ConvertHMAMPMToTime(vHour, vMinute, vAMPM);
589 end
590 end
591  
592 function CalendarEventEditor_EventTypeChanged(pMenuFrame, pValue)
593 CalendarEventEditor_SetEventType(pValue);
594  
595 -- Set the templated field values if available
596  
597 if gCalendarEventEditor_IsNewEvent then
598 -- Set the default limits for this dungeon (the template will
599 -- override this if it's present)
600  
601 gCalendarEventEditor_Event.mLimits = EventDatabase_GetStandardLimitsByID(pValue);
602  
603 -- Copy of template values
604  
605 if gGroupCalendar_PlayerSettings.EventTemplates then
606 local vEventTemplate = gGroupCalendar_PlayerSettings.EventTemplates[pValue];
607  
608 if vEventTemplate then
609 CalendarEventEditor_CopyTemplateFields(vEventTemplate, gCalendarEventEditor_Event);
610  
611 CalendarEventEditor_UpdateControlsFromEvent(gCalendarEventEditor_Event, true);
612  
613 if vEventTemplate.mSelfAttend then
614 CalendarEventEditor_SetSelfAttend(vEventTemplate.mSelfAttend);
615 end
616 end
617 end
618 end
619 end
620  
621 function CalendarEventEditor_ShowPanel(pPanelIndex)
622 CalendarAddPlayer_Cancel(); -- Force the dialog to close if it's open
623  
624 if gCalendarEventEditor_CurrentPanel > 0
625 and gCalendarEventEditor_CurrentPanel ~= pPanelIndex then
626 CalendarEventEditor_HidePanel(gCalendarEventEditor_CurrentPanel);
627 end
628  
629 -- NOTE: Don't check for redundant calls since this function
630 -- will be called to reset the field values as well as to
631 -- actuall show the panel when it's hidden
632  
633 gCalendarEventEditor_CurrentPanel = pPanelIndex;
634  
635 -- Update the control values
636  
637 if pPanelIndex == 1 then
638 -- Event panel
639  
640 CalendarEventEditorSelfAttend:SetChecked(CalendarEventEditor_GetSelfAttend());
641 CalendarEventEditorSelfAttendText:SetText(string.format(GroupCalendar_cSelfWillAttend, gGroupCalendar_PlayerName));
642  
643 elseif pPanelIndex == 2 then
644 -- Attendance panel
645  
646 if EventDatabase_IsQuestingEventType(gCalendarEventEditor_PreviousEventType) then
647 CalendarAttendanceList_SetClassTotalsVisible(CalendarEventEditorAttendance, true, true);
648 else
649 CalendarAttendanceList_SetClassTotalsVisible(CalendarEventEditorAttendance, false, false);
650 end
651 else
652 Calendar_DebugMessage("CalendarEventEditor_ShowPanel: Unknown index ("..pPanelIndex..")");
653 end
654  
655 getglobal(gCalendarEventEditor_PanelFrames[pPanelIndex]):Show();
656  
657 PanelTemplates_SetTab(CalendarEventEditorFrame, pPanelIndex);
658  
659 CalendarEventEditor_Update();
660 end
661  
662 function CalendarEventEditor_HidePanel(pFrameIndex)
663 if gCalendarEventEditor_CurrentPanel ~= pFrameIndex then
664 return;
665 end
666  
667 getglobal(gCalendarEventEditor_PanelFrames[pFrameIndex]):Hide();
668 gCalendarEventEditor_CurrentPanel = 0;
669 end
670  
671 function CalendarEventEditor_Update()
672 -- Event panel
673  
674 if gCalendarEventEditor_CurrentPanel == 1 then
675  
676 -- Attendance panel
677  
678 elseif gCalendarEventEditor_CurrentPanel == 2 then
679 CalendarAttendanceList_Update(CalendarEventEditorAttendance);
680 end
681 end
682  
683 Calendar_cStatusCodeStrings =
684 {
685 N = CalendarEventEditor_cNotAttending,
686 Y = CalendarEventEditor_cConfirmed,
687 D = CalendarEventEditor_cDeclined,
688 S = CalendarEventEditor_cStandby,
689 P = CalendarEventEditor_cPending,
690 Q = CalendarEventEditor_cQueued,
691 };
692  
693 function CalendarEventEditor_GetStatusString(pStatus)
694 local vStatus1 = string.sub(pStatus, 1, 1);
695 local vString = Calendar_cStatusCodeStrings[vStatus1];
696  
697 if vString then
698 return vString;
699 else
700 return format(CalendarEventEditor_cUnknownStatus, pStatus);
701 end
702 end
703  
704 function CalendarEventEditor_GetSelfAttend()
705 return EventDatabase_FindEventRSVPString(gCalendarEventEditor_Event, gGroupCalendar_PlayerName) ~= nil;
706 end
707  
708 function CalendarEventEditor_SetSelfAttend(pWillAttend)
709 if pWillAttend then
710 local vRSVP = EventDatabase_CreatePlayerRSVP(
711 gCalendarEventEditor_Database,
712 gCalendarEventEditor_Event,
713 gGroupCalendar_PlayerName,
714 EventDatabase_GetRaceCodeByRace(UnitRace("PLAYER")),
715 EventDatabase_GetClassCodeByClass(UnitClass("PLAYER")),
716 gGroupCalendar_PlayerLevel,
717 "Y",
718 nil,
719 gGroupCalendar_PlayerGuild,
720 gGroupCalendar_PlayerGuildRank,
721 gGroupCalendar_PlayerCharacters);
722  
723 EventDatabase_AddEventRSVP(
724 gCalendarEventEditor_Database,
725 gCalendarEventEditor_Event,
726 gGroupCalendar_PlayerName,
727 vRSVP)
728 else
729 EventDatabase_RemoveEventRSVP(
730 gCalendarEventEditor_Database,
731 gCalendarEventEditor_Event,
732 gGroupCalendar_PlayerName)
733 end
734 end
735  
736 function CalendarEventEditor_AskDeleteEvent()
737 -- If it's new just kill it without asking
738  
739 if gCalendarEventEditor_IsNewEvent then
740 CalendarEventEditor_DeleteEvent();
741 else
742 -- Update an event record so we can display a meaningful name
743  
744 local vChangedFields = {};
745 local vEvent = {};
746  
747 CalendarEventEditor_UpdateEventFromControls(vEvent, vChangedFields);
748  
749 StaticPopup_Show("CONFIRM_CALENDAR_EVENT_DELETE", EventDatabase_GetEventDisplayName(vEvent));
750 end
751 end
752  
753 function CalendarAttendanceList_AnyItemsCollapsed(pAttendanceList)
754 if not pAttendanceList.CollapsedCategories then
755 return false;
756 end
757  
758 for vCategory, vCollapsed in pAttendanceList.CollapsedCategories do
759 return true;
760 end
761  
762 return false;
763 end
764  
765 local gCalendar_WhisperLog = {mPlayers = {}, mEvent = nil};
766  
767 function CalendarWhisperLog_AddWhisper(pPlayerName, pMessage)
768 -- If no event is active then just ignore all whispers
769 -- NOTE: Disabling this for now, it seems like it's better to have too
770 -- many than too few whispers. With this feature enabled, the organizer
771 -- must remember to open the event before receiving whispers or else
772 -- they'll be lost. That can be a bit of a pain.
773  
774 --[[
775 if not gCalendar_WhisperLog.mEvent then
776 return;
777 end
778 ]]
779  
780 -- Ignore whispers which appear to be data from other addons
781  
782 local vFirstChar = string.sub(pMessage, 1, 1);
783  
784 if vFirstChar == "<"
785 or vFirstChar == "["
786 or vFirstChar == "{" then
787 return;
788 end
789  
790 -- Filter if necessary
791  
792 if gCalendar_WhisperLog.mWhisperFilterFunc
793 and not gCalendar_WhisperLog.mWhisperFilterFunc(gCalendar_WhisperLog.mWhisperFilterParam, pPlayerName) then
794 return;
795 end
796  
797 --
798  
799 local vPlayerLog = gCalendar_WhisperLog.mPlayers[pPlayerName];
800  
801 if not vPlayerLog then
802 vPlayerLog = {};
803  
804 vPlayerLog.mName = pPlayerName;
805 vPlayerLog.mDate, vPlayerLog.mTime = EventDatabase_GetServerDateTime60Stamp();
806 vPlayerLog.mWhispers = {};
807  
808 gCalendar_WhisperLog.mPlayers[pPlayerName] = vPlayerLog;
809 end
810  
811 local vLength = table.getn(vPlayerLog.mWhispers);
812  
813 if vLength > 3 then
814 table.remove(vPlayerLog.mWhispers, 1);
815 vLength = vLength - 1;
816 end
817  
818 vPlayerLog.mWhispers[vLength + 1] = pMessage;
819  
820 -- Notify
821  
822 if gCalendar_WhisperLog.mNotificationFunc then
823 gCalendar_WhisperLog.mNotificationFunc(gCalendar_WhisperLog.mNotifcationParam);
824 end
825 end
826  
827 function CalendarWhisperLog_AskClear()
828 StaticPopup_Show("CONFIRM_CALENDAR_CLEAR_WHISPERS");
829 end
830  
831 function CalendarWhisperLog_Clear()
832 gCalendar_WhisperLog.mPlayers = {};
833  
834 if gCalendar_WhisperLog.mNotificationFunc then
835 gCalendar_WhisperLog.mNotificationFunc(gCalendar_WhisperLog.mNotifcationParam);
836 end
837 end
838  
839 function CalendarWhisperLog_GetPlayerWhispers(pEvent)
840 if gCalendar_WhisperLog.mEvent ~= pEvent then
841 gCalendar_WhisperLog.mEvent = pEvent;
842 CalendarWhisperLog_Clear();
843 end
844  
845 return gCalendar_WhisperLog.mPlayers;
846 end
847  
848 function CalendarWhisperLog_SetNotificationFunc(pFunc, pParam)
849 gCalendar_WhisperLog.mNotificationFunc = pFunc;
850 gCalendar_WhisperLog.mNotifcationParam = pParam;
851 end
852  
853 function CalendarWhisperLog_SetWhisperFilterFunc(pFunc, pParam)
854 gCalendar_WhisperLog.mWhisperFilterFunc = pFunc;
855 gCalendar_WhisperLog.mWhisperFilterParam = pParam;
856 end
857  
858 function CalendarWhisperLog_RemovePlayer(pPlayerName)
859 gCalendar_WhisperLog.mPlayers[pPlayerName] = nil;
860  
861 -- Notify
862  
863 if gCalendar_WhisperLog.mNotificationFunc then
864 gCalendar_WhisperLog.mNotificationFunc(gCalendar_WhisperLog.mNotifcationParam);
865 end
866 end
867  
868 function CalendarWhisperLog_GetNextWhisper(pPlayerName)
869 -- Make an indexed list of the whispers
870  
871 local vWhispers = {};
872  
873 for vName, vWhisper in gCalendar_WhisperLog.mPlayers do
874 table.insert(vWhispers, vWhisper);
875 end
876  
877 -- Sort by time
878  
879 table.sort(vWhispers, EventDatabase_CompareRSVPsByDate);
880  
881 --
882  
883 local vLowerName = strlower(pPlayerName);
884 local vUseNext = false;
885  
886 for vIndex, vWhisper in vWhispers do
887 if vUseNext then
888 return vWhisper;
889 end
890  
891 if vLowerName == strlower(vWhisper.mName) then
892 vUseNext = true;
893 end
894 end
895  
896 return nil;
897 end
898  
899 function CalendarAttendanceList_GetManualConfirmEnable(pAttendanceList)
900 local vAutoConfirmEnable = getglobal(pAttendanceList:GetName().."MainViewAutoConfirmEnable");
901 local vManualConfirm = not vAutoConfirmEnable:GetChecked();
902  
903 if not vManualConfirm then
904 vManualConfirm = nil;
905 end
906  
907 return vManualConfirm;
908 end
909  
910 gCalendarAttendanceList_VerticalScrollList = nil;
911  
912 function CalendarAttendanceList_OnLoad()
913 local vListName = this:GetName();
914  
915 this.NumItems = gGroupCalendar_cNumAttendanceItems;
916 this.CollapsedCategories = {};
917 this.ListViewMode = "Date";
918  
919 -- Set the text color for the class totals
920  
921 for vClassID, vClassInfo in gGroupCalendar_ClassInfoByClassCode do
922 local vLabel = getglobal(vListName.."MainViewTotals"..vClassInfo.element.."sLabel");
923 local vCount = getglobal(vListName.."MainViewTotals"..vClassInfo.element.."s");
924 local vColor = RAID_CLASS_COLORS[vClassInfo.color];
925  
926 vLabel:SetTextColor(vColor.r, vColor.g, vColor.b);
927 vCount:SetTextColor(vColor.r, vColor.g, vColor.b);
928 end
929  
930 CalendarAttendanceList_SetClassTotalsVisible(this, true, true);
931 end
932  
933 function CalendarAttendanceList_OnShow()
934 CalendarAttendanceList_ShowPanel(this, "MainView");
935  
936 CalendarWhisperLog_SetNotificationFunc(CalendarAttendanceList_UpdateWhispers, this);
937 CalendarWhisperLog_SetWhisperFilterFunc(CalendarAttendanceList_FilterWhispers, this);
938 end
939  
940 function CalendarAttendanceList_OnHide()
941 CalendarWhisperLog_SetNotificationFunc(nil, nil, nil);
942  
943 if GetNumPartyMembers() == 0
944 and GetNumRaidMembers() == 0 then
945 CalendarGroupInvites_EndEvent(this.Event);
946 else
947 CalendarGroupInvites_SetChangedFunc(nil, nil);
948 end
949 end
950  
951 function CalendarAttendanceList_SetEvent(pAttendanceList, pDatabase, pEvent)
952 pAttendanceList.Database = pDatabase;
953 pAttendanceList.Event = pEvent;
954 pAttendanceList.Group = nil;
955  
956 pAttendanceList.ListViewMode = "Date";
957  
958 pAttendanceList.EventListInfo = {};
959 pAttendanceList.CollapsedCategories = {};
960  
961 -- Update the auto confirm enable
962  
963 local vAttendanceListName = pAttendanceList:GetName();
964 local vMainViewName = vAttendanceListName.."MainView";
965  
966 local vAutoConfirmEnable = getglobal(vMainViewName.."AutoConfirmEnable");
967 local vAutoConfirmOptions = getglobal(vMainViewName.."AutoConfirmOptions");
968  
969 vAutoConfirmEnable:SetChecked(not pAttendanceList.Event.mManualConfirm);
970 Calendar_SetButtonEnable(vAutoConfirmOptions, not pAttendanceList.Event.mManualConfirm);
971  
972 --
973  
974 CalendarAttendanceList_UpdateAttendanceCounts(pAttendanceList);
975 end
976  
977 function CalendarAttendanceList_SetGroup(pAttendanceList, pGroup)
978 pAttendanceList.Group = pGroup;
979 end
980  
981 function CalendarAttendanceList_EventChanged(pAttendanceList, pDatabase, pEvent)
982 pAttendanceList.Database = pDatabase;
983 pAttendanceList.Event = pEvent;
984  
985 CalendarAttendanceList_UpdateAttendanceCounts(pAttendanceList);
986 CalendarGroupInvites_EventChanged(pDatabase, pEvent);
987  
988 CalendarAttendanceList_Update(pAttendanceList);
989 end
990  
991 function CalendarAttendanceList_UpdateAttendanceCounts(pAttendanceList)
992 local vUseClassCategories = EventDatabase_IsQuestingEventType(pAttendanceList.Event.mType);
993 local vHadWhispers = pAttendanceList.EventListInfo.AttendanceCounts
994 and pAttendanceList.EventListInfo.AttendanceCounts.Categories["WHISPERS"] ~= nil;
995  
996 pAttendanceList.EventListInfo.AttendanceCounts =
997 CalendarEvent_GetAttendanceCounts(
998 pAttendanceList.Database,
999 pAttendanceList.Event,
1000 vUseClassCategories);
1001  
1002 -- Add in the recent whispers, but only if they're not in the attendance list
1003 -- and only if the event is editable
1004  
1005 if not vHadWhispers then
1006 pAttendanceList.CollapsedCategories["WHISPERS"] = true;
1007 end
1008  
1009 local vAttendanceList = pAttendanceList.EventListInfo.AttendanceCounts;
1010 local vGroupList = gGroupCalendar_Invites.Group;
1011  
1012 if pAttendanceList.mCanEdit then
1013 local vPlayerWhispers = CalendarWhisperLog_GetPlayerWhispers(pAttendanceList.Event);
1014  
1015 for vPlayerName, vWhispers in vPlayerWhispers do
1016 CalendarAttendanceList_AddWhisper(
1017 vAttendanceList,
1018 vPlayerName,
1019 vWhispers);
1020 end
1021 end
1022  
1023 CalendarEvent_SortAttendanceCounts(pAttendanceList.EventListInfo.AttendanceCounts, pAttendanceList.ListViewMode);
1024 end
1025  
1026 function CalendarAttendanceList_FilterWhispers(pAttendanceList, pPlayerName)
1027 local vAttendanceList = pAttendanceList.EventListInfo.AttendanceCounts;
1028  
1029 if vAttendanceList.Items
1030 and vAttendanceList.Items[pPlayerName] then
1031 return false;
1032 end
1033  
1034 if gGroupCalendar_Invites.Group
1035 and gGroupCalendar_Invites.Group.Items[pPlayerName] then
1036 return false;
1037 end
1038  
1039 return true;
1040 end
1041  
1042 function CalendarAttendanceList_UpdateWhispers(pAttendanceList)
1043 if not CalendarAttendanceList_RemoveCategory(pAttendanceList.EventListInfo.AttendanceCounts, "WHISPERS") then
1044 -- Collapse the category if this is the first one
1045  
1046 pAttendanceList.CollapsedCategories["WHISPERS"] = true;
1047 end
1048  
1049 local vAttendanceList = pAttendanceList.EventListInfo.AttendanceCounts;
1050 local vGroupList = gGroupCalendar_Invites.Group;
1051  
1052 local vPlayerWhispers = CalendarWhisperLog_GetPlayerWhispers(pAttendanceList.Event);
1053  
1054 for vPlayerName, vWhispers in vPlayerWhispers do
1055 CalendarAttendanceList_AddWhisper(
1056 vAttendanceList,
1057 vPlayerName,
1058 vWhispers);
1059 end
1060  
1061 CalendarEvent_SortAttendanceCounts(pAttendanceList.EventListInfo.AttendanceCounts, pAttendanceList.ListViewMode);
1062  
1063 CalendarAttendanceList_Update(pAttendanceList);
1064 end
1065  
1066 function CalendarAttendanceList_SetCanEdit(pAttendanceList, pCanEdit)
1067 pAttendanceList.mCanEdit = pCanEdit;
1068 end
1069  
1070 function CalendarScrollbarTrench_SizeChanged(pScrollbarTrench)
1071 local vScrollbarTrenchName = pScrollbarTrench:GetName();
1072 local vScrollbarTrenchMiddle = getglobal(vScrollbarTrenchName.."Middle");
1073  
1074 local vMiddleHeight= pScrollbarTrench:GetHeight() - 51;
1075 vScrollbarTrenchMiddle:SetHeight(vMiddleHeight);
1076 end
1077  
1078 function CalendarAttendanceList_SetClassTotalsVisible(pAttendanceList, pVisible, pShowAutoConfirm)
1079 pAttendanceList.ShowTotals = pVisible;
1080 pAttendanceList.ShowAutoConfirm = pShowAutoConfirm;
1081  
1082 CalendarAttendanceList_AdjustHeight(pAttendanceList);
1083 end
1084  
1085 function CalendarAttendanceList_AdjustHeight(pAttendanceList)
1086 local vListName = pAttendanceList:GetName();
1087 local vTotals = getglobal(vListName.."MainViewTotals");
1088 local vAutoConfirm = getglobal(vListName.."MainViewAutoConfirm");
1089 local vScrollFrame = getglobal(vListName.."ScrollFrame");
1090 local vScrollTrench = getglobal(vListName.."ScrollbarTrench");
1091 local vScrollFrameBaseHeight = 254;
1092 local vScrollTrenchBaseHeight = 261;
1093  
1094 if pAttendanceList.CurrentPanel == "GroupView"
1095 or pAttendanceList.ShowTotals then
1096 local vFooterHeight;
1097  
1098 vTotals:Show();
1099  
1100 if pAttendanceList.CurrentPanel ~= "GroupView"
1101 and pAttendanceList.ShowAutoConfirm then
1102 vAutoConfirm:Show();
1103 pAttendanceList.NumItems = gGroupCalendar_cNumAutoConfirmAttendanceItems;
1104 vFooterHeight = vAutoConfirm:GetHeight() + vTotals:GetHeight();
1105 else
1106 vAutoConfirm:Hide();
1107 pAttendanceList.NumItems = gGroupCalendar_cNumAttendanceItems;
1108 vFooterHeight = vTotals:GetHeight();
1109 end
1110  
1111 vScrollFrame:SetHeight(vScrollFrameBaseHeight - vFooterHeight);
1112 vScrollTrench:SetHeight(vScrollTrenchBaseHeight - vFooterHeight);
1113 else
1114 vTotals:Hide();
1115 vAutoConfirm:Hide();
1116 pAttendanceList.NumItems = gGroupCalendar_cNumPlainAttendanceItems;
1117 vScrollFrame:SetHeight(vScrollFrameBaseHeight);
1118 vScrollTrench:SetHeight(vScrollTrenchBaseHeight);
1119 end
1120 end
1121  
1122 function CalendarAttendanceList_Update(pAttendanceList)
1123 if not pAttendanceList:IsVisible() then
1124 return;
1125 end
1126  
1127 local vAttendanceListName = pAttendanceList:GetName();
1128 local vMainViewName = vAttendanceListName.."MainView";
1129  
1130 -- Update the view menu
1131  
1132 local vListViewMenu = getglobal(vAttendanceListName.."ViewMenu");
1133  
1134 CalendarDropDown_SetSelectedValue(vListViewMenu, pAttendanceList.ListViewMode);
1135  
1136 if pAttendanceList.CurrentPanel == "MainView" then
1137 -- Update the scroll frame
1138  
1139 local vTotalCount = 0;
1140  
1141 if pAttendanceList.EventListInfo.AttendanceCounts then
1142 for vCategory, vClassAttendanceInfo in pAttendanceList.EventListInfo.AttendanceCounts.Categories do
1143 vTotalCount = vTotalCount + 1;
1144  
1145 if not pAttendanceList.CollapsedCategories[vCategory] then
1146 vTotalCount = vTotalCount + vClassAttendanceInfo.mCount;
1147 end
1148 end
1149 end
1150  
1151 FauxScrollFrame_Update(
1152 getglobal(vAttendanceListName.."ScrollFrame"),
1153 vTotalCount,
1154 pAttendanceList.NumItems,
1155 gGroupCalendar_cAttendanceItemHeight,
1156 nil, nil, nil,
1157 nil,
1158 293, 316);
1159  
1160 CalendarAttendanceList_UpdateAttendanceList(pAttendanceList);
1161  
1162 -- Update the expand/collapse all button
1163  
1164 local vExpandAllButton = getglobal(vAttendanceListName.."ExpandAllButton")
1165  
1166 if CalendarAttendanceList_AnyItemsCollapsed(pAttendanceList) then
1167 vExpandAllButton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
1168 else
1169 vExpandAllButton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
1170 end
1171  
1172 CalendarAttendanceList_UpdateClassTotals(pAttendanceList);
1173  
1174 -- Show or hide the add button
1175  
1176 local vAddButton = getglobal(vMainViewName.."AddButton");
1177  
1178 if pAttendanceList.mCanEdit then
1179 vAddButton:Show();
1180 else
1181 vAddButton:Hide();
1182 end
1183  
1184 elseif pAttendanceList.CurrentPanel == "GroupView" then
1185 local vGroupViewName = vAttendanceListName.."GroupView";
1186 local vSelectionInfoText = getglobal(vGroupViewName.."SelectionInfo");
1187 local vStatusText = getglobal(vGroupViewName.."Status");
1188 local vStatusMessage = GroupCalendar_cInviteStatusMessages[gGroupCalendar_Invites.Status];
1189 local vInviteButton = getglobal(vGroupViewName.."Invite");
1190  
1191 if vStatusMessage then
1192 vStatusText:SetText(vStatusMessage);
1193 elseif gGroupCalendar_Invites.Status then
1194 vStatusText:SetText("Unknown "..gGroupCalendar_Invites.Status);
1195 else
1196 vStatusText:SetText("Unknown (nil)");
1197 end
1198  
1199 local vNumSelected = gGroupCalendar_Invites.NumSelected;
1200  
1201 if not vNumSelected
1202 or vNumSelected == 0 then
1203 vSelectionInfoText:SetText(GroupCalendar_cNoSelection);
1204 elseif vNumSelected == 1 then
1205 vSelectionInfoText:SetText(GroupCalendar_cSingleSelection);
1206 else
1207 vSelectionInfoText:SetText(format(GroupCalendar_cMultiSelection, vNumSelected));
1208 end
1209  
1210 -- Update the scroll frame
1211  
1212 local vTotalCount = 0;
1213  
1214 if pAttendanceList.EventListInfo.AttendanceCounts then
1215 for vCategory, vClassAttendanceInfo in gGroupCalendar_Invites.Group.Categories do
1216 vTotalCount = vTotalCount + 1;
1217  
1218 if not pAttendanceList.CollapsedCategories[vCategory] then
1219 vTotalCount = vTotalCount + vClassAttendanceInfo.mCount;
1220 end
1221 end
1222 end
1223  
1224 FauxScrollFrame_Update(
1225 getglobal(vAttendanceListName.."ScrollFrame"),
1226 vTotalCount,
1227 pAttendanceList.NumItems,
1228 gGroupCalendar_cAttendanceItemHeight,
1229 nil, nil, nil,
1230 nil,
1231 293, 316);
1232  
1233 CalendarAttendanceList_UpdateAttendanceList(pAttendanceList);
1234  
1235 -- Enable the invite button if the player is the raid or party leader
1236 -- or is not in a raid or pary
1237  
1238 local vEnableInvites = false;
1239 local vInParty = GetNumPartyMembers() > 0 or GetNumRaidMembers() > 0;
1240  
1241 if not vInParty
1242 or IsPartyLeader()
1243 or IsRaidLeader()
1244 or IsRaidOfficer() then
1245 vEnableInvites = true;
1246 end
1247  
1248 Calendar_SetButtonEnable(vInviteButton, vEnableInvites);
1249 else
1250 Calendar_ErrorMessage("CalendarAttendanceList_Update: Unknown panel "..pAttendanceList.CurrentPanel);
1251 end
1252 end
1253  
1254 function CalendarAttendanceList_ToggleExpandAll(pAttendanceList)
1255 -- Get the group
1256  
1257 local vGroup;
1258  
1259 if pAttendanceList.CurrentPanel == "MainView" then
1260 vGroup = pAttendanceList.EventListInfo.AttendanceCounts;
1261 elseif pAttendanceList.CurrentPanel == "GroupView" then
1262 vGroup = gGroupCalendar_Invites.Group;
1263 else
1264 Calendar_ErrorMessage("CalendarAttendanceList_ToggleExpandAll: Unknown view "..pAttendanceList.CurrentPanel);
1265 return;
1266 end
1267  
1268 -- Just return if there are no attendance items to toggle
1269  
1270 if not pAttendanceList
1271 or not vGroup then
1272 return;
1273 end
1274  
1275 if CalendarAttendanceList_AnyItemsCollapsed(pAttendanceList) then
1276 -- Expand all
1277  
1278 pAttendanceList.CollapsedCategories = {};
1279 else
1280 -- Collapse all
1281  
1282 pAttendanceList.CollapsedCategories = {};
1283  
1284 for vCategory, vClassAttendanceInfo in vGroup.Categories do
1285 pAttendanceList.CollapsedCategories[vCategory] = true;
1286 end
1287 end
1288  
1289 CalendarAttendanceList_Update(pAttendanceList);
1290 end
1291  
1292 function CalendarAttendanceList_UpdateClassTotals(pAttendanceList)
1293 local vListName = pAttendanceList:GetName();
1294  
1295 for vClassCode, vClassInfo in gGroupCalendar_ClassInfoByClassCode do
1296 local vClassTotal;
1297  
1298 if pAttendanceList.EventListInfo.AttendanceCounts then
1299 vClassTotal = pAttendanceList.EventListInfo.AttendanceCounts.ClassTotals[vClassCode];
1300 else
1301 vClassTotal = nil;
1302 end
1303  
1304 local vCountTextItem = getglobal(vListName.."MainViewTotals"..vClassInfo.element.."s");
1305  
1306 if not vClassTotal then
1307 vCountTextItem:SetText("0");
1308 vCountTextItem:SetTextColor(0.9, 0.2, 0.2);
1309 else
1310 local vColor = RAID_CLASS_COLORS[vClassInfo.color];
1311  
1312 vCountTextItem:SetText(vClassTotal);
1313 vCountTextItem:SetTextColor(vColor.r, vColor.g, vColor.b);
1314 end
1315 end
1316 end
1317  
1318 gGroupCalendar_cAttendanceCategories =
1319 {
1320 NO = GroupCalendar_cNotAttending,
1321 YES = GroupCalendar_cAttending,
1322 PENDING = GroupCalendar_cPendingApproval,
1323 STANDBY = GroupCalendar_cStandby,
1324 QUEUED = GroupCalendar_Queued,
1325 WHISPERS = GroupCalendar_cWhispers,
1326 };
1327  
1328 function CalendarAttendanceList_GetClassNameColor(pClassName)
1329 if not pClassName then
1330 return NORMAL_FONT_COLOR;
1331 end
1332  
1333 local vClassColorName = getglobal("GroupCalendar_c"..pClassName.."ClassColorName");
1334  
1335 return RAID_CLASS_COLORS[vClassColorName];
1336 end
1337  
1338 function CalendarAttendanceList_SetItem(
1339 pAttendanceList,
1340 pIndex,
1341 pItemInfo,
1342 pLeftFormat,
1343 pRightFormat,
1344 pShowMenu,
1345 pMenuValue,
1346 pColor,
1347 pOffline,
1348 pIconPath,
1349 pChecked,
1350 pTooltipName,
1351 pTooltipText,
1352 pTooltipTextColor)
1353 local vListName = pAttendanceList:GetName();
1354 local vItemName = vListName.."Item"..pIndex;
1355 local vItem = getglobal(vItemName);
1356 local vItemHighlight = getglobal(vItemName.."Highlight");
1357  
1358 local vItemCategory = getglobal(vItemName.."Category");
1359 local vItemLeftText = getglobal(vItemName.."Name");
1360 local vItemRightText = getglobal(vItemName.."Status");
1361 local vItemMenu = getglobal(vItemName.."Menu");
1362 local vItemActionButton = getglobal(vItemName.."Action");
1363  
1364 --
1365  
1366 vItemCategory:Hide();
1367 vItemLeftText:Show();
1368 vItemRightText:Show();
1369 vItemActionButton:Hide();
1370  
1371 if pShowMenu then
1372 CalendarDropDown_SetSelectedValue2(vItemMenu, pMenuValue);
1373 vItemMenu:Show();
1374 vItemRightText:SetWidth(112);
1375 else
1376 vItemMenu:Hide();
1377 vItemRightText:SetWidth(130);
1378 end
1379  
1380 vItemLeftText:SetText(string.gsub(pLeftFormat, "%$(%w+)", function (pField) return pItemInfo[pField]; end));
1381 vItemRightText:SetText(string.gsub(pRightFormat, "%$(%w+)", function (pField) return pItemInfo[pField]; end));
1382  
1383 if pColor then
1384 if pOffline then
1385 vItemLeftText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
1386 else
1387 vItemLeftText:SetTextColor(pColor.r, pColor.g, pColor.b);
1388 end
1389  
1390 vItemRightText:SetTextColor(pColor.r, pColor.g, pColor.b);
1391 else
1392 if pOffline then
1393 vItemLeftText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
1394 else
1395 vItemLeftText:SetTextColor(1, 1, 1);
1396 end
1397 vItemRightText:SetTextColor(1, 1, 1);
1398 end
1399  
1400 if pChecked ~= nil then
1401 vItem.Checkable = true;
1402 vItem:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up");
1403 vItem:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down");
1404 vItemHighlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight");
1405 vItem:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check");
1406 vItem:SetChecked(pChecked);
1407 else
1408 vItem.Checkable = false;
1409 if pIconPath then
1410 vItem:SetNormalTexture(pIconPath);
1411 else
1412 vItem:SetNormalTexture("");
1413 end
1414 vItem:SetPushedTexture("");
1415 vItem:SetCheckedTexture("");
1416 vItemHighlight:SetTexture("");
1417 vItem:SetChecked(false);
1418 end
1419  
1420 vItem.IsCategoryItem = false;
1421 vItem:Show();
1422  
1423 vItem.TooltipName = pTooltipName;
1424 vItem.TooltipText = pTooltipText;
1425 vItem.TooltipTextColor = pTooltipTextColor;
1426  
1427 return vItem;
1428 end
1429  
1430 function CalendarAttendanceList_SetItemToRSVP(pAttendanceList, pIndex, pCategory, pRSVP, pNameFormat, pShowRank)
1431 local vItemInfo =
1432 {
1433 name = pRSVP.mName,
1434 class = EventDatabase_GetClassByClassCode(pRSVP.mClassCode),
1435 race = EventDatabase_GetRaceByRaceCode(pRSVP.mRaceCode),
1436 level = tostring(pRSVP.mLevel),
1437 status = "",
1438 };
1439  
1440 -- Set the status
1441  
1442 local vShowStatusString = false;
1443  
1444 if vShowStatusString then
1445 vItemInfo.status = CalendarEventEditor_GetStatusString(pRSVP.mStatus);
1446 elseif pShowRank then
1447 local vRank = EventDatabase_MapGuildRank(pRSVP.mGuild, pRSVP.mGuildRank);
1448  
1449 if vRank then
1450 vItemInfo.status = GuildControlGetRankName(vRank + 1);
1451 else
1452 vItemInfo.status = GroupCalendar_cUnknown;
1453 end
1454  
1455 else
1456 local vDate, vTime = EventDatabase_GetRSVPOriginalDateTime(pRSVP);
1457  
1458 if vDate and vTime then
1459 vTime = vTime / 60; -- Convert from seconds to minutes
1460  
1461 if gGroupCalendar_Settings.ShowEventsInLocalTime then
1462 vDate, vTime = Calendar_GetLocalDateTimeFromServerDateTime(vDate, vTime);
1463 end
1464  
1465 local vShortDateString = Calendar_GetShortDateString(vDate);
1466 local vShortTimeString = Calendar_GetShortTimeString(vTime);
1467  
1468 vItemInfo.status = vShortDateString.." "..vShortTimeString;
1469 end
1470 end
1471  
1472 local vColor = CalendarAttendanceList_GetClassNameColor(vItemInfo.class);
1473  
1474 -- Get the icon path
1475  
1476 local vIconPath;
1477 local vTooltipName = nil;
1478 local vTooltipText = nil;
1479 local vTooltipTextColor = nil;
1480  
1481 if pRSVP.mComment and pRSVP.mComment ~= "" then
1482 vIconPath = "Interface\\Addons\\GroupCalendar\\Textures\\AttendanceNoteIcon";
1483 vTooltipName = pRSVP.mName;
1484 vTooltipText = Calendar_UnescapeString(pRSVP.mComment);
1485 elseif pRSVP.mType == "Whisper" then
1486 vIconPath = "Interface\\Addons\\GroupCalendar\\Textures\\AttendanceNoteIcon";
1487  
1488 vTooltipName = pRSVP.mName;
1489 vTooltipText = pRSVP.mWhispers;
1490 vTooltipTextColor = ChatTypeInfo["WHISPER"];
1491 vColor = vTooltipTextColor;
1492 else
1493 vIconPath = "";
1494 end
1495  
1496 -- Set the item
1497  
1498 local vItem = CalendarAttendanceList_SetItem(
1499 pAttendanceList,
1500 pIndex,
1501 vItemInfo,
1502 pNameFormat,
1503 "$status",
1504 pAttendanceList.mCanEdit,
1505 pRSVP.mStatus,
1506 vColor,
1507 false,
1508 vIconPath,
1509 nil,
1510 vTooltipName,
1511 vTooltipText,
1512 vTooltipTextColor);
1513  
1514 vItem.Item = pRSVP;
1515 end
1516  
1517 function CalendarAttendanceList_SetItemToCategory(pAttendanceList, pIndex, pCategory, pActionFunc, pActionParam)
1518 local vItemName = pAttendanceList:GetName().."Item"..pIndex;
1519 local vItem = getglobal(vItemName);
1520  
1521 local vItemHighlight = getglobal(vItemName.."Highlight");
1522 local vItemCategory = getglobal(vItemName.."Category");
1523 local vItemPlayerName = getglobal(vItemName.."Name");
1524 local vItemPlayerStatus = getglobal(vItemName.."Status");
1525 local vItemMenu = getglobal(vItemName.."Menu");
1526 local vItemActionButton = getglobal(vItemName.."Action");
1527  
1528 local vCategoryName;
1529  
1530 if type(pCategory) == "number" then
1531 vCategoryName = GuildControlGetRankName(pCategory + 1);
1532 else
1533 vCategoryName = gGroupCalendar_cAttendanceCategories[pCategory];
1534  
1535 if not vCategoryName then
1536 vCategoryName = EventDatabase_GetClassByClassCode(pCategory);
1537 end
1538 end
1539  
1540 vItemCategory:SetText(vCategoryName);
1541 vItemCategory:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
1542 vItemCategory:Show();
1543 vItemPlayerName:Hide();
1544 vItemPlayerStatus:Hide();
1545  
1546 if pActionFunc then
1547 vItemActionButton.ActionFunc = pActionFunc;
1548 vItemActionButton.ActionParam = pActionParam;
1549 vItemActionButton:Show();
1550 else
1551 vItemActionButton:Hide();
1552 end
1553  
1554 vItemMenu:Hide();
1555 vItemPlayerStatus:SetWidth(130);
1556  
1557 if pAttendanceList.CollapsedCategories[pCategory] then
1558 vItem:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
1559 vItem:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-Down");
1560 else
1561 vItem:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
1562 vItem:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-Down");
1563 end
1564  
1565 vItemHighlight:SetTexture("Interface\\Buttons\\UI-PlusButton-Hilight");
1566 vItem:SetChecked(false);
1567  
1568 vItem.Item = nil;
1569 vItem.IsCategoryItem = true;
1570 vItem.Category = pCategory;
1571  
1572 vItem.TooltipName = nil;
1573 vItem.TooltipText = nil;
1574 vItem.TooltipTextColor = nil;
1575  
1576 vItem:Show();
1577 end
1578  
1579 function CalendarAttendanceList_HideUnusedAttendanceItems(pAttendanceList, pFirstItem)
1580 local vListName = pAttendanceList:GetName();
1581  
1582 for vIndex = pFirstItem, gGroupCalendar_cNumPlainAttendanceItems - 1 do
1583 local vItemName = vListName.."Item"..vIndex;
1584 getglobal(vItemName):Hide();
1585 end
1586 end
1587  
1588 function CalendarAttendanceList_UpdateAttendanceList(pAttendanceList)
1589 if pAttendanceList.CurrentPanel == "MainView" then
1590 CalendarAttendanceList_UpdateEventAttendance(pAttendanceList);
1591 elseif pAttendanceList.CurrentPanel == "GroupView" then
1592 CalendarAttendanceList_UpdateGroupAttendance(pAttendanceList);
1593 else
1594 Calendar_ErrorMessage("Unknown attendance panel "..pAttendanceList.CurrentPanel);
1595 end
1596 end
1597  
1598 function CalendarAttendanceList_UpdateGroupAttendance(pAttendanceList)
1599 local vSortByFlags = GroupCalendar_cSortByFlags[pAttendanceList.ListViewMode];
1600  
1601 pAttendanceList.ViewType = "Class";
1602 pAttendanceList.ShowRank = vSortByFlags.Rank;
1603  
1604 CalendarAttendanceList_UpdateAttendanceItems(pAttendanceList, gGroupCalendar_Invites.Group, CalendarAttendanceList_SetGroupItem, GroupCalendar_cNumPlayersFormat);
1605 end
1606  
1607 function CalendarAttendanceList_UpdateEventAttendance(pAttendanceList)
1608 local vSetItemFunction;
1609  
1610 if EventDatabase_IsQuestingEventType(pAttendanceList.Event.mType) then
1611 pAttendanceList.ViewType = "Class";
1612 else
1613 pAttendanceList.ViewType = "Plain";
1614 end
1615  
1616 local vSortByFlags = GroupCalendar_cSortByFlags[pAttendanceList.ListViewMode];
1617  
1618 pAttendanceList.ShowRank = vSortByFlags.Class and vSortByFlags.Rank;
1619  
1620 CalendarAttendanceList_UpdateAttendanceItems(pAttendanceList, pAttendanceList.EventListInfo.AttendanceCounts, CalendarAttendanceList_SetAttendanceItem, GroupCalendar_cNumAttendeesFormat);
1621 end
1622  
1623 function CalendarAttendanceList_SetGroupItem(pAttendanceList, pItemIndex, pCategory, pItem)
1624 local vItemInfo = {};
1625 local vToolTipName, vTooltipText;
1626 local vIconPath;
1627  
1628 vItemInfo.name = pItem.mName;
1629 vItemInfo.status = GroupCalendar_cGroupStatusMessages[pItem.mGroupStatus];
1630 vItemInfo.class = EventDatabase_GetClassByClassCode(pItem.mClassCode);
1631 vItemInfo.race = EventDatabase_GetRaceByRaceCode(pItem.mRaceCode);
1632 vItemInfo.level = tostring(pItem.mLevel);
1633 vItemInfo.offline = pItem.mOffline;
1634  
1635 -- Set the status
1636  
1637 local vStatusColumnFormat = "";
1638  
1639 if pAttendanceList.ListViewMode == "Rank" then
1640 local vRank = EventDatabase_MapGuildRank(pItem.mGuild, pItem.mGuildRank);
1641  
1642 if vRank then
1643 vItemInfo.rank = GuildControlGetRankName(vRank + 1);
1644 else
1645 vItemInfo.rank = GroupCalendar_cUnknown;
1646 end
1647  
1648 vStatusColumnFormat = "$rank";
1649 elseif pAttendanceList.ListViewMode == "Date"
1650 or pAttendanceList.ListViewMode == "Name" then
1651 local vDate, vTime = EventDatabase_GetRSVPOriginalDateTime(pItem);
1652  
1653 if vDate and vTime then
1654 vTime = vTime / 60; -- Convert from seconds to minutes
1655  
1656 if gGroupCalendar_Settings.ShowEventsInLocalTime then
1657 vDate, vTime = Calendar_GetLocalDateTimeFromServerDateTime(vDate, vTime);
1658 end
1659  
1660 local vShortDateString = Calendar_GetShortDateString(vDate);
1661 local vShortTimeString = Calendar_GetShortTimeString(vTime);
1662  
1663 vItemInfo.date = vShortDateString.." "..vShortTimeString;
1664  
1665 vStatusColumnFormat = "$date";
1666 end
1667 end
1668  
1669 local vNameColumnFormat;
1670  
1671 if pCategory == "STANDBY" then
1672 vNameColumnFormat = GroupCalendar_cMeetingAttendanceNameFormat;
1673 else
1674 vNameColumnFormat = GroupCalendar_cGroupAttendanceNameFormat;
1675 end
1676  
1677 local vSelected;
1678  
1679 if pItem.mGroupStatus ~= "Joined" then
1680 vSelected = pItem.mSelected == true;
1681 end
1682  
1683 local vItem = CalendarAttendanceList_SetItem(
1684 pAttendanceList,
1685 pItemIndex,
1686 vItemInfo,
1687 vNameColumnFormat,
1688 vStatusColumnFormat,
1689 false,
1690 false,
1691 CalendarAttendanceList_GetClassNameColor(vItemInfo.class),
1692 pItem.mOffline,
1693 vIconPath,
1694 vSelected,
1695 vTooltipName,
1696 vTooltipText);
1697  
1698 vItem.Item = pItem;
1699 end
1700  
1701 function CalendarAttendanceList_SetAttendanceItem(pAttendanceList, pItemIndex, pCategory, pItem)
1702 if pItem.mType == "Whisper" then
1703 CalendarAttendanceList_SetItemToRSVP(pAttendanceList, pItemIndex, pCategory, pItem, GroupCalendar_cMeetingAttendanceNameFormat, pAttendanceList.ShowRank);
1704 elseif pAttendanceList.ViewType == "Questing" then
1705 local vNameFormat;
1706  
1707 if pCategory ~= "STANDBY" then
1708 vNameFormat = GroupCalendar_cQuestAttendanceNameFormat;
1709 else
1710 vNameFormat = GroupCalendar_cMeetingAttendanceNameFormat;
1711 end
1712  
1713 CalendarAttendanceList_SetItemToRSVP(pAttendanceList, pItemIndex, pCategory, pItem, vNameFormat, pAttendanceList.ShowRank);
1714 else
1715 CalendarAttendanceList_SetItemToRSVP(pAttendanceList, pItemIndex, pCategory, pItem, GroupCalendar_cMeetingAttendanceNameFormat, pAttendanceList.ShowRank);
1716 end
1717 end
1718  
1719 function CalendarAttendanceList_UpdateAttendanceItems(pAttendanceList, pAttendanceCounts, pSetItemFunction, pTotalAttendanceFormat)
1720 local vTotalAttendeesItem = getglobal(pAttendanceList:GetName().."Total");
1721  
1722 local vFirstItemIndex = FauxScrollFrame_GetOffset(getglobal(pAttendanceList:GetName().."ScrollFrame"));
1723 local vItemIndex = 0;
1724  
1725 if not pAttendanceCounts then
1726 CalendarAttendanceList_HideUnusedAttendanceItems(pAttendanceList, vItemIndex);
1727 vTotalAttendeesItem:SetText(string.format(pTotalAttendanceFormat, 0));
1728 return;
1729 end
1730  
1731 vTotalAttendeesItem:SetText(string.format(pTotalAttendanceFormat, pAttendanceCounts.NumAttendees));
1732  
1733 for vIndex, vCategory in pAttendanceCounts.SortedCategories do
1734 local vClassAttendanceInfo = pAttendanceCounts.Categories[vCategory];
1735  
1736 if vFirstItemIndex == 0 then
1737 local vActionFunc = nil;
1738  
1739 if vCategory == "WHISPERS" then
1740 vActionFunc = CalendarWhisperLog_AskClear;
1741 end
1742  
1743 CalendarAttendanceList_SetItemToCategory(pAttendanceList, vItemIndex, vCategory, vActionFunc, nil);
1744  
1745 vItemIndex = vItemIndex + 1;
1746  
1747 if vItemIndex >= pAttendanceList.NumItems then
1748 CalendarAttendanceList_HideUnusedAttendanceItems(pAttendanceList, vItemIndex);
1749 return;
1750 end
1751 else
1752 vFirstItemIndex = vFirstItemIndex - 1;
1753 end
1754  
1755 if not pAttendanceList.CollapsedCategories[vCategory] then
1756 if vFirstItemIndex >= vClassAttendanceInfo.mCount then
1757 vFirstItemIndex = vFirstItemIndex - vClassAttendanceInfo.mCount;
1758 else
1759 for vIndex, vRSVP in vClassAttendanceInfo.mAttendees do
1760 if vFirstItemIndex == 0 then
1761 pSetItemFunction(pAttendanceList, vItemIndex, vCategory, vRSVP);
1762  
1763 vItemIndex = vItemIndex + 1;
1764  
1765 if vItemIndex >= pAttendanceList.NumItems then
1766 CalendarAttendanceList_HideUnusedAttendanceItems(pAttendanceList, vItemIndex);
1767 return;
1768 end
1769 else
1770 vFirstItemIndex = vFirstItemIndex - 1;
1771 end
1772 end
1773 end
1774 end
1775 end
1776  
1777 CalendarAttendanceList_HideUnusedAttendanceItems(pAttendanceList, vItemIndex);
1778 end
1779  
1780 function CalendarAttendanceList_GetIndexedItem(pAttendanceList, pIndex)
1781 local vIndex = pIndex + FauxScrollFrame_GetOffset(getglobal(pAttendanceList:GetName().."ScrollFrame"));
1782  
1783 for vCategoryIndex, vCategory in pAttendanceList.EventListInfo.AttendanceCounts.SortedCategories do
1784 local vClassAttendanceInfo = pAttendanceList.EventListInfo.AttendanceCounts.Categories[vCategory];
1785  
1786 if vIndex == 0 then
1787 Calendar_DebugMessage("CalendarAttendanceList_GetIndexedItem: Index specifies a header");
1788 return nil;
1789 end
1790  
1791 vIndex = vIndex - 1;
1792  
1793 if not pAttendanceList.CollapsedCategories[vCategory] then
1794 if vIndex < vClassAttendanceInfo.mCount then
1795 return vClassAttendanceInfo.mAttendees[vIndex + 1];
1796 end
1797  
1798 vIndex = vIndex - vClassAttendanceInfo.mCount;
1799 end
1800 end
1801  
1802 Calendar_DebugMessage("CalendarAttendanceList_GetIndexedItem: Index too high");
1803 return nil;
1804 end
1805  
1806 function CalendarAttendanceList_OnVerticalScroll()
1807 CalendarAttendanceList_Update(gCalendarAttendanceList_VerticalScrollList);
1808 end
1809  
1810 function CalendarAttendanceList_OnClick(pButton)
1811 local vAttendanceList = pButton:GetParent();
1812  
1813 if pButton.IsCategoryItem then
1814 if not vAttendanceList.CollapsedCategories[pButton.Category] then
1815 vAttendanceList.CollapsedCategories[pButton.Category] = true;
1816 else
1817 vAttendanceList.CollapsedCategories[pButton.Category] = nil;
1818 end
1819  
1820 CalendarAttendanceList_Update(vAttendanceList);
1821 return;
1822 end
1823  
1824 if not pButton.Checkable then
1825 pButton:SetChecked(false);
1826 return;
1827 end
1828  
1829 if pButton.Item then
1830 if vAttendanceList.CurrentPanel == "GroupView" then
1831 CalendarGroupInvites_SetItemSelected(pButton.Item, not pButton.Item.mSelected);
1832 end
1833 end
1834 end
1835  
1836 function CalendarAttendanceList_ShowMessageTooltip(pOwner, pName, pMessages, pColor)
1837 if not pName then
1838 return;
1839 end
1840  
1841 GameTooltip:SetOwner(pOwner, "ANCHOR_LEFT");
1842 GameTooltip:AddLine(pName);
1843  
1844 local vColor = {r = 1, g = 1, b = 1};
1845  
1846 if pColor then
1847 vColor = pColor;
1848 end;
1849  
1850 if type(pMessages) == "table" then
1851 for vIndex, vText in pMessages do
1852 GameTooltip:AddLine(vText, vColor.r, vColor.g, vColor.b, 1);
1853 end
1854 else
1855 GameTooltip:AddLine(pMessages, vColor.r, vColor.g, vColor.b, 1);
1856 end
1857  
1858 GameTooltip:Show();
1859 end
1860  
1861 function CalendarAttendanceList_OnEnter()
1862 local vAttendanceList = this:GetParent();
1863  
1864 CalendarAttendanceList_ShowMessageTooltip(this, this.TooltipName, this.TooltipText, this.TooltipTextColor);
1865 end
1866  
1867 function CalendarAttendanceList_OnLeave()
1868 GameTooltip:Hide();
1869 end
1870  
1871 function CalendarAttendanceList_ListViewItemSelected(pMenu, pItem)
1872 local vAttendanceList = pMenu.AttendanceList;
1873  
1874 CalendarAttendanceList_SetListView(vAttendanceList, pItem);
1875 end
1876  
1877 function CalendarAttendanceList_SetListView(pAttendanceList, pViewMode)
1878 pAttendanceList.ListViewMode = pViewMode;
1879  
1880 CalendarAttendanceList_EventChanged(pAttendanceList, pAttendanceList.Database, pAttendanceList.Event);
1881 CalendarGroupInvites_SetSortMode(pViewMode);
1882 end
1883  
1884 CalendarAttendanceList_cPanelNames =
1885 {
1886 ExpandAll = "MainView",
1887 GroupTab = "GroupView",
1888 };
1889  
1890 function CalendarAttendanceList_GroupListChanged(pAttendanceList)
1891 CalendarAttendanceList_Update(pAttendanceList);
1892 end
1893  
1894 function CalendarAttendanceList_ShowPanel(pAttendanceList, pPanelName)
1895 local vAttendanceListName = pAttendanceList:GetName();
1896  
1897 for vTabName, vPanelName in CalendarAttendanceList_cPanelNames do
1898 local vPanel = getglobal(vAttendanceListName..vPanelName);
1899 local vTab = getglobal(vAttendanceListName..vTabName);
1900  
1901 if vPanelName == pPanelName then
1902 vPanel:Show();
1903 PanelTemplates_SelectTab(vTab);
1904  
1905 -- Handle panel-specific show code
1906  
1907 if pPanelName == "GroupView" then
1908 local vGroup = CalendarGroupInvites_BeginEvent(pAttendanceList.Database, pAttendanceList.Event);
1909  
1910 CalendarAttendanceList_SetGroup(pAttendanceList, vGroup);
1911 CalendarGroupInvites_SetChangedFunc(CalendarAttendanceList_GroupListChanged, pAttendanceList);
1912 end
1913 else
1914 if vPanelName == "GroupView" then
1915 CalendarGroupInvites_SetChangedFunc(nil, nil);
1916 end
1917  
1918 vPanel:Hide();
1919 PanelTemplates_DeselectTab(vTab);
1920 end
1921 end
1922  
1923 pAttendanceList.CurrentPanel = pPanelName;
1924  
1925 CalendarAttendanceList_AdjustHeight(pAttendanceList);
1926 CalendarAttendanceList_Update(pAttendanceList);
1927 end
1928  
1929 function CalendarAddPlayer_Open()
1930 CalendarAddPlayer_Reset();
1931  
1932 CalendarAddPlayerFrame:Show();
1933 CalendarAddPlayerFrameName:SetFocus();
1934 end
1935  
1936 function CalendarAddPlayer_Reset()
1937 CalendarAddPlayerFrame.IsWhisper = false;
1938 CalendarAddPlayerFrame.Guild = nil;
1939  
1940 CalendarAddPlayerFrameName:SetText("");
1941 CalendarAddPlayerFrameLevel:SetText("");
1942 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameGuildRankMenu, nil);
1943 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameStatusMenu, "Y");
1944 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameClassMenu, "?");
1945 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameRaceMenu, "?");
1946 CalendarAddPlayerFrameComment:SetText("");
1947  
1948 if IsInGuild() then
1949 CalendarAddPlayerFrameGuildRankMenu:Show();
1950 else
1951 CalendarAddPlayerFrameGuildRankMenu:Hide();
1952 end
1953  
1954 CalendarAddPlayerFrameDeleteButton:Hide();
1955  
1956 CalendarAddPlayerFrameWhisper:Hide();
1957 CalendarAddPlayerFrame:SetHeight(CalendarAddPlayerFrame.NormalHeight);
1958 end
1959  
1960 function CalendarAddPlayer_OpenWhisper(pName, pDate, pTime, pWhispers)
1961 CalendarAddPlayer_Reset();
1962  
1963 CalendarAddPlayerFrame.IsWhisper = true;
1964 CalendarAddPlayerFrame.Name = pName;
1965 CalendarAddPlayerFrame.Date = pDate;
1966 CalendarAddPlayerFrame.Time = pTime;
1967 CalendarAddPlayerFrame.Whispers = pWhispers;
1968  
1969 CalendarAddPlayerFrameName:SetText(pName);
1970 CalendarAddPlayer_AutoCompletePlayerInfo();
1971  
1972 CalendarAddPlayerFrameDeleteButton:Show();
1973  
1974 CalendarAddPlayerFrameWhisper:Show();
1975 CalendarAddPlayerFrameWhisperRecent:SetText(pWhispers[table.getn(pWhispers)]);
1976  
1977 if gGroupCalendar_PlayerSettings.LastWhisperConfirmMessage then
1978 CalendarAddPlayerFrameWhisperReply:SetText(gGroupCalendar_PlayerSettings.LastWhisperConfirmMessage);
1979 end
1980  
1981 if gGroupCalendar_PlayerSettings.LastWhisperStatus then
1982 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameStatusMenu, gGroupCalendar_PlayerSettings.LastWhisperStatus);
1983 end
1984  
1985 local vColor = ChatTypeInfo["WHISPER"];
1986  
1987 CalendarAddPlayerFrameWhisperRecent:SetTextColor(vColor.r, vColor.g, vColor.b);
1988 CalendarAddPlayerFrameWhisperReply:SetTextColor(vColor.r, vColor.g, vColor.b);
1989  
1990 CalendarAddPlayerFrame:SetHeight(CalendarAddPlayerFrame.NormalHeight + CalendarAddPlayerFrameWhisper:GetHeight());
1991  
1992 CalendarAddPlayerFrame:Show();
1993 CalendarAddPlayerFrameName:SetFocus();
1994 end
1995  
1996 function CalendarAddPlayer_SaveNext()
1997 if CalendarAddPlayerFrame.IsWhisper then
1998 local vNextWhisper = CalendarWhisperLog_GetNextWhisper(CalendarAddPlayerFrame.Name);
1999  
2000 CalendarAddPlayer_Save();
2001  
2002 if vNextWhisper then
2003 CalendarAddPlayer_OpenWhisper(vNextWhisper.mName, vNextWhisper.mDate, vNextWhisper.mTime, vNextWhisper.mWhispers);
2004 else
2005 CalendarAddPlayer_Cancel();
2006 end
2007 else
2008 CalendarAddPlayer_Save();
2009 CalendarAddPlayer_Open();
2010 end
2011 end
2012  
2013 function CalendarAddPlayer_Delete()
2014 if not CalendarAddPlayerFrame.IsWhisper then
2015 return;
2016 end
2017  
2018 local vNextWhisper = CalendarWhisperLog_GetNextWhisper(CalendarAddPlayerFrame.Name);
2019  
2020 CalendarWhisperLog_RemovePlayer(CalendarAddPlayerFrame.Name);
2021  
2022 if vNextWhisper then
2023 CalendarAddPlayer_OpenWhisper(vNextWhisper.mName, vNextWhisper.mDate, vNextWhisper.mTime, vNextWhisper.mWhispers);
2024 else
2025 CalendarAddPlayer_Cancel();
2026 end
2027 end
2028  
2029 function CalendarAddPlayer_EditRSVP(pRSVP)
2030 CalendarAddPlayer_Reset();
2031  
2032 CalendarAddPlayerFrame.RSVP = pRSVP;
2033 CalendarAddPlayerFrameName:SetText(pRSVP.mName);
2034 CalendarAddPlayerFrameLevel:SetText(pRSVP.mLevel);
2035 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameStatusMenu, pRSVP.mStatus);
2036 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameClassMenu, pRSVP.mClassCode);
2037 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameRaceMenu, pRSVP.mRaceCode);
2038  
2039 local vGuildRank = EventDatabase_MapGuildRank(pRSVP.mGuild, pRSVP.mGuildRank);
2040  
2041 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameGuildRankMenu, vGuildRank);
2042  
2043 if pRSVP.mComment then
2044 CalendarAddPlayerFrameComment:SetText(pRSVP.mComment);
2045 end
2046  
2047 CalendarAddPlayerFrame:Show();
2048 CalendarAddPlayerFrameName:SetFocus();
2049 end
2050  
2051 function CalendarAddPlayer_Done()
2052 CalendarAddPlayer_Save();
2053 CalendarAddPlayerFrame:Hide();
2054 end
2055  
2056 function CalendarAddPlayer_Cancel()
2057 CalendarAddPlayerFrame:Hide();
2058 end
2059  
2060 function CalendarAddPlayer_Save()
2061 local vName = CalendarAddPlayerFrameName:GetText();
2062  
2063 if vName == "" then
2064 return;
2065 end
2066  
2067 local vStatusCode = UIDropDownMenu_GetSelectedValue(CalendarAddPlayerFrameStatusMenu);
2068 local vClassCode = UIDropDownMenu_GetSelectedValue(CalendarAddPlayerFrameClassMenu);
2069 local vRaceCode = UIDropDownMenu_GetSelectedValue(CalendarAddPlayerFrameRaceMenu);
2070 local vLevel = tonumber(CalendarAddPlayerFrameLevel:GetText());
2071 local vComment = CalendarAddPlayerFrameComment:GetText();
2072 local vGuild = CalendarAddPlayerFrame.Guild;
2073 local vGuildRank = UIDropDownMenu_GetSelectedValue(CalendarAddPlayerFrameGuildRankMenu);
2074  
2075 if not vGuild then
2076 vGuild = gGroupCalendar_PlayerGuild;
2077 end
2078  
2079 if not vGuildRank then
2080 vGuild = nil;
2081 end
2082  
2083 local vRSVP = EventDatabase_CreatePlayerRSVP(
2084 gCalendarEventEditor_Database,
2085 gCalendarEventEditor_Event,
2086 vName,
2087 vRaceCode,
2088 vClassCode,
2089 vLevel,
2090 vStatusCode,
2091 vComment,
2092 vGuild,
2093 vGuildRank,
2094 nil);
2095  
2096 if CalendarAddPlayerFrame.RSVP then
2097 -- if CalendarAddPlayerFrame.RSVP.mGuild then
2098 -- vRSVP.mGuild = CalendarAddPlayerFrame.RSVP.mGuild;
2099 -- vRSVP.mGuildRank = CalendarAddPlayerFrame.RSVP.mGuildRank;
2100 -- end
2101  
2102 vRSVP.mDate = CalendarAddPlayerFrame.RSVP.mDate;
2103 vRSVP.mTime = CalendarAddPlayerFrame.RSVP.mTime;
2104 vRSVP.mAlts = CalendarAddPlayerFrame.RSVP.mAlts;
2105  
2106 -- Save the guild rank mapping
2107  
2108 EventDatabase_SetGuildRankMapping(
2109 CalendarAddPlayerFrame.RSVP.mGuild,
2110 CalendarAddPlayerFrame.RSVP.mGuildRank,
2111 vGuildRank);
2112 end
2113  
2114 --
2115  
2116 EventDatabase_AddEventRSVP(
2117 gCalendarEventEditor_Database,
2118 gCalendarEventEditor_Event,
2119 vName,
2120 vRSVP)
2121  
2122 if CalendarAddPlayerFrame.IsWhisper then
2123 CalendarWhisperLog_RemovePlayer(CalendarAddPlayerFrame.Name);
2124 end
2125  
2126 -- Send the reply /w if there is one
2127  
2128 if CalendarAddPlayerFrameWhisper:IsVisible() then
2129 local vReplyWhisper = CalendarAddPlayerFrameWhisperReply:GetText();
2130  
2131 if vReplyWhisper and vReplyWhisper ~= "" then
2132 gGroupCalendar_PlayerSettings.LastWhisperConfirmMessage = vReplyWhisper;
2133 SendChatMessage(vReplyWhisper, "WHISPER", nil, CalendarAddPlayerFrame.Name);
2134 end
2135  
2136 -- Remember what status was used
2137  
2138 gGroupCalendar_PlayerSettings.LastWhisperStatus = UIDropDownMenu_GetSelectedValue(CalendarAddPlayerFrameStatusMenu);
2139 end
2140 end
2141  
2142 function CalendarAddPlayer_AutoCompletePlayerInfo()
2143 local vName = CalendarAddPlayerFrameName:GetText();
2144 local vUpperName = strupper(vName);
2145  
2146 local vGuildMemberIndex = CalendarNetwork_GetGuildMemberIndex(vName);
2147  
2148 if vGuildMemberIndex then
2149 local vMemberName, vRank, vRankIndex, vLevel, vClass, vZone, vNote, vOfficerNote, vOnline = GetGuildRosterInfo(vGuildMemberIndex);
2150  
2151 CalendarAddPlayerFrameName:SetText(vMemberName);
2152 CalendarAddPlayerFrameLevel:SetText(vLevel);
2153 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameClassMenu, EventDatabase_GetClassCodeByClass(vClass));
2154 -- CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameRaceMenu, EventDatabase_GetRaceCodeByRace(vRace));
2155 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameGuildRankMenu, vRankIndex);
2156  
2157 CalendarAddPlayerFrame.Guild = gGroupCalendar_PlayerGuild;
2158  
2159 return true;
2160 end
2161  
2162 local vNumFriends = GetNumFriends();
2163  
2164 for vFriendIndex = 1, vNumFriends do
2165 local vFriendName, vLevel, vClass, vArea, vConnected = GetFriendInfo(vFriendIndex);
2166  
2167 if strupper(vFriendName) == vUpperName
2168 and vConnected then
2169 CalendarAddPlayerFrameName:SetText(vFriendName);
2170 CalendarAddPlayerFrameLevel:SetText(vLevel);
2171 CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameClassMenu, EventDatabase_GetClassCodeByClass(vClass));
2172 -- CalendarDropDown_SetSelectedValue(CalendarAddPlayerFrameRaceMenu, EventDatabase_GetRaceCodeByRace(vRace));
2173 end
2174 end
2175  
2176 return false;
2177 end
2178  
2179 function CalendarAddPlayerWhisper_OnEnter()
2180 if not CalendarAddPlayerFrame.IsWhisper then
2181 return;
2182 end
2183  
2184 CalendarAttendanceList_ShowMessageTooltip(this, CalendarAddPlayerFrame.Name, CalendarAddPlayerFrame.Whispers, ChatTypeInfo["WHISPER"]);
2185 end
2186  
2187 function CalendarAddPlayerWhisper_OnLeave()
2188 GameTooltip:Hide();
2189 end
2190  
2191 function CalendarAddPlayerWhisper_Reply()
2192 local vName;
2193  
2194 if CalendarAddPlayerFrame.Name then
2195 vName = CalendarAddPlayerFrame.Name;
2196 else
2197 vName = CalendarAddPlayerFrameName:GetText()
2198 end
2199  
2200 if not vName or vName == "" then
2201 return;
2202 end
2203  
2204 DEFAULT_CHAT_FRAME.editBox.chatType = "WHISPER";
2205 DEFAULT_CHAT_FRAME.editBox.tellTarget = vName;
2206  
2207 ChatEdit_UpdateHeader(DEFAULT_CHAT_FRAME.editBox);
2208  
2209 if not DEFAULT_CHAT_FRAME.editBox:IsVisible() then
2210 ChatFrame_OpenChat("", DEFAULT_CHAT_FRAME);
2211 end
2212 end
2213  
2214 function CalendarEventEditor_AttendanceMenuItemSelected(pOwner, pValue)
2215 local vAttendanceItem = pOwner:GetParent();
2216 local vLineIndex = vAttendanceItem:GetID();
2217 local vAttendanceList = vAttendanceItem:GetParent();
2218  
2219 local vItem = CalendarAttendanceList_GetIndexedItem(vAttendanceList, vLineIndex);
2220  
2221 if pValue == "DELETE" then
2222 if vItem.mType == "Whisper" then
2223 CalendarWhisperLog_RemovePlayer(vItem.mName);
2224 else
2225 gGroupCalendar_RSVPToDelete = vItem;
2226 StaticPopup_Show("CONFIRM_CALENDAR_RSVP_DELETE", vItem.mName);
2227 end
2228 elseif pValue == "ADD" then
2229 if vItem.mType == "Whisper" then
2230 CalendarAddPlayer_OpenWhisper(vItem.mName, vItem.mDate, vItem.mTime, vItem.mWhispers);
2231 end
2232 elseif pValue == "EDIT" then
2233 CalendarAddPlayer_EditRSVP(vItem);
2234 elseif pValue == "INVITE" then
2235 InviteByName(vItem.mName);
2236 else
2237 vItem.mStatus = pValue;
2238  
2239 EventDatabase_AddEventRSVP(
2240 gCalendarEventEditor_Database,
2241 gCalendarEventEditor_Event,
2242 vItem.mName,
2243 vItem);
2244 end
2245 end
2246  
2247 function CalendarClassLimitItem_SetClassName(pItem, pClassName)
2248 local vItemName = pItem:GetName();
2249 local vLabelItem = getglobal(vItemName.."Label");
2250 local vSeparatorItem = getglobal(vItemName.."Separator");
2251  
2252 local vLabel = getglobal("GroupCalendar_c"..pClassName.."sLabel");
2253 vLabelItem:SetText(vLabel);
2254  
2255 local vColor = RAID_CLASS_COLORS[getglobal("GroupCalendar_c"..pClassName.."ClassColorName")];
2256  
2257 vLabelItem:SetTextColor(vColor.r, vColor.g, vColor.b);
2258 vSeparatorItem:SetTextColor(vColor.r, vColor.g, vColor.b);
2259 end
2260  
2261 function CalendarAttendanceTotals_OnShow(pTotalsFrame)
2262 local vFrameName = this:GetName();
2263 local vPaladinsFrame = getglobal(vFrameName.."Paladins");
2264 local vPaladinsLabelFrame = getglobal(vFrameName.."PaladinsLabel");
2265 local vShamansFrame = getglobal(vFrameName.."Shamans");
2266 local vShamansLabelFrame = getglobal(vFrameName.."ShamansLabel");
2267  
2268 if gGroupCalendar_PlayerFactionGroup == "Alliance" then
2269 vPaladinsFrame:Show();
2270 vPaladinsLabelFrame:Show();
2271 vShamansFrame:Hide();
2272 vShamansLabelFrame:Hide();
2273 else
2274 vPaladinsFrame:Hide();
2275 vPaladinsLabelFrame:Hide();
2276 vShamansFrame:Show();
2277 vShamansLabelFrame:Show();
2278 end
2279 end