1
1
let piosk = {
2
- addNewUrl ( ) {
3
- let newUrl = $ ( '#new-url' ) . val ( )
4
- if ( ! newUrl ) return
2
+ addNewUrl ( ) {
3
+ let newUrl = $ ( '#new-url' ) . val ( ) ;
4
+ if ( ! newUrl ) return ;
5
5
6
- piosk . appendUrl ( newUrl )
7
- $ ( '#new-url' ) . val ( '' )
6
+ // Call appendUrl with just the URL, so it uses default settings (10s, 10 cycles)
7
+ piosk . appendUrl ( newUrl ) ;
8
+ $ ( '#new-url' ) . val ( '' ) ;
8
9
} ,
9
- appendUrl ( url ) {
10
- let tmpUrl = $ ( '#template-url' ) . contents ( ) . clone ( )
11
10
12
- $ ( tmpUrl ) . find ( 'a' ) . attr ( 'href' , url ) . html ( url )
13
- $ ( '#urls .list-group' ) . append ( tmpUrl )
11
+ // MODIFIED: Now accepts duration and cycles as arguments
12
+ appendUrl ( url , duration , cycles ) {
13
+ let tmpUrl = $ ( '#template-url' ) . contents ( ) . clone ( ) ;
14
+
15
+ $ ( tmpUrl ) . find ( 'a' ) . attr ( 'href' , url ) . html ( url ) ;
16
+
17
+ // If duration and cycles are provided from config, set them.
18
+ if ( duration ) {
19
+ $ ( tmpUrl ) . find ( '.duration-input' ) . val ( duration ) ;
20
+ }
21
+ if ( cycles ) {
22
+ $ ( tmpUrl ) . find ( '.cycles-input' ) . val ( cycles ) ;
23
+ }
24
+
25
+ $ ( '#urls .list-group' ) . append ( tmpUrl ) ;
14
26
} ,
15
- renderPage ( data ) {
16
- $ . each ( data . urls , ( index , item ) => {
17
- piosk . appendUrl ( item . url )
18
- } )
27
+
28
+ // MODIFIED: Now passes the full item data to appendUrl
29
+ renderPage ( data ) {
30
+ if ( data && data . urls ) {
31
+ $ . each ( data . urls , ( index , item ) => {
32
+ // Pass all the data (url, duration, cycles) to the updated function
33
+ piosk . appendUrl ( item . url , item . duration , item . cycles ) ;
34
+ } ) ;
35
+ }
19
36
} ,
20
- showStatus ( xhr ) {
21
- let tmpErr = $ ( '#template-err' ) . contents ( ) . clone ( )
22
- tmpErr . html ( xhr . responseText )
23
- $ ( '#urls' ) . append ( tmpErr )
24
- setTimeout ( _ => { $ ( '.alert-danger' ) . remove ( ) } , 5000 )
37
+
38
+ showStatus ( xhr ) {
39
+ let tmpErr = $ ( '#template-err' ) . contents ( ) . clone ( ) ;
40
+ tmpErr . html ( xhr . responseText ) ;
41
+ $ ( '#urls' ) . append ( tmpErr ) ;
42
+ setTimeout ( _ => { $ ( '.alert-danger' ) . remove ( ) } , 5000 ) ;
25
43
}
26
- }
44
+ } ;
27
45
28
46
$ ( document ) . ready ( ( ) => {
29
47
$ . getJSON ( '/config' )
30
- . done ( piosk . renderPage )
31
- . fail ( piosk . showStatus )
48
+ . done ( piosk . renderPage )
49
+ . fail ( piosk . showStatus ) ;
32
50
33
- $ ( '#add-url' ) . on ( 'click' , piosk . addNewUrl )
34
- $ ( '#new-url' ) . on ( 'keyup' , ( e ) => { if ( e . key === 'Enter' ) piosk . addNewUrl ( ) } )
51
+ $ ( '#add-url' ) . on ( 'click' , piosk . addNewUrl ) ;
52
+ $ ( '#new-url' ) . on ( 'keyup' , ( e ) => { if ( e . key === 'Enter' ) piosk . addNewUrl ( ) ; } ) ;
35
53
36
54
$ ( '#urls' ) . on ( 'click' , 'button.btn-close' , ( e ) => {
37
- $ ( e . target ) . parent ( ) . remove ( )
38
- } )
55
+ $ ( e . target ) . closest ( 'li.list-group-item' ) . remove ( ) ;
56
+ } ) ;
39
57
58
+ // MODIFIED: The #execute handler now saves all settings correctly
40
59
$ ( '#execute' ) . on ( 'click' , ( e ) => {
41
- let config = { }
42
- config . urls = [ ]
60
+ let config = { } ;
61
+ config . urls = [ ] ;
43
62
$ ( 'li.list-group-item' ) . each ( ( index , item ) => {
44
- config . urls . push ( { url : $ ( item ) . find ( 'a' ) . attr ( 'href' ) } )
45
- } )
63
+ // Now collecting all data: url, duration, and cycles
64
+ const url = $ ( item ) . find ( 'a' ) . attr ( 'href' ) ;
65
+ const duration = parseInt ( $ ( item ) . find ( '.duration-input' ) . val ( ) ) || 10 ;
66
+ const cycles = parseInt ( $ ( item ) . find ( '.cycles-input' ) . val ( ) ) || 10 ;
67
+
68
+ config . urls . push ( {
69
+ url : url ,
70
+ duration : duration ,
71
+ cycles : cycles
72
+ } ) ;
73
+ } ) ;
46
74
47
75
$ . ajax ( {
48
76
url : '/config' ,
@@ -52,6 +80,6 @@ $(document).ready(() => {
52
80
dataType : "json" ,
53
81
success : piosk . showStatus ,
54
82
error : piosk . showStatus
55
- } )
56
- } )
57
- } )
83
+ } ) ;
84
+ } ) ;
85
+ } ) ;
0 commit comments