@@ -6,6 +6,10 @@ document.addEventListener("DOMContentLoaded", () => {
66 const wifiOutput = document . getElementById ( "wifi-output" ) ;
77 const statusLoader = document . getElementById ( "status-loader" ) ;
88 const wifiLoader = document . getElementById ( "wifi-loader" ) ;
9+ const ntpInput = document . getElementById ( "ntp-input" ) ;
10+ const ntpOutput = document . getElementById ( "ntp-output" ) ;
11+ const ntpLoader = document . getElementById ( "ntp-loader" ) ;
12+ const ntpSetBtn = document . getElementById ( "ntp-set-btn" ) ;
913
1014 const showLoader = ( loader ) => {
1115 loader . style . display = "block" ;
@@ -15,6 +19,18 @@ document.addEventListener("DOMContentLoaded", () => {
1519 loader . style . display = "none" ;
1620 } ;
1721
22+ const disableButton = ( button ) => {
23+ button . disabled = true ;
24+ button . style . opacity = "0.6" ;
25+ button . innerText = "Loading..." ;
26+ } ;
27+
28+ const enableButton = ( button , originalText ) => {
29+ button . disabled = false ;
30+ button . style . opacity = "1" ;
31+ button . innerText = originalText ;
32+ } ;
33+
1834 const showOutput = ( section , html , loader ) => {
1935 hideLoader ( loader ) ;
2036 section . innerHTML = html ;
@@ -23,9 +39,7 @@ document.addEventListener("DOMContentLoaded", () => {
2339 const handleApi = ( url , formatter , outputSection , button , loader ) => {
2440 showLoader ( loader ) ;
2541 outputSection . innerHTML = "" ;
26- button . disabled = true ;
27- button . style . opacity = "0.6" ;
28- button . innerText = "Loading..." ;
42+ disableButton ( button ) ;
2943
3044 fetch ( url )
3145 . then ( ( res ) => res . json ( ) )
@@ -44,9 +58,7 @@ document.addEventListener("DOMContentLoaded", () => {
4458 } )
4559 . finally ( ( ) => {
4660 hideLoader ( loader ) ;
47- button . disabled = false ;
48- button . style . opacity = "1" ;
49- button . innerText = button . dataset . originalText ;
61+ enableButton ( button , button . dataset . originalText ) ;
5062 } ) ;
5163 } ;
5264
@@ -95,6 +107,38 @@ document.addEventListener("DOMContentLoaded", () => {
95107 ` ;
96108 } ;
97109
110+ const handleNtpUpdate = ( ) => {
111+ const ntpDomain = ntpInput . value . trim ( ) ;
112+ if ( ! ntpDomain ) {
113+ ntpOutput . innerHTML = `<p style="color: var(--error-color);">⚠️ Please enter an NTP server domain.</p>` ;
114+ return ;
115+ }
116+
117+ disableButton ( ntpSetBtn ) ;
118+ showLoader ( ntpLoader ) ;
119+ ntpOutput . innerHTML = "" ;
120+
121+ fetch ( "/api/v1/ntp/set" , {
122+ method : "POST" ,
123+ headers : { "Content-Type" : "application/json" } ,
124+ body : JSON . stringify ( { ntp_domain : ntpDomain } ) ,
125+ } )
126+ . then ( ( res ) => res . json ( ) )
127+ . then ( ( data ) => {
128+ if ( ! data || data . success === false ) {
129+ throw new Error ( data . message || "Unknown error" ) ;
130+ }
131+ ntpOutput . innerHTML = `<p style="color: #4CAF50;">✅ NTP server updated successfully to <strong>${ ntpDomain } </strong></p>` ;
132+ } )
133+ . catch ( ( err ) => {
134+ ntpOutput . innerHTML = `<p style="color: var(--error-color);">⚠️ ${ err . message } </p>` ;
135+ } )
136+ . finally ( ( ) => {
137+ hideLoader ( ntpLoader ) ;
138+ enableButton ( ntpSetBtn , "Set NTP Server" ) ;
139+ } ) ;
140+ } ;
141+
98142 document . addEventListener ( "click" , ( e ) => {
99143 if ( e . target . classList . contains ( "connect-btn" ) ) {
100144 const ssid = decodeURIComponent ( e . target . dataset . ssid ) ;
@@ -147,4 +191,7 @@ document.addEventListener("DOMContentLoaded", () => {
147191 wifiBtn ,
148192 wifiLoader
149193 ) ;
194+
195+ ntpSetBtn . dataset . originalText = ntpSetBtn . innerText ;
196+ ntpSetBtn . onclick = handleNtpUpdate ;
150197} ) ;
0 commit comments