@@ -17,7 +17,7 @@ var config = {
17
17
18
18
// Check that the config is complete first otherwise show config interface
19
19
if ( ! config . check ( ) ) {
20
- $ ( "#app-setup" ) . show ( ) ; // Show setup block
20
+ config . showConfig ( ) ; // Show setup block
21
21
$ ( ".ajax-loader" ) . hide ( ) ; // Hide AJAX loader
22
22
config . UI ( ) ; // Populate setup UI options
23
23
} else {
@@ -29,18 +29,21 @@ var config = {
29
29
config . initialized = true ; // Init app
30
30
config . showapp ( ) ;
31
31
}
32
-
33
- $ ( "body" ) . on ( "click" , ".openconfig" , function ( ) {
34
- $ ( "#app-block" ) . hide ( ) ;
35
- $ ( "#app-setup" ) . show ( ) ;
32
+
33
+ $ ( "body" ) . on ( "click" , ".openconfig" , function ( event ) {
34
+ config . showConfig ( ) ;
36
35
config . UI ( ) ;
37
- config . hideapp ( ) ;
38
36
} ) ;
39
37
40
- $ ( "body" ) . on ( "click" , ".launchapp" , function ( ) {
38
+ // don't save and just show app
39
+ $ ( "body" ) . on ( "click" , ".close-config" , function ( event ) {
40
+ config . closeConfig ( ) ;
41
+ } ) ;
42
+
43
+ // save and show app
44
+ $ ( "body" ) . on ( "click" , ".launchapp" , function ( ) {
41
45
$ ( ".ajax-loader" ) . show ( ) ;
42
- $ ( "#app-setup" ) . hide ( ) ;
43
- $ ( "#app-block" ) . show ( ) ;
46
+ config . closeConfig ( ) ;
44
47
config . load ( ) ;
45
48
if ( ! config . initialized ) { config . initapp ( ) ; config . initialized = true ; }
46
49
config . showapp ( ) ;
@@ -65,6 +68,31 @@ var config = {
65
68
} ) ;
66
69
} ) ;
67
70
} ,
71
+ /**
72
+ * hide the app config window and show the app.
73
+ * enable the buttons in the app header
74
+ */
75
+ closeConfig : function ( ) {
76
+ $ ( "#app-block" ) . toggleClass ( 'hide' , false ) . show ( ) ;
77
+
78
+ $ ( "#app-setup" ) . toggleClass ( 'hide' , true ) ;
79
+
80
+ $ ( '.openconfig' ) . toggleClass ( 'hide' , false ) ;
81
+ $ ( '.close-config' ) . toggleClass ( 'hide' , true ) ;
82
+ $ ( '#buttons #tabs .btn' ) . attr ( 'disabled' , false ) . css ( 'opacity' , 1 ) ;
83
+ } ,
84
+ /**
85
+ * hide the app window and show the config window.
86
+ * disable the buttons in the app header
87
+ */
88
+ showConfig : function ( ) {
89
+ $ ( "#app-block" ) . toggleClass ( 'hide' , true ) ;
90
+ $ ( "#app-setup" ) . toggleClass ( 'hide' , false ) . show ( ) ;
91
+
92
+ $ ( '.openconfig' ) . toggleClass ( 'hide' , true ) ;
93
+ $ ( '.close-config' ) . toggleClass ( 'hide' , false ) ;
94
+ $ ( '#buttons #tabs .btn' ) . attr ( 'disabled' , true ) . css ( 'opacity' , .2 ) ;
95
+ } ,
68
96
69
97
UI : function ( ) {
70
98
$ ( ".app-config" ) . html ( "" ) ;
@@ -111,9 +139,16 @@ var config = {
111
139
// Create list of feeds that satisfy engine requirement
112
140
var out = "<option value=0>Select " + z + " feed:</option>" ;
113
141
out += "<option value=auto>AUTO SELECT</option>" ;
114
- for ( var n in config . feedsbyname ) {
115
- if ( config . engine_check ( config . feedsbyname [ n ] , config . app [ z ] ) ) {
116
- out += "<option value=" + config . feedsbyname [ n ] . id + ">" + config . feedsbyname [ n ] . name + "</option>" ;
142
+ var sortedFeeds = [ ] ;
143
+ for ( var n in config . feedsbyname ) {
144
+ let feed = config . feedsbyname [ n ] ;
145
+ feed . longname = config . feedsbyname [ n ] . tag + ":" + config . feedsbyname [ n ] . name ;
146
+ sortedFeeds . push ( feed ) ;
147
+ }
148
+ sortedFeeds . sort ( config . sortByLongname )
149
+ for ( var n in sortedFeeds ) {
150
+ if ( config . engine_check ( sortedFeeds [ n ] , config . app [ z ] ) ) {
151
+ out += "<option value=" + sortedFeeds [ n ] . id + ">" + sortedFeeds [ n ] . tag + ":" + sortedFeeds [ n ] . name + "</option>" ;
117
152
}
118
153
}
119
154
configItem . find ( ".feed-select" ) . html ( out ) ;
@@ -336,9 +371,19 @@ var config = {
336
371
result = JSON . parse ( result ) ;
337
372
if ( result . success != undefined && ! result . success ) app_log ( "ERROR" , result . message ) ;
338
373
} catch ( e ) {
339
- app . log ( "ERROR" , "Could not parse /setconfig reply, error: " + e ) ;
374
+ try {
375
+ app . log ( "ERROR" , "Could not parse /setconfig reply, error: " + e ) ;
376
+ } catch ( e2 ) {
377
+ console . log ( e , e2 ) ;
378
+ }
340
379
}
341
380
}
342
381
} ) ;
382
+ } ,
383
+
384
+ sortByLongname : function ( a , b ) {
385
+ var aName = a . longname . toLowerCase ( ) ;
386
+ var bName = b . longname . toLowerCase ( ) ;
387
+ return ( ( aName < bName ) ? - 1 : ( ( aName > bName ) ? 1 : 0 ) ) ;
343
388
}
344
- }
389
+ }
0 commit comments