%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) %# %# %# LICENSE: %# %# This work is made available to you under the terms of Version 2 of %# the GNU General Public License. A copy of that license should have %# been provided with this software, but in any event can be snarfed %# from www.gnu.org. %# %# This work is distributed in the hope that it will be useful, but %# WITHOUT ANY WARRANTY; without even the implied warranty of %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %# General Public License for more details. %# %# You should have received a copy of the GNU General Public License %# along with this program; if not, write to the Free Software %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA %# 02110-1301 or visit their web page on the internet at %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. %# %# %# CONTRIBUTION SUBMISSION POLICY: %# %# (The following paragraph is not intended to limit the rights granted %# to you to modify and distribute this software under the terms of %# the GNU General Public License and is only of importance to you if %# you choose to contribute your changes and enhancements to the %# community by submitting them to Best Practical Solutions, LLC.) %# %# By intentionally submitting any modifications, corrections or %# derivatives to this work, or any other work intended for use with %# Request Tracker, to Best Practical Solutions, LLC, you confirm that %# you are the copyright holder for those contributions and you grant %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, %# royalty-free, perpetual, license to use, copy, create derivative %# works based on those contributions, and sublicense and distribute %# those contributions and any derivatives thereof. %# %# END BPS TAGGED BLOCK }}} <& /Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
<&| /Widgets/TitleBox, title => loc('Dashboard') &>
<&|/l&>Dashboard: <% $Dashboard->Name %>
<&|/l&>Queries: % my @portlets = grep { defined } $Dashboard->Portlets; % if (!@portlets) { (<&|/l&>none) % } else {
    % for my $portlet (@portlets) {
  1. <% loc( RT::SavedSearch->EscapeDescription($portlet->{description}), $fields{'Rows'}) %>
  2. % }
% }
<&| /Widgets/TitleBox, title => loc('Subscription') &> % $m->callback( %ARGS, CallbackName => 'SubscriptionFormEnd', FieldsRef => \%fields, % SubscriptionObj => $SubscriptionObj, DashboardObj => $Dashboard );
<&|/l&>Frequency: >
>
>
>
>
<&|/l&>Hour: (<%$timezone%>)
<&|/l&>Rows:
<&|/l&>Recipient:
<% loc("Leave blank to send to your current email address ([_1])", $session{'CurrentUser'}->EmailAddress) %>
% if ($SubscriptionObj) { <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &> % } else { <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &> % }
<%INIT> my ($title, @results); my $Loaded = 0; my $timezone = $session{'CurrentUser'}->UserObj->Timezone || RT->Config->Get('Timezone'); use RT::Dashboard; my $Dashboard = RT::Dashboard->new($session{'CurrentUser'}); my ($ok, $msg) = $Dashboard->LoadById($id); $ok || Abort(loc("Couldn't load dashboard [_1]: [_2]", $id, $msg)); my $SubscriptionObj = $Dashboard->Subscription; $id = $SubscriptionObj ? $SubscriptionObj->SubValue('DashboardId') : $ARGS{'id'}; my %fields = ( DashboardId => $id, Frequency => 'daily', Hour => '06:00', Dow => 'Monday', Dom => 1, Rows => 20, Recipient => '', Fow => 1, Counter => 0, ); $m->callback( %ARGS, CallbackName => 'SubscriptionFields', FieldsRef => \%fields, SubscriptionObj => $SubscriptionObj, DashboardObj => $Dashboard); # update any fields with the values from the subscription object if ($SubscriptionObj) { for my $field (keys %fields) { $fields{$field} = $SubscriptionObj->SubValue($field); } } # finally, update any fields with arguments passed in by the user for my $field (keys %fields) { next if $field eq 'DashboardId'; # but this one is immutable $fields{$field} = $ARGS{$field} if defined($ARGS{$field}); } $m->callback( %ARGS, CallbackName => 'MassageSubscriptionFields', FieldsRef => \%fields, SubscriptionObj => $SubscriptionObj, DashboardObj => $Dashboard); # this'll be defined on submit if (defined $ARGS{Save}) { my $ok = 1; # validation if ($fields{Recipient}) { my @addresses = Email::Address->parse($fields{Recipient}); if (@addresses == 0) { push @results, loc('Recipient must be an email address'); $ok = 0; } } if ($ok) { # update if ($SubscriptionObj) { $id = delete $fields{'DashboardId'}; # immutable ($ok, $msg) = $SubscriptionObj->SetSubValues(%fields); $fields{'DashboardId'} = $id; $msg = loc("Subscription updated") if $ok; push @results, $msg; } # create else { Abort(loc("Unable to subscribe to dashboard [_1]: Permission Denied", $id)) unless $Dashboard->CurrentUserCanSubscribe; $SubscriptionObj = RT::Attribute->new($session{CurrentUser}); ($ok, $msg) = $SubscriptionObj->Create( Name => 'Subscription', Description => 'Subscription to dashboard ' . $id, ContentType => 'storable', Object => $session{'CurrentUser'}->UserObj, Content => \%fields, ); if ($ok) { push @results, loc("Subscribed to dashboard [_1]", $Dashboard->Name); push @results, loc("Warning: you have no email address set, so you will not receive this dashboard until you have it set") unless $session{'CurrentUser'}->EmailAddress || $fields{Recipient}; } else { push @results, loc('Subscription could not be created: [_1]', $msg); } } } } if ($SubscriptionObj) { $title = loc("Modify the subscription to dashboard [_1]", $Dashboard->Name); } else { $title = loc("Subscribe to dashboard [_1]", $Dashboard->Name); } <%ARGS> $id => undef $Frequency => undef $Hour => undef $Dow => undef $Dom => undef $Rows => undef $Recipient => undef