1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2013 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 &>
51 <& /Elements/ListActions, actions => \@results &>
53 <form action="<%RT->Config->Get('WebPath')%>/Dashboards/Subscription.html" method="post" enctype="multipart/form-data" name="SubscribeDashboard">
54 <input type="hidden" class="hidden" name="id" value="<% $fields{'DashboardId'} %>" />
55 <table width="100%" border="0">
58 <td valign="top" class="boxcontainer">
59 <&| /Widgets/TitleBox, title => loc('Dashboard') &>
62 <tr><td class="label">
64 </td><td class="value">
65 <% $Dashboard->Name %>
68 <tr><td class="label">
70 </td><td class="value">
71 % my @portlets = grep { defined } $Dashboard->Portlets;
75 <ol class="dashboard-queries">
76 % for my $portlet (@portlets) {
77 <li class="dashboard-query">
78 <% loc($portlet->{description}, $fields{'Rows'}) %>
88 <&| /Widgets/TitleBox, title => loc('Subscription') &>
91 <tr><td class="label">
93 </td><td class="value">
95 <input type="radio" name="Frequency" value="daily" <% $fields{'Frequency'} eq 'daily' ? 'checked="checked"' : "" |n %>>
99 <input type="radio" name="Frequency" value="m-f" <% $fields{'Frequency'} eq 'm-f' ? 'checked="checked"' : "" |n %>>
100 <&|/l&>Monday through Friday</&>
103 <input type="radio" name="Frequency" value="weekly"<% $fields{'Frequency'} eq 'weekly' ? 'checked="checked"' : "" |n %>>
104 <&|/l&>weekly</&></input>, <&|/l&>on</&>
106 <option value="Monday" <% $fields{'Dow'} eq 'Monday' ? 'selected="selected"' : '' |n %>><&|/l&>Monday</&></option>
107 <option value="Tuesday" <% $fields{'Dow'} eq 'Tuesday' ? 'selected="selected"' : '' |n %>><&|/l&>Tuesday</&></option>
108 <option value="Wednesday" <% $fields{'Dow'} eq 'Wednesday' ? 'selected="selected"' : '' |n %>><&|/l&>Wednesday</&></option>
109 <option value="Thursday" <% $fields{'Dow'} eq 'Thursday' ? 'selected="selected"' : '' |n %>><&|/l&>Thursday</&></option>
110 <option value="Friday" <% $fields{'Dow'} eq 'Friday' ? 'selected="selected"' : '' |n %>><&|/l&>Friday</&></option>
111 <option value="Saturday" <% $fields{'Dow'} eq 'Saturday' ? 'selected="selected"' : '' |n %>><&|/l&>Saturday</&></option>
112 <option value="Sunday" <% $fields{'Dow'} eq 'Sunday' ? 'selected="selected"' : '' |n %>><&|/l&>Sunday</&></option>
116 % for my $f ( qw/1 2 3 4/ ) {
117 <option value="<%$f%>" <% $fields{'Fow'} == $f ? 'selected="selected"' : '' |n %>><% $f %></option>
123 <input type="radio" name="Frequency" value="monthly"<% $fields{'Frequency'} eq 'monthly' ? 'checked="checked"' : "" |n %>>
124 <&|/l&>monthly</&></input> , <&|/l&>on day</&>
126 % for my $dom (1..31) {
127 <option value="<% $dom %>" <% $fields{'Dom'} == $dom ? 'selected="selected"' : '' |n %>><% loc($dom) %></option>
132 <input type="radio" name="Frequency" value="never" <% $fields{'Frequency'} eq 'never' ? 'checked="checked"' : "" |n %>>
137 <tr><td class="label">
139 </td><td class="value">
141 % my $formatter = RT::Date->new($session{CurrentUser})->LocaleObj;
142 % my $dt = DateTime->now;
143 % $dt->set_minute(0);
144 % $dt->set_second(0);
146 % for my $hour (0..23) {
147 % $dt->set_hour($hour);
148 % my $formatted = $dt->format_cldr($formatter->time_format_short);
150 % my $value = sprintf '%02d:00', $hour;
151 % my $selected = $value eq $fields{'Hour'}
152 % ? 'selected="selected"'
155 <option value="<% $value %>" <%$selected|n %>><% $formatted %></option>
160 <tr><td class="label">
162 </td><td class="value">
164 % for my $rows (1, 2, 5, 10, 15, 20, 25, 50, 75, 100, 0) {
165 <option value="<% $rows %>" <% $fields{'Rows'} eq $rows ? 'selected="selected"' : '' |n %>><% loc($rows || 'Unlimited') %></option>
170 <tr><td class="label">
171 <&|/l&>Recipient</&>:
172 </td><td class="value">
173 <input name="Recipient" id="Recipient" size="30" value="<%$fields{Recipient} ? $fields{Recipient} : ''%>" />
174 <div class="hints"><% loc("Leave blank to send to your current email address ([_1])", $session{'CurrentUser'}->EmailAddress) %></div>
182 % if ($SubscriptionObj) {
183 <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &>
185 <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &>
191 my ($title, @results);
193 my $timezone = $session{'CurrentUser'}->UserObj->Timezone || RT->Config->Get('Timezone');
196 my $Dashboard = RT::Dashboard->new($session{'CurrentUser'});
197 my ($ok, $msg) = $Dashboard->LoadById($id);
198 $ok || Abort(loc("Couldn't load dashboard [_1]: [_2]", $id, $msg));
200 my $SubscriptionObj = $Dashboard->Subscription;
202 $id = $SubscriptionObj ? $SubscriptionObj->SubValue('DashboardId') : $ARGS{'id'};
206 Frequency => 'daily',
216 # update any fields with the values from the subscription object
217 if ($SubscriptionObj) {
218 for my $field (keys %fields) {
219 $fields{$field} = $SubscriptionObj->SubValue($field);
223 # finally, update any fields with arguments passed in by the user
224 for my $field (keys %fields) {
225 next if $field eq 'DashboardId'; # but this one is immutable
226 $fields{$field} = $ARGS{$field}
227 if defined($ARGS{$field});
231 # this'll be defined on submit
232 if (defined $ARGS{Save}) {
236 if ($fields{Recipient}) {
237 my @addresses = Email::Address->parse($fields{Recipient});
238 if (@addresses == 0) {
239 push @results, loc('Recipient must be an email address');
246 if ($SubscriptionObj) {
247 $id = delete $fields{'DashboardId'}; # immutable
248 ($ok, $msg) = $SubscriptionObj->SetSubValues(%fields);
249 $fields{'DashboardId'} = $id;
251 # not so good to spew base64-encoded data at the user :)
252 if ($msg =~ /^Content changed from/) {
253 $msg = "Subscription updated.";
260 Abort(loc("Unable to subscribe to dashboard [_1]: Permission denied", $id))
261 unless $Dashboard->CurrentUserCanSubscribe;
263 $SubscriptionObj = RT::Attribute->new($session{CurrentUser});
264 ($ok, $msg) = $SubscriptionObj->Create(
265 Name => 'Subscription',
266 Description => 'Subscription to dashboard ' . $id,
267 ContentType => 'storable',
268 Object => $session{'CurrentUser'}->UserObj,
272 push @results, loc("Subscribed to dashboard [_1]", $Dashboard->Name);
273 push @results, loc("Warning: you have no email address set, so you will not receive this dashboard until you have it set")
274 unless $session{'CurrentUser'}->EmailAddress || $fields{Recipient};
277 push @results, loc('Subscription could not be created: [_1]', $msg);
283 if ($SubscriptionObj) {
284 $title = loc("Modify the subscription to dashboard [_1]", $Dashboard->Name);
287 $title = loc("Subscribe to dashboard [_1]", $Dashboard->Name);