@@ -254,81 +254,77 @@ return view.extend({
254254 L . uci . set ( pkg . Name , section_id , "resolver_url" , formvalue ) ;
255255 } ;
256256
257- reply . providers . forEach ( ( prov , i ) => {
258- if ( prov . http2_only && ! reply . platform . http2_support ) return ;
259- if ( prov . http3_only && ! reply . platform . http3_support ) return ;
260- _provider . value ( prov . template , _ ( prov . title ) ) ;
257+ function createProviderWidget ( s , i , prov ) {
261258 if (
262259 prov . params &&
263260 prov . params . option &&
264- prov . params . option . type &&
265- prov . params . option . type === "select"
261+ prov . params . option . type
266262 ) {
267- let optName = prov . params . option . description || _ ( "Parameter" ) ;
268- var _paramList = s . option ( form . ListValue , "_paramList_" + i , optName ) ;
269- _paramList . template = prov . template ;
270- _paramList . modalonly = true ;
271- if ( prov . params . option . default ) {
272- _paramList . default = prov . params . option . default ;
273- }
274- prov . params . option . options . forEach ( ( opt ) => {
275- let val = opt . value || "" ;
276- let descr = opt . description || "" ;
277- _paramList . value ( val , descr ) ;
278- } ) ;
279- _paramList . depends ( "_provider" , prov . template ) ;
280- _paramList . write = function ( section_id , formvalue ) {
281- let template = this . map . data . get (
282- this . map . config ,
283- section_id ,
284- "resolver_url"
285- ) ;
286- if ( ! formvalue && _paramList . template !== template ) return 0 ;
287- let resolver = pkg . templateToResolver ( _paramList . template , {
288- option : formvalue || "" ,
263+ if ( prov . params . option . type === "select" ) {
264+ let optName = prov . params . option . description || _ ( "Parameter" ) ;
265+ var _paramList = s . option ( form . ListValue , "_paramList_" + i , optName ) ;
266+ _paramList . template = prov . template ;
267+ _paramList . modalonly = true ;
268+ if ( prov . params . option . default ) {
269+ _paramList . default = prov . params . option . default ;
270+ }
271+ prov . params . option . options . forEach ( ( opt ) => {
272+ let val = opt . value || "" ;
273+ let descr = opt . description || "" ;
274+ _paramList . value ( val , descr ) ;
289275 } ) ;
290- L . uci . set ( pkg . Name , section_id , "resolver_url" , resolver ) ;
291- } ;
292- _paramList . remove = _paramList . write ;
293- } else if (
294- prov . params &&
295- prov . params . option &&
296- prov . params . option . type &&
297- prov . params . option . type === "text"
298- ) {
299- let optName = prov . params . option . description || _ ( "Parameter" ) ;
300- var _paramText = s . option ( form . Value , "_paramText_" + i , optName ) ;
301- _paramText . template = prov . template ;
302- _paramText . modalonly = true ;
303- _paramText . depends ( "_provider" , prov . template ) ;
304- _paramText . optional = ! (
305- prov . params . option . default && prov . params . option . default !== ""
306- ) ;
307- _paramText . cfgvalue = function ( section_id ) {
308- let resolver = this . map . data . get (
309- this . map . config ,
310- section_id ,
311- "resolver_url"
312- ) ;
313- if ( resolver === undefined || resolver === null ) return null ;
314- let regexp = pkg . templateToRegexp ( prov . template ) ;
315- let match = resolver . match ( regexp ) ;
316- return ( match && match [ 1 ] ) || null ;
317- } ;
318- _paramText . write = function ( section_id , formvalue ) {
319- let template = this . map . data . get (
320- this . map . config ,
321- section_id ,
322- "resolver_url"
276+ _paramList . depends ( "_provider" , prov . template ) ;
277+ _paramList . write = function ( section_id , formvalue ) {
278+ let template = this . map . data . get (
279+ this . map . config ,
280+ section_id ,
281+ "resolver_url"
282+ ) ;
283+ if ( ! formvalue && _paramList . template !== template ) return 0 ;
284+ let resolver = pkg . templateToResolver ( _paramList . template , {
285+ option : formvalue || "" ,
286+ } ) ;
287+ L . uci . set ( pkg . Name , section_id , "resolver_url" , resolver ) ;
288+ } ;
289+ _paramList . remove = _paramList . write ;
290+ } else if ( prov . params . option . type === "text" ) {
291+ let optName = prov . params . option . description || _ ( "Parameter" ) ;
292+ var _paramText = s . option ( form . Value , "_paramText_" + i , optName ) ;
293+ _paramText . template = prov . template ;
294+ _paramText . modalonly = true ;
295+ _paramText . depends ( "_provider" , prov . template ) ;
296+ _paramText . optional = ! (
297+ prov . params . option . default && prov . params . option . default !== ""
323298 ) ;
324- if ( ! formvalue && _paramText . template !== template ) return 0 ;
325- let resolver = pkg . templateToResolver ( _paramText . template , {
326- option : formvalue || "" ,
327- } ) ;
328- L . uci . set ( pkg . Name , section_id , "resolver_url" , resolver ) ;
329- } ;
330- _paramText . remove = _paramText . write ;
299+ _paramText . cfgvalue = function ( section_id ) {
300+ let resolver = this . map . data . get (
301+ this . map . config ,
302+ section_id ,
303+ "resolver_url"
304+ ) ;
305+ if ( resolver === undefined || resolver === null ) return null ;
306+ let regexp = pkg . templateToRegexp ( prov . template ) ;
307+ let match = resolver . match ( regexp ) ;
308+ return ( match && match [ 1 ] ) || null ;
309+ } ;
310+ _paramText . write = function ( section_id , formvalue ) {
311+ let template = this . map . data . get (
312+ this . map . config ,
313+ section_id ,
314+ "resolver_url"
315+ ) ;
316+ if ( ! formvalue && _paramText . template !== template ) return 0 ;
317+ let resolver = pkg . templateToResolver ( _paramText . template , {
318+ option : formvalue || "" ,
319+ } ) ;
320+ L . uci . set ( pkg . Name , section_id , "resolver_url" , resolver ) ;
321+ } ;
322+ _paramText . remove = _paramText . write ;
323+ }
331324 }
325+ }
326+
327+ function createBootstrapWidget ( s , i , prov ) {
332328 const _boot_dns = s . option (
333329 form . Value ,
334330 "_bootstrap_dns_" + i ,
@@ -346,32 +342,25 @@ return view.extend({
346342 return c_value || prov . bootstrap_dns || "" ;
347343 } ;
348344 _boot_dns . write = function ( section_id , formvalue ) {
349- const resolver = this . map . data . get (
350- this . map . config ,
351- section_id ,
352- "resolver_url"
353- ) ;
354- const regexp = pkg . templateToRegexp ( _boot_dns . template ) ;
355- if ( regexp . test ( resolver ) ) {
356- console . log (
345+ if ( formvalue )
346+ L . uci . set ( pkg . Name , section_id , "bootstrap_dns" , formvalue ) ;
347+ else
348+ L . uci . set (
357349 pkg . Name ,
358350 section_id ,
359351 "bootstrap_dns" ,
360- formvalue ,
361352 this . cfgvalue ( section_id )
362353 ) ;
363- if ( formvalue )
364- L . uci . set ( pkg . Name , section_id , "bootstrap_dns" , formvalue ) ;
365- else
366- L . uci . set (
367- pkg . Name ,
368- section_id ,
369- "bootstrap_dns" ,
370- this . cfgvalue ( section_id )
371- ) ;
372- }
373354 _boot_dns . remove = _boot_dns . write ;
374355 } ;
356+ }
357+
358+ reply . providers . forEach ( ( prov , i ) => {
359+ if ( prov . http2_only && ! reply . platform . http2_support ) return ;
360+ if ( prov . http3_only && ! reply . platform . http3_support ) return ;
361+ _provider . value ( prov . template , _ ( prov . title ) ) ;
362+ createProviderWidget ( s , i , prov ) ;
363+ createBootstrapWidget ( s , i , prov ) ;
375364 } ) ;
376365
377366 o = s . option ( form . Value , "listen_addr" , _ ( "Listen Address" ) ) ;
0 commit comments