@@ -87,7 +87,6 @@ function load_html_elements() {
8787
8888function load_bots ( config ) {
8989 // Build side menu
90- console . log ( config ) ;
9190 for ( let bot_group of Object . keys ( config ) . reverse ( ) ) {
9291 let $bot_group = $ ( "#templates > ul.side-menu > li" ) . clone ( ) . prependTo ( "#side-menu" ) . css ( "border-bottom-color" , GROUP_COLORS [ bot_group ] [ 0 ] ) ;
9392 $bot_group . find ( "> a" ) . prepend ( bot_group ) ;
@@ -184,10 +183,11 @@ function load_bots(config) {
184183
185184function fill_editDefault ( data ) {
186185 table . innerHTML = '' ;
187-
186+ insertBorder ( BORDER_TYPES . DEFAULT ) ;
188187 for ( let key in data ) {
189- insertKeyValue ( key , data [ key ] , 'defaultConfig' , false ) ;
188+ insertKeyValue ( key , data [ key ] , BORDER_TYPES . DEFAULT , true ) ;
190189 }
190+
191191 // to enable scroll bar
192192 popup . setAttribute ( 'class' , "with-bot" ) ;
193193}
@@ -250,29 +250,18 @@ function save_data_on_files() {
250250 }
251251
252252 Promise . all ( [
253- authenticatedAjax ( { "type" : "POST" , "url" : API + '/save?file= runtime' , "data" : generate_runtime_conf ( app . nodes ) } )
253+ authenticatedAjax ( { "type" : "POST" , "url" : API + '/runtime' , "contentType" : "application/json" , " data" : generate_runtime_conf ( app . nodes , app . defaults ) } )
254254 . done ( saveSucceeded )
255255 . fail ( ( ) => {
256256 alert_error ( 'runtime' , ...arguments )
257257 } ) ,
258- authenticatedAjax ( { "type" : "POST" , "url" : API + '/save?file=pipeline' , "data" : generate_pipeline_conf ( app . edges ) } )
259- . done ( saveSucceeded )
260- . fail ( ( ) => {
261- alert_error ( 'pipeline' , ...arguments )
262- } ) ,
263- authenticatedAjax ( { "type" : "POST" , "url" : API + '/save?file=positions' , "data" : generate_positions_conf ( ) } )
258+ authenticatedAjax ( { "type" : "POST" , "url" : API + '/positions' , "contentType" : "application/json" , "data" : generate_positions_conf ( ) } )
264259 . done ( saveSucceeded )
265260 . fail ( ( ) => {
266261 alert_error ( 'positions' , ...arguments )
267- } ) ,
268- authenticatedAjax ( { "type" : "POST" , "url" : API + '/save?file=defaults' , "data" : generate_defaults_conf ( app . defaults ) } )
269- . done ( saveSucceeded )
270- . fail ( ( ) => {
271- alert_error ( 'defaults' , ...arguments )
272- } ) , ] )
262+ } ) ] )
273263 . then ( function ( ) {
274264 // all files were correctly saved
275- app . nodes = add_defaults_to_nodes ( app . nodes , app . defaults ) ;
276265 $saveButton . unblinking ( ) ;
277266 } ) ;
278267}
@@ -312,8 +301,8 @@ function convert_nodes(nodes, includePositions) {
312301
313302 for ( index in nodes ) {
314303 var new_node = { } ;
315- new_node . id = nodes [ index ] [ 'id ' ] ;
316- new_node . label = nodes [ index ] [ 'id ' ] ;
304+ new_node . id = nodes [ index ] [ 'bot_id ' ] ;
305+ new_node . label = nodes [ index ] [ 'bot_id ' ] ;
317306 new_node . group = nodes [ index ] [ 'group' ] ;
318307
319308 if ( includePositions === true ) {
@@ -359,7 +348,7 @@ function fill_bot(id, group, name) {
359348
360349 app . bot_before_altering = bot ;
361350
362- insertKeyValue ( 'id' , bot [ 'id ' ] , 'id' , false ) ;
351+ insertKeyValue ( 'id' , bot [ 'bot_id ' ] , 'id' , false ) ;
363352 insertBorder ( BORDER_TYPES . GENERIC ) ;
364353 for ( let key in bot ) {
365354 if ( STARTUP_KEYS . includes ( key ) ) {
@@ -370,10 +359,6 @@ function fill_bot(id, group, name) {
370359 for ( let key in bot . parameters ) {
371360 insertKeyValue ( key , bot . parameters [ key ] , BORDER_TYPES . RUNTIME , true ) ;
372361 }
373- insertBorder ( BORDER_TYPES . DEFAULT ) ;
374- for ( let key in bot . defaults ) {
375- insertKeyValue ( key , bot . defaults [ key ] , BORDER_TYPES . DEFAULT , false ) ;
376- }
377362
378363 const periodpos = bot [ 'module' ] . lastIndexOf ( '.' ) ;
379364 modulename = bot [ 'module' ] . substring ( 0 , periodpos ) . replace ( / \. / g, "-" ) . replace ( / _ / g, "-" ) ;
@@ -403,6 +388,8 @@ function insertBorder(border_type) {
403388 break ;
404389 case BORDER_TYPES . DEFAULT :
405390 new_row . setAttribute ( 'class' , BORDER_TYPE_CLASSES . DEFAULT ) ;
391+ $ ( addButtonCell ) . append ( $ ( "#templates > .new-key-btn" ) . clone ( ) . click ( addNewDefaultKey ) ) ;
392+ new_row . setAttribute ( 'id' , border_type ) ;
406393 break ;
407394 default :
408395 new_row . setAttribute ( 'class' , BORDER_TYPE_CLASSES . OTHERS ) ;
@@ -441,25 +428,14 @@ function insertKeyValue(key, value, section, allowXButtons, insertAt) {
441428 if ( allowXButtons === true ) {
442429 var xButton = document . createElement ( 'button' ) ;
443430 var xButtonSpan = document . createElement ( 'span' ) ;
444- if ( key in app . defaults ) {
445- xButtonSpan . setAttribute ( 'class' , 'glyphicon glyphicon-refresh' ) ;
446- xButton . setAttribute ( 'class' , 'btn btn-default' ) ;
447- xButton . setAttribute ( 'title' , 'reset to default' ) ;
448- xButton . addEventListener ( 'click' , function ( resetToDefault , key ) {
449- return function ( ) {
450- parameter_func ( resetToDefault , key )
451- }
452- } ( resetToDefault , key ) )
453- } else {
454- xButtonSpan . setAttribute ( 'class' , 'glyphicon glyphicon-remove-circle' ) ;
455- xButton . setAttribute ( 'class' , 'btn btn-danger' ) ;
456- xButton . setAttribute ( 'title' , 'delete parameter' ) ;
457- xButton . addEventListener ( 'click' , function ( deleteParameter , key ) {
458- return function ( ) {
459- parameter_func ( deleteParameter , key )
460- }
461- } ( deleteParameter , key ) )
462- }
431+ xButtonSpan . setAttribute ( 'class' , 'glyphicon glyphicon-remove-circle' ) ;
432+ xButton . setAttribute ( 'class' , 'btn btn-danger' ) ;
433+ xButton . setAttribute ( 'title' , 'delete parameter' ) ;
434+ xButton . addEventListener ( 'click' , function ( deleteParameter , key ) {
435+ return function ( ) {
436+ parameter_func ( deleteParameter , key )
437+ }
438+ } ( deleteParameter , key ) )
463439
464440 xButton . appendChild ( xButtonSpan ) ;
465441 xButtonCell . appendChild ( xButton ) ;
@@ -471,7 +447,9 @@ function insertKeyValue(key, value, section, allowXButtons, insertAt) {
471447 if ( value !== null && typeof value === "object" ) {
472448 value = JSON . stringify ( value ) ;
473449 }
474- valueInput . setAttribute ( 'value' , value ) ;
450+ if ( value !== null ) {
451+ valueInput . setAttribute ( 'value' , value ) ;
452+ }
475453}
476454
477455function resetToDefault ( input_id ) {
@@ -504,6 +482,28 @@ function addNewKey() {
504482 }
505483 } ) ;
506484}
485+ // same as above, with another border type
486+ function addNewDefaultKey ( ) {
487+ let $el = $ ( "#templates .modal-add-new-key" ) . clone ( ) ;
488+ popupModal ( "Add key" , $el , ( ) => {
489+ var current_index = $ ( '#' + BORDER_TYPES . RUNTIME ) . index ( ) ;
490+ var $key = $el . find ( "[name=newKeyInput]" ) ;
491+ var val = $el . find ( "[name=newValueInput]" ) . val ( ) ;
492+
493+ if ( ! PARAM_KEY_REGEX . test ( $key . val ( ) ) ) {
494+ show_error ( "Parameter names can only be composed of numbers, letters, hiphens and underscores" ) ;
495+ $key . focus ( ) ;
496+ return false ;
497+ } else {
498+ // inserts new value and focus the field
499+ insertKeyValue ( $key . val ( ) , val , BORDER_TYPES . DEFAULT , true , current_index + 1 ) ;
500+ // a bootstrap guru or somebody might want to rewrite this line without setTimeout
501+ setTimeout ( ( ) => {
502+ $ ( '#network-popUp .new-key-btn' ) . closest ( "tr" ) . next ( "tr" ) . find ( "input" ) . focus ( )
503+ } , 300 ) ;
504+ }
505+ } ) ;
506+ }
507507
508508$ ( document ) . keydown ( function ( event ) {
509509 if ( event . keyCode === 27 ) {
@@ -551,7 +551,7 @@ function saveFormData() {
551551
552552 switch ( keyCell . id ) {
553553 case 'id' :
554- node [ key ] = value ;
554+ node [ 'bot_id' ] = value ;
555555 break ;
556556 case 'generic' :
557557 node [ key ] = value ;
@@ -561,7 +561,7 @@ function saveFormData() {
561561 break ;
562562 case 'border' :
563563 break ;
564- case 'defaultConfig ' :
564+ case 'default ' :
565565 app . defaults [ key ] = value ;
566566 break ;
567567 default :
@@ -578,18 +578,18 @@ function saveData(data, callback) {
578578 saveFormData ( ) ;
579579
580580 // check inputs beeing valid
581- if ( node . id == '' && node . group == '' ) {
581+ if ( node . bot_id == '' && node . group == '' ) {
582582 show_error ( 'fields id and group must not be empty!' ) ;
583583 return ;
584584 }
585585
586- if ( node . id != app . bot_before_altering . id ) {
586+ if ( node . bot_id != app . bot_before_altering . bot_id ) {
587587 if ( ! confirm ( "When you edit an ID what you are doing in fact is to create a clone of the current bot. You will have to delete the old one manually. Proceed with the operation?" ) ) {
588588 return ;
589589 }
590590 }
591591
592- if ( ! BOT_ID_REGEX . test ( node . id ) ) {
592+ if ( ! BOT_ID_REGEX . test ( node . bot_id ) ) {
593593 show_error ( "Bot ID's can only be composed of numbers, letters and hiphens" ) ;
594594 return ;
595595 }
@@ -616,13 +616,13 @@ function saveData(data, callback) {
616616 }
617617 }
618618
619- data . id = node . id ;
620- data . label = node . id
619+ data . bot_id = node . bot_id ;
620+ data . label = node . bot_id
621621 data . group = node . group ;
622622 data . level = GROUP_LEVELS [ data . group ] ;
623623 data . title = JSON . stringify ( node , undefined , 2 ) . replace ( / \n / g, '\n<br>' ) . replace ( / / g, " " ) ;
624624
625- app . nodes [ node . id ] = node ;
625+ app . nodes [ node . bot_id ] = node ;
626626
627627 $saveButton . blinking ( ) ;
628628 clearPopUp ( data , callback ) ;
0 commit comments