Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / browse / msg_template.html
index 331906c..50afc28 100644 (file)
@@ -1,27 +1,49 @@
 <% include( 'elements/browse.html',
               'title'         => 'Message templates',
               'name_singular' => 'template',
-              'menubar'     => [ 'Add a new template' =>
-                                   $p.'edit/msg_template.html',
-                               ],
-              'query'       => { 'table' => 'msg_template', },
-              'count_query' => 'SELECT COUNT(*) FROM msg_template',
-              'disableable' => 1,
+              'menubar'       => \@menubar,
+              'query'         => { 'table' => 'msg_template', },
+              'count_query'   => 'SELECT COUNT(*) FROM msg_template',
+              'disableable'   => 1,
               'disabled_statuspos' => 2,
               'agent_virt'         => 1,
-              'agent_null_right'   => 'Edit global templates',
-              'agent_pos'          => 3,
-              'header' => [ 'Name' ],
-              'fields' => [ 'msgname' ],
-              'links'  => [ $link ],
+              'agent_null_right'   => ['View global templates','Edit global templates'],
+              'agent_pos'          => 1,
+              'header'     => [ 'Name', '', map '', @locales ],
+              'fields'     => [ 'msgname', @locales ],
+              'links'      => [ $link, @locale_links ],
+              'cell_style' => [ '', '', map $locale_style, @locales ],
           )
 %>
 <%init>
 
+my $curuser = $FS::CurrentUser::CurrentUser;
+
 die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Edit templates')
-  ||     $FS::CurrentUser::CurrentUser->access_right('Edit global templates');
+  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; background-color:';
 
-my $link = [ "${p}edit/msg_template.html?", 'msgnum' ];
+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>