[Bps-public-commit] rt-extension-hotkeys branch, master, updated. 9eb12bfa327263e439814ae13b419a9f3572e667
? sunnavy
sunnavy at bestpractical.com
Sun Jan 15 11:21:36 EST 2012
The branch, master has been updated
via 9eb12bfa327263e439814ae13b419a9f3572e667 (commit)
via ec371c58c85ed0b2ce3eb840a970da5501caaef4 (commit)
via d37919b70822d7de756e2c88279eb41d4ec25aa9 (commit)
via 28b2d02c498e20fe4f003c6786c2ddf24a3dd00d (commit)
from c46b0212e78b1958d32b502f04967917a7a7cffa (commit)
Summary of changes:
html/Callbacks/Hotkeys/Elements/Header/Head | 26 +++++++
html/Callbacks/Hotkeys/Elements/Tabs/Privileged | 11 +++
html/NoAuth/css/hotkeys.css | 5 +
html/NoAuth/js/hotkeys.js | 92 ++++++++---------------
html/Prefs/Hotkeys.html | 55 ++++++++++++++
lib/RT/Extension/Hotkeys.pm | 65 +++++++++++-----
6 files changed, 173 insertions(+), 81 deletions(-)
create mode 100644 html/Callbacks/Hotkeys/Elements/Header/Head
create mode 100644 html/Callbacks/Hotkeys/Elements/Tabs/Privileged
create mode 100644 html/Prefs/Hotkeys.html
- Log -----------------------------------------------------------------
commit 28b2d02c498e20fe4f003c6786c2ddf24a3dd00d
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sun Jan 15 23:39:01 2012 +0800
refactor to make hotkeys.js cacheable
move customized bind stuff out of it.
diff --git a/html/Callbacks/Hotkeys/Elements/Header/Head b/html/Callbacks/Hotkeys/Elements/Header/Head
new file mode 100644
index 0000000..0d41ea6
--- /dev/null
+++ b/html/Callbacks/Hotkeys/Elements/Header/Head
@@ -0,0 +1,23 @@
+<script type="text/javascript">
+jQuery( function() {
+ hotkeys.help = function () {
+ var string = 'RT::Extension::Hotkeys version <% $RT::Extension::Hotkeys::VERSION %>\n\n' +
+ '<% $help |n%>';
+ hotkeys.show(string);
+ };
+ hotkeys.version = function () {
+ var string = 'RT::Extension::Hotkeys version <% $RT::Extension::Hotkeys::VERSION %>\n';
+ hotkeys.show(string);
+ };
+ hotkeys.bind( <% $js_conf |n%> );
+});
+</script>
+
+<%INIT>
+my $user = $session{CurrentUser}->UserObj;
+my $conf = $user->Preferences('Hotkeys') || RT->Config->Get('Hotkeys') || {};
+
+my $js_conf = RT::Extension::Hotkeys::ConfAsJS( $conf );
+my $help = RT::Extension::Hotkeys::Help( $conf );
+$help =~ s!'!\\'!;
+</%INIT>
diff --git a/html/NoAuth/js/hotkeys.js b/html/NoAuth/js/hotkeys.js
index e3f74d3..caf0bac 100644
--- a/html/NoAuth/js/hotkeys.js
+++ b/html/NoAuth/js/hotkeys.js
@@ -1,74 +1,52 @@
-(function(jQuery){
- function help () {
- var string =
- 'RT::Extension::Hotkeys version <% $RT::Extension::Hotkeys::VERSION %>\n\n' +
- '<% $help |n%>';
+hotkeys = {
+ show: function( string ) {
jQuery('<pre>' + string + '</pre>').modal();
- }
-
- function version () {
- jQuery('<pre>' + 'RT::Extension::Hotkeys version <% $RT::Extension::Hotkeys::VERSION %></pre>' ).modal();
- }
-
- function home(){
- window.location = '<% $web_path %>/';
- }
-
- function notFound( string ) {
+ },
+ notFound: function( string ) {
jQuery('<pre>' + string + ' is not found</pre>').modal();
- }
-
- function submit( e ) {
+ },
+ submit: function( e ) {
var obj = jQuery(document).find(e).filter(':first');
if ( obj.size() ) {
obj.submit();
}
else {
- notFound( e );
+ hotkeys.notFound( e );
}
- }
-
- function click( e ) {
+ },
+ click: function( e ) {
var obj = jQuery(document).find(e).filter(':first');
if ( obj.size() ) {
obj.click();
}
else {
- notFound( e );
+ hotkeys.notFound( e );
}
- }
-
- function openLink( e ) {
- if ( e.match(/^\//) ) {
- window.location = '<% $web_path %>' + e;
- }
- else {
- window.location = e;
- }
- }
-
- function open( e ) {
+ },
+ openLink: function( e ) {
+ window.location = e;
+ },
+ open: function( e ) {
var obj = jQuery(document).find(e).filter(':first');
if ( obj.size() ) {
- window.location = jQuery(e).filter(':first').attr('href');
+ window.location = jQuery(e).attr('href');
}
else {
- notFound( e );
+ hotkeys.notFound( e );
+ }
+ },
+ ticket: function( number ) {
+ if ( !number ) {
+ number = prompt("<% loc('Goto Ticket') %>", "");
}
- }
- function ticket() {
- var number = prompt("<% loc('Goto Ticket') %>", "");
if (number){
- window.location = '<% $web_path %>/Ticket/Display.html?id=' + number;
+ window.location = '<% RT->Config->Get('WebPath') %>/Ticket/Display.html?id=' + number;
}
- }
-
- var hotkeys = <% RT::Extension::Hotkeys::Convert( $conf ) |n %>;
-
- function bind( conf, restore ) {
+ },
+ bind: function( conf, global ) {
jQuery(document).unbind('keydown.hotkeys');
- jQuery(document).bind('keydown.hotkeys', 'esc', function() { bind(hotkeys) } );
+ jQuery(document).bind('keydown.hotkeys', 'esc', function() { hotkeys.bind(global || conf) } );
for ( key in conf ) {
if ( typeof( conf[key] ) == 'function' ) {
@@ -76,8 +54,8 @@
jQuery(document).bind('keydown.hotkeys', key,
function() {
conf[key]();
- if ( restore ) {
- bind(hotkeys);
+ if ( global ) {
+ hotkeys.bind(global);
}
}
);
@@ -85,20 +63,10 @@
}
else {
(function(key) {
- jQuery(document).bind('keydown.hotkeys', key, function() { bind( conf[key], 1 ) } );
+ jQuery(document).bind('keydown.hotkeys', key, function() { hotkeys.bind( conf[key], global ) } );
})(key);
}
}
}
+};
- jQuery( function() {
- bind( hotkeys );
- });
-})(jQuery);
-
-<%INIT>
-my $web_path = RT->Config->Get('WebPath');
-my $conf = RT->Config->Get( 'Hotkeys', $session{CurrentUser} );
-my $help = RT::Extension::Hotkeys::Help( $conf );
-$help =~ s!'!\\'!g;
-</%INIT>
diff --git a/lib/RT/Extension/Hotkeys.pm b/lib/RT/Extension/Hotkeys.pm
index 3ea029c..b7fa2d8 100644
--- a/lib/RT/Extension/Hotkeys.pm
+++ b/lib/RT/Extension/Hotkeys.pm
@@ -17,9 +17,9 @@ RT->AddJavaScript(
RT->AddStyleSheets('hotkeys.css');
-sub Convert {
+sub ConfAsJS {
my $conf = shift;
- return {} unless $conf;
+ return {} unless $conf && keys %$conf;
my $str = '{';
for my $key ( keys %$conf ) {
@@ -29,7 +29,7 @@ sub Convert {
$str .= "'$key': function() { $conf->{$key}{body} },\n";
}
else {
- $str .= "'$key': " . Convert( $conf->{$key} ) . ",\n";
+ $str .= "'$key': " . ConfAsJS( $conf->{$key} ) . ",\n";
}
}
else {
@@ -43,7 +43,7 @@ sub Convert {
sub Help {
my $conf = shift;
my $level = shift || 0;
- return '' unless $conf;
+ return '' unless $conf && keys %$conf;
my $str;
@@ -97,33 +97,47 @@ customize %Hotkeys to meet your needs:
Set(
%Hotkeys,
(
- 'v' => { body => q!version()!, doc => 'version', },
- 'shift+/' => { body => q!help()!, doc => 'help', },
- 'h' => { body => q!openLink('/')!, doc => 'home', },
- '/' => {
- body => q!openLink('/Search/Build.html')!,
- doc => 'search builder',
- },
- 't' => { body => q!ticket()!, doc => 'goto ticket' },
- 'b' => {
+ '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!click('a[href*="/Helpers/Toggle/TicketBookmark"]:first')!,
+ q!hotkeys.click('a[href*="/Helpers/Toggle/TicketBookmark"]')!,
doc => 'toggle bookmark',
},
'c' => {
- body => q!open('a[href*="Action=Comment"]:first')!,
+ 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!open('a[href*="Action=Respond"]:first')!,
+ body => q!hotkeys.open('a[href*="Action=Respond"]')!,
+ doc => 'reply',
+ },
+ 'shift+r' => {
+ body => q!hotkeys.open('a[href*="Action=Respond"]:last')!,
doc => 'reply',
},
'g' => {
- 'a' => { body => q!openLink("/Admin")!, doc => 'admin', },
- 't' => { body => q!openLink("/Tools")!, doc => 'tools', },
+ 'a' =>
+ { body => q!hotkeys.openLink("/Admin")!, doc => 'admin', },
+ 'c' => {
+ body => q!hotkeys.openLink("/Prefs/Hotkeys.html")!,
+ doc => 'customize hotkeys',
+ },
+ 'h' => { body => q!hotkeys.openLink("/")!, doc => 'home', },
+ 's' => {
+ body => q!hotkeys.openLink('/Search/Build.html')!,
+ doc => 'search builder',
+ },
+ 't' =>
+ { body => q!hotkeys.openLink("/Tools")!, doc => 'tools', },
},
'n' => {
- body => q!submit('#CreateTicketInQueue')!,
+ body => q!hotkeys.submit('#CreateTicketInQueue')!,
doc => 'create ticket in default queue',
},
)
commit d37919b70822d7de756e2c88279eb41d4ec25aa9
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sun Jan 15 23:41:45 2012 +0800
/Prefs/Hotkeys page for user
diff --git a/html/Callbacks/Hotkeys/Elements/Tabs/Privileged b/html/Callbacks/Hotkeys/Elements/Tabs/Privileged
new file mode 100644
index 0000000..05876ad
--- /dev/null
+++ b/html/Callbacks/Hotkeys/Elements/Tabs/Privileged
@@ -0,0 +1,11 @@
+<%INIT>
+
+if ( $session{'CurrentUser'}->UserObj
+ && $session{'CurrentUser'}->HasRight( Right => 'ModifySelf', Object => RT->System ) )
+{
+ my $settings = Menu->child('preferences')->child('settings')->child(
+ hotkeys => title => loc('Hotkeys'),
+ path => '/Prefs/Hotkeys.html'
+ );
+}
+</%INIT>
diff --git a/html/NoAuth/css/hotkeys.css b/html/NoAuth/css/hotkeys.css
index 336956f..cb2c969 100644
--- a/html/NoAuth/css/hotkeys.css
+++ b/html/NoAuth/css/hotkeys.css
@@ -2,3 +2,8 @@
padding: 10px;
background: #888;
}
+
+textarea.hotkeys {
+ width: 90%;
+ height: 50ex;
+}
diff --git a/html/Prefs/Hotkeys.html b/html/Prefs/Hotkeys.html
new file mode 100644
index 0000000..ff73f21
--- /dev/null
+++ b/html/Prefs/Hotkeys.html
@@ -0,0 +1,47 @@
+<& /Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
+<& /Elements/ListActions, actions => \@results &>
+
+<form method="post" action="Hotkeys.html" name="ModifyHotkeys" id="ModifyHotkeys">
+<&|/Widgets/TitleBox, title => loc( 'Hotkeys' ) &>
+<textarea class="hotkeys" name="Hotkeys"><% $json %></textarea>
+</&>
+
+<& /Elements/Submit, Name => 'Reset', Label => loc('Reset') &>
+<& /Elements/Submit, Name => 'Save', Label => loc('Save Changes') &>
+</form>
+<%INIT>
+my @results;
+my $title = loc('Customize') . ' ' . loc('Hotkeys');
+
+my $user = $session{'CurrentUser'}->UserObj;
+use JSON;
+my $pref;
+
+if ( $Save ) {
+ eval { $pref = from_json($Hotkeys) };
+ if ( $@ ) {
+ my $err = $@;
+ $err =~ s!Stack:.*!!s;
+ $err =~ s!(.*) at .*!$1!s;
+ push @results, loc("Error") . ": $err";
+ }
+ else {
+ my ($ok, $msg) = $user->SetPreferences( 'Hotkeys', $pref );
+ push @results, $ok ? loc("Preferences saved.") : $msg;
+ }
+}
+elsif ( $Reset ) {
+ $pref = RT->Config->Get('Hotkeys') || {};
+ my ($ok, $msg) = $user->SetPreferences( 'Hotkeys', $pref );
+ push @results, $ok ? loc("Preferences saved.") : $msg;
+}
+
+$pref ||= $user->Preferences( 'Hotkeys' ) || {};
+my $json = to_json($pref, { pretty => 1 });
+</%INIT>
+<%ARGS>
+$Save => 0
+$Reset => 0
+$Hotkeys => ''
+</%ARGS>
commit ec371c58c85ed0b2ce3eb840a970da5501caaef4
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sun Jan 15 23:57:16 2012 +0800
use consistent word
diff --git a/html/Prefs/Hotkeys.html b/html/Prefs/Hotkeys.html
index ff73f21..b9ef5e0 100644
--- a/html/Prefs/Hotkeys.html
+++ b/html/Prefs/Hotkeys.html
@@ -7,7 +7,7 @@
<textarea class="hotkeys" name="Hotkeys"><% $json %></textarea>
</&>
-<& /Elements/Submit, Name => 'Reset', Label => loc('Reset') &>
+<& /Elements/Submit, Name => 'Reset', Label => loc('Reset to default') &>
<& /Elements/Submit, Name => 'Save', Label => loc('Save Changes') &>
</form>
<%INIT>
commit 9eb12bfa327263e439814ae13b419a9f3572e667
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Jan 16 00:19:15 2012 +0800
add DisableHotkeys config option
diff --git a/html/Callbacks/Hotkeys/Elements/Header/Head b/html/Callbacks/Hotkeys/Elements/Header/Head
index 0d41ea6..39a260b 100644
--- a/html/Callbacks/Hotkeys/Elements/Header/Head
+++ b/html/Callbacks/Hotkeys/Elements/Header/Head
@@ -15,6 +15,9 @@ 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 $js_conf = RT::Extension::Hotkeys::ConfAsJS( $conf );
diff --git a/html/Prefs/Hotkeys.html b/html/Prefs/Hotkeys.html
index b9ef5e0..e194bc7 100644
--- a/html/Prefs/Hotkeys.html
+++ b/html/Prefs/Hotkeys.html
@@ -13,8 +13,16 @@
<%INIT>
my @results;
my $title = loc('Customize') . ' ' . loc('Hotkeys');
-
my $user = $session{'CurrentUser'}->UserObj;
+
+my $disabled = RT->Config->Get('DisableHotkeys', $user);
+if ( $disabled ) {
+ push @results,
+ loc(
+ 'Hotkeys is currently disabled, you need to enable it to use this functionality.'
+ );
+}
+
use JSON;
my $pref;
diff --git a/lib/RT/Extension/Hotkeys.pm b/lib/RT/Extension/Hotkeys.pm
index b7fa2d8..fea3cf6 100644
--- a/lib/RT/Extension/Hotkeys.pm
+++ b/lib/RT/Extension/Hotkeys.pm
@@ -17,6 +17,18 @@ RT->AddJavaScript(
RT->AddStyleSheets('hotkeys.css');
+use RT::Config;
+
+$RT::Config::META{DisableHotkeys} = {
+ Section => 'General',
+ Overridable => 1,
+ SortOrder => 10,
+ Widget => '/Widgets/Form/Boolean',
+ WidgetArguments => {
+ Description => 'Disable hotkeys' # loc
+ },
+};
+
sub ConfAsJS {
my $conf = shift;
return {} unless $conf && keys %$conf;
@@ -91,6 +103,7 @@ To install this module, run the following commands:
add RT::Extension::Hotkeys to @Plugins in RT's etc/RT_SiteConfig.pm:
Set( @Plugins, qw(... RT::Extension::Hotkeys) );
+ Set( $DisableHotkeys, 1 ); # disable it by default
customize %Hotkeys to meet your needs:
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list