1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, Title => $title &>
49 <& /Dashboards/Elements/Tabs,
50 current_subtab => $current_subtab,
52 DashboardObj => $DashboardObj &>
54 <& /Elements/ListActions, actions => \@results &>
56 <form action="<%RT->Config->Get('WebPath')%>/Dashboards/Subscription.html" method="post" enctype="multipart/form-data" name="SubscribeDashboard">
57 <input type="hidden" class="hidden" name="DashboardId" value="<% $fields{'DashboardId'} %>" />
58 <table width="100%" border="0">
61 <td valign="top" class="boxcontainer">
62 <&| /Widgets/TitleBox, title => loc('Dashboard') &>
65 <tr><td class="label">
67 </td><td class="value">
68 <% $DashboardObj->Name %>
71 <tr><td class="label">
73 </td><td class="value">
74 % my @portlets = grep { defined } $DashboardObj->Portlets;
78 <ol class="dashboard-queries">
79 % for my $portlet (@portlets) {
80 <li class="dashboard-query">
81 <% loc($portlet->{description}, $fields{'Rows'}) %>
91 <&| /Widgets/TitleBox, title => loc('Subscription') &>
94 <tr><td class="label">
96 </td><td class="value">
98 <input type="radio" name="Frequency" value="daily" <% $fields{'Frequency'} eq 'daily' ? 'checked="checked"' : "" %>>
102 <input type="radio" name="Frequency" value="m-f" <% $fields{'Frequency'} eq 'm-f' ? 'checked="checked"' : "" %>>
103 <&|/l&>Monday through Friday</&>
106 <input type="radio" name="Frequency" value="weekly"<% $fields{'Frequency'} eq 'weekly' ? 'checked="checked"' : "" %>>
107 <&|/l&>weekly</&></input>, <&|/l&>on</&>
109 <option value="Monday" <% $fields{'Dow'} eq 'Monday' ? 'selected="selected"' : '' %>><&|/l&>Monday</&></option>
110 <option value="Tuesday" <% $fields{'Dow'} eq 'Tuesday' ? 'selected="selected"' : '' %>><&|/l&>Tuesday</&></option>
111 <option value="Wednesday" <% $fields{'Dow'} eq 'Wednesday' ? 'selected="selected"' : '' %>><&|/l&>Wednesday</&></option>
112 <option value="Thursday" <% $fields{'Dow'} eq 'Thursday' ? 'selected="selected"' : '' %>><&|/l&>Thursday</&></option>
113 <option value="Friday" <% $fields{'Dow'} eq 'Friday' ? 'selected="selected"' : '' %>><&|/l&>Friday</&></option>
114 <option value="Saturday" <% $fields{'Dow'} eq 'Saturday' ? 'selected="selected"' : '' %>><&|/l&>Saturday</&></option>
115 <option value="Sunday" <% $fields{'Dow'} eq 'Sunday' ? 'selected="selected"' : '' %>><&|/l&>Sunday</&></option>
119 % for my $f ( qw/1 2 3 4/ ) {
120 <option value="<%$f%>" <% $fields{'Fow'} == $f ? 'selected="selected"' : '' %>><% $f %></option>
126 <input type="radio" name="Frequency" value="monthly"<% $fields{'Frequency'} eq 'monthly' ? 'checked="checked"' : "" %>>
127 <&|/l&>monthly</&></input> , <&|/l&>on day</&>
129 % for my $dom (1..31) {
130 <option value="<% $dom %>" <% $fields{'Dom'} == $dom ? 'selected="selected"' : '' %>><% loc($dom) %></option>
135 <input type="radio" name="Frequency" value="never" <% $fields{'Frequency'} eq 'never' ? 'checked="checked"' : "" %>>
140 <tr><td class="label">
142 </td><td class="value">
144 % for my $hour (0..23) {
145 % my $formatted = sprintf '%02d:00', $hour;
146 % my $selected = $formatted eq $fields{'Hour'}
147 % ? 'selected="selected"'
150 <option value="<% $formatted %>" <%$selected%>><% $formatted %></option>
155 <tr><td class="label">
157 </td><td class="value">
159 % for my $rows (1, 2, 5, 10, 15, 20, 25, 50, 75, 100, 0) {
160 <option value="<% $rows %>" <% $fields{'Rows'} eq $rows ? 'selected="selected"' : '' %>><% loc($rows || 'Unlimited') %></option>
165 <tr><td class="label">
166 <&|/l&>Recipient</&>:
167 </td><td class="value">
168 <input name="Recipient" id="Recipient" size="30" value="<%$fields{Recipient} ? $fields{Recipient} : ''%>" />
169 <div class="hints"><% loc("Leave blank to send to your current email address ([_1])", $session{'CurrentUser'}->UserObj->EmailAddress) %></div>
177 % if ($SubscriptionObj->Id) {
178 <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &>
180 <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &>
186 my $current_subtab = 'Dashboards/Subscription.html?DashboardId=' . $DashboardId;
188 my ($title, @results);
191 my $timezone = $session{'CurrentUser'}->UserObj->Timezone || RT->Config->Get('Timezone');
194 my $DashboardObj = RT::Dashboard->new($session{'CurrentUser'});
196 my $SubscriptionObj = RT::Attribute->new($session{'CurrentUser'});
198 # first let's see if we already have a subscription to this DashboardId
199 for my $sub ($session{'CurrentUser'}->UserObj->Attributes->Named('Subscription')) {
200 next unless $sub->SubValue('DashboardId') == $DashboardId;
201 $SubscriptionObj = $sub;
205 $DashboardId = $SubscriptionObj->Id
206 ? $SubscriptionObj->SubValue('DashboardId')
207 : $ARGS{'DashboardId'};
209 ($val, $msg) = $DashboardObj->LoadById($DashboardId);
210 $val || Abort(loc("Couldn't load dashboard [_1]: [_2].", $DashboardId, $msg));
213 DashboardId => $DashboardId,
214 Frequency => 'daily',
224 # update any fields with the values from the subscription object
225 if ($SubscriptionObj->Id) {
226 for my $field (keys %fields) {
227 $fields{$field} = $SubscriptionObj->SubValue($field);
231 # finally, update any fields with arguments passed in by the user
232 for my $field (keys %fields) {
233 next if $field eq 'DashboardId'; # but this one is immutable
234 $fields{$field} = $ARGS{$field}
235 if defined($ARGS{$field});
237 # this'll be defined on submit
238 if (defined $ARGS{Save}) {
240 if ($SubscriptionObj->Id) {
241 $DashboardId = delete $fields{'DashboardId'}; # immutable
242 ($val, $msg) = $SubscriptionObj->SetSubValues(%fields);
243 $fields{'DashboardId'} = $DashboardId;
245 # not so good to spew base64-encoded data at the user :)
246 if ($msg =~ /^Content changed from/) {
247 $msg = "Subscription updated.";
254 Abort(loc("Unable to subscribe to dashboard [_1]: Permission denied", $DashboardId))
255 unless $DashboardObj->CurrentUserCanSubscribe;
257 my ($val, $msg) = $SubscriptionObj->Create(
258 Name => 'Subscription',
259 Description => 'Subscription to dashboard ' . $DashboardId,
260 ContentType => 'storable',
261 Object => $session{'CurrentUser'}->UserObj,
265 push @results, loc("Subscribed to dashboard [_1]", $DashboardObj->Name);
266 push @results, loc("Warning: you have no email address set, so you will not receive this dashboard until you have it set")
267 unless $session{'CurrentUser'}->EmailAddress || $fields{Recipient};
270 push @results, loc('Subscription could not be created: [_1]', $msg);
275 if ($SubscriptionObj->Id) {
276 $title = loc("Modify the subscription to dashboard [_1]", $DashboardObj->Name);
279 $title = loc("Subscribe to dashboard [_1]", $DashboardObj->Name);
284 $DashboardId => undef