[Rt-commit] rtir branch, 2.9-trunk, updated. 86adddf9e52bc73742298acfe4ad5e18c8106a9d

Ruslan Zakirov ruz at bestpractical.com
Fri Dec 24 05:14:40 EST 2010


The branch, 2.9-trunk has been updated
       via  86adddf9e52bc73742298acfe4ad5e18c8106a9d (commit)
       via  a83be479725eef48709ee11c76f023388b93558d (commit)
       via  7639b461176c9a992456001bdd220da6fb47963e (commit)
       via  5ec80a909f39367b73b09cea2e7d679767505f4f (commit)
       via  e3922a11701f828ecb86366a67527c34234833ad (commit)
       via  9528606b44a46142f21c556123be474f66f3bdfe (commit)
       via  99ffb9ebf1a4f9672b738fc4bd12f351de7a01ed (commit)
       via  9b068bd125ccab0e94390eec79cda4f2a3a1764b (commit)
       via  102388963784ead07138a8f7d3566a5936f7e5d1 (commit)
       via  c3912875679c02ba21ff53e6d3a86bcce8fab0e0 (commit)
       via  622f0a675b098ed2b1ecd669f19ab76a25c8b32a (commit)
       via  cbdaafc49bb07f40d7d56bf84ee51b7e9959187b (commit)
       via  d5f58df33b8e04ced8e55b27cd5b17674db49078 (commit)
       via  eff924ee6fa776570254520e9717ff8cc5bf86b0 (commit)
       via  7de877c00a6a86ac5c1f2b9e1b72f5448e850fcd (commit)
       via  229ab0815e1074e7960926eed881941a28c99091 (commit)
       via  ed13881c169b34d65a258467dfe1224c16bcd7f1 (commit)
       via  03faa0ccf125e64121cd28fee766fba90ae411e9 (commit)
       via  cdf926eb12ddd2bb693f23b9e9d668872a67ea16 (commit)
       via  b7a2e5cd033d1336a6fe75f307e244f0631c44d9 (commit)
       via  5d95667c2020db157fe86de508d036f322dfc681 (commit)
       via  a991584db71e69a5635c5f3eeb0f8a85df3fdeaf (commit)
       via  4ecd371f30f533aebe82ca4ad6bdff7506f97ac5 (commit)
       via  0d8e5810e8c65e634cc299fcd48bab4f61ca83ad (commit)
       via  de8f1ba0b80c384c72986345b4aeb30e9620f486 (commit)
       via  db4a1054f83ea753da55b2dc431b751b02a98476 (commit)
       via  25179a63419a6903b3ba074b8389c968a812f33c (commit)
       via  a872bab47e54df2b9a6208cb6ede613ad2711d67 (commit)
       via  c6ecb9e88b921a7aa2146dacfa4b1b0008a9cf38 (commit)
       via  71312dc7c0535be8186ca685684108fc59c2a8e4 (commit)
       via  82f3c277698ad621e19ebb3aacafeb9e6d68f809 (commit)
       via  a752817eb35ea259a7eea07afce71df760086515 (commit)
       via  66c1ce4b38cc5ee33d13a8db5349ddf92f9457ba (commit)
       via  77501866a9d882a93591d5449b78bb06121ce0d6 (commit)
       via  ac0b921a1232d653942a032a5db5b09af61c825d (commit)
       via  abab460627a37204100e20e9ffc52aa7c5d136e5 (commit)
      from  42372f1804562ac39df7eb378c07df863104bf0d (commit)

Summary of changes:
 etc/RTIR_Config.pm                                 |    9 +-
 etc/add_constituency                               |    2 +-
 etc/initialdata                                    |   11 +-
 etc/upgrade/upgrade.pl                             |    2 +-
 html/Callbacks/RTIR/Elements/Tabs/Default          |   25 --
 html/Callbacks/RTIR/Elements/Tabs/Privileged       |  319 +++++++++++++++++++
 html/RTIR/Advanced.html                            |    7 +-
 html/RTIR/Block/Elements/Tabs                      |   25 --
 html/RTIR/Create.html                              |    7 +-
 html/RTIR/Display.html                             |   13 +-
 html/RTIR/Edit.html                                |    7 +-
 html/RTIR/Elements/BaseQuery                       |    7 -
 html/RTIR/Elements/ChildrenQuery                   |   19 --
 html/RTIR/Elements/DueIncidents                    |    4 +-
 html/RTIR/Elements/MergeWith                       |   12 +-
 html/RTIR/Elements/NewQuery                        |   21 --
 html/RTIR/Elements/NewReports                      |    4 +-
 html/RTIR/Elements/QueueTabs                       |  323 --------------------
 html/RTIR/Elements/ShowIncidents                   |    2 +-
 html/RTIR/Elements/SimpleSearch                    |   28 --
 html/RTIR/Elements/Tabs                            |   85 -----
 html/RTIR/Forward.html                             |   13 +-
 html/RTIR/Incident/BulkAbandon.html                |   30 +--
 html/RTIR/Incident/Create.html                     |   10 +-
 html/RTIR/Incident/Display.html                    |    6 +-
 html/RTIR/Incident/Elements/ShowChildren           |    6 +-
 html/RTIR/Incident/Elements/Tabs                   |   25 --
 html/RTIR/Incident/LinkToIncident.html             |  122 --------
 html/RTIR/Incident/Reply.html                      |   19 +-
 html/RTIR/Incident/ShowChildren.html               |   22 +-
 html/RTIR/Investigation/Elements/Tabs              |   25 --
 html/RTIR/Link/FromIncident/Refine.html            |   16 +
 .../FromIncident/index.html}                       |   68 ++---
 html/RTIR/Link/ToIncident/Refine.html              |   13 +
 html/RTIR/Link/ToIncident/index.html               |   84 +++++
 html/RTIR/Merge.html                               |   11 +-
 html/RTIR/Report/BulkReject.html                   |   22 +--
 html/RTIR/Report/Elements/Tabs                     |   25 --
 html/RTIR/Search/Elements/RefinePage               |   29 ++
 html/RTIR/Search/Elements/Tabs                     |   45 ---
 html/RTIR/Search/Refine.html                       |   47 +---
 html/RTIR/Search/Reporting.html                    |    5 +-
 html/RTIR/Search/Results.html                      |   38 +--
 html/RTIR/Search/index.html                        |   12 +-
 html/RTIR/Split.html                               |    6 +-
 html/RTIR/Tools/Elements/Tabs                      |   62 ----
 html/RTIR/Tools/Lookup.html                        |   10 +-
 html/RTIR/Tools/ScriptedAction.html                |   14 +-
 html/RTIR/Tools/index.html                         |    4 +
 html/RTIR/index.html                               |   13 +-
 lib/RT/IR.pm                                       |  101 ++++++-
 lib/RT/IR/Test.pm                                  |    5 +-
 52 files changed, 662 insertions(+), 1178 deletions(-)
 delete mode 100644 html/Callbacks/RTIR/Elements/Tabs/Default
 create mode 100644 html/Callbacks/RTIR/Elements/Tabs/Privileged
 delete mode 100644 html/RTIR/Block/Elements/Tabs
 delete mode 100644 html/RTIR/Elements/BaseQuery
 delete mode 100644 html/RTIR/Elements/ChildrenQuery
 delete mode 100644 html/RTIR/Elements/NewQuery
 delete mode 100644 html/RTIR/Elements/QueueTabs
 delete mode 100644 html/RTIR/Elements/SimpleSearch
 delete mode 100644 html/RTIR/Elements/Tabs
 delete mode 100644 html/RTIR/Incident/Elements/Tabs
 delete mode 100644 html/RTIR/Incident/LinkToIncident.html
 delete mode 100644 html/RTIR/Investigation/Elements/Tabs
 create mode 100644 html/RTIR/Link/FromIncident/Refine.html
 rename html/RTIR/{Incident/LinkChildren.html => Link/FromIncident/index.html} (60%)
 create mode 100644 html/RTIR/Link/ToIncident/Refine.html
 create mode 100644 html/RTIR/Link/ToIncident/index.html
 delete mode 100644 html/RTIR/Report/Elements/Tabs
 create mode 100644 html/RTIR/Search/Elements/RefinePage
 delete mode 100644 html/RTIR/Search/Elements/Tabs
 delete mode 100644 html/RTIR/Tools/Elements/Tabs
 create mode 100644 html/RTIR/Tools/index.html

- Log -----------------------------------------------------------------
commit abab460627a37204100e20e9ffc52aa7c5d136e5
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Dec 14 02:26:36 2010 +0300

    use id argument in Split.html instead of Ticket

diff --git a/html/RTIR/Split.html b/html/RTIR/Split.html
index f5d05af..a22616c 100644
--- a/html/RTIR/Split.html
+++ b/html/RTIR/Split.html
@@ -44,7 +44,7 @@
 &>
 
 <%INIT>
-my $TicketObj = LoadTicket( $Ticket );
+my $TicketObj = LoadTicket( $id );
 
 $m->callback(CallbackName => 'Initial', %ARGS, Ticket => $TicketObj);
 
@@ -54,7 +54,7 @@ if ( $m->comp_exists("/RTIR/$Type/Split.html") ) {
 }
 
 my $query = "Queue = 'Incidents' AND HasMember = " . $TicketObj->Id;
-my $incidents = new RT::Tickets( $session{'CurrentUser'} );
+my $incidents = RT::Tickets->new( $session{'CurrentUser'} );
 $incidents->FromSQL( $query );
 
 my $Incident;
@@ -65,5 +65,5 @@ if ( my $obj = $incidents->First ) {
 </%INIT>
 <%ARGS>
 $QuoteTransaction => undef
-$Ticket => undef
+$id => undef
 </%ARGS>

commit ac0b921a1232d653942a032a5db5b09af61c825d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:01:46 2010 +0300

    default path is /opt/rt4

diff --git a/lib/RT/IR/Test.pm b/lib/RT/IR/Test.pm
index 3f50e98..5562c98 100644
--- a/lib/RT/IR/Test.pm
+++ b/lib/RT/IR/Test.pm
@@ -2,7 +2,7 @@ use strict;
 use warnings;
 
 ### after: use lib qw(@RT_LIB_PATH@);
-use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
+use lib qw(/opt/rt4/local/lib /opt/rt4//lib);
 
 package RT::IR::Test;
 

commit 77501866a9d882a93591d5449b78bb06121ce0d6
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:02:16 2010 +0300

    RTFM is part of RT right now

diff --git a/lib/RT/IR/Test.pm b/lib/RT/IR/Test.pm
index 5562c98..f682418 100644
--- a/lib/RT/IR/Test.pm
+++ b/lib/RT/IR/Test.pm
@@ -36,7 +36,6 @@ sub import {
     } else {
         $args{'testing'} = 'RT::IR';
     }
-    unshift @{ $args{'requires'} }, 'RT::FM';
 
     $class->SUPER::import( %args );
     $class->export_to_level(1);

commit 66c1ce4b38cc5ee33d13a8db5349ddf92f9457ba
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:02:42 2010 +0300

    fill_cache -> FillCache

diff --git a/lib/RT/IR/Test.pm b/lib/RT/IR/Test.pm
index f682418..50086a8 100644
--- a/lib/RT/IR/Test.pm
+++ b/lib/RT/IR/Test.pm
@@ -44,7 +44,7 @@ sub import {
     RT->Config->Set( 'rtirname' => 'regression_tests' );
 
     require RT::Lifecycle;
-    RT::Lifecycle->fill_cache;
+    RT::Lifecycle->FillCache;
 
     require RT::IR;
 }

commit a752817eb35ea259a7eea07afce71df760086515
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:03:31 2010 +0300

    simple RT::IR->Types method

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 97c9528..7837bc3 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -146,6 +146,11 @@ sub OurQueue {
     return $TYPE{ lc $queue };
 }
 
+sub Types {
+    my $self = shift;
+    return values %TYPE;
+}
+
 =head2 TicketType
 
 Returns type of a ticket. Takes either Ticket or Queue argument.

commit 82f3c277698ad621e19ebb3aacafeb9e6d68f809
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:04:08 2010 +0300

    camelcase Lifecycle API usage

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 7837bc3..44afacd 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -207,8 +207,8 @@ sub States {
         my $queue = RT::Queue->new($RT::SystemUser);
         $queue->Load($name);
         if ( $queue->id ) {
-            push @states, $queue->lifecycle->active   if $arg{'Active'};
-            push @states, $queue->lifecycle->inactive if $arg{'Inactive'};
+            push @states, $queue->Lifecycle->Active   if $arg{'Active'};
+            push @states, $queue->Lifecycle->Inactive if $arg{'Inactive'};
         }
         else {
             $RT::Logger->error( "failed to load queue $name" );

commit 71312dc7c0535be8186ca685684108fc59c2a8e4
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:04:44 2010 +0300

    move NewQuery and BaseQuery from html into lib

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 44afacd..bc15d34 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -220,6 +220,63 @@ sub States {
     return sort grep !$seen{$_}++, @states;
 }
 
+sub NewQuery {
+    my $self = shift;
+    my %args = (
+        Queue => undef,
+        states => undef,
+        add_states => undef,
+        @_,
+    );
+    my @states = ref $args{'states'}? @{ $args{'states'} } : ( $args{'states'} );
+    @states = grep $_, @states;
+    unless( @states ) {
+        @states = RT::IR::States( %args );
+    }
+
+    my @add_states = ref $args{'add_states'}? @{ $args{'add_states'} } : ( $args{'add_states'} );
+    my %seen = ();
+    @states =  grep !$seen{$_}++, map lc, grep $_, @states, @add_states;
+
+    my $query = join " OR ",
+                map "'Status' = '$_'",
+                @states;
+    $query = "( $query )" if $query;
+    return $query;
+}
+
+
+sub BaseQuery {
+    my $self = shift;
+    my %args = (
+        Queue => undef,
+        HasNoMember => undef,
+        Constituency => undef,
+        @_
+    );
+    my $res = '';
+    if ( defined $args{'Queue'} && length $args{'Queue'} ) {
+        $res = "Queue = '$args{Queue}'";
+    }
+    if ( my $t = $args{'HasNoMember'} ) {
+        $res .= ' AND ' if $res;
+        $res .= 'HasMember != '. (ref $t? $t->id : int $t);
+    }
+    if (
+        my $t = $args{'Constituency'}
+        and RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject'
+    ) {
+        unless ( ref $t ) {
+            my $tmp = RT::Ticket->new( RT->SystemUser );
+            $tmp->Load( $t );
+            $t = $tmp;
+        }
+        $res .= ' AND ' if $res;
+        $res .= "CustomField.{Constituency} = '". $t->FirstCustomFieldValue('Constituency') ."'";
+    }
+    return $res;
+}
+
 sub GetCustomField {
     my $field = shift or return;
     return (__PACKAGE__->CustomFields( $field ))[0];

commit c6ecb9e88b921a7aa2146dacfa4b1b0008a9cf38
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:05:42 2010 +0300

    we don't need RT::FM checker in initialdata

diff --git a/etc/initialdata b/etc/initialdata
index 02da995..7b67037 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -1,12 +1,5 @@
 # Initial data for a fresh RTIR Installation.
 
- at Initial = ( sub {
-    eval { require RT::FM; };
-    if ($@) {
-        die "RTIR is built on top of RTFM; please install RTFM before continuing.\n";
-    }
-} );
-
 @Queues = (
     {
         Name              => 'Incidents',

commit a872bab47e54df2b9a6208cb6ede613ad2711d67
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:06:48 2010 +0300

    defaults for lifecycles now are in a separate hash

diff --git a/etc/RTIR_Config.pm b/etc/RTIR_Config.pm
index cebd00e..b7c9eed 100644
--- a/etc/RTIR_Config.pm
+++ b/etc/RTIR_Config.pm
@@ -280,11 +280,14 @@ Set(@Active_MakeClicky, qw(httpurl_overwrite ip email domain));
 Set(
     %Lifecycles,
     incidents => {
-        default_initial => 'open',
         initial         => ['open'],
         active          => ['open'],
-        inactive        => [ 'resolved', 'abandoned' ],
-        default_inactive  => 'resolved',
+        inactive        => ['resolved', 'abandoned'],
+
+        defaults => {
+            on_create => 'open',
+            on_merge  => 'resolved',
+        },
 
         transitions => {
             # from   => [ to list ],

commit 25179a63419a6903b3ba074b8389c968a812f33c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:07:33 2010 +0300

    /opt/rt4 path

diff --git a/etc/add_constituency b/etc/add_constituency
index 196a8c5..45a2fcd 100644
--- a/etc/add_constituency
+++ b/etc/add_constituency
@@ -52,7 +52,7 @@ use warnings;
 use strict;
 
 ### after: use lib qw(@RT_LIB_PATH@);
-use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
+use lib qw(/opt/rt4/local/lib /opt/rt4//lib);
 
 use RT;
 RT::LoadConfig;
diff --git a/etc/upgrade/upgrade.pl b/etc/upgrade/upgrade.pl
index 6937847..d6760a0 100644
--- a/etc/upgrade/upgrade.pl
+++ b/etc/upgrade/upgrade.pl
@@ -4,7 +4,7 @@ use warnings;
 use strict;
 
 ### after: use lib qw(@RT_LIB_PATH@);
-use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
+use lib qw(/opt/rt4/local/lib /opt/rt4//lib);
 
 use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc); 
 use RT::Tickets; 

commit db4a1054f83ea753da55b2dc431b751b02a98476
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:08:58 2010 +0300

    we don't need per type Tabs files

diff --git a/html/RTIR/Block/Elements/Tabs b/html/RTIR/Block/Elements/Tabs
deleted file mode 100644
index 6dc27d0..0000000
--- a/html/RTIR/Block/Elements/Tabs
+++ /dev/null
@@ -1,25 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-<& /RTIR/Elements/QueueTabs, QueueName => 'Blocks', %ARGS &>
diff --git a/html/RTIR/Incident/Elements/Tabs b/html/RTIR/Incident/Elements/Tabs
deleted file mode 100644
index 20ac518..0000000
--- a/html/RTIR/Incident/Elements/Tabs
+++ /dev/null
@@ -1,25 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-<& /RTIR/Elements/QueueTabs, QueueName => 'Incidents', %ARGS &>
diff --git a/html/RTIR/Investigation/Elements/Tabs b/html/RTIR/Investigation/Elements/Tabs
deleted file mode 100644
index 0ca0ca6..0000000
--- a/html/RTIR/Investigation/Elements/Tabs
+++ /dev/null
@@ -1,25 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-<& /RTIR/Elements/QueueTabs, QueueName => 'Investigations', %ARGS &>
diff --git a/html/RTIR/Report/Elements/Tabs b/html/RTIR/Report/Elements/Tabs
deleted file mode 100644
index 80ad298..0000000
--- a/html/RTIR/Report/Elements/Tabs
+++ /dev/null
@@ -1,25 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-<& /RTIR/Elements/QueueTabs, QueueName => 'Incident Reports', %ARGS &>

commit de8f1ba0b80c384c72986345b4aeb30e9620f486
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:19:47 2010 +0300

    first stab at new menu

diff --git a/html/Callbacks/RTIR/Elements/Tabs/Default b/html/Callbacks/RTIR/Elements/Tabs/Default
deleted file mode 100644
index 391e856..0000000
--- a/html/Callbacks/RTIR/Elements/Tabs/Default
+++ /dev/null
@@ -1,25 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%#  Copyright (c) 2002-2003 Jesse Vincent <jesse at bestpractical.com>
-%#  
-%#  This program is free software; you can redistribute it and/or modify
-%#  it under the terms of version 2 of the GNU General Public License 
-%#  as published by the Free Software Foundation.
-%# 
-%#  A copy of that license should have arrived with this
-%#  software, but in any event can be snarfed from www.gnu.org.
-%# 
-%#  This program is distributed in the hope that it will be useful,
-%#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-%#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-%#  GNU General Public License for more details.
-%# 
-%# END LICENSE BLOCK
-
-<%init>
-$toptabs->{'BB-RTIR'} = { title =>loc("RTIR"),
-                          path  => "RTIR/index.html" };
-</%init>
-<%args>
-$toptabs =>undef
-</%args>
diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
new file mode 100644
index 0000000..d0f6537
--- /dev/null
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -0,0 +1,220 @@
+%# BEGIN LICENSE BLOCK
+%# 
+%#  Copyright (c) 2002-2003 Jesse Vincent <jesse at bestpractical.com>
+%#  
+%#  This program is free software; you can redistribute it and/or modify
+%#  it under the terms of version 2 of the GNU General Public License 
+%#  as published by the Free Software Foundation.
+%# 
+%#  A copy of that license should have arrived with this
+%#  software, but in any event can be snarfed from www.gnu.org.
+%# 
+%#  This program is distributed in the hope that it will be useful,
+%#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+%#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%#  GNU General Public License for more details.
+%# 
+%# END LICENSE BLOCK
+<%INIT>
+
+my $query_string = sub {
+    my %args = @_;
+    my $u    = URI->new();
+    $u->query_form(%args);
+    return $u->query;
+};
+
+my $root = Menu->child( rtir => title => loc('RTIR'), path => '/RTIR/' );
+
+my $search = $root->child( search => title => loc('Search'), path => '/RTIR/Search/' );
+$search->child( new => title => loc('New Query'), path => '/RTIR/Search/?NewQuery=1' );
+# XXX: query string
+$search->child( build => title => loc('Build Search'), path => '/RTIR/Search/' );
+if ( $session{'CurrentSearchHash'} ) {
+    $search->child( results => title => loc('Show Results'), path => '/RTIR/Search/Results.html' );
+} else {
+
+}
+
+$root->child( incidents => title => loc('Incidents'), path => '/RTIR/Search/Results.html?Queue=Incidents' );
+$root->child( reports => title => loc('Incident Reports'), path => '/RTIR/Search/Results.html?Queue=Incident%20Reports' );
+$root->child( investigations => title => loc('Investigations'), path => '/RTIR/Search/Results.html?Queue=Investigations' );
+unless ( RT->Config->Get('RTIR_DisableBlocksQueue') ) {
+    $root->child( blocks => title => loc('Blocks'), path => '/RTIR/Search/Results.html?Queue=Blocks' );
+}
+my $tools = $root->child( tools => title => loc('Tools'), path => '/RTIR/Tools/' );
+$tools->child( lookup => title => loc('Lookup'), path => '/RTIR/Tools/Lookup.html' );
+$tools->child( reporting => title => loc('Reporting'), path => '/RTIR/Reporting/' );
+my $scripted_actions = $tools->child( scripted_actions => title => loc('Scripted Action') );
+$scripted_actions->child( email => title => loc('By Email address'), path => '/RTIR/Tools/ScriptedAction.html' );
+$scripted_actions->child( ip => title => loc('By IP address'), path => '/RTIR/Tools/ScriptedAction.html?loop=IP' );
+
+my $request_path = $HTML::Mason::Commands::r->path_info;
+return unless $request_path =~ m{^/RTIR/};
+
+my $args = $m->request_args;
+my $re_rtir_types = '(?:'. join( '|', map "\Q$_\E", RT::IR->Types ) .')';
+
+if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$} ) {
+    my $id = $args->{'id'};
+
+    # we'll never get here unless ticket is there and it's rtir's type
+    my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
+    $ticket->Load($id);
+    $id = $ticket->id;
+
+    my $queue = $ticket->QueueObj;
+    my $type = RT::IR::TicketType( Queue => $queue );
+
+    my %can;
+    my $can = sub {
+        return $can{$_[0]} if exists $can{$_[0]};
+        return $can{$_[0]} = $ticket->CurrentUserHasRight( $_[0] );
+    };
+
+    PageMenu()->child( display => title => loc('Display'), path => "/RTIR/Display.html?id=$id" );
+    if ( $can->('ModifyTicket') ) {
+        PageMenu()->child( edit => title => loc('Edit'), path => "/RTIR/Edit.html?id=$id" );
+        PageMenu()->child( split => title => loc('Split'), path => "/RTIR/Split.html?id=$id" );
+        # XXX: we're missing query string here
+        PageMenu()->child( merge => title => loc('Merge'), path => "/RTIR/Merge.html?id=$id" );
+        PageMenu()->child( advanced => title => loc('Advanced'), path => "/RTIR/Advanced.html?id=$id" );
+    }
+
+    if ( $can->('ModifyTicket') || $can->('ReplyToTicket') ) {
+        if ( $type eq 'Incident' ) {
+            PageMenu()->child(
+                reply_reporters => title => loc('Reply to Reporters'),
+                path  => "/RTIR/Incident/Reply.html?id=$id&SelectAllTickets=1",
+            );
+            PageMenu()->child(
+                reply_all => title => loc('Reply to All'),
+                path  => "/RTIR/Incident/Reply.html?id=$id&SelectAllTickets=1&All=1",
+            );
+        } else {
+            PageMenu()->child(
+                reply => title => loc('Reply'),
+                path  => "/RTIR/Update.html?id=$id&Action=Respond",
+            );
+        }
+    }
+    if ( $can->('OwnTicket') ) {
+        if ( $ticket->Owner == $RT::Nobody->id ) {
+            PageMenu()->child(
+                take => title => loc('Take'),
+                path  => "/RTIR/Display.html?Action=Take&id=$id",
+            ) if $can->('ModifyTicket') || $can->('TakeTicket');
+        } elsif ( $ticket->Owner != $session{CurrentUser}->id ) {
+            PageMenu()->child(
+                steal => title => loc('Steal'),
+                path  => "/RTIR/Display.html?Action=Steal&id=$id",
+            ) if $can->('ModifyTicket') || $can->('StealTicket');
+        }
+    }
+
+    my $i = 0;
+    my $status = $ticket->Status;
+    my $lifecycle = $queue->Lifecycle;
+    foreach my $info ( $lifecycle->Actions( $status ) ) {
+        my $next = $info->{'to'};
+        next unless $lifecycle->IsTransition( $status => $next );
+
+        my %args = (%$info, id => $id);
+        delete @args{qw(to from label update)};
+
+        # if user will be owner then he will get more rights
+        # TODO: check actually if he will get required rights
+        if ( !$args{'TakeOrStealFirst'} || $session{'CurrentUser'}->id == $ticket->Owner ) {
+            my $check = $lifecycle->CheckRight( $status => $next );
+            next unless $can->( $check );
+        }
+
+        my $path = '/RTIR/';
+        $path .= 'Incident/' if $type eq 'Incident';
+        if ( my $update = $info->{'update'} ) {
+            $path .= $type eq 'Incident'? 'Reply.html' : 'Update.html';
+            $path .= "?". $m->comp(
+                '/Elements/QueryString',
+                %args,
+                Action        => $update,
+                DefaultStatus => $next,
+            );
+        } else {
+            $path .= "Display.html?". $m->comp(
+                '/Elements/QueryString',
+                %args,
+                Status => $next,
+            );
+        }
+        PageMenu()->child(
+            lc($info->{'label'} || $next),
+            title => loc( $info->{'label'} || ucfirst($next) ),
+            path  => $path,
+        );
+    }
+
+    if ( $can->('ModifyTicket') || $can->('CommentOnTicket') ) {
+        PageMenu()->child(
+            comment => title => loc('Comment'),
+            path  => "RTIR/Update.html?Action=Comment&id=$id",
+        );
+    }
+
+    PageMenu()->child(
+        bookmark => title => $m->scomp( '/Ticket/Elements/Bookmark', id => $id ),
+        escape_title => 0,
+        link_item    => 0,
+        sort_order   => 99
+    );
+} elsif ( $request_path =~ m{^/RTIR/Link/ToIncident/} ) {
+    my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
+    $ticket->Load( $args->{'id'} );
+    my $id = $ticket->id;
+
+    my $queue = $ticket->QueueObj;
+    my $type = RT::IR::TicketType( Queue => $queue );
+
+    my %args = (
+        id => $id,
+    );
+    my @query_fields = qw(Query Format RowPerPage Page OrderBy Order);
+    if ( my $refined = $m->notes('RefinedSearch') ) {
+        @args{ @query_fields } = @{ $refined->{'query'} }{ @query_fields };
+    } else {
+        @args{ @query_fields } = @{ $args }{ @query_fields };
+    }
+
+    PageMenu()->child(
+        link => title => loc('Show Results'),
+        path => "/RTIR/Link/ToIncident/?". $query_string->( %args ),
+    );
+    PageMenu()->child(
+        edit_search => title => loc('Edit Search'),
+        path => "/RTIR/Link/ToIncident/Refine.html?". $query_string->( %args ),
+    );
+    PageMenu()->child(
+        new_search => title => loc('New Search'),
+        path => "/RTIR/Link/ToIncident/Refine.html?id=$id&NewSearch=1",
+    );
+    PageMenu()->child(
+        new => title => loc('New Incident'),
+        path => "/RTIR/Create.html?Child=$id&Queue=Incidents",
+    );
+    PageMenu()->child(
+        back => title => loc('Back to ticket #[_1]', $id),
+        path => "/RTIR/Display.html?id=$id",
+    );
+}
+
+
+if ( $request_path =~ m{^/RTIR/(?:index\.html|)$} ) {
+    PageMenu()->child( edit => title => loc('Edit'), path => '/RTIR/Prefs/MyRT.html' )
+        if $session{'CurrentUser'}->HasRight(Right => 'ModifySelf', Object => $RT::System);
+}
+
+PageWidgets()->child('simple_search')->title( $m->scomp(
+    '/Elements/SimpleSearch',
+    SendTo => '/RTIR/index.html'
+) );
+
+</%INIT>

commit 0d8e5810e8c65e634cc299fcd48bab4f61ca83ad
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:21:58 2010 +0300

    cover menuing in /RTIR/Tools

diff --git a/html/RTIR/Tools/Elements/Tabs b/html/RTIR/Tools/Elements/Tabs
deleted file mode 100644
index ea6a491..0000000
--- a/html/RTIR/Tools/Elements/Tabs
+++ /dev/null
@@ -1,62 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-% $m->callback( tabs => $tabs, %ARGS );
-<& /RTIR/Elements/Tabs,
-    tabs           => $tabs,
-    current_toptab => $current_toptab,
-    current_tab    => $current_tab,
-    current_subtab => $current_subtab,
-    Title          => $Title,
-&>
-
-<%INIT>
-my $tabs = {};
-my $current_toptab = "RTIR/Tools/Lookup.html";
-
-$tabs->{"A"} = { path      => 'RTIR/Tools/Lookup.html?NewSearch=1',
-                 title     => loc('Lookup') };
-
-$tabs->{"B"} = { path      => 'RTIR/Reporting/index.html',
-                 title     => loc('Reporting') };
-
-my $script_tabs = {
-    _A => { title => loc('By Email address'),
-            path  => 'RTIR/Tools/ScriptedAction.html' },
-    _B => { title => loc('By IP address'),
-            path  => 'RTIR/Tools/ScriptedAction.html?loop=IP' },
-};
-
-$tabs->{"C"} = { path           => 'RTIR/Tools/ScriptedAction.html',
-                 title          => loc('Scripted Action'),
-                 subtabs        => $script_tabs,
-                 current_subtab => $current_subtab };
-</%INIT>
-
-<%ARGS>
-$subtabs => undef
-$current_tab => undef
-$current_subtab => undef
-$Title => undef
-</%ARGS>
diff --git a/html/RTIR/Tools/Lookup.html b/html/RTIR/Tools/Lookup.html
index 0100b80..39b6d00 100644
--- a/html/RTIR/Tools/Lookup.html
+++ b/html/RTIR/Tools/Lookup.html
@@ -23,12 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& /RTIR/Elements/Header, Title => $title &>
-<& /RTIR/Tools/Elements/Tabs, 
-    current_toptab => 'RTIR/Tools/Lookup.html',
-    current_tab    => 'RTIR/Tools/Lookup.html?NewSearch=1',
-    current_subtab => $current_subtab,
-    Title          => $title,
-&>
+<& /Elements/Tabs &>
 
 % if ( $ticket ) {
 <&| /Widgets/TitleBox, title => loc("Current [_1]: #[_2]", $TicketType, $ticket), class => 'ticket-info-basics' &>
@@ -242,10 +237,7 @@ $now->AddDays( $max_age );
 
 $session{'tickets'} = RT::Tickets->new( $session{'CurrentUser'} );
 
-my $current_subtab = 'RTIR/Tools/Lookup.html';
 if ( $q ) {
-    $current_subtab .= '?'. $m->comp('/Elements/QueryString', q => $q, server => $server );
-
     my $query;
     if ( $type && RT::IR->CustomFields( Field => $type ) ) {
         $query = "'CF.{$type}' = '$q'"
diff --git a/html/RTIR/Tools/ScriptedAction.html b/html/RTIR/Tools/ScriptedAction.html
index 191c176..ffc6888 100644
--- a/html/RTIR/Tools/ScriptedAction.html
+++ b/html/RTIR/Tools/ScriptedAction.html
@@ -23,11 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& /RTIR/Elements/Header, Title => $Title &>
-<& /RTIR/Tools/Elements/Tabs, 
-    current_tab => $current_tab, 
-    current_subtab => $current_subtab, 
-    Title => $Title &>
-
+<& /Elements/Tabs &>
 <& /Elements/ListActions, actions => \@finalresults &>
 
 <form method="get" action="ScriptedAction.html" name="ScriptedAction" enctype="multipart/form-data">
@@ -225,12 +221,6 @@ if ($incidentid) {
 
 $ARGS{'loop'} = $loop if !defined $ARGS{'loop'};
 
-if ($loop eq 'address') {
-    $current_subtab = "RTIR/Tools/ScriptedAction.html",
-} else {
-    $current_subtab = 'RTIR/Tools/ScriptedAction.html?loop=IP';
-}
-
 # get the list of WHOIS servers
 my $whois_servers = RT->Config->Get('whois');
 unless ( $server ) {
@@ -455,7 +445,5 @@ sub parse_csv {
 $incidentid => undef
 $Requestors => undef
 $server => undef
-$current_tab => "RTIR/Tools/ScriptedAction.html"; 
-$current_subtab => undef
 $loop => 'address'
 </%ARGS>
diff --git a/html/RTIR/Tools/index.html b/html/RTIR/Tools/index.html
new file mode 100644
index 0000000..5d4ad2a
--- /dev/null
+++ b/html/RTIR/Tools/index.html
@@ -0,0 +1,4 @@
+<& /RTIR/Elements/Header, Title => loc('RTIR Tools') &>
+<& /Elements/Tabs &>
+<& /Elements/ListMenu, menu => Menu()->child('rtir')->child('tools')  &>
+

commit 4ecd371f30f533aebe82ca4ad6bdff7506f97ac5
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:23:12 2010 +0300

    cover menuing on index page

diff --git a/html/RTIR/index.html b/html/RTIR/index.html
index b1c58c9..dc12311 100644
--- a/html/RTIR/index.html
+++ b/html/RTIR/index.html
@@ -23,8 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& /RTIR/Elements/Header, Title => "RTIR at a glance", Refresh => $session{'home_refresh_interval'} &>
-<& /RTIR/Elements/Tabs, Title => "RT for Incident Response", actions => $actions, current_toptab => 'RTIR/index.html' &>
-
+<& /Elements/Tabs &>
 <& /Elements/ListActions, actions => \@results &>
 <& /Elements/MyRT, Portlets => $portlets &>
 <%INIT>
@@ -95,16 +94,6 @@ if ( $HomeRefreshInterval ) {
     push @results, loc( 'Updated refresh interval.');
 }
 
-my $actions;
-if ($session{'CurrentUser'}->HasRight(Right => 'ModifySelf', Object => $RT::System)) {
-    $actions = {
-        A => { title => loc('Edit'),
-               path  => 'RTIR/Prefs/Home.html',
-             },
-    };
-}
-
-
 </%INIT>
 <%ARGS>
 @results => ()

commit a991584db71e69a5635c5f3eeb0f8a85df3fdeaf
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:24:22 2010 +0300

    switch to generic SimpleSearch widget

diff --git a/html/RTIR/Elements/SimpleSearch b/html/RTIR/Elements/SimpleSearch
deleted file mode 100644
index f28d310..0000000
--- a/html/RTIR/Elements/SimpleSearch
+++ /dev/null
@@ -1,28 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org.
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-<form action="<% RT->Config->Get('WebPath') %>/RTIR/index.html" id="simple-search">
-<input type="hidden" name="NewSearch" value="1" />
-<input type="hidden" name="Queue" value="Incidents" />
-<input size="15" name="q" accesskey="0" value="<&|/l&>Search Incidents</&>..." onfocus="if (this.value=='<&|/l&>Search Incidents</&>...') this.value=''" />
-</form>

commit 5d95667c2020db157fe86de508d036f322dfc681
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 04:25:42 2010 +0300

    main Tabs are in the callback

diff --git a/html/RTIR/Elements/Tabs b/html/RTIR/Elements/Tabs
deleted file mode 100644
index 47e88c1..0000000
--- a/html/RTIR/Elements/Tabs
+++ /dev/null
@@ -1,85 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-<& /Elements/PageLayout, 
-    topactions => $topactions,
-    actions => $actions,
-
-    toptabs => $toptabs,
-    current_toptab => $current_toptab,
-
-    tabs => $tabs,
-    current_tab => $current_tab,
-    current_subtab => $current_subtab,
-    title => $Title,
-&>
-
-<%INIT>
-
-unless ( RT->Config->Get('rtirname') ) {
-    die q{Couldn't get an "rtirname" configuration variable. This usually only happens if you haven't sourced RTIR's default configuration file. Check out RTIR's README for details
-    };
-
-}
-
-my $toptabs = { 
-    A => { title => loc('RT'),
-           path  => '' },
-    B => { title => loc('RTIR Home'),
-           path => 'RTIR/index.html' },
-    BA => { title => loc('Search'),
-           path => 'RTIR/Search/index.html' },
-    C => { title => loc('Incidents'),
-           path => 'RTIR/Search/Results.html?Queue=Incidents' },
-    D => { title => loc('Incident Reports'),
-           path => 'RTIR/Search/Results.html?Queue=Incident%20Reports' },
-    E => { title => loc('Investigations'),
-           path => 'RTIR/Search/Results.html?Queue=Investigations' },
-    G => { title => loc('Tools'),
-           path => 'RTIR/Tools/Lookup.html' },
-};
-
-unless ( RT->Config->Get('RTIR_DisableBlocksQueue') ) {
-    $toptabs->{'F'} = {
-        title => loc('Blocks'),
-        path => 'RTIR/Search/Results.html?Queue=Blocks',
-    };
-}
-
-my $topactions = {
-    A => { html => $m->scomp('/Elements/CreateTicket') },
-    B => { html => $m->scomp('/RTIR/Elements/SimpleSearch') },
-};
-
-$m->callback( toptabs => $toptabs, topactions => $topactions, %ARGS );
-
-</%INIT>
-<%ARGS>
-$current_toptab => undef
-$current_tab => undef
-$current_subtab => undef
-$tabs => undef
-$actions => undef
-$Title => undef
-</%ARGS>

commit b7a2e5cd033d1336a6fe75f307e244f0631c44d9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 09:59:18 2010 +0300

    add RefinePage - element that renders whole query builder page

diff --git a/html/RTIR/Search/Elements/RefinePage b/html/RTIR/Search/Elements/RefinePage
new file mode 100644
index 0000000..4d0ec5e
--- /dev/null
+++ b/html/RTIR/Search/Elements/RefinePage
@@ -0,0 +1,29 @@
+<& /RTIR/Elements/Header, Title => $Title &>
+<& /Elements/Tabs &> 
+<& BuildQuery,
+    %query_state,
+
+    BaseQuery  => $BaseQuery,
+    ResultPage => $ResultPage,
+
+    actions    => \@results, 
+&>
+
+<%INIT>
+my %query_state = $m->comp('ProcessQuery',
+    %ARGS,
+    BaseQuery  => $BaseQuery,
+    ResultPage => $ResultPage,
+);
+
+$m->notes( 'RefinedSearch' => \%query_state );
+
+my @results = @{ delete $query_state{'results'} };
+
+my $QueryString = $m->comp( '/Elements/QueryString', %{ $query_state{'query'} } );
+</%INIT>
+<%ARGS>
+$Title => loc("Refine Search")
+$ResultPage => 'RTIR/Search/Results.html',
+$BaseQuery => '',
+</%ARGS>
diff --git a/html/RTIR/Search/Refine.html b/html/RTIR/Search/Refine.html
index 42c30a1..edaeb44 100644
--- a/html/RTIR/Search/Refine.html
+++ b/html/RTIR/Search/Refine.html
@@ -43,51 +43,6 @@
 %# those contributions and any derivatives thereof.
 %#
 %# }}} END BPS TAGGED BLOCK
-<& /Elements/Header, Title => $title &>
-
-<& Elements/RefineTabs, 
-   Title => $title,
-
-   BaseQuery   => $BaseQuery,
-   QueryString => $QueryString,
-
-   current_tab           => $ResultPage,
-   current_subtab        => 'RTIR/Search/Refine.html',
-   current_subtab_active => 1,
-&>
-
-<& Elements/BuildQuery,
-    %query_state,
-
-    BaseQuery  => $BaseQuery,
-    ResultPage => $ResultPage,
-
-    actions => \@results, 
-&>
-
 <%INIT>
-
-my %query_state = $m->comp('Elements/ProcessQuery',
-    %ARGS,
-    BaseQuery  => $BaseQuery,
-    ResultPage => $ResultPage,
-);
-
-my @results = @{ delete $query_state{'results'} };
-
-my $QueryString = $m->comp( '/Elements/QueryString', %{ $query_state{'query'} } );
+return $m->comp( 'Elements/RefinePage' => %ARGS );
 </%INIT>
-
-<%ARGS>
-$title      => loc("Refine Search")
-$ResultPage => 'RTIR/Search/Results.html'
-$NewQuery   => 0
-
-$BaseQuery  => ''
-$Query      => ''
-$Format     => undef
-$Rows       => 50
-$Page       => 1
-$OrderBy    => 'id'
-$Order      => 'ASC'
-</%ARGS>

commit cdf926eb12ddd2bb693f23b9e9d668872a67ea16
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Dec 15 10:00:21 2010 +0300

    move LinkToIncident.html and use Refine

diff --git a/html/RTIR/Incident/LinkToIncident.html b/html/RTIR/Incident/LinkToIncident.html
deleted file mode 100644
index ce777cb..0000000
--- a/html/RTIR/Incident/LinkToIncident.html
+++ /dev/null
@@ -1,122 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-<& /RTIR/Elements/Header, 
-    Title => $title,
-    Refresh => $session{'tickets_refresh_interval'},
-&>
-
-<& '/RTIR/Search/Elements/RefineTabs',
-   Title          => $title,
-   Ticket         => $ChildObj, 
-   Queue          => $Queue,
-   BaseQuery      => $BaseQuery,
-   QueryString    => $QueryString,
-
-   current_tab    => $current_tab,
-   current_subtab => "RTIR/Search/Refine.html",
-   subtabs        => {
-        _z => {
-            title => loc('New Incident'),
-            path  => "RTIR/Create.html?Child=$id&Queue=Incidents",
-        },
-   },
-&>
-
-% $m->callback(CallbackName => 'BeforeActionList', ARGSRef => \%ARGS, Ticket => $ChildObj);
-
-<form action="<% RT->Config->Get('WebPath') %>/RTIR/Incident/Display.html" method="post">
-<input type="hidden" name="Child" value="<% $id %>" />
-
-<& /RTIR/Search/Elements/ShowResults, 
-    Queue         => $Queue,
-    BaseQuery     => $BaseQuery,
-    Query         => $Query,
-    DisplayFormat => "__RadioButton__, $Format",
-    Format        => $Format,
-    Rows          => $Rows,
-    Page          => $Page,
-    OrderBy       => $OrderBy,
-    Order         => $Order,
-    BaseURL       => $current_tab,
-    ShowNavigation  => 1,
-    ShowListActions => 0,
-&>
-
-<& /Elements/Submit,
-    Name => "LinkChild",
-    Caption => $title,
-    Label => loc("Link"),
-&>
-</form>
-
-<%INIT>
-my $ChildObj = LoadTicket($id);
-
-$ARGS{'id'} = $id = $ChildObj->id;
-
-
-$m->callback(CallbackName => 'Initial', %ARGS, Ticket => $ChildObj);
-
-my $Type = RT::IR::TicketType( Ticket => $ChildObj );
-my $title = loc( "Link [_1] #[_2] to selected Incident", $Type, $id );
-
-my $Queue = 'Incidents';
-my $BaseQuery = $m->comp( '/RTIR/Elements/BaseQuery', Queue => $Queue );
-$BaseQuery = join ' AND ', map "( $_ )", grep $_,
-             $BaseQuery, "HasMember != $id";
-if ( RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject' ) {
-    $BaseQuery = join ' AND ', map "( $_ )",
-        $BaseQuery, "CustomField.{Constituency} = '".
-            $ChildObj->FirstCustomFieldValue('Constituency') ."'"
-}
-
-$Query ||= $m->comp( '/RTIR/Elements/NewQuery', Queue => $Queue );
-
-my $QueryString = $m->comp('/Elements/QueryString',
-                               Query   => $Query,
-                               Format  => $Format,
-                               Rows    => $Rows,
-                               Page    => $Page,
-                               OrderBy => $OrderBy,
-                               Order   => $Order,
-                          );
-
-my $current_tab = "RTIR/Incident/LinkToIncident.html?"
-    . $m->comp( '/Elements/QueryString',
-        id    => $id,
-        Queue => $Queue,
-    );
-
-</%INIT>
-<%ARGS>
-$id      => undef
-
-$Query   => undef
-$Format  => RT->Config->Get('RTIRSearchResultFormats')->{'LinkIncident'}
-$Rows    => 50
-$Page    => 1
-$OrderBy => 'id'
-$Order   => 'ASC'
-</%ARGS>
diff --git a/html/RTIR/Link/ToIncident/Refine.html b/html/RTIR/Link/ToIncident/Refine.html
new file mode 100644
index 0000000..e285529
--- /dev/null
+++ b/html/RTIR/Link/ToIncident/Refine.html
@@ -0,0 +1,13 @@
+<%INIT>
+return $m->comp(
+    '/RTIR/Search/Elements/RefinePage',
+    %ARGS,
+    ResultPage => 'RTIR/Link/ToIncident/?id='. $ARGS{'id'},
+    BaseQuery => RT::IR->BaseQuery(
+        Queue => 'Incidents',
+        HasNoMember => $ARGS{'id'},
+        Costituency => $ARGS{'id'},
+    ),
+);
+</%INIT>
+
diff --git a/html/RTIR/Link/ToIncident/index.html b/html/RTIR/Link/ToIncident/index.html
new file mode 100644
index 0000000..67e8744
--- /dev/null
+++ b/html/RTIR/Link/ToIncident/index.html
@@ -0,0 +1,84 @@
+%# BEGIN LICENSE BLOCK
+%# 
+%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
+%# 
+%# (Except where explictly superceded by other copyright notices)
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%# 
+%# 
+%# Unless otherwise specified, all modifications, corrections or
+%# extensions to this work which alter its source code become the
+%# property of Best Practical Solutions, LLC when submitted for
+%# inclusion in the work.
+%# 
+%# 
+%# END LICENSE BLOCK
+<& /RTIR/Elements/Header, 
+    Title => $title,
+    Refresh => $session{'tickets_refresh_interval'},
+&>
+
+<& /Elements/Tabs &>
+
+% $m->callback(CallbackName => 'BeforeActionList', ARGSRef => \%ARGS, Ticket => $Ticket);
+
+<form action="<% RT->Config->Get('WebPath') %>/RTIR/Incident/Display.html" method="post">
+<input type="hidden" name="Child" value="<% $id %>" />
+
+<& /RTIR/Search/Elements/ShowResults, 
+    BaseQuery     => $BaseQuery,
+    Query         => $Query,
+    DisplayFormat => "__RadioButton__, $Format",
+    Format        => $Format,
+    Rows          => $Rows,
+    Page          => $Page,
+    OrderBy       => $OrderBy,
+    Order         => $Order,
+    BaseURL       => "RTIR/Link/ToIncident/?id=$id&Queue=Incidents",
+    ShowNavigation  => 1,
+    ShowListActions => 0,
+&>
+
+<& /Elements/Submit,
+    Name => "LinkChild",
+    Caption => $title,
+    Label => loc("Link"),
+&>
+</form>
+
+<%INIT>
+my $Ticket = LoadTicket($id);
+$ARGS{'id'} = $id = $Ticket->id;
+
+$m->callback(CallbackName => 'Initial', %ARGS, Ticket => $Ticket);
+
+my $Type = RT::IR::TicketType( Ticket => $Ticket );
+my $title = loc( "Link [_1] #[_2] to selected Incident", $Type, $id );
+
+my $BaseQuery = RT::IR->BaseQuery(
+    Queue => 'Incidents',
+    HasNoMember => $id,
+    Costituency => $Ticket,
+);
+$Query ||= RT::IR->NewQuery( Queue => 'Incidents' );
+
+</%INIT>
+<%ARGS>
+$id      => undef
+
+$Query   => undef
+$Format  => RT->Config->Get('RTIRSearchResultFormats')->{'LinkIncident'}
+$Rows    => 50
+$Page    => 1
+$OrderBy => 'id'
+$Order   => 'ASC'
+</%ARGS>

commit 03faa0ccf125e64121cd28fee766fba90ae411e9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Dec 16 05:44:06 2010 +0300

    NotMemberOf arg in BaseQuery

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index bc15d34..a32edd4 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -251,6 +251,7 @@ sub BaseQuery {
     my %args = (
         Queue => undef,
         HasNoMember => undef,
+        NotMemberOf => undef,
         Constituency => undef,
         @_
     );
@@ -262,6 +263,10 @@ sub BaseQuery {
         $res .= ' AND ' if $res;
         $res .= 'HasMember != '. (ref $t? $t->id : int $t);
     }
+    if ( my $t = $args{'NotMemberOf'} ) {
+        $res .= ' AND ' if $res;
+        $res .= 'MemberOf != '. (ref $t? $t->id : int $t);
+    }
     if (
         my $t = $args{'Constituency'}
         and RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject'

commit ed13881c169b34d65a258467dfe1224c16bcd7f1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Dec 16 05:46:00 2010 +0300

    LinkToIncident.html has been moved

diff --git a/html/RTIR/Elements/ShowIncidents b/html/RTIR/Elements/ShowIncidents
index e5d30b0..c5a7863 100644
--- a/html/RTIR/Elements/ShowIncidents
+++ b/html/RTIR/Elements/ShowIncidents
@@ -43,7 +43,7 @@
 
 % if ( $depth == 1 ) {
 %   unless ( $action ) {
-<b><a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkToIncident.html?id=<% $Ticket->Id %>">[Link]</a></b>
+<b><a href="<%RT->Config->Get('WebPath')%>/RTIR/Link/ToIncident/?id=<% $Ticket->Id %>">[Link]</a></b>
 <b><a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Child=<% $Ticket->Id %>&Queue=Incidents">[New]</a></b>
 %   } elsif ( $action ne 'No' ) {
 <a href="<% RT->Config->Get('WebPath') %>/RTIR/Display.html?Action=<% $action %>&id=<% $Ticket->Id %>">[<% loc( $action ) %>]</a>

commit 229ab0815e1074e7960926eed881941a28c99091
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Dec 16 05:48:06 2010 +0300

    LinkChildren.html -> /Link/FromIncident/ and menuing

diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
index d0f6537..ad9c108 100644
--- a/html/Callbacks/RTIR/Elements/Tabs/Privileged
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -166,16 +166,18 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$}
         link_item    => 0,
         sort_order   => 99
     );
-} elsif ( $request_path =~ m{^/RTIR/Link/ToIncident/} ) {
+} elsif ( $request_path =~ m{^/RTIR/Link/(ToIncident|FromIncident)/} ) {
+    my $direction = $1;
+    my $queue = $args->{'Queue'};
+    my $type = RT::IR::TicketType( Queue => $queue || 'Incidents' );
+
     my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
     $ticket->Load( $args->{'id'} );
     my $id = $ticket->id;
 
-    my $queue = $ticket->QueueObj;
-    my $type = RT::IR::TicketType( Queue => $queue );
-
     my %args = (
         id => $id,
+        Queue => $queue,
     );
     my @query_fields = qw(Query Format RowPerPage Page OrderBy Order);
     if ( my $refined = $m->notes('RefinedSearch') ) {
@@ -183,22 +185,26 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$}
     } else {
         @args{ @query_fields } = @{ $args }{ @query_fields };
     }
+    delete $args{$_} foreach grep !defined $args{$_}, keys %args;
 
     PageMenu()->child(
         link => title => loc('Show Results'),
-        path => "/RTIR/Link/ToIncident/?". $query_string->( %args ),
+        path => "/RTIR/Link/$direction/?". $query_string->( %args ),
     );
     PageMenu()->child(
         edit_search => title => loc('Edit Search'),
-        path => "/RTIR/Link/ToIncident/Refine.html?". $query_string->( %args ),
+        path => "/RTIR/Link/$direction/Refine.html?". $query_string->( %args ),
     );
     PageMenu()->child(
         new_search => title => loc('New Search'),
-        path => "/RTIR/Link/ToIncident/Refine.html?id=$id&NewSearch=1",
+        path => "/RTIR/Link/$direction/Refine.html?id=$id&NewQuery=1",
     );
     PageMenu()->child(
-        new => title => loc('New Incident'),
-        path => "/RTIR/Create.html?Child=$id&Queue=Incidents",
+        new => title => loc("New $type"),
+        path => !$queue
+            ? "/RTIR/Create.html?Child=$id&Queue=Incidents"
+            : "/RTIR/Create.html?". $query_string->( Incident => $id, Queue => $queue )
+        ,
     );
     PageMenu()->child(
         back => title => loc('Back to ticket #[_1]', $id),
diff --git a/html/RTIR/Incident/Elements/ShowChildren b/html/RTIR/Incident/Elements/ShowChildren
index aec268e..bf98706 100644
--- a/html/RTIR/Incident/Elements/ShowChildren
+++ b/html/RTIR/Incident/Elements/ShowChildren
@@ -14,7 +14,7 @@
 %   if ( $QueueObj->Id and $QueueObj->CurrentUserHasRight('CreateTicket') ) {
         | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Create.html?Incident=<% $id %>&Queue=<% $Queue |u %>"><% $new_caption %></a> 
 %   }
-        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Incident/LinkChildren.html?id=<% $id %>&Queue=<% $Queue |u %>"><%loc("Link")%></a> |
+        | <a href="<%RT->Config->Get('WebPath')%>/RTIR/Link/FromIncident/?id=<% $id %>&Queue=<% $Queue |u %>"><%loc("Link")%></a> |
     </font></td></tr></table>
 % }
 
diff --git a/html/RTIR/Link/FromIncident/Refine.html b/html/RTIR/Link/FromIncident/Refine.html
new file mode 100644
index 0000000..f77168b
--- /dev/null
+++ b/html/RTIR/Link/FromIncident/Refine.html
@@ -0,0 +1,16 @@
+<%INIT>
+return $m->comp(
+    '/RTIR/Search/Elements/RefinePage',
+    %ARGS,
+    ResultPage => 'RTIR/Link/FromIncident/?'. $m->comp(
+        '/Elements/QueryString',
+        id    => $ARGS{'id'},
+        Queue => $ARGS{'Queue'},
+    ),
+    BaseQuery => RT::IR->BaseQuery(
+        Queue       => $ARGS{'Queue'},
+        NotMemberOf => $ARGS{'id'},
+        Costituency => $ARGS{'id'},
+    ),
+);
+</%INIT>
diff --git a/html/RTIR/Incident/LinkChildren.html b/html/RTIR/Link/FromIncident/index.html
similarity index 60%
rename from html/RTIR/Incident/LinkChildren.html
rename to html/RTIR/Link/FromIncident/index.html
index 9121b98..17e2b7c 100644
--- a/html/RTIR/Incident/LinkChildren.html
+++ b/html/RTIR/Link/FromIncident/index.html
@@ -22,21 +22,8 @@
 %# 
 %# 
 %# END LICENSE BLOCK
-<& /RTIR/Elements/Header,
-    Title => $title,
-    Refresh => $session{'tickets_refresh_interval'},
-&>
-
-<& /RTIR/Search/Elements/RefineTabs, 
-    Title             => $title,
-    Ticket            => $IncidentObj,
-    Queue             => $Queue,
-    BaseQuery         => $BaseQuery,
-    QueryString       => $QueryString,
-
-    current_tab       => $current_tab,
-    current_subtab    => 'RTIR/Search/Refine.html',
-&>
+<& /RTIR/Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
 
 <form action="Display.html" method="get">
 <input type="hidden" name="id" value="<% $id %>" />
@@ -52,7 +39,7 @@
     Page          => $Page,
     OrderBy       => $OrderBy,
     Order         => $Order,
-    BaseURL       => $current_tab,
+    BaseURL       => $base_url,
     ShowNavigation  => 1,
     ShowListActions => 0,
 &>
@@ -60,6 +47,18 @@
 <& /Elements/Submit, Name => "SubmitTicket", Caption => $title, Label => loc("Link") &>
 </form>
 
+<%ARGS>
+$id          => undef
+$Queue       => undef
+
+$Query       => $m->comp('/RTIR/Elements/NewQuery', Queue => $Queue)
+$Format      => RT->Config->Get('RTIRSearchResultFormats')->{'LinkChildren'}
+$Rows        => 50
+$Page        => 1
+$OrderBy     => 'id'
+$Order       => 'ASC'
+</%ARGS>
+
 <%INIT>
 my $IncidentObj = LoadTicket($id);
 $ARGS{'id'} = $id = $IncidentObj->id;
@@ -67,38 +66,13 @@ $ARGS{'id'} = $id = $IncidentObj->id;
 my $Type = RT::IR::TicketType( Queue => $Queue );
 my $title = loc("Link selected [_1] to Incident #[_2]", $Type, $id);
 
-my $QueryString = $m->comp('/Elements/QueryString',
-                               Query   => $Query,
-                               Format  => $Format,
-                               Rows    => $Rows,
-                               Page    => $Page,
-                               OrderBy => $OrderBy,
-                               Order   => $Order,
-                          );
+my $BaseQuery = RT::IR->BaseQuery(
+    Queue => $Queue,
+    NotMemberOf => $id,
+    Constituency => $IncidentObj,
+);
 
-unless ( $BaseQuery ) {
-    $BaseQuery = $m->comp('/RTIR/Elements/BaseQuery', Queue => $Queue);
-    $BaseQuery = join ' AND ', map "( $_ )", $BaseQuery, "MemberOf != $id";
-    if ( RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject' ) {
-        $BaseQuery = join ' AND ', map "( $_ )",
-            $BaseQuery, "CustomField.{Constituency} = '".
-                $IncidentObj->FirstCustomFieldValue('Constituency') ."'"
-    }
-}
-
-my $current_tab = 'RTIR/Incident/LinkChildren.html?'
+my $base_url = 'RTIR/Link/FromIncident/?'
     . $m->comp( '/Elements/QueryString', id => $id, Queue => $Queue );
 
 </%INIT>
-
-<%ARGS>
-$id          => undef
-$Queue       => undef
-$BaseQuery   => undef
-$Query       => $m->comp('/RTIR/Elements/NewQuery', Queue => $Queue)
-$Format      => RT->Config->Get('RTIRSearchResultFormats')->{'LinkChildren'}
-$Rows        => 50
-$Page        => 1
-$OrderBy     => 'id'
-$Order       => 'ASC'
-</%ARGS>

commit 7de877c00a6a86ac5c1f2b9e1b72f5448e850fcd
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Dec 16 05:56:09 2010 +0300

    another tab file gone

diff --git a/html/RTIR/Search/Elements/Tabs b/html/RTIR/Search/Elements/Tabs
deleted file mode 100644
index c438419..0000000
--- a/html/RTIR/Search/Elements/Tabs
+++ /dev/null
@@ -1,45 +0,0 @@
-<& '/RTIR/Elements/Tabs',
-    %ARGS,
-    current_toptab => 'RTIR/Search/index.html',
-    tabs        => $tabs,
-    current_tab => $current_tab,
-&>
-<%INIT>
-my $tabs = {
-    A => {
-        title => loc('New Query'),
-        path => 'RTIR/Search/index.html?NewQuery=1',
-    },
-    B => {
-        title => loc('Build Search'),
-        path => 'RTIR/Search/index.html',
-        add_query => 1,
-    },
-    C => {
-        title => loc('Show Results'),
-        path => 'RTIR/Search/Results.html',
-        add_query => 1,
-    },
-};
-
-if ( $QueryString ) {
-    foreach ( grep $_ && $_->{add_query}, values %$tabs ) {
-        if ( $_->{'path'} eq $current_tab ) {
-            $current_tab .= ($current_tab =~ /\?/? '&': '?')
-                . $QueryString;
-        }
-        $_->{'path'} .= ($_->{'path'} =~ /\?/? '&': '?')
-            . $QueryString;
-    }
-}
-
-</%INIT>
-<%ARGS>
-$current_tab    => ''
-
-$subtabs        => {}
-$current_subtab => ''
-
-$QueryString    => ''
-$BaseQuery      => ''
-</%ARGS>

commit eff924ee6fa776570254520e9717ff8cc5bf86b0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Dec 16 05:57:41 2010 +0300

    MaybeRedirect API has been changed

diff --git a/html/RTIR/Display.html b/html/RTIR/Display.html
index 4297eea..6583155 100644
--- a/html/RTIR/Display.html
+++ b/html/RTIR/Display.html
@@ -220,10 +220,10 @@ unless ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
 $ARGS{'id'} = $id = $Ticket->Id;
 
 $m->comp(
-    '/Ticket/Elements/MaybeRedirectForResults',
-    Actions     => \@results,
+    '/Elements/MaybeRedirectForResults',
     Path        => 'RTIR/Display.html',
-    TicketObj   => $Ticket,
+    id          => $id,
+    Actions     => \@results,
 );
 
 

commit d5f58df33b8e04ced8e55b27cd5b17674db49078
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 17 09:44:40 2010 +0300

    set lifecycles when we create queues

diff --git a/etc/initialdata b/etc/initialdata
index 7b67037..ab1cfef 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -3,22 +3,26 @@
 @Queues = (
     {
         Name              => 'Incidents',
+        Lifecycle         => 'incidents',
         CorrespondAddress => "",
         CommentAddress    => "",
         InitialPriority   => 50,
     },
     {
         Name              => 'Incident Reports',
+        Lifecycle         => 'incident_reports',
         CorrespondAddress => "",
         CommentAddress    => "",
     },
     {
         Name              => 'Investigations',
+        Lifecycle         => 'investigations',
         CorrespondAddress => "",
         CommentAddress    => "",
     },
     {
         Name              => 'Blocks',
+        Lifecycle         => 'blocks',
         CorrespondAddress => "",
         CommentAddress    => "",
     },

commit cbdaafc49bb07f40d7d56bf84ee51b7e9959187b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 17 09:46:20 2010 +0300

    menuing for search  pages

diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
index ad9c108..5ba6f18 100644
--- a/html/Callbacks/RTIR/Elements/Tabs/Privileged
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -55,6 +55,18 @@ return unless $request_path =~ m{^/RTIR/};
 my $args = $m->request_args;
 my $re_rtir_types = '(?:'. join( '|', map "\Q$_\E", RT::IR->Types ) .')';
 
+my $search_arguments = sub {
+    my %res = ();
+    my @query_fields = qw(Query Format RowPerPage Page OrderBy Order);
+    if ( my $refined = $m->notes('RefinedSearch') ) {
+        @res{ @query_fields } = @{ $refined->{'query'} }{ @query_fields };
+    } else {
+        @res{ @query_fields } = @{ $args }{ @query_fields };
+    }
+    delete $res{$_} foreach grep !defined $res{$_}, keys %res;
+    return %res;
+};
+
 if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$} ) {
     my $id = $args->{'id'};
 
@@ -176,16 +188,10 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$}
     my $id = $ticket->id;
 
     my %args = (
+        $search_arguments->(),
         id => $id,
         Queue => $queue,
     );
-    my @query_fields = qw(Query Format RowPerPage Page OrderBy Order);
-    if ( my $refined = $m->notes('RefinedSearch') ) {
-        @args{ @query_fields } = @{ $refined->{'query'} }{ @query_fields };
-    } else {
-        @args{ @query_fields } = @{ $args }{ @query_fields };
-    }
-    delete $args{$_} foreach grep !defined $args{$_}, keys %args;
 
     PageMenu()->child(
         link => title => loc('Show Results'),
@@ -210,6 +216,47 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$}
         back => title => loc('Back to ticket #[_1]', $id),
         path => "/RTIR/Display.html?id=$id",
     );
+} elsif ( $request_path =~ m{^/RTIR/(Search/|Incident/BulkAbandon\.html$)} ) {
+    my $queue = $args->{'Queue'} || '';
+    my $type = RT::IR::TicketType( Queue => $queue );
+
+    my %args = (
+        $search_arguments->(),
+        Queue => $queue,
+    );
+
+    PageMenu()->child(
+        link => title => loc('Show Results'),
+        path => "/RTIR/Search/Results.html?". $query_string->( %args ),
+    );
+    PageMenu()->child(
+        edit_search => title => loc('Edit Search'),
+        path => "/RTIR/Search/Refine.html?". $query_string->( %args ),
+    );
+    PageMenu()->child(
+        new_search => title => loc('New Search'),
+        path => "/RTIR/Search/Refine.html?". $query_string->(
+            NewQuery => 1,
+            Queue => $queue,
+        ),
+    );
+    PageMenu()->child(
+        new => title => loc("New $type"),
+        path => "/RTIR/Create.html?". $query_string->( Queue => $queue ),
+    ) if $type;
+
+    if ( $type eq 'Incident' ) {
+        PageMenu()->child(
+            abandon => title => loc('Bulk Abandon'),
+            path => "/RTIR/Incident/BulkAbandon.html?". $query_string->( %args ),
+        );
+    }
+    elsif ( $type eq 'Report' ) {
+        PageMenu()->child(
+            reject => title => loc('Bulk Reject'),
+            path => "RTIR/Report/BulkReject.html?". $query_string->( %args ),
+        );
+    }
 }
 
 

commit 622f0a675b098ed2b1ecd669f19ab76a25c8b32a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 17 09:46:50 2010 +0300

    menu items for tickets' item map

diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
index 5ba6f18..422b4cc 100644
--- a/html/Callbacks/RTIR/Elements/Tabs/Privileged
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -85,6 +85,45 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$}
     };
 
     PageMenu()->child( display => title => loc('Display'), path => "/RTIR/Display.html?id=$id" );
+
+    # RT4 TODO: something wrong, this doesn't work
+    if ( $session{'tickets'} ) {
+        # we have to update session data if we get new ItemMap
+        my $updatesession = 1 unless ( $session{"tickets"}->{'item_map'} );
+        my $item_map = $session{"tickets"}->ItemMap;
+        $session{"tickets"}->PrepForSerialization
+            if $updatesession;
+
+        # Don't display prev links if we're on the first ticket
+        my $top = PageMenu();
+        if ( my $t = $item_map->{$id}->{'prev'} ) {
+            $top = $top->child(
+                previouse => path => "RTIR/Display.html?id=$id",
+                title => '< ' . loc('Prev')
+            );
+        }
+        if ( my $t = $item_map->{'first'} ) {
+            $top->child(
+                first => path  => "RTIR/Display.html?id=$t",
+                title => '<< ' . loc('First')
+            );
+        }
+
+        $top = PageMenu();
+        if ( my $t = $item_map->{$id}->{'next'} ) {
+            $top = $top->child(
+                next => path  => "RTIR/Display.html?id=$t",
+                title => loc('Next') . ' >'
+            );
+        }
+        if ( my $t = $item_map->{'last'} ) {
+            $top->child(
+                last => path  => "RTIR/Display.html?id=$t",
+                title => loc('Last') . ' >>'
+            );
+        }
+    }
+
     if ( $can->('ModifyTicket') ) {
         PageMenu()->child( edit => title => loc('Edit'), path => "/RTIR/Edit.html?id=$id" );
         PageMenu()->child( split => title => loc('Split'), path => "/RTIR/Split.html?id=$id" );

commit c3912875679c02ba21ff53e6d3a86bcce8fab0e0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 17 09:47:28 2010 +0300

    pass queue around as well

diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
index 422b4cc..58c74c5 100644
--- a/html/Callbacks/RTIR/Elements/Tabs/Privileged
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -242,7 +242,9 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$}
     );
     PageMenu()->child(
         new_search => title => loc('New Search'),
-        path => "/RTIR/Link/$direction/Refine.html?id=$id&NewQuery=1",
+        path => "/RTIR/Link/$direction/Refine.html?". $query_string->(
+            NewQuery => 1, id => $id, Queue => $queue,
+        ),
     );
     PageMenu()->child(
         new => title => loc("New $type"),

commit 102388963784ead07138a8f7d3566a5936f7e5d1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 17 09:52:07 2010 +0300

    delete QueueTabs

diff --git a/html/RTIR/Elements/QueueTabs b/html/RTIR/Elements/QueueTabs
deleted file mode 100644
index 7c1cbd9..0000000
--- a/html/RTIR/Elements/QueueTabs
+++ /dev/null
@@ -1,323 +0,0 @@
-%# BEGIN LICENSE BLOCK
-%# 
-%# Copyright (c) 1996-2002 Jesse Vincent <jesse at bestpractical.com>
-%# 
-%# (Except where explictly superceded by other copyright notices)
-%# 
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org
-%# 
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%# 
-%# 
-%# Unless otherwise specified, all modifications, corrections or
-%# extensions to this work which alter its source code become the
-%# property of Best Practical Solutions, LLC when submitted for
-%# inclusion in the work.
-%# 
-%# 
-%# END LICENSE BLOCK
-% $m->callback( %ARGS, CallbackPage => '/Ticket/Elements/Tabs', Ticket => $Ticket, actions=> $actions, tabs => $tabs);
-<& /RTIR/Elements/Tabs,
-    %ARGS,
-    tabs => $tabs, 
-    actions => $actions, 
-    current_toptab => $current_toptab,
-    current_tab => $mytab,
-    current_subtab => $current_subtab,
-    Title => $Title,
-&> 
-
-<%INIT>
-if ( $QueryString =~ s/^&// ) {
-    $RT::Logger->warning("query string has leading &");
-}
-
-if ( !$Ticket && $id ) {
-    $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
-    $Ticket->Load( $id );
-}
-$id = $Ticket->id if $Ticket;
-
-my $Type = RT::IR::TicketType( Queue => $QueueName );
-
-my $EscapedQueueName
-    = $m->comp( '/Elements/QueryString', Queue => $QueueName );
-my $current_toptab = 'RTIR/Search/Results.html?' . $EscapedQueueName;
-
-my $tabs = {};
-
-my ( $actions, $mytab );
-my $searchtabs = {};
-
-if ( $Ticket && $Ticket->QueueObj->Name eq $QueueName ) {
-    $mytab = "RTIR/Display.html?id=$id";
-
-    if ( $session{'tickets'} ) {
-        my $item_map = $session{'tickets'}->ItemMap;
-
-        # Don't display prev links if we're on the first ticket
-        if ( $item_map->{$id}->{'prev'} ) {
-            $searchtabs->{'_a'} = {
-                class => "nav",
-                path  => "RTIR/Display.html?id=" . $item_map->{'first'},
-                title => '<< ' . loc('First')
-            };
-            $searchtabs->{"_b"} = {
-                class => "nav",
-                path  => "RTIR/Display.html?id=" . $item_map->{$id}->{'prev'},
-                title => '< ' . loc('Prev')
-            };
-        }
-
-        # Don't display next links if we're on the last ticket
-        if ( $item_map->{$id}->{'next'} ) {
-            $searchtabs->{'d'} = {
-                class => "nav",
-                path  => "RTIR/Display.html?id=" . $item_map->{$id}->{'next'},
-                title => loc('Next') . ' >'
-            };
-            $searchtabs->{'e'} = {
-                class => "nav",
-                path  => "RTIR/Display.html?id=" . $item_map->{'last'},
-                title => loc('Last') . ' >>'
-            };
-        }
-    }
-
-    $tabs->{'this'} = {
-        class => "currentnav",
-        path  => "RTIR/Display.html?id=$id",
-        title => loc( "$Type #[_1]", $id )
-    };
-
-    my %can = map { $_, $Ticket->CurrentUserHasRight($_) }
-        qw(ModifyTicket ReplyToTicket OwnTicket CommentOnTicket);
-
-
-    
-
-    my $ticket_page_tabs = {
-        _A => {
-            title => loc('Display'),
-            path  => "RTIR/Display.html?id=$id"
-        }
-    };
-
-    # only show edit option if they can do it
-    if ( $can{'ModifyTicket'} ) {
-        $ticket_page_tabs->{'_E'} = {
-            title => loc('Edit'),
-            path  => "RTIR/Edit.html?id=$id"
-        };
-
-        $ticket_page_tabs->{'_F'} = {
-            title => loc('Split'),
-            path  => "RTIR/Split.html?Ticket=$id"
-        };
-
-        $ticket_page_tabs->{'_G'} = {
-            title => loc('Merge'),
-            path  => "RTIR/Merge.html?id=$id&$QueryString"
-        };
-
-        $ticket_page_tabs->{'_H'} = {
-            title     => loc('Advanced'),
-            path      => "RTIR/Advanced.html?id=$id",
-            separator => 1,
-        };
-
-        foreach my $key ( keys %$appendtabs ) {
-            foreach ( qw(title path subtabs current_subtab) ) {
-                $ticket_page_tabs->{ $key }->{ $_ } = $appendtabs->{ $key }->{ $_ };
-            }
-        }
-    }
-
-    $current_subtab ||= "RTIR/Display.html?id=$id";
-    $tabs->{'this'}->{'subtabs'} = $ticket_page_tabs;
-    foreach my $tab ( values %$ticket_page_tabs ) {
-        next unless $tab->{'path'} eq $current_subtab;
-
-        $tab->{'subtabs'} = { %{ $tab->{'subtabs'} || {} }, %$subtabs } if $subtabs;
-        $tabs->{'this'}->{'current_subtab'} = $tab->{'path'};
-    }
-
-    ### Reply ###
-    if ( $can{'ModifyTicket'} || $can{'ReplyToTicket'} ) {
-
-        if ( $Type eq 'Incident' ) {
-            $actions->{'A'} = {
-                title => loc('Reply to Reporters'),
-                path  =>
-                    "RTIR/Incident/Reply.html?id=$id&SelectAllTickets=1",
-            };
-            $actions->{'Ab'} = {
-                title => loc('Reply to All'),
-                path  =>
-                    "RTIR/Incident/Reply.html?id=$id&SelectAllTickets=1&All=1",
-            };
-        } elsif ( $Type eq 'Block' ) {
-            $actions->{'A'} = {
-                title => loc('Reply'),
-                path  =>
-                    "RTIR/Update.html?id=$id&Action=Respond",
-            };
-        } else {
-            $actions->{'A'} = {
-                title => loc('Reply'),
-                path  =>
-                    "RTIR/Update.html?id=$id&Action=Respond",
-            };
-        }
-    }
-
-    if ( $can{'OwnTicket'} ) {
-        if ( $Ticket->Owner == $RT::Nobody->id ) {
-            $actions->{'D'} = {
-                path  => "RTIR/Display.html?Action=Take&id=$id",
-                title => loc('Take')
-            } if $can{'ModifyTicket'} || $Ticket->CurrentUserHasRight('TakeTicket');
-        } elsif ( $Ticket->Owner != $session{CurrentUser}->id ) {
-            $actions->{'E'} = {
-                path  => "RTIR/Display.html?Action=Steal&id=$id",
-                title => loc('Steal')
-            } if $can{'ModifyTicket'} || $Ticket->CurrentUserHasRight('StealTicket');
-        }
-    }
-
-    my $i = 0;
-    my $status = $Ticket->Status;
-    my $lifecycle = $Ticket->QueueObj->lifecycle;
-    foreach my $info ( $lifecycle->actions( $status ) ) {
-        my $next = $info->{'to'};
-        next unless $lifecycle->is_transition( $status => $next );
-
-        my %args = (%$info, id => $id);
-        delete @args{qw(to from label update)};
-
-        # if user will be owner then he will get more rights
-        # TODO: check actually if he will get required rights
-        if ( !$args{'TakeOrStealFirst'} || $session{'CurrentUser'}->id == $Ticket->Owner ) {
-            my $check = $lifecycle->check_right( $status => $next );
-            $can{$check} = $Ticket->CurrentUserHasRight($check)
-                unless exists $can{$check};
-            next unless $can{$check};
-        }
-
-        my $path = 'RTIR/';
-        $path .= 'Incident/' if $Type eq 'Incident';
-        if ( my $update = $info->{'update'} ) {
-            $path .= $Type eq 'Incident'? 'Reply.html' : 'Update.html';
-            $path .= "?". $m->comp(
-                '/Elements/QueryString',
-                %args,
-                Action        => $update,
-                DefaultStatus => $next,
-            );
-        } else {
-            $path .= "Display.html?". $m->comp(
-                '/Elements/QueryString',
-                %args,
-                Status => $next,
-            );
-        }
-        $actions->{ 'Ab'. $i++ } = {
-            path  => $path,
-            title => loc( $info->{'label'} || ucfirst($next) ),
-        };
-    }
-
-    if ( $can{'ModifyTicket'} || $can{'CommentOnTicket'} ) {
-        $actions->{'F'} = {
-            title => loc('Comment'),
-            path  => "RTIR/Update.html?Action=Comment&id=$id"
-        };
-    }
-
-    $actions->{'_ZZ'} = {
-        html => $m->scomp( '/Ticket/Elements/Bookmark', id => $id ),
-    };
-
-} else {
-    $mytab = $current_tab;
-}
-
-$tabs->{"A"} = {
-    path  => "RTIR/Create.html?$EscapedQueueName",
-    title => loc("New $Type"),
-};
-
-$tabs->{"g"} = {
-    path      => "RTIR/Search/Results.html?$EscapedQueueName&$QueryString",
-    title     => loc('Results'),
-};
-$tabs->{"j"} = {
-    path      => "RTIR/Search/Reporting.html?$EscapedQueueName&$QueryString",
-    title     => loc('Report'),
-};
-unless ( $id ) {
-    $tabs->{'ga'} = {
-        class => "nav",
-        path  => "RTIR/Search/Refine.html?$EscapedQueueName&$QueryString&"
-            . $m->comp('/Elements/QueryString',
-                BaseQuery  => $BaseQuery,
-                ResultPage => "/RTIR/Search/Results.html?$EscapedQueueName",
-            ),
-        title => loc('Refine'),
-    };
-}
-
-
-if ( $Type eq 'Report' ) {
-    $tabs->{"h"} = {
-        path      => "RTIR/Report/BulkReject.html?$EscapedQueueName&$QueryString",
-        title     => loc('Bulk Reject'),
-        separator => 1
-    };
-} elsif ( $Type eq 'Incident' ) {
-    if ( $Ticket && $Ticket->QueueObj->Name ne 'Incidents' ) {
-        my $childtype = RT::IR::TicketType( Ticket => $Ticket );
-
-        $tabs->{'h'} = {
-            title => loc( 'Link [_1] #[_2]', $childtype, $Ticket->Id ),
-            path => "RTIR/Incident/LinkToIncident.html?id=" . $Ticket->Id,
-            separator => 1
-        };
-    }
-    $tabs->{'k'} = {
-        path      => "RTIR/Incident/BulkAbandon.html?$EscapedQueueName&$QueryString",
-        title     => loc('Bulk Abandon'),
-        separator => 1
-    };
-}
-
-if ( $subtabs && $current_tab ) {
-    foreach my $tab ( values %{$tabs} ) {
-        next unless $tab->{'path'} eq $current_tab;
-
-        $tab->{'subtabs'} = { %{ $tab->{'subtabs'} || {} }, %$subtabs };
-    }
-}
-
-</%INIT>
-<%ARGS>
-$Title          => ''
-$id             => undef
-$Ticket         => undef
-$QueueName      => 'Incident Reports'
-
-$BaseQuery      => ''
-$QueryString    => ''
-
-$appendtabs     => undef
-$current_tab    => undef
-
-$subtabs        => {}
-$current_subtab => undef
-</%ARGS>

commit 9b068bd125ccab0e94390eec79cda4f2a3a1764b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 17 09:52:49 2010 +0300

    reporting menu item

diff --git a/html/Callbacks/RTIR/Elements/Tabs/Privileged b/html/Callbacks/RTIR/Elements/Tabs/Privileged
index 58c74c5..5d62b44 100644
--- a/html/Callbacks/RTIR/Elements/Tabs/Privileged
+++ b/html/Callbacks/RTIR/Elements/Tabs/Privileged
@@ -286,6 +286,11 @@ if ( $request_path =~ m{^/RTIR/(?:$re_rtir_types/)?(Display|Edit|Update)\.html$}
         path => "/RTIR/Create.html?". $query_string->( Queue => $queue ),
     ) if $type;
 
+    PageMenu()->child(
+        report => title => loc('Report'),
+        path => "RTIR/Report/Reporting.html?". $query_string->( %args ),
+    );
+
     if ( $type eq 'Incident' ) {
         PageMenu()->child(
             abandon => title => loc('Bulk Abandon'),

commit 99ffb9ebf1a4f9672b738fc4bd12f351de7a01ed
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat Dec 18 00:51:43 2010 +0300

    mass switch over /Elements/Tabs

diff --git a/html/RTIR/Advanced.html b/html/RTIR/Advanced.html
index a234bab..5deb2f4 100644
--- a/html/RTIR/Advanced.html
+++ b/html/RTIR/Advanced.html
@@ -1,10 +1,5 @@
 <& /RTIR/Elements/Header, Title => $Title &>
-<& '/RTIR/'.$Type.'/Elements/Tabs', 
-    Ticket         => $Ticket,
-    current_tab    => "RTIR/Advanced.html?id=".$Ticket->Id,
-    current_subtab => "RTIR/Advanced.html?id=".$Ticket->Id,
-    Title          => $Title,
-&>
+<& /Elements/Tabs &>
 
 <& /Elements/ListActions, actions => \@results &>
 
diff --git a/html/RTIR/Create.html b/html/RTIR/Create.html
index 32d07ef..1ffcdd5 100644
--- a/html/RTIR/Create.html
+++ b/html/RTIR/Create.html
@@ -39,12 +39,7 @@
     current_tab    => "RTIR/Create.html?Incident=$Incident&$EscapedQueue",
 &>
 % } else {
-<& "/RTIR/".$Type."/Elements/Tabs",
-    Title          => $Title,
-    Ticket         => $TicketObj,
-    current_tab    => "RTIR/Create.html?$EscapedQueue",
-    current_subtab => "RTIR/Create.html?$EscapedQueue",
-&>
+<& "/Elements/Tabs" &>
 % }
 
 % $m->callback(CallbackName => 'BeforeActionList', %ARGS, Actions => \@results, ARGSRef => \%ARGS, Ticket => $TicketObj);
diff --git a/html/RTIR/Display.html b/html/RTIR/Display.html
index 6583155..b43a36f 100644
--- a/html/RTIR/Display.html
+++ b/html/RTIR/Display.html
@@ -23,12 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& /RTIR/Elements/Header, Title => $Title &>
-
-<& "/RTIR/".$Type."/Elements/Tabs", 
-    Ticket => $Ticket, 
-    current_tab => 'RTIR/Display.html?id='.$Ticket->id,
-    current_subtab => 'RTIR/Display.html?id='.$Ticket->id,
-    Title => $Title &>
+<& /Elements/Tabs &>
 
 % $m->callback(CallbackName => 'BeforeActionList', %ARGS, Actions => \@results, ARGSRef => \%ARGS, Ticket => $Ticket);
 
diff --git a/html/RTIR/Edit.html b/html/RTIR/Edit.html
index 3de93ce..4d8232d 100644
--- a/html/RTIR/Edit.html
+++ b/html/RTIR/Edit.html
@@ -23,11 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& /RTIR/Elements/Header, Title => $Title &>
-<& '/RTIR/'.$Type.'/Elements/Tabs', 
-    Ticket => $Ticket, 
-    current_tab => "RTIR/Edit.html?id=".$Ticket->Id, 
-    current_subtab => "RTIR/Edit.html?id=".$Ticket->Id, 
-    Title => $Title &>
+<& /Elements/Tabs &>
 
 % $m->callback(CallbackName => 'BeforeActionList', Actions => \@results, ARGSRef => \%ARGS, Ticket => $Ticket);          
 <& /Elements/ListActions, actions => \@results &>
@@ -130,7 +126,6 @@
 
 <%INIT>
 my $Ticket = LoadTicket($id);
-
 $id = $ARGS{'id'} = $Ticket->Id;
 
 $m->callback(CallbackName => 'Initial', %ARGS, Ticket => $Ticket);
diff --git a/html/RTIR/Forward.html b/html/RTIR/Forward.html
index 1b9c00e..9a5ade8 100644
--- a/html/RTIR/Forward.html
+++ b/html/RTIR/Forward.html
@@ -1,16 +1,5 @@
 <& /RTIR/Elements/Header, Title => $Title &>
-
-<& "/RTIR/". $Type ."/Elements/Tabs", 
-    Title          => $Title,
-    Ticket         => $TicketObj,
-    current_tab    => 'RTIR/Display.html?id='. $id,
-    appendtabs     => { _ZF => {
-        title => loc( 'Forward transaction #[_1]', $QuoteTransaction ),
-        path  => 'RTIR/Forward.html?id='. $id .'&QuoteTransaction='. $QuoteTransaction,
-    } },
-    current_subtab => 'RTIR/Forward.html?id='. $id .'&QuoteTransaction='. $QuoteTransaction,
-&>
-
+<& /Elements/Tabs &>
 <& /Elements/ListActions, actions => \@results &>
 
 <form action="Forward.html" name="ForwardMessage" method="post">
diff --git a/html/RTIR/Incident/BulkAbandon.html b/html/RTIR/Incident/BulkAbandon.html
index 739f169..c587bac 100644
--- a/html/RTIR/Incident/BulkAbandon.html
+++ b/html/RTIR/Incident/BulkAbandon.html
@@ -23,13 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& '/RTIR/Elements/Header', Title => $title &>
-<& '/RTIR/Search/Elements/RefineTabs',
-    Title       => $title,
-    Queue       => $Queue,
-    QueryString => $QueryString,
-    BaseQuery   => $BaseQuery,
-    current_tab => $current_tab, 
-&>
+<& '/Elements/Tabs' &>
 
 <& /Elements/ListActions, actions => \@results &>
 
@@ -41,7 +35,7 @@
 my $result_set = $m->scomp('/RTIR/Search/Elements/ShowResults',
     Queue         => $Queue,
     BaseURL       => $BaseURL,
-    BaseQuery     => $BaseQuery,
+    BaseQuery     => RT::IR->BaseQuery( Queue => $Queue ),
     Query         => $Query,
     DisplayFormat => "__CheckBox__, $Format",
     Format        => $Format,
@@ -113,9 +107,10 @@ if ( $ARGS{'BulkAbandon'} ) {
         # process replies
         if( scalar @ReplyToAll ) {
             # XXX: why do we limit to open?
+            # RT4 TODO
             my $query = "Status = 'open' AND MemberOf = $id";
             $query .= " AND (". join(' OR ', map "Queue = '$_'", @ReplyToAll) .")";
-            my $members = new RT::Tickets( $t->CurrentUser );
+            my $members = RT::Tickets->new( $t->CurrentUser );
             $members->FromSQL( $query );
             while( my $member = $members->Next ) {
                 $ARGS{'UpdateAttachments'} = delete $session{'Attachments'} if $session{'Attachments'};
@@ -126,10 +121,11 @@ if ( $ARGS{'BulkAbandon'} ) {
         # process status updates
         my @tmp;
         {
+            # RT4 TODO
             my $query = "MemberOf = $id"
                 ." AND ( ". join(" OR ", map "Status = '$_'", RT->Config->Get('ActiveStatus') ) ." )"
                 ." AND ( Queue = 'Incident Reports' OR Queue = 'Blocks' OR Queue = 'Investigations' )";
-            
+
             my $members = new RT::Tickets( $t->CurrentUser );
             $members->FromSQL( $query );
             while( my $member = $members->Next ) {
@@ -151,27 +147,15 @@ if ( $ARGS{'BulkAbandon'} ) {
     # force redo search if we changed tickets
     $session{'tickets'}->RedoSearch if $session{'tickets'};
 }
-
-# We can only reject new tickets, so set the states.
-my $QueryString = $m->comp(
-    '/Elements/QueryString',
-    Query   => $Query,
-    Format  => $Format,
-    Rows    => $Rows,
-    OrderBy => $OrderBy,
-    Order   => $Order,
-    Page    => $Page
-);
 my $BaseURL = "RTIR/Incident/BulkAbandon.html?"
     . $m->comp('/Elements/QueryString', Queue => $Queue, Status => $Status);
-my $current_tab = $BaseURL ."&$QueryString";
 
 </%INIT>
 <%ARGS>
+# RT4 TODO
 $Status          => 'abandoned'
 $Queue           => 'Incidents'
 
-$BaseQuery       => $m->comp( '/RTIR/Elements/BaseQuery', Queue => $Queue );
 $Query           => $m->comp( '/RTIR/Elements/NewQuery', Queue => $Queue );
 $Format          => RT->Config->Get('RTIRSearchResultFormats')->{'AbandonIncidents'};
 $Rows            => 50
diff --git a/html/RTIR/Incident/Create.html b/html/RTIR/Incident/Create.html
index 04c2373..44296f6 100644
--- a/html/RTIR/Incident/Create.html
+++ b/html/RTIR/Incident/Create.html
@@ -23,12 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& /RTIR/Elements/Header, Title => $Title &>
-<& /RTIR/Incident/Elements/Tabs, 
-    current_tab => $current_tab, 
-    current_subtab => $current_subtab, 
-    Title => $Title,
-    Ticket => $TicketObj &>
-
+<& /Elements/Tabs &>
 
 % $m->callback(CallbackName => 'BeforeActionList', %ARGS, Actions => \@results, ARGSRef => \%ARGS, Ticket => $TicketObj);
 <& /Elements/ListActions, actions => \@results &>
@@ -364,7 +359,4 @@ $Split                   => 0
 $TicketObj               => undef
 
 $Child                   => undef
-
-$current_tab             => "RTIR/Create.html?Queue=Incidents"
-$current_subtab          => "RTIR/Create.html?Queue=Incidents"
 </%ARGS>
diff --git a/html/RTIR/Incident/Display.html b/html/RTIR/Incident/Display.html
index 90bb2b8..d312b7a 100644
--- a/html/RTIR/Incident/Display.html
+++ b/html/RTIR/Incident/Display.html
@@ -24,11 +24,7 @@
 %# END LICENSE BLOCK
 
 <& /RTIR/Elements/Header, Title => loc("Incident #[_1]: [_2]", $id, $TicketObj->Subject) &>
-<& /RTIR/Incident/Elements/Tabs, 
-    Ticket => $TicketObj, 
-    current_tab => 'RTIR/Display.html?id='.$id,
-    current_subtab => 'RTIR/Display.html?id='.$id,
-    Title => loc("Incident #[_1]: [_2]", $id, $TicketObj->Subject) &>
+<& /Elements/Tabs &>
     
 % $m->callback(CallbackName => 'BeforeActionList', %ARGS, Actions => \@results, ARGSRef => \%ARGS, Ticket => $TicketObj);
 <& /Elements/ListActions, actions => \@results &>
diff --git a/html/RTIR/Report/BulkReject.html b/html/RTIR/Report/BulkReject.html
index e24bee3..831d46b 100644
--- a/html/RTIR/Report/BulkReject.html
+++ b/html/RTIR/Report/BulkReject.html
@@ -23,13 +23,7 @@
 %# 
 %# END LICENSE BLOCK
 <& '/RTIR/Elements/Header', Title => $title &>
-<& '/RTIR/Search/Elements/RefineTabs',
-   Title       => $title,
-   Queue       => $Queue,
-   BaseQuery   => $BaseQuery,
-   QueryString => $QueryString,
-   current_tab => $current_tab,
-&>
+<& '/Elements/Tabs' &>
 
 <& /Elements/ListActions, actions => \@results &>
 
@@ -141,18 +135,8 @@ if ( $BulkReject ) {
     }
 }
 
-my $QueryString = $m->comp('/Elements/QueryString',
-    Query     => $Query,
-    Format    => $Format,
-    Rows      => $Rows,
-    Page      => $Page,
-    OrderBy   => $OrderBy,
-    Order     => $Order,
-);
-
 my $BaseURL = "RTIR/Report/BulkReject.html?"
     . $m->comp('/Elements/QueryString', Queue => $Queue);
-my $current_tab = "$BaseURL&$QueryString";
 
 </%INIT>
 <%ARGS>
diff --git a/html/RTIR/Search/Results.html b/html/RTIR/Search/Results.html
index 937d00b..f12d1da 100644
--- a/html/RTIR/Search/Results.html
+++ b/html/RTIR/Search/Results.html
@@ -44,24 +44,7 @@
 %# 
 %# }}} END BPS TAGGED BLOCK
 <& /Elements/Header, Title => $title, Refresh => $session{'tickets_refresh_interval'} || 0 &>
-% if ( $Type ) {
-<& '/RTIR/'.$Type.'/Elements/Tabs',
-    Title       => $title,
-    BaseQuery   => $BaseQuery,
-    QueryString => $QueryString,
-
-    current_tab => $current_tab,
-&>
-% } else {
-<& '/RTIR/Search/Elements/Tabs',
-    Title       => $title,
-
-    BaseQuery   => $BaseQuery,
-    QueryString => $QueryString,
-
-    current_tab => 'RTIR/Search/Results.html',
-&>
-% }
+<& /Elements/Tabs &>
 
 <& /Elements/ListActions, actions => \@results &>
 
@@ -84,22 +67,15 @@
 my $title = loc("Results");
 
 my $Type = RT::IR::TicketType( Queue => $Queue ) || '';
-$Format  ||= RT->Config->Get('RTIRSearchResultFormats')->{ $Type . 'Default' };
+$Format ||= RT->Config->Get('RTIRSearchResultFormats')->{ $Type . 'Default' };
 if ( $Type ) {
     $BaseQuery ||= $m->comp( '/RTIR/Elements/BaseQuery', Queue => $Queue );
     $Query     ||= $m->comp( '/RTIR/Elements/NewQuery', Queue => $Queue );
 }
 
-my $QueryString = $m->comp( '/Elements/QueryString',
-                            Query     => $Query,
-                            Format    => $Format,
-                            Rows      => $Rows,
-                            Page      => $Page,
-                            OrderBy   => $OrderBy,
-                            Order     => $Order,
-                          );
-my $BaseURL = "RTIR/Search/Results.html?". $m->comp( '/Elements/QueryString', Queue => $Queue );
-my $current_tab = "$BaseURL&$QueryString";
+my $BaseURL = "RTIR/Search/Results.html";
+$BaseURL .= '?'. $m->comp( '/Elements/QueryString', Queue => $Queue )
+    if $Queue;
 
 </%INIT>
 <%ARGS>
diff --git a/html/RTIR/Search/index.html b/html/RTIR/Search/index.html
index 5eb22d9..e2f2e3d 100644
--- a/html/RTIR/Search/index.html
+++ b/html/RTIR/Search/index.html
@@ -44,15 +44,7 @@
 %#
 %# }}} END BPS TAGGED BLOCK
 <& /Elements/Header, Title => $title &>
-
-<& /RTIR/Search/Elements/Tabs,
-   Title => $title,
-
-   BaseQuery   => $BaseQuery,
-   QueryString => $QueryString,
-
-   current_tab => 'RTIR/Search/index.html',
-&>
+<& /Elements/Tabs &>
 
 <& Elements/BuildQuery,
     %query_state,
@@ -72,8 +64,6 @@ my %query_state = $m->comp('Elements/ProcessQuery',
 );
 
 my @results = @{ delete $query_state{'results'} };
-
-my $QueryString = $m->comp( '/Elements/QueryString', %{ $query_state{'query'} } );
 </%INIT>
 
 <%ARGS>

commit 9528606b44a46142f21c556123be474f66f3bdfe
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat Dec 18 01:03:52 2010 +0300

    ChildrenQuery from comp into RT::IR

diff --git a/html/RTIR/Elements/ChildrenQuery b/html/RTIR/Elements/ChildrenQuery
deleted file mode 100644
index 4d7e7c2..0000000
--- a/html/RTIR/Elements/ChildrenQuery
+++ /dev/null
@@ -1,19 +0,0 @@
-<%INIT>
-my @parts;
-push @parts, $BaseQuery || $m->comp('/RTIR/Elements/BaseQuery', Queue => $Queue);
-push @parts, $m->comp('/RTIR/Elements/NewQuery', Queue  => $Queue,
-                                                 states => [@States],
-                                                 add_states => [@AddStates],
-                     );
-push @parts, "MemberOf = ". $Ticket->id if $Ticket;
-
-return join " AND ", map "($_)", @parts;
-
-</%INIT>
-<%ARGS>
-$BaseQuery => ''
-$Ticket => undef
-$Queue => ''
- at States => ()
- at AddStates => ()
-</%ARGS>
diff --git a/html/RTIR/Incident/Elements/ShowChildren b/html/RTIR/Incident/Elements/ShowChildren
index bf98706..68261b5 100644
--- a/html/RTIR/Incident/Elements/ShowChildren
+++ b/html/RTIR/Incident/Elements/ShowChildren
@@ -56,7 +56,7 @@ my @inactive_states = RT::IR::States( Queue => $Queue, Active => 0, Inactive =>
 
 my $active = RT::Tickets->new( $session{'CurrentUser'} );
 $active->FromSQL(
-    $m->comp( '/RTIR/Elements/ChildrenQuery',
+    RT::IR->ChildrenQuery(
         Queue  => $Queue,
         Ticket => $IncidentObj,
         States => [ @active_states ],
@@ -65,7 +65,7 @@ $active->FromSQL(
 
 my $inactive = RT::Tickets->new( $session{'CurrentUser'} );
 $inactive->FromSQL(
-    $m->comp( '/RTIR/Elements/ChildrenQuery',
+    RT::IR->ChildrenQuery(
         Queue  => $Queue,
         Ticket => $IncidentObj,
         States => [ @inactive_states ],
diff --git a/html/RTIR/Incident/Reply.html b/html/RTIR/Incident/Reply.html
index 1f6ad36..f4466f4 100644
--- a/html/RTIR/Incident/Reply.html
+++ b/html/RTIR/Incident/Reply.html
@@ -148,6 +148,7 @@ my $ActiveStatesQuery =
 
 $Query ||= "( $ActiveStatesQuery )";
 
+# TODO: why don't we use RT::IR->ChildrenQuery ?
 my $ActiveChildrenQuery = join ' AND ', map "( $_ )", grep $_,
     "MemberOf = $id",
     $ActiveStatesQuery,
diff --git a/html/RTIR/Incident/ShowChildren.html b/html/RTIR/Incident/ShowChildren.html
index eef7f03..2b1f98b 100644
--- a/html/RTIR/Incident/ShowChildren.html
+++ b/html/RTIR/Incident/ShowChildren.html
@@ -78,21 +78,19 @@ my $Title = loc("$Queue for Incident #[_1]: [_2]", $id, $Incident->Subject);
 my $delete = $Incident->CurrentUserHasRight('ModifyTicket') ? 1: 0;
 
 my $children = RT::Tickets->new( $session{'CurrentUser'} );
-$children->FromSQL( $m->comp( '/RTIR/Elements/ChildrenQuery',
-                              Queue  => $Queue,
-                              Ticket => $Incident,
-                              States => [@States],
-                            )
-                  );
+$children->FromSQL( RT::IR->ChildrenQuery(
+    Queue  => $Queue,
+    Ticket => $Incident,
+    States => [@States],
+) );
 
 my @possible_states = RT::IR::States( Queue => $Queue, Inactive => 1 );
 my $all_children = RT::Tickets->new( $session{'CurrentUser'} );
-$all_children->FromSQL( $m->comp( '/RTIR/Elements/ChildrenQuery',
-                                  Queue  => $Queue,
-                                  Ticket => $Incident,
-                                  States => [@possible_states],
-                                )
-                      );
+$all_children->FromSQL( RT::IR->ChildrenQuery(
+    Queue  => $Queue,
+    Ticket => $Incident,
+    States => [@possible_states],
+) );
 my $current_tab = 'RTIR/Incident/ShowChildren.html?'
     . $m->comp( '/Elements/QueryString', id => $id, Queue => $Queue );
 </%INIT>
diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index a32edd4..b87e282 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -282,6 +282,24 @@ sub BaseQuery {
     return $res;
 }
 
+sub ChildrenQuery {
+    my $self = shift;
+    my %args = (
+        @_
+    );
+
+    my @parts;
+    push @parts, $self->NewQuery(
+        Queue  => $Queue,
+        states => $arga{'States'},
+        add_states => $args{'AddStates'},
+    );
+    push @parts, $self->BaseQuery( Queue => $args{'Queue'} );
+    push @parts, "MemberOf = ". $args{'Ticket'}->id if $args{'Ticket'};
+
+    return join " AND ", map "($_)", @parts;
+}
+
 sub GetCustomField {
     my $field = shift or return;
     return (__PACKAGE__->CustomFields( $field ))[0];

commit e3922a11701f828ecb86366a67527c34234833ad
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 24 13:02:37 2010 +0300

    add support for array of queues in BaseQuery

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index b87e282..6caa57e 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -256,8 +256,10 @@ sub BaseQuery {
         @_
     );
     my $res = '';
-    if ( defined $args{'Queue'} && length $args{'Queue'} ) {
-        $res = "Queue = '$args{Queue}'";
+    if ( $args{'Queue'} ) {
+        $res = join ' OR ', map "Queue = '$_'", grep defined && length,
+            ref $args{'Queue'} ? ( @{ $args{'Queue'} } ) : ( $args{'Queue'} );
+        $res = '( $res )' if $res && $res =~ / OR /;
     }
     if ( my $t = $args{'HasNoMember'} ) {
         $res .= ' AND ' if $res;

commit 5ec80a909f39367b73b09cea2e7d679767505f4f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 24 13:03:12 2010 +0300

    add suport of MemberOf in BaseQuery

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 6caa57e..dc03726 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -269,6 +269,10 @@ sub BaseQuery {
         $res .= ' AND ' if $res;
         $res .= 'MemberOf != '. (ref $t? $t->id : int $t);
     }
+    if ( my $t = $args{'MemberOf'} ) {
+        $res .= ' AND ' if $res;
+        $res .= 'MemberOf = '. (ref $t? $t->id : int $t);
+    }
     if (
         my $t = $args{'Constituency'}
         and RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject'

commit 7639b461176c9a992456001bdd220da6fb47963e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 24 13:12:11 2010 +0300

    Exlude argument in BaseQuery

diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index dc03726..a9a057b 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -249,9 +249,11 @@ sub NewQuery {
 sub BaseQuery {
     my $self = shift;
     my %args = (
-        Queue => undef,
-        HasNoMember => undef,
-        NotMemberOf => undef,
+        Queue        => undef,
+        Exclude      => undef,
+        HasNoMember  => undef,
+        NotMemberOf  => undef,
+        MemberOf     => undef,
         Constituency => undef,
         @_
     );
@@ -261,6 +263,10 @@ sub BaseQuery {
             ref $args{'Queue'} ? ( @{ $args{'Queue'} } ) : ( $args{'Queue'} );
         $res = '( $res )' if $res && $res =~ / OR /;
     }
+    if ( my $t = $args{'Exclude'} ) {
+        $res .= ' AND ' if $res;
+        $res .= '('. join( ' AND ', map "id != '$_'", map int $_, ref $t? (@$t) : ($t) ) .')';
+    }
     if ( my $t = $args{'HasNoMember'} ) {
         $res .= ' AND ' if $res;
         $res .= 'HasMember != '. (ref $t? $t->id : int $t);

commit a83be479725eef48709ee11c76f023388b93558d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 24 13:12:55 2010 +0300

    use BaseQuery from API instead of mason

diff --git a/html/RTIR/Elements/DueIncidents b/html/RTIR/Elements/DueIncidents
index b2c36f3..b1b004d 100644
--- a/html/RTIR/Elements/DueIncidents
+++ b/html/RTIR/Elements/DueIncidents
@@ -59,8 +59,8 @@ my $QueryString = $m->comp('/Elements/QueryString',
 </%INIT>
 <%ARGS>
 $Title           => loc("Most due incidents")
-$BaseQuery       => $m->comp( '/RTIR/Elements/BaseQuery', Queue => 'Incidents' )
-$Query           => $m->comp( '/RTIR/Elements/NewQuery', Queue => 'Incidents' )
+$BaseQuery       => RT::IR->BaseQuery( Queue => 'Incidents' )
+$Query           => RT::IR->NewQuery( Queue => 'Incidents' )
 $Format          => RT->Config->Get('RTIRSearchResultFormats')->{'DueIncidents'}
 $Rows            => RT->Config->Get('DefaultSummaryRows', $session{'CurrentUser'})
 $Page            => 1
diff --git a/html/RTIR/Elements/MergeWith b/html/RTIR/Elements/MergeWith
index 8848fe2..35fa6b4 100644
--- a/html/RTIR/Elements/MergeWith
+++ b/html/RTIR/Elements/MergeWith
@@ -16,16 +16,8 @@
 my $Type = RT::IR::TicketType( Queue => $Queue );
 $Title ||= $Type .'s';
 
-$Query ||= $m->comp('/RTIR/Elements/NewQuery', Queue => $Queue);
-unless ( $BaseQuery ) {
-    my @parts;
-    push @parts, "id != $id";
-    push @parts, $m->comp('/RTIR/Elements/BaseQuery', Queue => $Queue) if $Queue;
-    push @parts, "CF.{Constituency} = '". $Ticket->FirstCustomFieldValue('Constituency') ."'"
-        if RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject'
-            && RT::IR->CustomFields(Constituency => Queue => $Queue);
-    $BaseQuery = join ' AND ', map "( $_ )", grep $_, @parts;
-}
+$Query ||= RT::IR->NewQuery( Queue => $Queue );
+$BaseQuery ||= RT::IR->BaseQuery( Queue => $Queue, Exclude => $id, Constituency => $Ticket );
 
 </%INIT>
       
diff --git a/html/RTIR/Elements/NewReports b/html/RTIR/Elements/NewReports
index 69d7cf7..158abef 100644
--- a/html/RTIR/Elements/NewReports
+++ b/html/RTIR/Elements/NewReports
@@ -48,7 +48,7 @@
 my $title = loc("New unlinked Incident Reports...");
 
 unless( $Query ) {
-    $Query = $m->comp( '/RTIR/Elements/NewQuery',  Queue => $Queue, states => [ 'new' ] );
+    $Query = RT::IR->NewQuery( Queue => $Queue, states => [ 'new' ] );
     $Query = join ' AND ', $Query, 'MemberOf IS NULL';
 }
 
@@ -73,7 +73,7 @@ my $BulkQS = $m->comp('/Elements/QueryString',
 
 <%ARGS>
 $Queue     => 'Incident Reports'
-$BaseQuery => $m->comp( '/RTIR/Elements/BaseQuery', Queue => $Queue )
+$BaseQuery => RT::IR->BaseQuery( Queue => $Queue )
 $Query     => undef
 $Format    => RT->Config->Get('RTIRSearchResultFormats')->{'NewReports'}
 $Rows      => RT->Config->Get('DefaultSummaryRows', $session{'CurrentUser'})
diff --git a/html/RTIR/Incident/Reply.html b/html/RTIR/Incident/Reply.html
index f4466f4..123df09 100644
--- a/html/RTIR/Incident/Reply.html
+++ b/html/RTIR/Incident/Reply.html
@@ -28,7 +28,6 @@
 
     Queue          => 'Incident Reports',
     Ticket         => $IncidentObj,
-    BaseQuery      => $BaseQuery,
     QueryString    => $QueryString,
 
     current_tab    => $current_tab,
@@ -53,7 +52,7 @@
 <& /RTIR/Search/Elements/ShowResults,
     Queue         => 'Incident Reports',
     BaseURL       => $current_tab,
-    BaseQuery     => $BaseQuery{'Incident Reports'},
+    BaseQuery     => RT::IR->BaseQuery(Queue => 'Incident Reports', MemberOf => $id),
     Query         => $Query,
     DisplayFormat => "__CheckBox.{SelectedReports}__, $Format",
     Format        => $Format,
@@ -68,7 +67,7 @@
 <& /RTIR/Search/Elements/ShowResults,
     Queue         => 'Investigations',
     BaseURL       => $current_tab,
-    BaseQuery     => $BaseQuery{'Investigations'},
+    BaseQuery     => RT::IR->BaseQuery(Queue => 'Investigations', MemberOf => $id),
     Query         => $Query,
     DisplayFormat => "__CheckBox.{SelectedInvestigations}__, $Format",
     Format        => $Format,
@@ -83,7 +82,7 @@
 <& /RTIR/Search/Elements/ShowResults,
     Queue         => 'Investigations',
     BaseURL       => $current_tab,
-    BaseQuery     => $BaseQuery{'Blocks'},
+    BaseQuery     => RT::IR->BaseQuery(Queue => 'Blocks', MemberOf => $id),
     Query         => $Query,
     DisplayFormat => "__CheckBox.{SelectedBlocks}__, $Format",
     Format        => $Format,
@@ -246,17 +245,6 @@ foreach (qw(SelectedReports SelectedInvestigations SelectedBlocks)) {
     }
 }
 
-my ($BaseQuery, %BaseQuery) = ( '', () );
-foreach my $queue ( @queues ) {
-    my $tmp = $m->comp('/RTIR/Elements/BaseQuery', Queue => $queue);
-    $BaseQuery .= ' OR ' if $BaseQuery;
-    $BaseQuery .= "( $tmp )";
-
-    $BaseQuery{ $queue } = join ' AND ', map "( $_ )", grep $_,
-        $tmp, "MemberOf = $id";
-}
-$BaseQuery = join ' AND ', map "( $_ )", grep $_, $BaseQuery, "MemberOf = $id";
-
 my $QueryString = $m->comp( '/Elements/QueryString',
                             Query => $Query,
                             Format => $Format,
diff --git a/html/RTIR/Merge.html b/html/RTIR/Merge.html
index c186237..9a3f200 100644
--- a/html/RTIR/Merge.html
+++ b/html/RTIR/Merge.html
@@ -128,15 +128,8 @@ my $Queue = $Ticket->QueueObj->Name;
 
 my $title = loc("Merge [_1] #[_2]: [_3]", $Type, $id, $Ticket->Subject);
 
-$Query ||= $m->comp('/RTIR/Elements/NewQuery', Queue => $Queue);
-unless ( $BaseQuery ) {
-    my @parts;
-    push @parts, "id != $id";
-    push @parts, $m->comp('/RTIR/Elements/BaseQuery', Queue => $Queue);
-    push @parts, "CF.{Constituency} = '". $Ticket->FirstCustomFieldValue('Constituency') ."'"
-        if RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject';
-    $BaseQuery = join ' AND ', map "( $_ )", grep $_, @parts;
-}
+$Query     ||= RT::IR->NewQuery( Queue => $Queue);
+$BaseQuery ||= RT::IR->BaseQuery( Queue => $Queue, Exclude => $id, Constituency => $Ticket );
 
 my %defaults = (
     Format  => $Format,
diff --git a/html/RTIR/Report/BulkReject.html b/html/RTIR/Report/BulkReject.html
index 831d46b..4129ea3 100644
--- a/html/RTIR/Report/BulkReject.html
+++ b/html/RTIR/Report/BulkReject.html
@@ -143,8 +143,8 @@ my $BaseURL = "RTIR/Report/BulkReject.html?"
 $Status              => 'rejected'
 $Queue               => 'Incident Reports'
 
-$BaseQuery           => $m->comp( '/RTIR/Elements/BaseQuery', Queue => $Queue )
-$Query               => $m->comp( '/RTIR/Elements/NewQuery',  Queue => $Queue )
+$BaseQuery           => RT::IR->BaseQuery( Queue => $Queue )
+$Query               => RT::IR->NewQuery( Queue => $Queue )
 $Format              => RT->Config->Get('RTIRSearchResultFormats')->{'RejectReports'}
 $Rows                => 50
 $Page                => 1
diff --git a/html/RTIR/Search/Reporting.html b/html/RTIR/Search/Reporting.html
index 6298faf..5444dc1 100644
--- a/html/RTIR/Search/Reporting.html
+++ b/html/RTIR/Search/Reporting.html
@@ -1,7 +1,6 @@
 <& /Elements/Header, Title => $title &>
 <& '/RTIR/'.$Type.'/Elements/Tabs',
     Title       => $title,
-    BaseQuery   => $BaseQuery,
     QueryString => $QueryString,
 
     current_tab => $current_tab,
@@ -53,8 +52,8 @@ $ShowChart      => 0
 
 $Queue     => ''
 
-$BaseQuery => $m->comp( '/RTIR/Elements/BaseQuery', Queue => $Queue )
-$Query     => $m->comp( '/RTIR/Elements/NewQuery', Queue => $Queue )
+$BaseQuery => RT::IR->BaseQuery( Queue => $Queue )
+$Query     => RT::IR->NewQuery( Queue => $Queue )
 $Format    => undef
 $Rows      => 50
 $Page      => 1
diff --git a/html/RTIR/Search/Results.html b/html/RTIR/Search/Results.html
index f12d1da..7120aef 100644
--- a/html/RTIR/Search/Results.html
+++ b/html/RTIR/Search/Results.html
@@ -69,8 +69,8 @@ my $title = loc("Results");
 my $Type = RT::IR::TicketType( Queue => $Queue ) || '';
 $Format ||= RT->Config->Get('RTIRSearchResultFormats')->{ $Type . 'Default' };
 if ( $Type ) {
-    $BaseQuery ||= $m->comp( '/RTIR/Elements/BaseQuery', Queue => $Queue );
-    $Query     ||= $m->comp( '/RTIR/Elements/NewQuery', Queue => $Queue );
+    $BaseQuery ||= RT::IR->BaseQuery( Queue => $Queue );
+    $Query     ||= RT::IR->NewQuery( Queue => $Queue );
 }
 
 my $BaseURL = "RTIR/Search/Results.html";

commit 86adddf9e52bc73742298acfe4ad5e18c8106a9d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Dec 24 13:14:14 2010 +0300

    delete components we moved into API

diff --git a/html/RTIR/Elements/BaseQuery b/html/RTIR/Elements/BaseQuery
deleted file mode 100644
index 4cf83e8..0000000
--- a/html/RTIR/Elements/BaseQuery
+++ /dev/null
@@ -1,7 +0,0 @@
-<%INIT>
-return '' unless $Queue;
-return "Queue = '$Queue'";
-</%INIT>
-<%ARGS>
-$Queue => ''
-</%ARGS>
diff --git a/html/RTIR/Elements/NewQuery b/html/RTIR/Elements/NewQuery
deleted file mode 100644
index f948565..0000000
--- a/html/RTIR/Elements/NewQuery
+++ /dev/null
@@ -1,21 +0,0 @@
-<%INIT>
- at states = grep $_, @states;
-unless( @states ) {
-    @states = RT::IR::States( %ARGS );
-}
-
-my %seen = ();
- at states =  grep !$seen{$_}++, map lc, grep $_, @states, @add_states;
-
-my $query = join " OR ",
-            map "'Status' = '$_'",
-            @states;
-$query = "( $query )" if $query;
-return $query;
-
-</%INIT>
-<%ARGS>
-$Queue => undef
- at states => ()
- at add_states => ()
-</%ARGS>

-----------------------------------------------------------------------


More information about the Rt-commit mailing list