Subject: | Make the popup display fields configurable [patch] |
Hi Nicolas,
A client of ours is using RTx::Calendar and is very happy with it.
They've asked us to change what is displayed in the popup window. I've
made the fields configurable so everyone can benefit. :)
It reuses some (kinda scary) code from Results.tsv. The default display
hasn't really changed (I think requestors show email addresses instead
of names).
Shawn M Moore
for Best Practical
Subject: | parameterize-popup.diff |
=== html/Elements/CalendarEvent
==================================================================
--- html/Elements/CalendarEvent (revision 76799)
+++ html/Elements/CalendarEvent (revision 76801)
@@ -52,36 +52,24 @@
</a>
:</strong> <% $subject%><br />
<br />
- <strong><&|/l&>Owner</&>:</strong> <%$Object->OwnerObj->Name %><br />
- <strong><&|/l&>Created</&>:</strong> <%$Object->CreatedObj->AsString %><br />
-% # Shoud we keep thoses dates ?
- <strong><&|/l&>Starts</&>:</strong> <% $Object->StartsObj->Unix > 0 ? $Object->StartsObj->AsString : '-' %><br />
- <strong><&|/l&>Started</&>:</strong> <% $Object->StartedObj->Unix > 0 ? $Object->StartedObj->AsString : '-' %><br />
- <strong><&|/l&>LastUpdated</&>:</strong> <% $Object->LastUpdatedObj->Unix > 0 ? $Object->LastUpdatedObj->AsString : '-' %><br />
+%# logic taken from Ticket/Search/Results.tsv
+% foreach my $attr (@display_fields) {
+% my $value;
+%
+% if ($attr =~ /(.*)->ISO$/ and $Object->$1->Unix <= 0) {
+% $value = '-';
+% } else {
+% my $method = '$Object->'.$attr.'()';
+% $method =~ s/->ISO\(\)$/->ISO( Timezone => 'user' )/;
+% $value = eval $method;
+% if ($@) {die "Failed to find $attr - ". $@};
+% }
- <strong><&|/l&>Due</&>:</strong> <% $Object->DueObj->Unix > 0 ? $Object->DueObj->AsString : '-' %><br />
+ <strong><&|/l&><% $label_of{$attr} %></&>:</strong> <% $value %><br />
+% }
-% # and those one
- <strong><&|/l&>Resolved</&>:</strong> <% $Object->ResolvedObj->Unix > 0 ? $Object->ResolvedObj->AsString : '-' %><br />
-
-% unless ($IsReminder) {
- <strong><&|/l&>Status</&>:</strong> <%loc($Object->Status) %><br />
- <strong><&|/l&>Priority</&>:</strong> <%$Object->Priority %><br />
- <strong><&|/l&>Requestors</&>:</strong>
-
-% my $members = $Object->Requestors->MembersObj;
-% if ($members->Count == 0) {
-<&|/l&>none</&>
-% } else {
-% my @requestors;
-% while (my $watcher = $members->Next) {
-% push @requestors, $watcher->MemberObj->Object->Name;
-% }
-<% join ", ", @requestors %>
-% }
<br />
-% }
</span>
</div>
@@ -107,4 +95,29 @@
$TicketId = $Object->Id;
$subject = $Object->Subject;
}
+
+# 3.6 config
+my @display_fields = @RT::CalendarPopupFields;
+
+# 3.8 config
+@display_fields = RT->Config->Get('CalendarPopupFields')
+ if @display_fields == 0;
+
+# defaults
+if (@display_fields == 0) {
+ @display_fields = qw(
+ OwnerObj->Name CreatedObj->ISO StartsObj->ISO StartedObj->ISO
+ LastUpdatedObj->ISO DueObj->ISO ResolvedObj->ISO Status Priority
+ Requestors->MemberEmailAddressesAsString
+ );
+}
+
+my %label_of;
+for my $field (@display_fields) {
+ my $label = $field;
+ $label =~ s'Obj-.(?:AsString|Name|ISO)''g;
+ $label =~ s'-\>MemberEmailAddressesAsString''g;
+ $label_of{$field} = $label;
+}
+
</%init>