summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-04-28 20:19:49 -0700
committerMark Wells <mark@freeside.biz>2016-04-28 20:19:49 -0700
commit2eb1e959493a77e061243df03a474edf4eb24db9 (patch)
tree256221e4f69f07c85189ac52f5401db94a6e50ad
parentea734eb2f16a632a9c79bf17b6954f8571d85f3f (diff)
more convenient selection of domain in svc_acct definition, #40962
-rw-r--r--FS/FS/svc_acct.pm1
-rw-r--r--httemplate/edit/elements/part_svc_column.html5
-rw-r--r--httemplate/elements/select-svc.html73
-rw-r--r--httemplate/elements/select.html2
4 files changed, 80 insertions, 1 deletions
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index b4db082e1..93659f98f 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -316,6 +316,7 @@ sub table_info {
'domsvc' => {
label => 'Domain',
type => 'select',
+ select_svc => 1,
select_table => 'svc_domain',
select_key => 'svcnum',
select_label => 'domain',
diff --git a/httemplate/edit/elements/part_svc_column.html b/httemplate/edit/elements/part_svc_column.html
index bc679e577..4e112c078 100644
--- a/httemplate/edit/elements/part_svc_column.html
+++ b/httemplate/edit/elements/part_svc_column.html
@@ -132,7 +132,10 @@ my %communigate_fields = (
% } elsif ( $def->{'type'} eq 'select' ) {
%
% if ( $def->{'select_table'} ) {
- <& /elements/select-table.html,
+% # set the 'select_svc' flag to enable two-step selection of services
+% my $comp = '/elements/select-table.html';
+% $comp = '/elements/select-svc.html' if $def->{'select_svc'};
+ <& $comp,
'field' => $name,
'id' => $name.'_select',
'table' => $def->{'select_table'},
diff --git a/httemplate/elements/select-svc.html b/httemplate/elements/select-svc.html
new file mode 100644
index 000000000..b439a2852
--- /dev/null
+++ b/httemplate/elements/select-svc.html
@@ -0,0 +1,73 @@
+<%init>
+my %opt = @_;
+my $svcdb = $opt{table};
+my $field = $opt{field} || 'svcnum';
+my $id = $opt{id} || $opt{field};
+my $curr_value = [ split(',', $opt{curr_value} || '') ];
+my $label = $opt{name_col} || 'label';
+
+# cut-down, jquerified version of select-tiered
+# XXX do we need to agent-virt this? edit/part_svc is Configuration-access.
+my @part_svc = qsearch('part_svc', {
+ disabled => '',
+ svcdb => $svcdb
+});
+my %labels; # service labels, of some kind
+my %values; # svcnums
+my (@all_l, @all_v);
+foreach my $part_svc (@part_svc) {
+ my (@l, @v);
+ foreach my $svc_x (qsearch({
+ 'table' => 'cust_svc',
+ 'addl_from' => " JOIN $svcdb USING (svcnum)",
+ 'select' => "$svcdb.*, cust_svc.svcpart",
+ 'hashref' => { 'svcpart' => $part_svc->svcpart },
+ }))
+ {
+ push @l, $svc_x->$label;
+ push @all_l, $svc_x->$label;
+ push @v, $svc_x->svcnum;
+ push @all_v, $svc_x->svcnum;
+ }
+ $labels{ $part_svc->svcpart } = \@l;
+ $values{ $part_svc->svcpart } = \@v;
+}
+$labels{ '' } = \@all_l;
+$values{ '' } = \@all_v;
+
+</%init>
+<& /elements/select-table.html,
+ 'table' => 'part_svc',
+ 'records' => \@part_svc,
+ 'id' => $id.'_svcpart',
+ 'name_col' => 'svc',
+ 'empty_label' => 'any',
+ 'curr_value' => '',
+ 'field' => $id.'_svcpart', # avoid confusion with any other field
+&>
+<BR>
+<& /elements/select.html,
+ %opt,
+ 'field' => $field,
+ 'id' => $id,
+&>
+<script>
+$().ready(function() {
+ var labels = <% encode_json(\%labels) %>;
+ var values = <% encode_json(\%values) %>;
+ var select_svcpart = $('#<% $id.'_svcpart' %>');
+ var select_svcnum = $('#<% $id %>');
+ var onchange_svcpart = function() {
+ var l = labels[ this.value ];
+ var v = values[ this.value ];
+ select_svcnum.empty();
+ for (var i = 0; i < v.length; i++) {
+ var opt = $('<option />').val(v[i]).text(l[i]);
+ select_svcnum.append(opt);
+ }
+ };
+ select_svcpart.on('change', onchange_svcpart);
+ select_svcpart.change();
+ select_svcnum.val(<% encode_json($curr_value) %>);
+});
+</script>
diff --git a/httemplate/elements/select.html b/httemplate/elements/select.html
index 42cd89504..3a0dc5b68 100644
--- a/httemplate/elements/select.html
+++ b/httemplate/elements/select.html
@@ -21,6 +21,7 @@
disabled => 0,
onchange => 'do_something()',
js_only => 0, # disables the whole thing
+ element_etc => '', # anything else to put in the <select> tag
&>
</%doc>
@@ -35,6 +36,7 @@
<% $style %>
<% $opt{disabled} %>
<% $onchange %>
+ <% $opt{'element_etc'} %>
>
% if ( $opt{options} ) {