+# {{{ Move things around
+if ( $ARGS{"Up"} ) {
+ if (@current_values) {
+ foreach my $value (@current_values) {
+ my $index = $value->getIndex();
+ if ( $value->getIndex() > 0 ) {
+ my $parent = $value->getParent();
+ $parent->removeChild($index);
+ $parent->insertChild( $index - 1, $value );
+ $value = $parent->getChild( $index - 1 );
+ }
+ else {
+ push( @actions, [ loc("error: can't move up"), -1 ] );
+ }
+ }
+ }
+ else {
+ push( @actions, [ loc("error: nothing to move"), -1 ] );
+ }
+}
+elsif ( $ARGS{"Down"} ) {
+ if (@current_values) {
+ foreach my $value (@current_values) {
+ my $index = $value->getIndex();
+ my $parent = $value->getParent();
+ if ( $value->getIndex() < ( $parent->getChildCount - 1 ) ) {
+ $parent->removeChild($index);
+ $parent->insertChild( $index + 1, $value );
+ $value = $parent->getChild( $index + 1 );
+ }
+ else {
+ push( @actions, [ loc("error: can't move down"), -1 ] );
+ }
+ }
+ }
+ else {
+ push( @actions, [ loc("error: nothing to move"), -1 ] );
+ }
+}
+elsif ( $ARGS{"Left"} ) {
+ if (@current_values) {
+ foreach my $value (@current_values) {
+ my $parent = $value->getParent();
+ my $grandparent = $parent->getParent();
+ if ( !$grandparent->isRoot ) {
+ my $index = $parent->getIndex();
+ $parent->removeChild($value);
+ $grandparent->insertChild( $index, $value );
+ if ( $parent->isLeaf() ) {
+ $grandparent->removeChild($parent);
+ }
+ }
+ else {
+ push( @actions, [ loc("error: can't move left"), -1 ] );
+ }
+ }
+ }
+ else {
+ push( @actions, [ loc("error: nothing to move"), -1 ] );
+ }
+}
+elsif ( $ARGS{"Right"} ) {
+ if (@current_values) {
+ foreach my $value (@current_values) {
+ my $parent = $value->getParent();
+ my $index = $value->getIndex();
+ my $newparent;
+ if ( $index > 0 ) {
+ my $sibling = $parent->getChild( $index - 1 );
+ if ( ref( $sibling->getNodeValue ) ) {
+ $parent->removeChild($value);
+ my $newtree = RT::Interface::Web::QueryBuilder::Tree->new( 'AND', $parent );
+ $newtree->addChild($value);
+ }
+ else {
+ $parent->removeChild($index);
+ $sibling->addChild($value);
+ }
+ }
+ else {
+ $parent->removeChild($value);
+ $newparent = RT::Interface::Web::QueryBuilder::Tree->new( 'AND', $parent );
+ $newparent->addChild($value);
+ }
+ }
+ }
+ else {
+ push( @actions, [ loc("error: nothing to move"), -1 ] );
+ }