]>
Commit | Line | Data |
---|---|---|
84fb5b46 MKG |
1 | %# BEGIN BPS TAGGED BLOCK {{{ |
2 | %# | |
3 | %# COPYRIGHT: | |
4 | %# | |
320f0092 | 5 | %# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC |
84fb5b46 MKG |
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 | <& /Elements/Tabs &> | |
50 | <& /Elements/ListActions, actions => \@results &> | |
51 | ||
52 | <form action="<%RT->Config->Get('WebPath')%>/Dashboards/Modify.html" method="post" enctype="multipart/form-data" name="ModifyDashboard" id="ModifyDashboard"> | |
53 | ||
54 | %unless ($Dashboard->Id) { | |
55 | <input type="hidden" class="hidden" name="id" value="new" /> | |
56 | % } else { | |
57 | <input type="hidden" class="hidden" name="id" value="<%$Dashboard->Id%>" /> | |
58 | % } | |
59 | ||
60 | <&|/Widgets/TitleBox, title => loc('Basics') &> | |
61 | <table> | |
62 | <tr> | |
63 | <td class="label"><&|/l&>Name</&>:</td> | |
64 | <td class="value"><input name="Name" value="<%$Dashboard->Name%>" /></td> | |
65 | </tr> | |
66 | <tr> | |
67 | <td class="label"><&|/l&>Privacy</&>:</td> | |
68 | <td><& /Dashboards/Elements/SelectPrivacy, Name => "Privacy", Objects => \@privacies, Default => $Dashboard->Privacy &></td> | |
69 | </tr> | |
70 | </table> | |
71 | </&> | |
72 | <& /Elements/Submit, Name => 'Save', Label =>( $Create ? loc('Create') : loc('Save Changes') ) &> | |
73 | ||
74 | % if ($Dashboard->Id && $can_delete) { | |
75 | <& /Elements/Submit, Name => 'Delete', Label => loc('Delete') &> | |
76 | % } | |
77 | </form> | |
78 | <%INIT> | |
79 | ||
80 | my ($title, @results); | |
81 | my $tried_create = 0; | |
82 | ||
83 | # user went directly to Modify.html | |
84 | $Create = 1 if !$id; | |
85 | ||
86 | ||
87 | my $redirect_to ='/Dashboards/Modify.html'; | |
88 | ||
89 | use RT::Dashboard; | |
90 | ||
91 | my $Dashboard = RT::Dashboard->new($session{'CurrentUser'}); | |
92 | my $method = $Create ? 'ObjectsForCreating' : 'ObjectsForModifying'; | |
93 | my @privacies = $Dashboard->$method; | |
94 | ||
af59614d | 95 | Abort(loc("Permission Denied")) if @privacies == 0; |
84fb5b46 MKG |
96 | |
97 | if ($Create) { | |
98 | $title = loc("Create a new dashboard"); | |
99 | } | |
100 | else { | |
101 | if ($id eq 'new') { | |
102 | $tried_create = 1; | |
103 | ||
104 | my ($val, $msg) = $Dashboard->Save( | |
105 | Name => $ARGS{'Name'}, | |
106 | Privacy => $ARGS{'Privacy'}, | |
107 | ); | |
108 | ||
109 | if (!$val) { | |
110 | Abort(loc("Dashboard could not be created: [_1]", $msg)); | |
111 | } | |
112 | ||
113 | push @results, $msg; | |
114 | $id = $Dashboard->Id; | |
115 | if (!$Dashboard->id || ! $Dashboard->CurrentUserCanSee) { | |
116 | $redirect_to='/Dashboards/index.html'; | |
117 | ||
118 | } | |
119 | } | |
120 | else { | |
121 | my ($ok, $msg) = $Dashboard->LoadById($id); | |
122 | $ok || Abort(loc("Couldn't load dashboard [_1]: [_2]", $id, $msg)); | |
123 | } | |
124 | ||
125 | if ($id) { | |
126 | $title = loc("Modify the dashboard [_1]", $Dashboard->Name); | |
af59614d | 127 | } |
84fb5b46 MKG |
128 | # If the create failed |
129 | else { | |
130 | $Create = 1; | |
131 | $title = loc("Create a new dashboard"); | |
132 | } | |
133 | } | |
134 | ||
135 | if (!$Create && !$tried_create && $id && $ARGS{'Save'}) { | |
136 | my ($ok, $msg) = $Dashboard->Update(Privacy => $ARGS{'Privacy'}, | |
137 | Name => $ARGS{'Name'}); | |
138 | ||
139 | if ($ok) { | |
af59614d | 140 | push @results, loc("Dashboard [_1] updated", $Dashboard->Name); |
84fb5b46 MKG |
141 | } |
142 | else { | |
af59614d | 143 | push @results, loc("Dashboard [_1] could not be updated: [_2]", $Dashboard->Name, $msg); |
84fb5b46 MKG |
144 | } |
145 | ||
146 | } | |
147 | ||
148 | ||
149 | my $can_delete = $Dashboard->CurrentUserCanDelete; | |
150 | ||
151 | if (!$Create && !$tried_create && $id && $ARGS{'Delete'}) { | |
152 | my ($ok, $msg) = $Dashboard->Delete(); | |
153 | if (!$ok) { | |
154 | Abort(loc("Couldn't delete dashboard [_1]: [_2]", $id, $msg)); | |
155 | } | |
156 | ||
157 | push @results, $msg; | |
158 | $redirect_to = '/Dashboards/index.html'; | |
159 | } | |
160 | ||
161 | # This code does automatic redirection if any updates happen. | |
162 | MaybeRedirectForResults( | |
163 | Actions => \@results, | |
164 | Path => $redirect_to, | |
165 | Arguments => { id => $id }, | |
166 | ); | |
167 | ||
168 | </%INIT> | |
169 | ||
170 | <%ARGS> | |
171 | $Create => undef | |
172 | $Name => undef | |
173 | $id => '' unless defined $id | |
174 | $Delete => undef | |
175 | </%ARGS> | |
176 |