From a9a791f0e93cf43f93a4bd720c7681d08d84f18c Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 22 Aug 2013 17:13:49 -0700 Subject: [PATCH] better locale support in message template UI, #24659 --- FS/FS/Locales.pm | 3 +++ httemplate/browse/msg_template.html | 2 +- httemplate/edit/msg_template.html | 39 +++++++++++++++++++++++----- httemplate/misc/delete-template_content.html | 18 +++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 httemplate/misc/delete-template_content.html diff --git a/FS/FS/Locales.pm b/FS/FS/Locales.pm index 10bf72ac3..bf10990a9 100644 --- a/FS/FS/Locales.pm +++ b/FS/FS/Locales.pm @@ -37,6 +37,9 @@ tie our %locales, 'Tie::IxHash', 'iw_IL', { name => 'Hebrew', country => 'Israel', rtl=>1, }, ; +$_->{label} = $_->{name} . ' (' . $_->{country} . ')' + foreach values %locales; + sub locales { keys %locales; } diff --git a/httemplate/browse/msg_template.html b/httemplate/browse/msg_template.html index 50afc283e..bb5ac94a0 100644 --- a/httemplate/browse/msg_template.html +++ b/httemplate/browse/msg_template.html @@ -36,7 +36,7 @@ my (@locales, @locale_links); foreach my $l ( FS::Locales->locales ) { push @locales, sub { exists ( $_[0]->content_locales->{$l} ) - ? +{ FS::Locales->locale_info($l) }->{'name'} + ? +{ FS::Locales->locale_info($l) }->{'label'} : ''; }; push @locale_links, sub { diff --git a/httemplate/edit/msg_template.html b/httemplate/edit/msg_template.html index 115032a07..7205ba844 100644 --- a/httemplate/edit/msg_template.html +++ b/httemplate/edit/msg_template.html @@ -15,13 +15,14 @@ 'msgname' => 'Template name', 'from_addr' => 'From: ', 'bcc_addr' => 'Bcc: ', - 'locale' => 'Language', + 'locale' => 'Locale', 'subject' => 'Subject: ', 'body' => 'Message body', }, 'edit_callback' => \&edit_callback, 'error_callback' => \&edit_callback, 'html_bottom' => '', + 'html_table_bottom'=> \&html_table_bottom, 'html_foot' => ( $no_submit ? '' : "$sidebar" ), 'no_submit' => $no_submit, &> @@ -120,11 +121,12 @@ sub edit_callback { # make a list of available locales my $content_locales = $object->content_locales; - my @locales = grep { !exists($content_locales->{$_}) } FS::Locales->locales; + my @locales = grep { !exists($content_locales->{$_}) } + FS::Conf->new->config('available-locales'); my %labels; foreach (@locales) { my %info = FS::Locales->locale_info($_); - $labels{$_} = $info{'name'}; # ignoring country for now + $labels{$_} = $info{'label'}; } unshift @locales, 'new'; $labels{'new'} = 'Select language'; @@ -145,7 +147,7 @@ sub edit_callback { curr_value => 'new', onchange => $onchange_locale, ); - } # else it's already set up correctly + } } sub menubar_opt_callback { @@ -159,10 +161,10 @@ sub menubar_opt_callback { foreach my $l (FS::Locales->locales) { if ( exists $object->content_locales->{$l} ) { my %info = FS::Locales->locale_info($l); - push @tabs, - $info{'name'}, + push @tabs, + $info{'label'}, ';locale='.$l; - $selected = $info{'name'} if $object->locale eq $l; + $selected = $info{'label'} if $object->locale eq $l; } else { $display_new = 1; # there is at least one unused locale left @@ -329,6 +331,11 @@ function insertHtml(what) { var oEditor = FCKeditorAPI.GetInstance("body"); oEditor.InsertHtml(what); }; + +function areyousure(url, message) { + if (confirm(message)) + window.location.href = url; +}
Substitutions: ' @@ -340,4 +347,22 @@ Substitutions: ' '; +sub html_table_bottom { + my $object = shift; + $cgi->param('locale') =~ /^(\w+)$/; + my $locale = $1; + my $html; + if ( $locale and $locale ne 'new' ) { + # set up a delete link + my $msgnum = $object->msgnum; + my $url = $p."misc/delete-template_content.html?msgnum=$msgnum;locale=$1"; + my $link = qq!! . + 'Delete this template' . + ''; + $html = qq! + $link!; + } + $html; +} + diff --git a/httemplate/misc/delete-template_content.html b/httemplate/misc/delete-template_content.html new file mode 100644 index 000000000..e77878c25 --- /dev/null +++ b/httemplate/misc/delete-template_content.html @@ -0,0 +1,18 @@ +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right(['Edit templates', 'Edit global templates']); + +my ($msgnum, $locale); +$cgi->param('msgnum') =~ /^(\d+)$/ or die "bad msgnum"; +$msgnum = $1; +$cgi->param('locale') =~ /^(\w+)$/ or die "bad locale"; +$locale = $1; +my $content = qsearchs('template_content', + { msgnum => $msgnum, locale => $locale }) + or die "couldn't find $locale version of template #$msgnum"; + +my $error = $content->delete; +my $url = $p.'edit/msg_template.html?msgnum='.$msgnum; +$url .= ";locale=$locale;error=$error" if $error; + +<% $cgi->redirect($url) %> -- 2.11.0