1+ /**
2+ * Copyright (C) 2025, Axis Communications AB, Lund, Sweden
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
117const w = 640 ;
218const h = 360 ;
319const msize = 5 ;
@@ -7,9 +23,10 @@ const State = {
723 Min : Symbol ( 2 ) ,
824 Max : Symbol ( 3 )
925}
26+ const paramappname = 'Opcuagaugereader' ;
1027const parambaseurl = '/axis-cgi/param.cgi?action=' ;
11- const paramgeturl = parambaseurl + ' list&group=opcuagaugereader.' ;
12- const paramseturl = parambaseurl + ' update&opcuagaugereader.' ;
28+ const paramgeturl = ` ${ parambaseurl } list&group=${ paramappname } .` ;
29+ const paramseturl = ` ${ parambaseurl } update&${ paramappname } .` ;
1330var points = { } ;
1431points [ 'centerX' ] = 0 ;
1532points [ 'centerY' ] = 0 ;
@@ -19,7 +36,7 @@ points['maxX'] = 0;
1936points [ 'maxY' ] = 0 ;
2037
2138function getPointText ( param ) {
22- return param + ' : (' + points [ param + 'X' ] + ', ' + points [ param + 'Y' ] + ')' ;
39+ return ` ${ param } : (${ points [ ` ${ param } X` ] } , ${ points [ ` ${ param } Y` ] } )` ;
2340}
2441
2542function drawMarker ( X , Y , color ) {
@@ -31,7 +48,7 @@ function drawMarker(X, Y, color) {
3148 ctx . arc ( X , Y , msize , 1 , 2 * Math . PI , false ) ;
3249 ctx . stroke ( ) ;
3350 document . getElementById ( "values" ) . textContent =
34- getPointText ( 'center' ) + ' ' + getPointText ( 'min' ) + ' ' + getPointText ( 'max' ) ;
51+ ` ${ getPointText ( 'center' ) } ${ getPointText ( 'min' ) } ${ getPointText ( 'max' ) } ` ;
3552}
3653
3754function drawCenter ( ) {
@@ -54,25 +71,35 @@ function drawDefaultPoints() {
5471}
5572
5673function getCurrentValue ( param ) {
57- $ . get ( paramgeturl + param )
58- . done ( function ( data ) {
59- points [ param ] = data . split ( '=' ) [ 1 ] ;
60- console . log ( 'Got ' + param + ' value ' + points [ param ] ) ;
61- drawDefaultPoints ( ) ;
74+ return fetch ( `${ paramgeturl } ${ param } ` )
75+ . then ( response => {
76+ if ( ! response . ok ) {
77+ throw new Error ( `Getting parameter value, the network response was not ok: ${ response . status } ${ response . statusText } ` ) ;
78+ }
79+ return response . text ( ) ;
80+ } )
81+ . then ( data => {
82+ var value = data . split ( '=' ) [ 1 ] ;
83+ console . log ( `Got ${ param } value ${ value } ` ) ;
84+ return Number ( value ) ;
6285 } )
63- . fail ( function ( data ) {
64- alert ( 'FAILED to get ' + param ) ;
86+ . catch ( error => {
87+ alert ( `FAILED to get ${ param } ` ) ;
88+ throw error ;
6589 } ) ;
6690}
6791
6892function setParam ( param , value ) {
6993 points [ param ] = value ;
70- $ . get ( paramseturl + param + '=' + value )
71- . done ( function ( data ) {
72- console . log ( 'Set ' + param + ' to ' + value ) ;
94+ fetch ( `${ paramseturl } ${ param } =${ value } ` )
95+ . then ( response => {
96+ if ( ! response . ok ) {
97+ throw new Error ( `Setting parameter value, the network response was not ok: ${ response . status } ${ response . statusText } ` ) ;
98+ }
99+ console . log ( `Set ${ param } to ${ value } ` ) ;
73100 } )
74- . fail ( function ( jqXHR , textStatus , errorThrown ) {
75- alert ( ' FAILED to set ' + param ) ;
101+ . catch ( error => {
102+ alert ( ` FAILED to set ${ param } : ${ error . message } ` ) ;
76103 } ) ;
77104}
78105
@@ -129,7 +156,7 @@ var draw = document.getElementById('draw');
129156var infoTxt = document . getElementById ( 'info' ) ;
130157preview . width = preview . style . width = draw . width = w ;
131158preview . height = preview . style . height = draw . height = h ;
132- preview . src = ' /axis-cgi/mjpg/video.cgi?resolution=' + w + 'x' + h ;
159+ preview . src = ` /axis-cgi/mjpg/video.cgi?resolution=${ w } x ${ h } ` ;
133160var ctx = draw . getContext ( '2d' ) ;
134161initWithCurrentValues ( ) ;
135162handleCoord ( 0 , 0 ) ;
0 commit comments