[freeside-commits] freeside/httemplate/edit svc_broadband.cgi, 1.22.4.1, 1.22.4.2
Erik Levinson
levinse at wavetail.420.am
Thu Jun 9 22:16:58 PDT 2011
Update of /home/cvs/cvsroot/freeside/httemplate/edit
In directory wavetail.420.am:/tmp/cvs-serv22824/httemplate/edit
Modified Files:
Tag: FREESIDE_2_1_BRANCH
svc_broadband.cgi
Log Message:
svc_broadband add/edit: configurable require co-ordinates in NW quadrant, RT12925
Index: svc_broadband.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/svc_broadband.cgi,v
retrieving revision 1.22.4.1
retrieving revision 1.22.4.2
diff -u -w -d -r1.22.4.1 -r1.22.4.2
--- svc_broadband.cgi 22 Jan 2011 02:45:32 -0000 1.22.4.1
+++ svc_broadband.cgi 10 Jun 2011 05:16:56 -0000 1.22.4.2
@@ -5,6 +5,8 @@
'fields' => \@fields,
'field_callback' => $callback,
'dummy' => $cgi->query_string,
+ 'onsubmit' => 'validate_coords',
+ 'html_foot' => $js,
)
%>
<%init>
@@ -17,6 +19,84 @@
my $conf = new FS::Conf;
+my $js = <<END
+ <script type="text/javascript">
+ function validate_coords(f){
+END
+;
+if ( $conf->exists('svc_broadband-require-nw-coordinates') ) {
+$js .= <<END
+ var lon = f.longitude;
+ var lat = f.latitude;
+ if ( lon == null || lat == null ||
+ lon.value.length == 0 || lat.value.length == 0 ) return true;
+
+ return (ut_coord(lat.value,1,90) && ut_coord(lon.value,-180,-1));
+ } // validate_coords
+
+ /* this is a JS re-implementation of FS::Record::ut_coord */
+ function ut_coord(coord,lower,upper) {
+ var neg = /^-/.test(coord);
+ coord = coord.replace(/^-/,'');
+
+ var d = 0;
+ var m = 0;
+ var s = 0;
+
+ var t1 = /^(\\s*\\d{1,3}(?:\\.\\d+)?)\\s*\$/.exec(coord);
+ var t2 = /^(\\s*\\d{1,3})\\s+(\\d{1,2}(?:\\.\\d+))\\s*\$/.exec(coord);
+ var t3 = /^(\\s*\\d{1,3})\\s+(\\d{1,2})\\s+(\\d{1,3})\\s*\$/.exec(coord);
+ if ( t1 != null ) {
+ d = t1[1];
+ } else if ( t2 != null ) {
+ d = t2[1];
+ m = t2[2];
+ } else if ( t3 != null ) {
+ d = t3[1];
+ m = t3[2];
+ s = t3[3];
+ } else {
+ alert('Invalid co-ordinates! Latitude must be positive and longitude must be negative.');
+ return false;
+ }
+
+ var ts = /^\\d{3}\$/.exec(s);
+ if ( ts != null || s > 59 ) {
+ s /= 1000;
+ } else {
+ s /= 60;
+ }
+ s /= 60;
+
+ m /= 60;
+ if ( m > 59 ) {
+ alert('Invalid coordinate with minutes > 59');
+ return false;
+ }
+
+ var tmp = parseInt(d)+parseInt(m)+parseInt(s);
+ tmp = tmp.toFixed(8);
+ coord = (neg ? -1 : 1) * tmp;
+
+ if(coord < lower) {
+ alert('Error: invalid coordinate < '+lower);
+ return false;
+ }
+ if(coord > upper) {
+ alert('Error: invalid coordinate > '+upper);
+ return false;
+ }
+
+ return true;
+END
+;
+}
+$js .= <<END
+ }
+ </script>
+END
+;
+
my @fields = (
qw( description ip_addr speed_down speed_up blocknum ),
{ field=>'block_label', type=>'fixed' },
More information about the freeside-commits
mailing list