all files / component/combo-list/container/ combo-list.component.ts

100% Statements 20/20
66.67% Branches 4/6
100% Functions 6/6
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                                                         
/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
import { Component } from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { IDejaAction } from '../../../common/core/action.interface';
import { DejaComboListBase } from '../model/combo-list.base';
 
@Component({
    selector: 'deja-combo-list',
    template: require('./combo-list.component.html'),
    styles: [require('./combo-list.component.scss')],
    providers: [{
        provide: NG_VALUE_ACCESSOR,
        useExisting: DejaComboListComponent,
        multi: true,
    }],
})
export class DejaComboListComponent<T> extends DejaComboListBase<T> implements ControlValueAccessor {
 
    // Select
    public toSelectListAction(listAction: IDejaAction): void {
        this.doAction(listAction, 'toggleSelectable', 'raiseOne');
    }
 
    // Deselect
    public selectedListAction(listAction: IDejaAction): void {
        this.doAction(listAction, 'toggleSelected', 'dropOne');
    }
 
    // ActionBar
    public actionBarAction(listAction: IDejaAction): void {
        Eif (listAction.type) {
            this.state[listAction.type]();
        }
    }
 
    // action launcher
    private doAction(listAction: IDejaAction, singleAction: string, doubleAction: string) {
        if (listAction.type === 'single') {
            this.state[singleAction](listAction.payload);
        } else Eif (listAction.type === 'double') {
            this.state[doubleAction](listAction.payload);
        }
 
    }
}