[Bps-public-commit] rt-extension-hotkeys branch, master, updated. f4435daa9fc0c8262edc4885a627c71a8ef55b05

? sunnavy sunnavy at bestpractical.com
Sun Jan 15 12:16:54 EST 2012


The branch, master has been updated
       via  f4435daa9fc0c8262edc4885a627c71a8ef55b05 (commit)
       via  cc985af907f4c4aeaac92720bf5128f5f80b0cc4 (commit)
      from  9eb12bfa327263e439814ae13b419a9f3572e667 (commit)

Summary of changes:
 html/Callbacks/Hotkeys/Elements/Header/Head |   18 +++-
 lib/RT/Extension/Hotkeys.pm                 |  155 ++++++++++++++++++---------
 2 files changed, 119 insertions(+), 54 deletions(-)

- Log -----------------------------------------------------------------
commit cc985af907f4c4aeaac92720bf5128f5f80b0cc4
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Jan 16 01:12:04 2012 +0800

    different hotkeys for different pages

diff --git a/html/Callbacks/Hotkeys/Elements/Header/Head b/html/Callbacks/Hotkeys/Elements/Header/Head
index 39a260b..4971fcb 100644
--- a/html/Callbacks/Hotkeys/Elements/Header/Head
+++ b/html/Callbacks/Hotkeys/Elements/Header/Head
@@ -15,12 +15,21 @@ jQuery( function() {
 
 <%INIT>
 my $user = $session{CurrentUser}->UserObj;
-
 return if RT->Config->Get('DisableHotkeys', $user);
 
 my $conf = $user->Preferences('Hotkeys') || RT->Config->Get('Hotkeys') || {};
+my $path = $r->path_info;
+
+my $flat_conf = {};
+for my $item ( keys %$conf ) {
+    if ( $item eq 'global' || $path =~ /^$item/ ) {
+        for my $key ( keys %{$conf->{$item}} ) {
+            $flat_conf->{$key} = $conf->{$item}{$key};
+        }
+    }
+}
 
-my $js_conf = RT::Extension::Hotkeys::ConfAsJS( $conf );
+my $js_conf = RT::Extension::Hotkeys::ConfAsJS( $flat_conf );
 my $help = RT::Extension::Hotkeys::Help( $conf );
 $help =~ s!'!\\'!;
 </%INIT>
diff --git a/lib/RT/Extension/Hotkeys.pm b/lib/RT/Extension/Hotkeys.pm
index fea3cf6..e77d5c0 100644
--- a/lib/RT/Extension/Hotkeys.pm
+++ b/lib/RT/Extension/Hotkeys.pm
@@ -33,7 +33,7 @@ sub ConfAsJS {
     my $conf = shift;
     return {} unless $conf && keys %$conf;
 
-    my $str  = '{';
+    my $str = '{';
     for my $key ( keys %$conf ) {
         $key =~ s!'!\\'!g;
         if ( ref $conf->{$key} ) {
@@ -59,22 +59,32 @@ sub Help {
 
     my $str;
 
-    for my $key ( sort keys %$conf ) {
-        if ( ref $conf->{$key} ) {
-            if ( !ref $conf->{$key} || exists $conf->{$key}{body} ) {
-                my $doc = $conf->{$key}{doc} || $conf->{$key}{body};
-                $str .= '    ' x $level . "$key -> $doc\\n";
+    if ( $level == 0 ) {
+        for my $item ( sort { $a eq 'global' ? -1 : $a <=> $b }keys %$conf ) {
+            $str .= "===== $item =====\\n\\n";
+            $str .= Help( $conf->{$item}, $level + 1 );
+            $str .= "\\n";
+        }
+    }
+    else {
+
+        for my $key ( sort keys %$conf ) {
+            if ( ref $conf->{$key} ) {
+                if ( !ref $conf->{$key} || exists $conf->{$key}{body} ) {
+                    my $doc = $conf->{$key}{doc} || $conf->{$key}{body};
+                    $str .= '  ' x ($level-1) . "$key -> $doc\\n";
+                }
+                else {
+                    $str .=
+                        '  ' x ($level-1)
+                      . "$key ->\\n"
+                      . Help( $conf->{$key}, $level + 1 );
+                }
             }
             else {
-                $str .=
-                    '    ' x $level
-                  . "$key ->\\n"
-                  . Help( $conf->{$key}, $level + 1 );
+                $str .= '    ' x ($level-1) . "$key -> $conf->{$key}\\n";
             }
         }
-        else {
-            $str .= '    ' x $level . "$key -> $conf->{$key}\\n";
-        }
     }
     return $str;
 }
@@ -110,48 +120,91 @@ customize %Hotkeys to meet your needs:
     Set(
         %Hotkeys,
         (
-            'v'       => { body => q!hotkeys.version()!, doc => 'version', },
-            'shift+/' => { body => q!hotkeys.help()!,    doc => 'help', },
-            't'       => { body => q!hotkeys.ticket()!,  doc => 'goto ticket' },
-            'b'       => {
-                body =>
-                  q!hotkeys.click('a[href*="/Helpers/Toggle/TicketBookmark"]')!,
-                doc => 'toggle bookmark',
-            },
-            'c' => {
-                body => q!hotkeys.open('a[href*="Action=Comment"]')!,
-                doc  => 'comment',
-            },
-            'shift+c' => {
-                body => q!hotkeys.open('a[href*="Action=Comment"]:last')!,
-                doc  => 'comment',
-            },
-            'r' => {
-                body => q!hotkeys.open('a[href*="Action=Respond"]')!,
-                doc  => 'reply',
-            },
-            'shift+r' => {
-                body => q!hotkeys.open('a[href*="Action=Respond"]:last')!,
-                doc  => 'reply',
+            global => {
+                'v' => { body => q!hotkeys.version()!, doc => 'version', },
+                'shift+/' => { body => q!hotkeys.help()!, doc => 'help', },
+                't' => { body => q!hotkeys.ticket()!, doc => 'goto ticket' },
+                'g' => {
+                    'a' => {
+                        body => q!hotkeys.openLink("/Approvals")!,
+                        doc  => 'approvals',
+                    },
+                    'c' => {
+                        'c' => {
+                            body => q!hotkeys.openLink("/Admin/")!,
+                            doc  => 'admin',
+                        },
+                        'g' => {
+                            body => q!hotkeys.openLink("/Admin/Global.html")!,
+                            doc  => 'admin global',
+                        },
+                    },
+                    'h' => { body => q!hotkeys.openLink("/")!, doc => 'home', },
+                    'l' => {
+                        body => q!hotkeys.openLink("/NoAuth/Logout.html")!,
+                        doc  => 'logout',
+                    },
+                    'p' => {
+                        'h' => {
+                            body => q!hotkeys.openLink("/Prefs/Hotkeys.html")!,
+                            doc  => 'customize hotkeys',
+                        },
+                        'p' => {
+                            body => q!hotkeys.openLink("/Prefs/Other.html")!,
+                            doc  => 'customize options',
+                        },
+                    },
+                    's' => {
+                        body => q!hotkeys.openLink('/Search/Build.html')!,
+                        doc  => 'search builder',
+                    },
+                    't' => {
+                        'd' => {
+                            body => q!hotkeys.openLink("/Tools/MyDay.html")!,
+                            doc  => 'my day',
+                        },
+                        'o' => {
+                            body => q!hotkeys.openLink("/Tools/Offline.html")!,
+                            doc  => 'offline',
+                        },
+                        'm' => {
+                            body => q!hotkeys.openLink("/Tools/MyReminders")!,
+                            doc  => 'my reminders',
+                        },
+                        't' => {
+                            body => q!hotkeys.openLink("/Tools")!,
+                            doc  => 'tools',
+                        },
+                    },
+                },
+                'n' => {
+                    body => q!hotkeys.submit('#CreateTicketInQueue')!,
+                    doc  => 'create ticket in default queue',
+                },
+
             },
-            'g' => {
-                'a' =>
-                  { body => q!hotkeys.openLink("/Admin")!, doc => 'admin', },
+            '/Ticket/' => {
+                'b' => {
+                    body =>
+q!hotkeys.click('a[href*="/Helpers/Toggle/TicketBookmark"]')!,
+                    doc => 'toggle bookmark',
+                },
                 'c' => {
-                    body => q!hotkeys.openLink("/Prefs/Hotkeys.html")!,
-                    doc  => 'customize hotkeys',
+                    body => q!hotkeys.open('a[href*="Action=Comment"]')!,
+                    doc  => 'comment',
                 },
-                'h' => { body => q!hotkeys.openLink("/")!, doc => 'home', },
-                's' => {
-                    body => q!hotkeys.openLink('/Search/Build.html')!,
-                    doc  => 'search builder',
+                'shift+c' => {
+                    body => q!hotkeys.open('a[href*="Action=Comment"]:last')!,
+                    doc  => 'comment',
+                },
+                'r' => {
+                    body => q!hotkeys.open('a[href*="Action=Respond"]')!,
+                    doc  => 'reply',
+                },
+                'shift+r' => {
+                    body => q!hotkeys.open('a[href*="Action=Respond"]:last')!,
+                    doc  => 'reply',
                 },
-                't' =>
-                  { body => q!hotkeys.openLink("/Tools")!, doc => 'tools', },
-            },
-            'n' => {
-                body => q!hotkeys.submit('#CreateTicketInQueue')!,
-                doc  => 'create ticket in default queue',
             },
         )
     );

commit f4435daa9fc0c8262edc4885a627c71a8ef55b05
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Jan 16 01:16:49 2012 +0800

    $session{CurrentUser} could be undef when user is not logged in

diff --git a/html/Callbacks/Hotkeys/Elements/Header/Head b/html/Callbacks/Hotkeys/Elements/Header/Head
index 4971fcb..460e988 100644
--- a/html/Callbacks/Hotkeys/Elements/Header/Head
+++ b/html/Callbacks/Hotkeys/Elements/Header/Head
@@ -14,8 +14,11 @@ jQuery( function() {
 </script>
 
 <%INIT>
+return
+  unless $session{CurrentUser}
+      && !RT->Config->Get( 'DisableHotkeys', $session{CurrentUser}->UserObj );
+
 my $user = $session{CurrentUser}->UserObj;
-return if RT->Config->Get('DisableHotkeys', $user);
 
 my $conf = $user->Preferences('Hotkeys') || RT->Config->Get('Hotkeys') || {};
 my $path = $r->path_info;

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



More information about the Bps-public-commit mailing list