summaryrefslogtreecommitdiff
path: root/httemplate/browse/msg_template.html
blob: ef0b2dafd318f9daeca4c1cd2b81bd0dbee98564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<% include( 'elements/browse.html',
              'title'         => 'Message templates',
              'name_singular' => 'template',
              'menubar'       => \@menubar,
              'query'         => { 'table' => 'msg_template', },
              'count_query'   => 'SELECT COUNT(*) FROM msg_template',
              'disableable'   => 1,
              'disabled_statuspos' => (scalar(@locales) + 3),
              'agent_virt'         => 1,
              'agent_null_right'   => ['View global templates','Edit global templates'],
              'agent_pos'          => 1,
              'header'      => [ 'Name', '', map ('', @locales), '' ],
              'fields'      => [ 'msgname', @locales, $disable_link_label ],
              'links'       => [ $link, @locale_links, '' ],
              'link_onclicks' => [ '', map('', @locale_links), $disable_link ],
              'cell_style'    => [ '', '', map ($locale_style, @locales), $locale_style ],
          )
%>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;

die "access denied"
  unless $curuser->access_right([ 'View templates', 'View global templates',
                                  'Edit templates', 'Edit global templates', ]);

my @menubar = ();
if ( $curuser->access_right(['Edit templates', 'Edit global templates']) ) {
  push @menubar, 'Add a new template' => $p.'edit/msg_template.html';
}

my $link = [ "${p}edit/msg_template.html?msgnum=", 'msgnum' ];

my $locale_style = 'font-size:0.8em; padding:3px';

my (@locales, @locale_links);
foreach my $l ( FS::Locales->locales ) {
  push @locales, sub {
    exists ( $_[0]->content_locales->{$l} )
    ? +{ FS::Locales->locale_info($l) }->{'label'} 
    : '';
  };
  push @locale_links, sub {
    my $content = $_[0]->content_locales->{$l} or return '';
    [ "${p}edit/msg_template.html?locale=$l;msgnum=", 'msgnum' ];
  };
}

my $disable_link = sub {
  my $template = shift;
  include('/elements/popup_link_onclick.html',
    action      => $p.'misc/disable-msg_template.cgi?msgnum=' .
                     $template->msgnum .
                     ($template->disabled ? ';enable=1' : ''),
    actionlabel => 'Disable lemplate',
  );
};

my $disable_link_label = sub {
  my $template = shift;
  $template->disabled ? '(enable)' : '(disable)' ;
};

</%init>