import rt 3.8.9
[freeside.git] / rt / share / html / Dashboards / Modify.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 %#                                          <sales@bestpractical.com>
7 %#
8 %# (Except where explicitly superseded by other copyright notices)
9 %#
10 %#
11 %# LICENSE:
12 %#
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
16 %# from www.gnu.org.
17 %#
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.
22 %#
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.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
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.)
37 %#
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.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, Title => $title &>
49 <& /Dashboards/Elements/Tabs,
50     current_subtab => $current_subtab,
51     Title => $title,
52     $Create ? () : (DashboardObj => $Dashboard),
53 &>
54 <& /Elements/ListActions, actions => \@results &>
55
56 <form action="<%RT->Config->Get('WebPath')%>/Dashboards/Modify.html" method="post" enctype="multipart/form-data" name="ModifyDashboard">
57
58 %unless ($Dashboard->Id) {
59 <input type="hidden" class="hidden" name="id" value="new" />
60 % } else {
61 <input type="hidden" class="hidden" name="id" value="<%$Dashboard->Id%>" />
62 % }
63 <table>
64 <tr><td align="right">
65 <&|/l&>Name</&>:
66 </td>
67 <td><input name="Name" value="<%$Dashboard->Name%>" /></td>
68 </tr>
69 <tr><td align="right">
70 <&|/l&>Privacy</&>:
71 </td><td>
72 <& /Dashboards/Elements/SelectPrivacy, Name => "Privacy", Objects => \@privacies, Default => $Dashboard->Privacy &>
73 </td></tr>
74 </table>
75 % if ( $Create ) {
76 <& /Elements/Submit, Name => 'Save', Label => loc('Create') &>
77 % } else {
78 <& /Elements/Submit, Name => 'Save', Label => loc('Save Changes') &>
79 % }
80 % if ($Dashboard->Id && $can_delete) {
81 <& /Elements/Submit, Name => 'Delete', Label => loc('Delete') &>
82 % }
83 </form>
84 <%INIT>
85
86 my $current_subtab;
87 my ($title, @results);
88 my $tried_create = 0;
89
90 # user went directly to Modify.html
91 $Create = 1 if !$id;
92
93 use RT::Dashboard;
94
95 my $Dashboard = RT::Dashboard->new($session{'CurrentUser'});
96 my @privacies = $Dashboard->_PrivacyObjects(($Create ? 'Create' : 'Modify') => 1);
97
98 Abort(loc("Permission denied")) if @privacies == 0;
99
100 if ($Create) {
101     $current_subtab = 'Dashboards/Modify.html?Create=1';
102     $title = loc("Create a new dashboard");
103 }
104 else {
105     if ($id eq 'new') {
106         $tried_create = 1;
107
108         my ($val, $msg) = $Dashboard->Save(
109             Name    => $ARGS{'Name'},
110             Privacy => $ARGS{'Privacy'},
111         );
112
113         if (!$val) {
114             Abort(loc("Dashboard could not be created: [_1]", $msg));
115         }
116
117         push @results, $msg;
118         $id = $Dashboard->Id;
119     }
120     else {
121         my ($ok, $msg) = $Dashboard->LoadById($id);
122         $ok || Abort($msg);
123     }
124
125     if ($id) {
126         $title = loc("Modify the dashboard [_1]", $Dashboard->Name);
127         $current_subtab = 'Dashboards/Modify.html?id=' . $id;
128     }   
129     # If the create failed
130     else {
131         $Create = 1;
132         $current_subtab = 'Dashboards/Modify.html?Create=1';
133         $title = loc("Create a new dashboard");
134     }
135 }
136
137 if (!$Create && !$tried_create && $id && $ARGS{'Save'}) {
138     my ($ok, $msg) = $Dashboard->Update(Privacy  => $ARGS{'Privacy'},
139                                         Name     => $ARGS{'Name'});
140
141     if ($ok) {
142         push @results, loc("Dashboard updated");
143     }
144     else {
145         push @results, loc("Dashboard could not be updated: [_1]", $msg);
146     }
147
148 }
149
150 my $can_delete = $Dashboard->CurrentUserCanDelete;
151
152 if (!$Create && !$tried_create && $id && $ARGS{'Delete'}) {
153     my ($ok, $msg) = $Dashboard->Delete();
154     $ok || Abort(loc("Couldn't delete dashboard [_1]: [_2]", $id, $msg));
155
156     # put the user back into a useful place with a message
157     RT::Interface::Web::Redirect(RT->Config->Get('WebURL')."Dashboards/index.html?Deleted=$id");
158
159 }
160 </%INIT>
161
162 <%ARGS>
163 $Create => undef
164 $Name => undef
165 $id => '' unless defined $id
166 $Delete => undef
167 </%ARGS>
168