@@ -231,7 +231,7 @@ export default class AcademicSubquery extends Morph {
231231 default :
232232 return op ;
233233 } } ;
234-
234+
235235 this . updateView ( ) ;
236236
237237 observer = new MutationObserver ( ( mutations ) => {
@@ -395,15 +395,15 @@ export default class AcademicSubquery extends Morph {
395395 var attribute , comp , val ;
396396 if ( this . editing ) { // edit mode
397397 var attrElement = innerSpan . querySelector ( '#attribute' ) ;
398- attribute = attrElement . options [ attrElement . selectedIndex ] . value // or .text;
398+ attribute = attrElement . options [ attrElement . selectedIndex ] . value ; // or .text;
399399 var compElement = innerSpan . querySelector ( '#comparator' ) ;
400- comp = compElement . options [ compElement . selectedIndex ] . value // or .text;
400+ comp = compElement . options [ compElement . selectedIndex ] . value ; // or .text;
401401 val = innerSpan . querySelector ( '#value' ) . value ;
402402 } else { // read mode
403403 //lively.notify("INNERSPAN", innerSpan)
404404 [ attribute , comp , val ] = innerSpan
405- . querySelectorAll ( "span[name='queryPart']" )
406- . map ( e => e . textContent ) ;
405+ . querySelectorAll ( "span[name='queryPart']" )
406+ . map ( e => e . textContent ) ;
407407 }
408408
409409 var currentAttribute ;
@@ -431,43 +431,72 @@ export default class AcademicSubquery extends Morph {
431431 }
432432
433433 async toggleEditing ( ) {
434- await this . setQuery ( await this . viewToQuery ( ) ) ; // update query from changes
434+ var currentQuery = await this . viewToQuery ( )
435435 this . editing = ! this . editing ;
436- this . ui = await this . queryToView ( ) ; // update ui to read-mode
436+ await this . setQuery ( currentQuery ) ; // update query from changes
437+ //this.ui = await this.queryToView(); // update ui to read-mode
437438 this . updateView ( ) ;
438439 }
439440
441+ onChangeAttribute ( ) {
442+ var innerSpan = this . get ( '#inner' ) ;
443+ var compElement = innerSpan . querySelector ( '#comparator' ) ;
444+ var attrElement = innerSpan . querySelector ( '#attribute' ) ;
445+
446+ var selectedAttribute = attrElement . options [ attrElement . selectedIndex ] . value ;
447+ var currentAttribute ;
448+ this . schemaFiltered . forEach ( option => {
449+ if ( option . name == selectedAttribute ) { currentAttribute = option ; }
450+ } )
451+
452+ var selectedComparator = compElement . options [ compElement . selectedIndex ] . value ;
453+ // clear options
454+ var optionsLength = compElement . options . length ;
455+ for ( var i = optionsLength ; i >= 0 ; i -- ) {
456+ compElement . remove ( i ) ;
457+ }
458+ currentAttribute . operations . split ( ", " )
459+ . map ( operation => this . mapOperationToSymbol ( operation ) ) // map words to arrays of symbols
460+ . flat ( )
461+ . filter ( ( item , pos , self ) => self . indexOf ( item ) == pos ) // deduplicate
462+ . forEach ( option => {
463+ var selected = ( option == selectedComparator ) ;
464+ compElement . options . add ( new Option ( option , option , selected , selected ) )
465+ } ) ;
466+ }
467+
440468 // builds the UI in edit mode
441469 async buildEditable ( ast ) {
442470 var inner = < span id = "inner" > </ span > ;
443471 var query = < span name = "sub" draggable = 'false' > </ span > ;
444472
445473 // attribute
446- var attribute = < select name = 'attribute' id = 'attribute' > </ select > ;
447- // var selectedAttribute; // TODO: Klassenvariable?
474+ var attrElement = < select name = 'attribute' id = 'attribute' > </ select > ;
475+ var currentAttribute ;
448476 this . schemaFiltered . forEach ( option => {
449477 var selected = ( option . name == ast . attribute ) ;
450- if ( selected ) { this . selectedAttribute = option ; }
451- attribute . options . add ( new Option ( option . shortDesc , option . name , selected , selected ) )
478+ if ( selected ) { currentAttribute = option ; }
479+ attrElement . options . add ( new Option ( option . shortDesc , option . name , selected , selected ) )
452480 } )
453- query . appendChild ( attribute ) ;
481+ attrElement . onchange = ( ) => this . onChangeAttribute ( ) ;
482+ query . appendChild ( attrElement ) ;
454483
455484 // comparator
456- var comparator = < select name = 'comparator' id = 'comparator' > </ select > ;
457- this . selectedAttribute . operations . split ( ", " )
485+ var compElement = < select name = 'comparator' id = 'comparator' > </ select > ;
486+ currentAttribute . operations . split ( ", " )
458487 . map ( operation => this . mapOperationToSymbol ( operation ) ) // map words to arrays of symbols
459488 . flat ( )
460489 . filter ( ( item , pos , self ) => self . indexOf ( item ) == pos ) // deduplicate
461490 . forEach ( option => {
462491 var selected = ( option == ast . comparator ) ;
463- comparator . options . add ( new Option ( option , option , selected , selected ) )
492+ compElement . options . add ( new Option ( option , option , selected , selected ) )
464493 } ) ;
465- query . appendChild ( comparator ) ;
494+ query . appendChild ( compElement ) ;
466495
467496 // value
468- var value = < input id = "value" name = "value" value = { ast . value } > </ input > ;
497+ var valElement = < input id = "value" name = "value" value = { ast . value } > </ input > ;
469498 // TODO: fit input type to attribute type
470- query . appendChild ( value ) ;
499+ query . appendChild ( valElement ) ;
471500
472501 inner . appendChild ( query ) ;
473502
0 commit comments