From 8c39c41a00e15164ea306bfd73b2ae187dade9a5 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Mon, 9 Dec 2013 23:37:20 -0800 Subject: on-the-fly alarm vendor / type / CS adding, RT#23694 --- httemplate/elements/select-alarm_station.html | 7 +- httemplate/elements/select-alarm_system.html | 15 ++-- httemplate/elements/select-alarm_type.html | 7 +- httemplate/elements/tr-select-alarm_station.html | 21 +++--- httemplate/elements/tr-select-alarm_system.html | 21 +++--- httemplate/elements/tr-select-alarm_type.html | 21 +++--- httemplate/elements/tr-select-table.html | 87 +++++++++++++++++++++++- 7 files changed, 129 insertions(+), 50 deletions(-) (limited to 'httemplate') diff --git a/httemplate/elements/select-alarm_station.html b/httemplate/elements/select-alarm_station.html index 04d1383b0..2bae7b15b 100644 --- a/httemplate/elements/select-alarm_station.html +++ b/httemplate/elements/select-alarm_station.html @@ -1,7 +1,8 @@ -<% include( '/elements/select-table.html', +<& /elements/select-table.html, 'table' => 'alarm_station', 'name_col' => 'stationname', 'empty_label' => 'Select central station', + 'agent_virt' => 1, + 'agent_null' => 1, @_, - ) -%> +&> diff --git a/httemplate/elements/select-alarm_system.html b/httemplate/elements/select-alarm_system.html index 7f22fcefa..6bde51874 100644 --- a/httemplate/elements/select-alarm_system.html +++ b/httemplate/elements/select-alarm_system.html @@ -1,7 +1,8 @@ -<% include( '/elements/select-table.html', - 'table' => 'alarm_system', - 'name_col' => 'systemname', - 'empty_label' => 'Select vendor', - @_, - ) -%> +<& /elements/select-table.html, + table => 'alarm_system', + name_col => 'systemname', + empty_label => 'Select vendor', + 'agent_virt' => 1, + 'agent_null' => 1, + @_, +&> diff --git a/httemplate/elements/select-alarm_type.html b/httemplate/elements/select-alarm_type.html index 5f15988b0..fc1f98696 100644 --- a/httemplate/elements/select-alarm_type.html +++ b/httemplate/elements/select-alarm_type.html @@ -1,8 +1,9 @@ -<% include( '/elements/select-table.html', +<& /elements/select-table.html, 'table' => 'alarm_type', 'name_col' => 'typename', 'order_by' => 'ORDER BY inputs, outputs', 'empty_label' => 'Select type', + 'agent_virt' => 1, + 'agent_null' => 1, @_, - ) -%> +&> diff --git a/httemplate/elements/tr-select-alarm_station.html b/httemplate/elements/tr-select-alarm_station.html index 71ed0db0c..919282264 100644 --- a/httemplate/elements/tr-select-alarm_station.html +++ b/httemplate/elements/tr-select-alarm_station.html @@ -1,12 +1,9 @@ -% #if ( scalar(@domains) < 2 ) { -% #} else { - - <% $opt{'label'} || 'Central Station' %> - - <% include( '/elements/select-alarm_station.html', %opt) %> - - -% #} -<%init> - my %opt = @_; - +<& /elements/tr-select-table.html, + label => 'Central Station', + table => 'alarm_station', + #name_col => 'stationname', + add_inline => 1, + add_fields => [ 'stationname' ], + add_right => [ 'Alarm configuration', 'Alarm global configuration' ], + @_, +&> diff --git a/httemplate/elements/tr-select-alarm_system.html b/httemplate/elements/tr-select-alarm_system.html index a46a015f2..e1b2ae329 100644 --- a/httemplate/elements/tr-select-alarm_system.html +++ b/httemplate/elements/tr-select-alarm_system.html @@ -1,12 +1,9 @@ -% #if ( scalar(@domains) < 2 ) { -% #} else { - - <% $opt{'label'} || 'Vendor' %> - - <% include( '/elements/select-alarm_system.html', %opt) %> - - -% #} -<%init> - my %opt = @_; - +<& /elements/tr-select-table.html, + label => 'Vendor', + table => 'alarm_system', + #name_col => 'systemname', + add_inline => 1, + add_fields => [ 'systemname' ], + add_right => [ 'Alarm configuration', 'Alarm global configuration' ], + @_, +&> diff --git a/httemplate/elements/tr-select-alarm_type.html b/httemplate/elements/tr-select-alarm_type.html index b929fb8e6..1fc93555e 100644 --- a/httemplate/elements/tr-select-alarm_type.html +++ b/httemplate/elements/tr-select-alarm_type.html @@ -1,12 +1,9 @@ -% #if ( scalar(@domains) < 2 ) { -% #} else { - - <% $opt{'label'} || 'Type' %> - - <% include( '/elements/select-alarm_type.html', %opt) %> - - -% #} -<%init> - my %opt = @_; - +<& /elements/tr-select-table.html, + label => 'Type', + table => 'alarm_type', + #name_col => + add_inline => 1, + add_fields => [ 'inputs', 'outputs' ], + add_right => [ 'Alarm configuration', 'Alarm global configuration' ], + @_, +&> diff --git a/httemplate/elements/tr-select-table.html b/httemplate/elements/tr-select-table.html index 6ac748782..2e62d8717 100644 --- a/httemplate/elements/tr-select-table.html +++ b/httemplate/elements/tr-select-table.html @@ -1,3 +1,16 @@ +<%doc> + +Example: + + <& /elements/tr-select-table, + + 'add_inline' => 0, #enable "on the fly" adding + + #options passed to tr-td-label.html and select-$table.html (or + #select-table.html if that does not exist) + &> + + % unless ( $opt{'js_only'} ) { <% include('tr-td-label.html', @_ ) %> @@ -5,16 +18,88 @@ > % } - <% include( '/elements/select-table.html', %opt ) %> +% my $element = '/elements/select-'.$opt{table}.'.html'; +% if ( $m->interp->comp_exists($element) ) { + <& $element, %opt &> +% } else { + <& /elements/select-table.html, %opt &> +% } % unless ( $opt{'js_only'} ) { % } + +% if ( $opt{'add_inline'} ) { + +% foreach my $add_field ( @{ $opt{'add_fields'} } ) { +% my $label = scalar(@{ $opt{'add_fields'} }) > 1 +% ? $add_field : $opt{'label'}; + + <& /elements/tr-input-text.html, + 'label' => "New $label", + 'field' => $field."_$add_field", + 'id' => $field."_$add_field", + 'colspan' => $opt{'colspan'}, + &> + +% } + + +% unless ( $opt{'html_only'} ) { + + + +% } + +% } + <%init> my( %opt ) = @_; my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : ''; +my $curuser = $FS::CurrentUser::CurrentUser; + +my $field = ''; +if ( $opt{'add_inline'} && $curuser->access_right($opt{'add_right'}) ) { + + push @{ $opt{'post_options'} }, '-1' => 'Add new '. lc($opt{'label'}); + + $field = $opt{'field'} || dbdef->table($opt{'table'})->primary_key; + + my $onchange = ( $opt{'onchange'} ? delete($opt{'onchange'}).';' : '' ). + $field.'_changed(this);'; + $opt{'onchange'} = $onchange; + +} + -- cgit v1.2.1