@@ -56,6 +56,7 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
5656 this . workergroupPanels . push ( workerPanel ) ;
5757 if ( workergroup != null )
5858 {
59+ this . serials [ workergroupName ] = workergroup [ "serial" ]
5960 _ . forEach ( workergroup [ "profiles" ] , function ( profile , profileName ) {
6061 this . addProfileToPanel ( workerPanel , profile , profileName ) ;
6162 } , this ) ;
@@ -79,19 +80,21 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
7980 remove_profile : function ( ) {
8081 } ,
8182
82- reload : function ( ) {
83- if ( confirm ( 'It will discard every changes that hasn\'t be saved. Are you sure?' ) ) {
83+ reload : function ( force = false ) {
84+ if ( force || confirm ( 'It will discard every changes that hasn\'t be saved. Are you sure?' ) ) {
8485 _ . forEach ( this . workergroupPanels , function ( panel ) {
85- if ( panel != null && panel != undefined )
86+ if ( panel !== null && panel != = undefined )
8687 panel . destroy ( ) ;
8788 delete panel ;
8889 } )
8990 this . render ( ) ;
9091 }
9192 } ,
9293
94+
9395 // Check for "continue" usage instead of nested ifs
9496 save : function ( ) {
97+ var _this = this ;
9598 this . commandPanel . _controls [ "Status" ] . setValue ( "<font color=\"orange\">Saving...</font>" ) ;
9699
97100 data = { } ;
@@ -106,9 +109,12 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
106109 "profiles" : { } ,
107110 "process_termination_timeout" : parseInt ( panelJSON [ "Process Termination Timeout" ] , 10 )
108111 }
112+
113+ if ( panelJSON [ "Workgroup Name" ] in _this . serials )
114+ workergroup [ "serial" ] = _this . serials [ panelJSON [ "Workgroup Name" ] ] ;
115+
109116 _ . forEach ( _ . range ( 1 , panel . profilesNumber + 1 ) , function ( index ) {
110117 header = "Profile " + String ( index ) + " - " ;
111- console . log ( panelJSON [ header + "Profile Name" ] )
112118 if ( $ . inArray ( panelJSON [ header + "Profile Name" ] , [ null , "" ] ) == - 1 )
113119 {
114120 profile = { } ;
@@ -124,21 +130,35 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
124130 }
125131 }
126132 } )
127- console . log ( data )
128133
129134 $ . post ( "/api/workergroups" , { "workergroups" : JSON . stringify ( data ) } ) . done ( function ( result ) {
130- if ( result . status != "ok" ) {
135+ if ( result . status === "ok" )
136+ {
137+ _this . commandPanel . _controls [ "Status" ] . setValue ( "<font color=\"green\">Saved</font>" ) ;
138+ _this . reload ( true ) ;
139+ }
140+ else if ( result . status === "outdated" )
141+ {
142+ string = "" ;
143+ _ . forEach ( result . outdated_wgcs , function ( wgc ) {
144+ string += "- " + wgc + "<br>" ;
145+ } )
146+ _this . commandPanel . _controls [ "Status" ] . setValue ( "<font color=\"red\">These configurations were outdated and were not saved:<br>" + string + "</font><br>The others were saved." ) ;
147+ }
148+ else
149+ {
150+ _this . commandPanel . _controls [ "Status" ] . setValue ( "<font color=\"red\">FAILED</font>" ) ;
131151 return alert ( "There was an error while saving!" ) ;
132152 }
133153 } ) ;
134- this . commandPanel . _controls [ "Status" ] . setValue ( "<font color=\"green\">Saved</font>" ) ;
135154 } ,
136155
137156 render : function ( ) {
138157 var _this = this ;
139158
140159 this . workergroupPanels = [ ] ;
141160 this . addCommandPanel ( ) ;
161+ this . serials = { } ;
142162
143163 $ . get ( "/api/workergroups" ) . done ( function ( data ) {
144164 _ . forEach ( data [ "workergroups" ] , function ( workergroup , workergroupName ) {
0 commit comments