summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/svc_Common.pm14
-rw-r--r--FS/FS/svc_alarm.pm71
-rw-r--r--httemplate/elements/select-alarm_station.html7
-rw-r--r--httemplate/elements/select-alarm_system.html15
-rw-r--r--httemplate/elements/select-alarm_type.html7
-rw-r--r--httemplate/elements/tr-select-alarm_station.html21
-rw-r--r--httemplate/elements/tr-select-alarm_system.html21
-rw-r--r--httemplate/elements/tr-select-alarm_type.html21
-rw-r--r--httemplate/elements/tr-select-table.html87
9 files changed, 196 insertions, 68 deletions
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index 3993d3d..56567e8 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -335,6 +335,7 @@ sub preinsert_hook_first { ''; }
sub _check_duplcate { ''; }
sub preinsert_hook { ''; }
sub table_dupcheck_fields { (); }
+sub prereplace_hook { ''; }
sub predelete_hook { ''; }
sub predelete_hook_first { ''; }
@@ -472,15 +473,10 @@ sub replace {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my $error = $new->set_auto_inventory($old);
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
-
- #redundant, but so any duplicate fields are maniuplated as appropriate
- # (svc_phone.phonenum)
- $error = $new->check;
+ my $error = $new->prereplace_hook_first($old)
+ || $new->set_auto_inventory($old)
+ || $new->check; #redundant, but so any duplicate fields are
+ #maniuplated as appropriate (svc_phone.phonenum)
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
diff --git a/FS/FS/svc_alarm.pm b/FS/FS/svc_alarm.pm
index 3e910f0..4a355c7 100644
--- a/FS/FS/svc_alarm.pm
+++ b/FS/FS/svc_alarm.pm
@@ -99,12 +99,15 @@ sub table_info {
;
{
- 'name' => 'Alarm service',
- 'sorts' => 'acctnum',
- 'display_weight' => 80,
- 'cancel_weight' => 85,
- 'fields' => \%fields,
-
+ 'name' => 'Alarm service',
+ 'sorts' => 'acctnum',
+ 'display_weight' => 80,
+ 'cancel_weight' => 85,
+ 'fields' => \%fields,
+ 'addl_process_fields' => [qw( alarmsystemnum_systemname
+ alarmtypenum_inputs alarmtypenum_outputs
+ alarmstationnum_stationname
+ )],
};
}
@@ -134,6 +137,50 @@ Delete this record from the database.
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
+=cut
+
+sub preinsert_hook_first { shift->_inline_add(@_); }
+sub prereplace_hook_first { shift->_inline_add(@_); }
+
+sub _inline_add {
+ my $self = shift;
+
+ my $agentnum = $self->cust_svc->cust_pkg->cust_main->agentnum;
+
+ if ( $self->alarmsystemnum == -1 ) {
+ my $alarm_system = new FS::alarm_system {
+ 'agentnum' => $agentnum,
+ 'systemname' => $self->alarmsystemnum_systemname,
+ };
+ my $error = $alarm_system->insert;
+ return $error if $error;
+ $self->alarmsystemnum($alarm_system->alarmsystemnum);
+ }
+
+ if ( $self->alarmtypenum == -1 ) {
+ my $alarm_type = new FS::alarm_type {
+ 'agentnum' => $agentnum,
+ 'inputs' => $self->alarmtypenum_inputs,
+ 'outputs' => $self->alarmtypenum_outputs,
+ };
+ my $error = $alarm_type->insert;
+ return $error if $error;
+ $self->alarmtypenum($alarm_type->alarmtypenum);
+ }
+
+ if ( $self->alarmstationnum == -1 ) {
+ my $alarm_station = new FS::alarm_station {
+ 'agentnum' => $agentnum,
+ 'stationname' => $self->alarmstationnum_stationname,
+ };
+ my $error = $alarm_station->insert;
+ return $error if $error;
+ $self->alarmstationnum($alarm_station->alarmstationnum)
+ }
+
+ '';
+}
+
=item check
Checks all fields to make sure this is a valid service. If there is
@@ -162,9 +209,15 @@ sub check {
$self->SUPER::check;
}
-sub alarm_system { qsearchs('alarm_system', {systemnum =>shift->systemnum } ) }
-sub alarm_type { qsearchs('alarm_type', {typenum =>shift->systemnum } ) }
-sub alarm_station { qsearchs('alarm_station',{stationnum=>shift->stationnum} ) }
+sub alarm_system {
+ qsearchs('alarm_system', { alarmsystemnum => shift->alarmsystemnum } );
+}
+sub alarm_type {
+ qsearchs('alarm_type', { alarmtypenum => shift->alarmtypenum } );
+}
+sub alarm_station {
+ qsearchs('alarm_station', { alarmstationnum => shift->alarmstationnum } );
+}
=back
diff --git a/httemplate/elements/select-alarm_station.html b/httemplate/elements/select-alarm_station.html
index 04d1383..2bae7b1 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 7f22fce..6bde518 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 5f15988..fc1f986 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 71ed0db..9192822 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 {
- <TR>
- <TD ALIGN="right"><% $opt{'label'} || 'Central Station' %></TD>
- <TD>
- <% include( '/elements/select-alarm_station.html', %opt) %>
- </TD>
- </TR>
-% #}
-<%init>
- my %opt = @_;
-</%init>
+<& /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 a46a015..e1b2ae3 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 {
- <TR>
- <TD ALIGN="right"><% $opt{'label'} || 'Vendor' %></TD>
- <TD>
- <% include( '/elements/select-alarm_system.html', %opt) %>
- </TD>
- </TR>
-% #}
-<%init>
- my %opt = @_;
-</%init>
+<& /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 b929fb8..1fc9355 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 {
- <TR>
- <TD ALIGN="right"><% $opt{'label'} || 'Type' %></TD>
- <TD>
- <% include( '/elements/select-alarm_type.html', %opt) %>
- </TD>
- </TR>
-% #}
-<%init>
- my %opt = @_;
-</%init>
+<& /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 6ac7487..2e62d87 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)
+ &>
+
+</%doc>
% unless ( $opt{'js_only'} ) {
<% include('tr-td-label.html', @_ ) %>
@@ -5,16 +18,88 @@
<TD <% $style %>>
% }
- <% 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'} ) {
</TD>
</TR>
% }
+
+% 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'} ) {
+
+ <SCRIPT TYPE="text/javascript">
+
+% my $ge = 'document.getElementById';
+
+ function <% $field %>_changed(what) {
+
+ var value = what.options[what.selectedIndex].value;
+
+ var display = 'none';
+ var visibility = 'hidden';
+ if ( value == '-1' && ! what.disabled ) {
+ display = '';
+ visibility = '';
+ }
+
+% foreach my $add_field ( @{ $opt{'add_fields'} } ) {
+% my $ge_f = "$ge('${field}_$add_field";
+ <% $ge_f %>_label0').style.display = display;
+ <% $ge_f %>_label0').style.visibility = visibility;
+ <% $ge_f %>_input0').style.display = display;
+ <% $ge_f %>_input0').style.visibility = visibility;
+% }
+
+ }
+
+ <% $field %>_changed(<% $ge %>('<% $field %>'));
+
+ </SCRIPT>
+
+% }
+
+% }
+
<%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;
+
+}
+
</%init>