aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/checklist/models/Checklist.ts
blob: 7b50dd309c3b708be7bc066468ec909f19ca8bb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { ChecklistItemModel } from "./ChecklistItem";

export class ChecklistModel {
    public selectedValues: any[];
    public checkboxes: ChecklistItemModel[];
    constructor(selectedValues: any[], checkboxes: ChecklistItemModel[]) {
        this.selectedValues = selectedValues || [];
        this.checkboxes = checkboxes;
        // align the selected values list and checkboxes isChecked param
        this.checkboxes.forEach((checkbox: ChecklistItemModel) => {
            if (this.selectedValues.indexOf(checkbox.value) > -1) {
                checkbox.isChecked = true;
            }else if (checkbox.isChecked) {
                this.selectedValues.push(checkbox.value);
            }
        });
    }
}