1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2018 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 <& NewListActions, actions => $actions &>
49 <&|/Widgets/TitleBox, title => join(': ', grep defined, loc("Current search"), $Description) &>
51 <select size="10" name="clauses" style="width: 100%" multiple="multiple">
52 % $m->out($optionlist);
56 <input type="submit" class="button" name="Up" value=" ↑ " />
57 <input type="submit" class="button" name="Down" value=" ↓ " />
58 <input type="submit" class="button" name="Left" value=" ← " />
59 <input type="submit" class="button" name="Right" value=" → " />
60 <input type="submit" class="button" name="Toggle" value="<&|/l&>And/Or</&>" />
61 <input type="submit" class="button" name="DeleteClause" value="<&|/l&>Delete</&>" />
62 %#<input type="submit" class="button" name="EditQuery" value="Advanced" />
80 my @NewSelection = ();
83 if ( $ARGS{'Up'} || $ARGS{'Down'} ) {
85 foreach my $value (@$Selected) {
86 my $parent = $value->getParent;
87 my $index = $value->getIndex;
88 my $newindex = $index;
89 $newindex++ if $ARGS{'Down'};
90 $newindex-- if $ARGS{'Up'};
91 if ( $newindex < 0 || $newindex >= $parent->getChildCount ) {
92 push( @results, [ loc("error: can't move up"), -1 ] ) if $ARGS{'Up'};
93 push( @results, [ loc("error: can't move down"), -1 ] ) if $ARGS{'Down'};
97 $parent->removeChild( $index );
98 $parent->insertChild( $newindex, $value );
102 push( @results, [ loc("error: nothing to move"), -1 ] );
105 elsif ( $ARGS{"Left"} ) {
107 foreach my $value (@$Selected) {
108 my $parent = $value->getParent;
109 if( $value->isRoot || $parent->isRoot ) {
110 push( @results, [ loc("error: can't move left"), -1 ] );
114 my $grandparent = $parent->getParent;
115 if( $grandparent->isRoot ) {
116 push( @results, [ loc("error: can't move left"), -1 ] );
120 my $index = $parent->getIndex;
121 $parent->removeChild($value);
122 $grandparent->insertChild( $index, $value );
123 if ( $parent->isLeaf ) {
124 $grandparent->removeChild($parent);
129 push( @results, [ loc("error: nothing to move"), -1 ] );
132 elsif ( $ARGS{"Right"} ) {
134 foreach my $value (@$Selected) {
135 my $parent = $value->getParent;
136 my $index = $value->getIndex;
140 my $sibling = $parent->getChild( $index - 1 );
141 $newparent = $sibling unless $sibling->isLeaf;
143 $newparent ||= RT::Interface::Web::QueryBuilder::Tree->new( $ARGS{'AndOr'} || 'AND', $parent );
145 $parent->removeChild($value);
146 $newparent->addChild($value);
150 push( @results, [ loc("error: nothing to move"), -1 ] );
153 elsif ( $ARGS{"DeleteClause"} ) {
156 my %Selected = map { $_ => 1 } @$Selected;
157 foreach my $node ( @$Selected ) {
158 my $tmp = $node->getParent;
159 while ( !$Selected{ $tmp } && !$tmp->isRoot ) {
160 $tmp = $tmp->getParent;
162 next if $Selected{ $tmp };
167 my @non_siblings_top = grep !$seen{ $_->getParent }++, @top;
171 foreach my $selected( @non_siblings_top ) {
172 my $newindex = $selected->getIndex + 1;
173 $selected->insertSibling( $newindex, $add );
175 $add->getParent->setNodeValue( $ARGS{'AndOr'} );
176 push @NewSelection, $add;
180 while( my $node = shift @top ) {
181 my $parent = $node->getParent;
182 $parent->removeChild($node);
188 push( @results, [ loc("error: nothing to delete"), -1 ] );
191 elsif ( $ARGS{"Toggle"} ) {
194 my @unique_nodes = grep !$seen{ $_ + 0 }++,
195 map ref $_->getNodeValue? $_->getParent: $_,
198 foreach my $node ( @unique_nodes ) {
199 if ( $node->getNodeValue eq 'AND' ) {
200 $node->setNodeValue('OR');
203 $node->setNodeValue('AND');
208 push( @results, [ loc("error: nothing to toggle"), -1 ] );
212 if ( @New && @$Selected ) {
214 my @non_siblings_selected = grep !$seen{ $_->getParent }++, @$Selected;
218 foreach my $selected( @non_siblings_selected ) {
219 my $newindex = $selected->getIndex + 1;
220 $selected->insertSibling( $newindex, $add );
222 $add->getParent->setNodeValue( $ARGS{'AndOr'} );
223 push @NewSelection, $add;
230 $Tree->addChild( $add );
231 push @NewSelection, $add;
233 $Tree->setNodeValue( $ARGS{'AndOr'} );
235 $_->DESTROY foreach @New;
237 push @$Selected, @NewSelection;
239 $Tree->PruneChildlessAggregators;