[Rt-commit] rt branch, development, updated. 20bfa574ab81b459843ef324687eb160bdfd2dd0

Thomas Sibley trs at bestpractical.com
Tue Jul 20 16:59:45 EDT 2010


The branch, development has been updated
       via  20bfa574ab81b459843ef324687eb160bdfd2dd0 (commit)
      from  72146f679fc03b2863e58f360edbe034f746bcc8 (commit)

Summary of changes:
 lib/RT.pm                            |   20 +++-
 lib/RT/Action/ConfigSystem.pm        |   10 ++
 lib/RT/Config.pod                    |   16 ++--
 lib/RT/View/SetupWizard.pm           |   83 ++++++----------
 lib/RT/View/SetupWizard/Helpers.pm   |  180 ++++++++++++++++++++++++++++++++++
 share/web/static/css/setupwizard.css |    1 -
 share/web/static/js/setupwizard.js   |   21 ++++
 7 files changed, 265 insertions(+), 66 deletions(-)
 create mode 100644 lib/RT/View/SetupWizard/Helpers.pm
 create mode 100644 share/web/static/js/setupwizard.js

- Log -----------------------------------------------------------------
commit 20bfa574ab81b459843ef324687eb160bdfd2dd0
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Jul 20 17:00:25 2010 -0400

    Setup mailer with a widget similar to the DB widget
    
    A bunch of refactoring in RT::View::SetupWizard::Helpers and a related
    JS file is involved.

diff --git a/lib/RT.pm b/lib/RT.pm
index ed10b11..56171fe 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -438,11 +438,21 @@ sub start {
     *Jifty::Plugin::Halo::is_proscribed = sub { 1 };
     RT->init();
 
-    Jifty->web->add_javascript(
-        qw( joose.js titlebox-state.js util.js ahah.js list.js 
-            jquery.createdomnodes.js jquery.menu.js combobox.js  cascaded.js rulebuilder.js
-      )
-    );
+    Jifty->web->add_javascript(qw(
+        joose.js
+        titlebox-state.js
+        util.js
+        ahah.js
+        list.js 
+        jquery.createdomnodes.js
+        jquery.menu.js
+        combobox.js
+        cascaded.js
+        rulebuilder.js
+    ));
+
+    Jifty->web->add_javascript('setupwizard.js')
+        if Jifty->config->framework('SetupMode');
 
     Jifty::Web->add_trigger(
         name      => 'after_include_javascript',
diff --git a/lib/RT/Action/ConfigSystem.pm b/lib/RT/Action/ConfigSystem.pm
index 272e97c..3241175 100644
--- a/lib/RT/Action/ConfigSystem.pm
+++ b/lib/RT/Action/ConfigSystem.pm
@@ -48,6 +48,16 @@ sub arguments {
             };
             $args->{$config->name}{'render_as'} = 'Select';
         }
+        elsif ( $config->name eq 'mail_command' ) {
+            # Populate with the standards, but anything is valid (kinda)
+            $args->{$config->name}{'available_values'} = [
+                { display => 'Sendmail pipe',   value => 'sendmailpipe' },
+                { display => 'Sendmail',        value => 'sendmail' },
+                { display => 'SMTP',            value => 'smtp' },
+                { display => 'qmail',           value => 'qmail' },
+            ];
+            $args->{$config->name}{'render_as'} = 'Select';
+        }
     }
     return $self->{__cached_arguments} = $args;
 }
diff --git a/lib/RT/Config.pod b/lib/RT/Config.pod
index 3520412..feebece 100644
--- a/lib/RT/Config.pod
+++ b/lib/RT/Config.pod
@@ -246,7 +246,7 @@ doesn't work well for you, try 'sendmail'.  Other options are 'smtp'
 or 'qmail'.
 
 Note that you should remove the '-t' from C<sendmail_arguments>
-if you use 'sendmail' rather than 'sendmailpipe'
+if you use 'sendmail' rather than 'sendmailpipe'.
 
 Default: C<'sendmailpipe'>
 
@@ -255,18 +255,18 @@ Default: C<'sendmailpipe'>
 =head1 Sendmail
 
 These options only take effect if C<mail_command> is 'sendmail' or
-'sendmailpipe'
+'sendmailpipe'.
 
 =over 4
 
 =item C<sendmail_arguments> 
 
-C<sendmail_arguments> defines what flags to pass to C<sendmail_path>
-If you picked 'sendmailpipe', you MUST add a -t flag to C<sendmail_arguments>
-These options are good for most sendmail wrappers and workalikes
+C<sendmail_arguments> defines what flags to pass to C<sendmail_path>.
+If you picked 'sendmailpipe', you MUST add a C<-t> flag to C<sendmail_arguments>
+The default is good for most sendmail wrappers and workalikes.
 
-These arguments are good for sendmail brand sendmail 8 and newer
-C<default: C<"-oi -t -ODeliveryMode=b -OErrorMode=m">>
+These arguments are good for Sendmail-brand sendmail version 8 or newer
+C<default: C<"-oi -t -ODeliveryMode=b -OErrorMode=m">>.
 
 Default: C<"-oi -t">
 
@@ -276,7 +276,7 @@ Default: C<"-oi -t">
 C<sendmail_bounce_arguments> defines what flags to pass to C<sendmail>
 assuming RT needs to send an error (ie. bounce).
 
-Default: C<'-f "<>"'>
+Default: C<< '-f "<>"' >>
 
 =item C<sendmail_path>
 
diff --git a/lib/RT/View/SetupWizard.pm b/lib/RT/View/SetupWizard.pm
index 82f7b69..6159647 100644
--- a/lib/RT/View/SetupWizard.pm
+++ b/lib/RT/View/SetupWizard.pm
@@ -50,7 +50,7 @@ use strict;
 
 package RT::View::SetupWizard;
 use Jifty::View::Declare -base;
-use base qw/ Jifty::Plugin::SetupWizard::View::Helpers /;
+use base qw/ RT::View::SetupWizard::Helpers /;
 
 sub setup_page (&) {
     my ($code) = @_;
@@ -73,19 +73,19 @@ sub setup_page (&) {
             };
             hr {{ class is 'clear' }};
         };
-        show '_config_javascript';
     };
 }
 
 sub steps {
     return (
-        [ start         => _('Start') ],
-        [ database      => _('Configure your database') ],
-        [ root          => _('Change the default root password') ],
-        [ organization  => _('About your organization') ],
-        [ email         => _('Sending and receiving email') ],
-        [ web           => _('Web interface') ],
-        [ done          => _('Turn off Setup Mode') ],
+        [ start             => _('Start') ],
+        [ database          => _('Configure your database') ],
+        [ root              => _('Change the default root password') ],
+        [ organization      => _('About your organization') ],
+        [ email_addresses   => _('Email addresses') ],
+        [ sending_email     => _('Sending email') ],
+        [ web               => _('Web interface') ],
+        [ done              => _('Turn off Setup Mode') ],
     );
 }
 
@@ -141,15 +141,17 @@ template 'root' => setup_page {
 };
 
 template 'organization' => setup_page {
+    my $self = shift;
     show title => 'organization';
 
     p { _("Now tell RT just the very basics about your organization.") };
 
-    show 'rt_config_fields' => qw( rtname organization time_zone );
+    $self->rt_config_field( field => [qw( rtname organization time_zone )] );
 };
 
-template 'email' => setup_page {
-    show title => 'email';
+template 'email_addresses' => setup_page {
+    my $self = shift;
+    show title => 'email_addresses';
 
     p {
         _(<<'EOT');
@@ -158,19 +160,32 @@ addresses for it and who to send errors to.
 EOT
     };
 
-    # XXX TODO: We should do a mail_command handler like the db chooser and then
-    # show smtp/sendmail/etc specific options
-    show 'rt_config_fields' => qw( owner_email correspond_address comment_address );
+    $self->rt_config_field( field => [qw( owner_email correspond_address comment_address )] );
+};
+
+template 'sending_email' => setup_page {
+    my $self = shift;
+    show title => 'sending_email';
+
+    p {
+        _(<<'EOT');
+RT needs to know how to send email out from your server.  There are four
+standard mailers you can use, each with their own configuration.
+EOT
+    };
+
+    show 'mail_widget';
 };
 
 template 'web' => setup_page {
+    my $self = shift;
     show title => 'web';
 
     p { _("RT needs to know a little bit about how you have it setup on your webserver.") };
 
     # XXX TODO: How can we set the jifty BaseUrl and Port without respawning
     # the current server
-    show 'rt_config_fields' => qw( web_path logo_url );
+    $self->rt_config_field( field => [qw( web_path logo_url )] );
 };
 
 template 'done' => setup_page {
@@ -246,41 +261,5 @@ sub intuit_current_step {
     return $self->step_for($template)->[0] ? $template : undef;
 }
 
-private template 'rt_config_fields' => sub {
-    my $self = shift;
-
-    my $config = new_action( class => 'RT::Action::ConfigSystem' );
-    my $meta = $config->metadata;
-
-    for my $field ( @_ ) {
-        div {{ class is 'config-field' };
-            render_param( $config => $field );
-            div {{ class is 'doc' };
-                outs_raw( $meta->{$field}{'doc'} )
-            } if $meta->{$field} and defined $meta->{$field}{'doc'};
-        };
-    }
-};
-
-private template '_config_javascript' => sub {
-    script {
-        outs_raw(<<'JSEND');
-jQuery(function() {
-    jQuery('.config-field .widget').focus(
-        function(){
-            var thisdoc = jQuery(this).parent().parent().find(".doc");
-
-            // Slide up everything else and slide down this doc
-            jQuery('.config-field .doc').not(thisdoc).slideUp();
-            thisdoc.slideDown();
-        }
-    );
-    jQuery('.config-field .doc').hide();
-    jQuery('.config-field .widget')[0].focus();
-});
-JSEND
-    };
-};
-
 1;
 
diff --git a/lib/RT/View/SetupWizard/Helpers.pm b/lib/RT/View/SetupWizard/Helpers.pm
new file mode 100644
index 0000000..54c82b7
--- /dev/null
+++ b/lib/RT/View/SetupWizard/Helpers.pm
@@ -0,0 +1,180 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+#                                          <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/copyleft/gpl.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+use warnings;
+use strict;
+
+=head1 NAME
+
+RT::View::SetupWizard::Helpers - Helpers for RT's setup wizard, inherits from
+Jifty's SetupWizard plugin helpers
+
+=cut
+
+package RT::View::SetupWizard::Helpers;
+use Jifty::View::Declare -base;
+use base qw/ Jifty::Plugin::SetupWizard::View::Helpers /;
+
+=head1 TEMPLATES
+
+=head2 mail_widget
+
+Provides a mail configuration widget for RT's setup wizard.
+
+Much of it is based on the database config widget provided by Jifty's
+SetupWizard plugin.
+
+=cut
+
+private template 'mail_widget' => sub {
+    my $self = shift;
+    # XXX: We've got to add a sane way to unquote stuff in onfoo handlers...
+    my $onchange = 'Jifty.update('
+                 . Jifty::JSON::encode_json({
+                    actions          => {},
+                    action_arguments => {},
+                    fragments        => [
+                        {
+                            mode => 'Replace',
+                            path => $self->fragment_for('mail_widget/PLACEHOLDER'),
+                            region => Jifty->web->qualified_region('mail_command_details'),
+                        },
+                    ],
+                    continuation     => undef,
+
+                 })
+                 . ', this)';
+
+    $onchange =~ s/PLACEHOLDER/"+this.value+"/;
+
+    $self->rt_config_field(
+        field       => 'mail_command',
+        doc_class   => 'static-doc',
+        value_args  => {
+            onchange => [$onchange]
+        }
+    );
+
+    my $current_command = RT->config->get('mail_command');
+
+    render_region(
+        name => 'mail_command_details',
+        path => $self->fragment_for("mail_widget/$current_command"),
+    );
+};
+
+template 'mail_widget/sendmail' => sub {
+    my $self = shift;
+    $self->rt_config_field(
+        field => [qw(
+            sendmail_path
+            sendmail_arguments
+            sendmail_bounce_arguments
+        )],
+    );
+};
+
+template 'mail_widget/sendmailpipe' => sub {
+    show 'sendmail';
+};
+
+template 'mail_widget/smtp' => sub {
+    my $self = shift;
+    $self->rt_config_field(
+        field => [qw(
+            smtp_server
+            smtp_from
+        )],
+    );
+};
+
+template 'mail_widget/qmail' => sub {
+    show 'other';
+};
+
+template 'mail_widget/other' => sub {
+    my $self = shift;
+    $self->rt_config_field( field => 'mail_params' );
+};
+
+=head1 METHODS
+
+=head2 rt_config_field FIELD [FIELD2] [FIELD3]
+
+Renders fields and doc of L<RT::Action::ConfigSystem> parameters.  Returns the
+action created.
+
+=cut
+
+sub rt_config_field {
+    my $self = shift;
+    my %args = (
+        field       => [],
+        value_args  => {},
+        doc_class   => '',
+        @_
+    );
+
+    my $config = new_action( class => 'RT::Action::ConfigSystem' );
+    my $meta = $config->metadata;
+
+    $args{'field'} = [ $args{'field'} ]
+        if not ref $args{'field'};
+
+    for my $field ( @{$args{'field'}} ) {
+        div {{ class is 'config-field' };
+            render_param( $config => $field, %{ $args{'value_args'} } );
+            div {{ class is join(' ', 'doc', $args{'doc_class'}) };
+                outs_raw( $meta->{$field}{'doc'} )
+            } if $meta->{$field} and defined $meta->{$field}{'doc'};
+        };
+    }
+
+    return $config;
+}
+
+1;
diff --git a/share/web/static/css/setupwizard.css b/share/web/static/css/setupwizard.css
index f54d9f4..0c6bd82 100644
--- a/share/web/static/css/setupwizard.css
+++ b/share/web/static/css/setupwizard.css
@@ -97,7 +97,6 @@
 
 #setupwizard .config-field .doc {
     display: block;
-    width: 50%;
     margin-left: 12.7em;
 }
 
diff --git a/share/web/static/js/setupwizard.js b/share/web/static/js/setupwizard.js
new file mode 100644
index 0000000..60a34a9
--- /dev/null
+++ b/share/web/static/js/setupwizard.js
@@ -0,0 +1,21 @@
+Behaviour.register({
+    ".config-field .widget": function(e) {
+        jQuery(e).focus(
+            function(){
+                var thisdoc = jQuery(this).parent().parent().find(".doc");
+
+                // Slide up everything else and slide down this doc
+                jQuery('.config-field .doc').not(thisdoc).not(".static-doc").slideUp();
+                thisdoc.not(".static-doc").slideDown();
+            }
+        );
+    },
+    ".config-field .doc": function(e) {
+        jQuery(e).not(".static-doc").hide();
+    }
+});
+
+jQuery(function() {
+    jQuery('.config-field .widget')[0].focus();
+});
+

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


More information about the Rt-commit mailing list