summaryrefslogtreecommitdiff
path: root/httemplate/elements
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-07-06 11:53:13 -0700
committerMark Wells <mark@freeside.biz>2016-07-06 11:53:13 -0700
commitf413badbfe4676563d11b528838a21d9ceb8da14 (patch)
treecfd1749f7241890cb08b369aca1959cb18e1003f /httemplate/elements
parentdf43a12a1c219709f27297ad6b53f6662b56c10c (diff)
service label localization, internals and UI, #71347
Diffstat (limited to 'httemplate/elements')
-rw-r--r--httemplate/elements/freeside.css2
-rw-r--r--httemplate/elements/progress-init.html14
-rw-r--r--httemplate/elements/tr-input-locale-text.html120
3 files changed, 132 insertions, 4 deletions
diff --git a/httemplate/elements/freeside.css b/httemplate/elements/freeside.css
index fb5e7d961..cc104a196 100644
--- a/httemplate/elements/freeside.css
+++ b/httemplate/elements/freeside.css
@@ -235,7 +235,7 @@ div.fstabcontainer {
.fsinnerbox th {
font-weight:normal;
font-size:80%;
- valign: bottom;
+ vertical-align: bottom;
color: #666666;
}
diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html
index e38dde65f..0c2b8165a 100644
--- a/httemplate/elements/progress-init.html
+++ b/httemplate/elements/progress-init.html
@@ -98,14 +98,14 @@ function <%$key%>process () {
overlib( 'Submitting job to server...', WIDTH, 444, HEIGHT, 168, CAPTION, 'Please wait...', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', CLOSECLICK, MIDX, 0, MIDY, 0 );
+ // jQuery .serializeArray() maybe?
+ var copy_fields = <% encode_json(\%copy_fields) %>;
var Hash = new Array();
var x = 0;
var fieldName;
for (var i = 0; i<document.<%$formname%>.elements.length; i++) {
field = document.<%$formname%>.elements[i];
- if ( <% join(' || ', map { "(field.name.indexOf('$_') > -1)" } @$fields ) %>
- )
- {
+ if ( <% $all_fields %> || copy_fields[ field.name ] ) {
if ( field.type == 'select-multiple' ) {
//alert('select-multiple ' + field.name);
for (var j=0; j < field.options.length; j++) {
@@ -168,6 +168,14 @@ $progress_url->query_form(
%dest_info,
);
+my $all_fields = 0;
+my %copy_fields;
+if (grep '/^ALL$/', @$fields) {
+ $all_fields = 1;
+} else {
+ %copy_fields = map { $_ => 1 } @$fields;
+}
+
#stupid safari is caching the "location" of popup iframs, and submitting them
#instead of displaying them. this should prevent that.
my $popup_name = 'popup-'.random_id();
diff --git a/httemplate/elements/tr-input-locale-text.html b/httemplate/elements/tr-input-locale-text.html
new file mode 100644
index 000000000..110a8aa9b
--- /dev/null
+++ b/httemplate/elements/tr-input-locale-text.html
@@ -0,0 +1,120 @@
+<%doc>
+Usage:
+
+In edit/foo.html:
+
+<& /elements/tr-input-locale-text.html,
+ cgi => $cgi, # needed to preserve values in error redirect
+ object => $record,
+ field => 'myfield',
+ label => 'My Field',
+&>
+
+And in edit/process/foo.html:
+<& elements/process.html,
+ ...
+ process_locale => 'myfield',
+&>
+
+'object' needs to be an FS::Record subclass instance for a table that has
+a '_msgcat' localization table. For a table "foo" where "foo.myfield"
+contains some customer-visible label (in the default locale),
+"foo_msgcat.myfield" contains the translation of that label for a customer
+locale. The foreign key in foo_msgcat must have the same name as the primary
+key of foo.
+
+Currently only a single field can be localized this way; including this
+element more than once in the form will lead to conflicts. This is how
+it should work; if at some point we need to localize several fields of the
+same record, we should modify this element to show multiple inputs for each
+locale.
+
+</%doc>
+<%init>
+
+my %opt = @_;
+my $object = delete $opt{object};
+my $field = delete $opt{field};
+
+# identify our locales
+my $conf = FS::Conf->new;
+my $default_locale = $conf->config('locale') || 'en_';
+my @locales = grep { ! /^$default_locale/ } $conf->config('available-locales');
+
+my $label = delete $opt{label};
+my %labels = map { $_ => "$label&mdash;".FS::Locales->description($_) }
+ @locales;
+@locales = sort { $labels{$a} cmp $labels{$b} } @locales;
+my %curr_values;
+
+# where are the msgcat records?
+my $msgcat_table = $object->table . '_msgcat';
+my $msgcat_pkey = dbdef->table($msgcat_table)->primary_key;
+my %msgcat_pkeyvals;
+
+# find existing msgcat records, if any, and record their message values
+# and pkeys
+my $pkey = $object->primary_key;
+my $pkeyval = $object->get($pkey);
+if ($pkeyval) { # of course if this is a new record there won't be any
+ my @linked = qsearch($msgcat_table, { $pkey => $pkeyval });
+ foreach (@linked) {
+ $curr_values{ $_->locale } = $_->get( $field );
+ $msgcat_pkeyvals{ $_->locale } = $_->get( $msgcat_pkey );
+ }
+}
+
+# sticky-on-error the locale inputs
+if( my $cgi = $opt{cgi} ) {
+ my $i = 0;
+ # they're named 'foomsgnum0_locale' and 'foomsgnum0_myfield'
+ while ( my $locale = $cgi->param($msgcat_pkey . $i . '_locale') ) {
+ my $value = $cgi->param($msgcat_pkey . $i . '_' . $field);
+ $curr_values{ $locale } = $value;
+ $i++;
+ }
+}
+
+# compat with tr-input-text for styling
+my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+
+my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';
+
+
+</%init>
+% # pass through %opt on all of these to retain formatting
+% # one tr, td, and input for the default locale
+<& tr-input-text.html,
+ %opt,
+ 'label' => $label,
+ 'field' => $field
+&>
+% # and one for each of the others
+% my $i = 0;
+% foreach my $locale (@locales) {
+% my $basename = $msgcat_pkey . $i;
+% my $lfield = $basename . '_' . $field;
+<& tr-td-label.html,
+ %opt,
+ 'id' => $lfield, # uniqueness
+ 'label' => $labels{$locale}
+&>
+ <TD <% $colspan %><% $cell_style %> ID="<% $lfield %>_input0">
+ <& hidden.html,
+ 'field' => $basename,
+ 'curr_value' => $msgcat_pkeyvals{$locale},
+ # will be empty if this is a new record and/or new locale, that's fine
+ &>
+ <& hidden.html,
+ 'field' => $basename . '_locale',
+ 'curr_value' => $locale,
+ &>
+ <& input-text.html,
+ %opt,
+ 'field' => $lfield,
+ 'curr_value' => $curr_values{$locale},
+ &>
+ </TD>
+</TR>
+% $i++;
+% } # foreach $locale