diff options
Diffstat (limited to 'httemplate')
| -rw-r--r-- | httemplate/browse/msg_template.html | 28 | ||||
| -rw-r--r-- | httemplate/edit/msg_template.html | 156 | ||||
| -rw-r--r-- | httemplate/edit/process/msg_template.html | 26 | ||||
| -rw-r--r-- | httemplate/elements/tablebreak-tabs.html | 34 | 
4 files changed, 214 insertions, 30 deletions
diff --git a/httemplate/browse/msg_template.html b/httemplate/browse/msg_template.html index 252ee1ff8..8a6ccf741 100644 --- a/httemplate/browse/msg_template.html +++ b/httemplate/browse/msg_template.html @@ -10,10 +10,12 @@                'disabled_statuspos' => 2,                'agent_virt'         => 1,                'agent_null_right'   => ['Edit global templates','Configuration'], -              'agent_pos'          => 3, -              'header' => [ 'Name' ], -              'fields' => [ 'msgname' ], -              'links'  => [ $link ], +              'agent_pos'          => 1, +              'header' => [ 'Name', '', ('' x scalar @locales) ], +              'fields' => [ 'msgname', @locales ], +              'links'  => [ $link, @locale_links ], +              'cell_style' =>  +                          [ '', '', ($locale_style) x (scalar @locales) ],            )  %>  <%init> @@ -23,6 +25,22 @@ die "access denied"    ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates')    ||     $FS::CurrentUser::CurrentUser->access_right('Configuration'); -my $link = [ "${p}edit/msg_template.html?", 'msgnum' ]; +my $link = [ "${p}edit/msg_template.html?msgnum=", 'msgnum' ]; + +my $locale_style = 'font-size:0.8em; padding:3px; background-color:'; + +my (@locales, @locale_links); +foreach my $l ( FS::Locales->locales ) { +  push @locales, sub { +    exists ( $_[0]->content_locales->{$l} ) +    ? +{ FS::Locales->locale_info($l) }->{'name'}  +    : ''; +  }; +  push @locale_links, sub { +    my $content = $_[0]->content_locales->{$l} or return ''; +    [ "${p}edit/msg_template.html?locale=$l;msgnum=", 'msgnum' ]; +  }; +} +      </%init> diff --git a/httemplate/edit/msg_template.html b/httemplate/edit/msg_template.html index 758aab6e4..941554532 100644 --- a/httemplate/edit/msg_template.html +++ b/httemplate/edit/msg_template.html @@ -1,28 +1,47 @@  <% include( 'elements/edit.html',   -              'html_init'     => '<TABLE id="outerTable"><TR><TD>', -              'name_singular' => 'template', -              'table'         => 'msg_template', -              'viewall_dir'   => 'browse', -              'agent_virt'    => 1, -              'agent_null'    => 1, -              'agent_null_right' => ['Edit global templates', 'Configuration'], - -              'fields' => [ 'msgname', -                            { field=>'from_addr', size=>60, }, -                            { field=>'bcc_addr',  size=>60, }, -                            { field=>'subject',   size=>80, }, -                            { field=>'body', type=>'htmlarea', width=>763 }, -                          ], -              'labels' => { 'msgnum'    => 'Template', -                            'msgname'   => 'Template name', -                            'from_addr' => 'From: ', -                            'bcc_addr'  => 'Bcc: ', -                            'subject'   => 'Subject: ', -                            'body'      => 'Message template', -                          }, -              'html_foot' => "</TD>$sidebar</TR></TABLE>", -          ) -%> +    'html_init'     => '<TABLE id="outerTable"><TR><TD>', +    'body_etc'      => $body_etc, +    'name_singular' => 'template', +    'table'         => 'msg_template', +    'viewall_dir'   => 'browse', +    'agent_virt'    => 1, +    'agent_null'    => 1, +    'agent_null_right' => ['Edit global templates', 'Configuration'], + +    'fields' => [ +      { field => 'agentnum', +        type  => 'select-agent', +      }, +      { field => 'msgname',   size=>60, }, +      { field => 'from_addr', size=>60, }, +      { field => 'bcc_addr',  size=>60, }, +      { type  => 'tablebreak-tabs', +        include_opt_callback => \&menubar_opt_callback, +      }, +      # template_content fields +      { field => 'locale', type => 'hidden' }, +      { field => 'subject',   size=>60, }, +      { field => 'body', +        type  => 'htmlarea', +        width => 763 +      }, +    ], +    'labels' => {  +      'msgnum'    => 'Template', +      'agentnum'  => 'Agent', +      'msgname'   => 'Template name', +      'from_addr' => 'From: ', +      'bcc_addr'  => 'Bcc: ', +      'locale'    => 'Language', +      'subject'   => 'Subject: ', +      'body'      => 'Message body', +    }, +    'edit_callback'   => \&edit_callback, +    'error_callback'  => \&edit_callback, +    'html_bottom' => '</DIV>', +    'html_foot' => "</TD>$sidebar</TR></TABLE>", +    ) +    %>  <%init>  die "access denied" @@ -30,6 +49,95 @@ die "access denied"    ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates')    ||     $FS::CurrentUser::CurrentUser->access_right('Configuration'); +my $body_etc = ''; +$body_etc = q!onload="document.getElementById('locale').onchange()"! +  if $cgi->param('locale') eq 'new'; + +sub new_callback { +  my ($cgi, $object, $fields_listref, $opt_hashref) = @_; +  my $template_content = new FS::template_content { 'locale' => '' }; +  $object->{'Hash'} = { $object->hash, $template_content->hash }; +} + +sub edit_callback { +  my ($cgi, $object, $fields_listref, $opt_hashref) = @_; +  $cgi->param('locale') =~ /^(\w*)$/ or die 'bad locale '.$cgi->param('locale'); +  my $locale = $1; + +  # fetch the content object and merge its fields +  my %args = ( +    'msgnum' => $object->msgnum, +    'locale' => $locale +  ); +  my $template_content = qsearchs('template_content', \%args)  +                        || new FS::template_content( { %args }); +  $object->{'Hash'} = { $object->hash, $template_content->hash }; + +  # set up the locale selector if this is a new content +  if ( $locale eq 'new' ) { + +    # make a list of available locales +    my $content_locales = $object->content_locales; +    my @locales = grep { !exists($content_locales->{$_}) } FS::Locales->locales; +    my %labels; +    foreach (@locales) { +      my %info = FS::Locales->locale_info($_); +      $labels{$_} = $info{'name'}; # ignoring country for now +    } +    unshift @locales, 'new'; +    $labels{'new'} = 'Select language'; + +    # insert a field def +    my $i = 0; +    $i++ until ( $fields_listref->[$i]->{'field'} eq 'locale' ); +    my $locale_field = $fields_listref->[$i]; + +    my $onchange_locale = "document.getElementById('submit').disabled =  +    (this.options[this.selectedIndex].value == 'new');"; + +    %$locale_field = ( +      field   => 'locale', +      type    => 'select', +      options => \@locales, +      labels  => \%labels, +      curr_value  => 'new', +      onchange    => $onchange_locale, +    ); +  } # else it's already set up correctly +} + +sub menubar_opt_callback { +  my $object = shift; +  # generate no tabs for new msg_templates. +  my $msgnum = $object->msgnum or return;  +  my (@tabs, @options, %labels); +  push @tabs, mt('Default'), ''; +  my $display_new = 0; +  my $selected = ''; +  foreach my $l (FS::Locales->locales) { +    if ( exists $object->content_locales->{$l} ) { +      my %info = FS::Locales->locale_info($l); +      push @tabs, +           $info{'name'}, +           ';locale='.$l; +      $selected = $info{'name'} if $object->locale eq $l; +    } +    else { +      $display_new = 1; # there is at least one unused locale left +    } +  } +  push @tabs, mt('New'), ';locale=new' if $display_new; +  $selected = mt('New') if $object->locale eq 'new'; +  $selected ||= mt('Default'); +  ( +    'url_base' => $p.'edit/msg_template.html?msgnum='.$msgnum, +    'selected' => $selected, +    'tabs'     => \@tabs +  ); +} + +my $onchange_locale = ''; +  # Create hints pane  my %substitutions = ( diff --git a/httemplate/edit/process/msg_template.html b/httemplate/edit/process/msg_template.html index 70d451b72..f43d17216 100644 --- a/httemplate/edit/process/msg_template.html +++ b/httemplate/edit/process/msg_template.html @@ -1,13 +1,37 @@  <% include( 'elements/process.html',                  'table'       => 'msg_template',                'viewall_dir' => 'browse', +              #'popup_reload'=> 1, +              'debug'       => 1, +              'precheck_callback' => \&precheck_callback, +              'args_callback' => \&args_callback,            )  %>  <%init> -  die "access denied"    unless $FS::CurrentUser::CurrentUser->access_right('Edit templates')    ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates')    ||     $FS::CurrentUser::CurrentUser->access_right('Configuration'); +sub precheck_callback { +  my $cgi = shift; +  # validate some fields +  $cgi->param('locale') =~ /^(\w*)$/; +  my $locale = $1; +  return mt('Language required') if $locale eq 'new'; # the user didn't choose +  die "unknown locale $locale" if ( $locale and  +                                    !FS::Locales->locale_info($locale) ); +} + +sub args_callback { +  my ($cgi, $object) = @_; +  my %content; +  $cgi->param('locale') =~ /^(\w*)$/; +  $content{'locale'} = $1; +  # no validation of these; they can contain just about anything +  $content{'subject'} = $cgi->param('subject') || ''; +  $content{'body'} = $cgi->param('body') || ''; +  return %content; +} +  </%init> diff --git a/httemplate/elements/tablebreak-tabs.html b/httemplate/elements/tablebreak-tabs.html new file mode 100644 index 000000000..91c28ce19 --- /dev/null +++ b/httemplate/elements/tablebreak-tabs.html @@ -0,0 +1,34 @@ +<%doc> +<& /elements/tablebreak-tabs.html, +   tabs => [                              #required +     'Foo' => ';mode=foo', +     'Bar' => ';mode=bar', +     'Other' => '', +   ], +   selected => 'Foo',                     #required +   url_base => $p.'edit/something.html',  #optional +   table_id => 'OneTrueTable',            #optional +   always_show_tabs => 0, #optional,  +                          #controls whether this will show only one tab +&> + +For use in edit/elements/edit.html 'fields' hashes. + +</%doc> +% if (scalar(@$tabs) >= 2 or $opt{'always_show_tabs'}) { +</TABLE><BR> +<& /elements/menubar.html, +    { newstyle => 1, %opt }, +    @$tabs &> +<DIV CLASS="fstabcontainer"> +<TABLE <% $id %> BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0> +% } +<%init> + +my %opt = @_; +my $tabs = delete $opt{'tabs'} || []; # must be an arrayref + +my $id = ''; +$id = 'ID="'. $opt{'table_id'}. '"' if $opt{'table_id'}; + +</%init>  | 
