1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2014 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/ListActions, actions => \@results &>
50 <form action="<%RT->Config->Get('WebPath')%><% $m->request_comp->path |n %>" method="post">
51 <input type="hidden" name="id" value="<%$RootObj->Id%>" />
56 <td><&|/l&>Topic Name</&></td>
57 <td><input type="text" name="Name" size="30" /></td>
60 <td><&|/l&>Description</&></td>
61 <td><input type="text" name="Description" size="50" /></td>
65 <a href="Topics.html">New topic</a>
68 <& .tree, Element => $tree, Action => $Modify ? "Move" : "Add", Prefix => $Modify ? "Topic-$Modify-Parent" : "Insert", RootObj => $RootObj, Modify => $Modify &>
74 <table style="margin-top: -0.75em">
77 <td><input type="text" name="Topic-<%$topic->Id%>-Name" size="20" value="<%$topic->Name%>" /></td>
78 <td><input type="submit" name="Update" value="Update"><br /></td>
82 <td> <input type="text" name="Topic-<%$topic->Id%>-Description" size="20" value="<%$topic->Description%>" /></td>
83 <td><input type="submit" name="Delete-Topic-<%$topic->Id%>" value="Delete" /></td>
92 % my $topic = $Element->getNodeValue;
93 % unless ($Element->isRoot) {
94 % if ($Modify and $topic->Id == $Modify) {
96 <& .edit, topic => $topic &>
98 <a href="<%RT->Config->Get('WebPath')%><% $m->request_comp->path |n %>?id=<%$RootObj->Id%>&Modify=<%$topic->Id%>"
99 title="<%$topic->Description%>"><%$topic->Name || loc("(no name)") %></a>
103 % for my $e (sort {$a->getNodeValue->Name cmp $b->getNodeValue->Name} $Element->getAllChildren) {
104 <li><& .tree, Element => $e, Action => $Action, Prefix => $Prefix, RootObj => $RootObj, Modify => $Modify &></li>
107 % unless ($Action eq "Move" and grep {$_->getNodeValue->Id == $Modify} $Element->getAllChildren) {
108 <li><input type="submit" name="<%$Prefix%>-<%$topic eq "root" ? 0 : $topic->Id%>" value="<% $Action eq 'Move' ? loc('Move here') : loc('Add here') %>" /></li>
125 for my $k (keys %ARGS) {
126 if ($k =~ /^Topic-(\d+)-(Name|Description)/) {
127 my $topic = RT::Topic->new($session{'CurrentUser'});
130 next if $ARGS{$k} eq $topic->$2;
132 my ($val, $msg) = $topic->$proc($ARGS{$k});
135 $m->comp("/Elements/Error", Why => loc("Topic not found"));
137 } elsif ($k =~ /^Topic-(\d+)-Parent-(\d+)/) {
138 my $topic = RT::Topic->new($session{'CurrentUser'});
141 next if $2 eq $topic->Parent;
142 my $old = $topic->Parent;
144 my ($val, $msg) = $topic->setParent($new);
147 $m->comp("/Elements/Error", Why => loc("Topic not found"));
149 } elsif ($k =~ /^Insert-(\d+)/) {
150 my $topic = RT::Topic->new($session{'CurrentUser'});
151 my ($id, $msg) = $topic->Create(
153 Name => $ARGS{'Name'},
154 Description => $ARGS{'Description'},
155 ObjectType => ref($RootObj),
156 ObjectId => $RootObj->Id,
161 for my $k (keys %ARGS) {
162 next unless $k =~ /^Delete-Topic-(\d+)/;
163 my $topic = RT::Topic->new($session{'CurrentUser'});
166 my ($val, $msg) = $topic->DeleteAll();
169 $m->comp("/Elements/Error", Why => loc("Topic not found"));
173 my $topics = RT::Topics->new($session{'CurrentUser'});
174 $topics->LimitToObject($RootObj);
175 $topics->OrderByCols({FIELD => 'Parent'}, {FIELD => 'id'});
178 my $tree = Tree::Simple->new(Tree::Simple->ROOT);
179 my %lookup = (0 => $tree);
182 while (my $topic = $topics->Next) {
190 for my $topic (@work) {
191 if (defined $lookup{$topic->Parent}) {
192 $lookup{$topic->Id} = Tree::Simple->new($topic, $lookup{$topic->Parent});
198 redo unless $changed == 0;
201 for my $topic (@todo) {
202 $topic->setParent(0);
203 $lookup{$topic->Id} = Tree::Simple->new($topic, $tree);
204 push @results, "Reparented orphan ".$topic->Id." to root";