From 75159fa6df40171b78d19c1edaeb15d815b0b68b Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 28 Mar 2016 17:36:25 -0700 Subject: slightly better error reporting for DID selector, from #39914 --- httemplate/elements/select-areacode.html | 10 ++++++++-- httemplate/elements/select-exchange.html | 11 +++++++++-- httemplate/elements/select-phonenum.html | 10 ++++++++-- httemplate/elements/select-region.html | 10 ++++++++-- httemplate/misc/areacodes.cgi | 11 ++++++++--- httemplate/misc/exchanges.cgi | 11 ++++++++--- httemplate/misc/phonenums.cgi | 11 ++++++++--- httemplate/misc/regions.cgi | 11 ++++++++--- 8 files changed, 65 insertions(+), 20 deletions(-) (limited to 'httemplate') diff --git a/httemplate/elements/select-areacode.html b/httemplate/elements/select-areacode.html index f0f56d56d..612f03a8b 100644 --- a/httemplate/elements/select-areacode.html +++ b/httemplate/elements/select-areacode.html @@ -28,6 +28,7 @@ function <% $opt{'prefix'} %>update_areacodes(areacodes) { + var reply = JSON.parse(areacodes); // blank the current areacode for ( var i = what.form.<% $opt{'prefix'} %>areacode.length; i >= 0; i-- ) what.form.<% $opt{'prefix'} %>areacode.options[i] = null; @@ -47,7 +48,7 @@ % } // add the new areacodes - var areacodeArray = eval('(' + areacodes + ')' ); + var areacodeArray = reply.areacodes; for ( var s = 0; s < areacodeArray.length; s++ ) { var areacodeLabel = areacodeArray[s]; if ( areacodeLabel == "" ) @@ -62,6 +63,11 @@ } else { var areacodeerror = document.getElementById('<% $opt{'prefix'} %>areacodeerror'); areacodeerror.style.display = 'inline'; + if ( reply.error ) { + areacodeerror.textContent = reply.error; + } else { + areacodeerror.textContent = 'Select a different state'; + } } //run the callback @@ -78,7 +84,7 @@ - + > diff --git a/httemplate/elements/select-phonenum.html b/httemplate/elements/select-phonenum.html index 118fe4901..dd1b84736 100644 --- a/httemplate/elements/select-phonenum.html +++ b/httemplate/elements/select-phonenum.html @@ -56,6 +56,7 @@ passing the exchange (or region) and function <% $opt{'prefix'} %>update_phonenums(phonenums) { + var reply = JSON.parse(phonenums); // blank the current phonenum for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- ) what.form.<% $opt{'prefix'} %>phonenum.options[i] = null; @@ -67,7 +68,7 @@ passing the exchange (or region) and % } // add the new phonenums - var phonenumArray = eval('(' + phonenums + ')' ); + var phonenumArray = reply.phonenums; for ( var s = 0; s < phonenumArray.length; s++ ) { var phonenumLabel = phonenumArray[s]; if ( phonenumLabel == "" ) @@ -86,6 +87,11 @@ passing the exchange (or region) and } else { var phonenumerror = document.getElementById('<% $opt{'prefix'} %>phonenumerror'); phonenumerror.style.display = 'inline'; + if ( reply.error ) { + phonenumerror.textContent = reply.error; + } else { + phonenumerror.textContent = 'Select a different <% $opt{'region'} ? 'region' : 'city/exchange' %>'; + } } //run the callback @@ -157,7 +163,7 @@ passing the exchange (or region) and % unless ( $opt{'tollfree'} ) { - + % } > diff --git a/httemplate/misc/areacodes.cgi b/httemplate/misc/areacodes.cgi index 4b31deb00..afbe93e91 100644 --- a/httemplate/misc/areacodes.cgi +++ b/httemplate/misc/areacodes.cgi @@ -1,4 +1,4 @@ -<% encode_json(\@areacodes) %>\ +<% encode_json({ error => $error, areacodes => \@areacodes}) %>\ <%init> my( $state, $svcpart ) = $cgi->param('arg'); @@ -7,6 +7,8 @@ my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } ); die "unknown svcpart $svcpart" unless $part_svc; my @areacodes = (); +my $error; + if ( $state ) { my @exports = $part_svc->part_export_did; @@ -17,9 +19,12 @@ if ( $state ) { } my $export = $exports[0]; - my $something = $export->get_dids('state'=>$state); + local $@; + local $SIG{__DIE__}; + my $something = eval { $export->get_dids('state'=>$state) }; + $error = $@; - @areacodes = @{ $something }; + @areacodes = @{ $something } if $something; } diff --git a/httemplate/misc/exchanges.cgi b/httemplate/misc/exchanges.cgi index 0de4ace25..d62679191 100644 --- a/httemplate/misc/exchanges.cgi +++ b/httemplate/misc/exchanges.cgi @@ -1,4 +1,4 @@ -<% encode_json(\@exchanges) %>\ +<% encode_json({ error => $error, exchanges => \@exchanges}) %>\ <%init> my( $areacode, $svcpart ) = $cgi->param('arg'); @@ -7,6 +7,8 @@ my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } ); die "unknown svcpart $svcpart" unless $part_svc; my @exchanges = (); +my $error; + if ( $areacode ) { my @exports = $part_svc->part_export_did; @@ -17,9 +19,12 @@ if ( $areacode ) { } my $export = $exports[0]; - my $something = $export->get_dids('areacode'=>$areacode); + local $@; + local $SIG{__DIE__}; + my $something = eval { $export->get_dids('areacode'=>$areacode) }; + $error = $@; - @exchanges = @{ $something }; + @exchanges = @{ $something } if $something; } diff --git a/httemplate/misc/phonenums.cgi b/httemplate/misc/phonenums.cgi index 62923ac62..aae04f5d1 100644 --- a/httemplate/misc/phonenums.cgi +++ b/httemplate/misc/phonenums.cgi @@ -1,4 +1,4 @@ -<% encode_json(\@phonenums) %>\ +<% encode_json({ error => $error, phonenums => \@phonenums}) %>\ <%init> my( $exchangestring, $svcpart ) = $cgi->param('arg'); @@ -7,6 +7,7 @@ my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } ); die "unknown svcpart $svcpart" unless $part_svc; my @phonenums = (); +my $error; if ( $exchangestring ) { @@ -35,8 +36,12 @@ if ( $exchangestring ) { $opts{'exchange'} = $exchange; } - my $something = $export->get_dids(%opts); - @phonenums = @{ $something }; + local $@; + local $SIG{__DIE__}; + my $something = eval { $export->get_dids(%opts) }; + $error = $@; + + @phonenums = @{ $something } if $something; } diff --git a/httemplate/misc/regions.cgi b/httemplate/misc/regions.cgi index 31538b08e..882dd48df 100644 --- a/httemplate/misc/regions.cgi +++ b/httemplate/misc/regions.cgi @@ -1,4 +1,4 @@ -<% encode_json(\@regions) %>\ +<% encode_json({ error => $error, regions => \@regions}) %>\ <%init> my( $state, $svcpart ) = $cgi->param('arg'); @@ -7,6 +7,8 @@ my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } ); die "unknown svcpart $svcpart" unless $part_svc; my @regions = (); +my $error; + if ( $state ) { my @exports = $part_svc->part_export_did; @@ -17,9 +19,12 @@ if ( $state ) { } my $export = $exports[0]; - my $something = $export->get_dids('state'=>$state); + local $@; + local $SIG{__DIE__}; + my $something = eval { $export->get_dids('state'=>$state) }; + $error = $@; - @regions = @{ $something }; + @regions = @{ $something } if $something; } -- cgit v1.2.1