regionschools.actions.ts 1.67 KB
Newer Older
1
import { NgRedux } from "@angular-redux/store";
2
3
4
5
6
7
8
9
import { Injectable } from "@angular/core";

import {
    REGIONSCHOOLS_INIT,
    REGIONSCHOOLS_ORDER_SAVE,
    REGIONSCHOOLS_RECEIVED,
    REGIONSCHOOLS_SELECTED_SAVE,
} from "../constants";
10
import { HelperDataService } from "../services/helper-data-service";
11
import { IAppState } from "../store";
12
13
14

@Injectable()
export class RegionSchoolsActions {
15
16
17
    constructor(
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService) { }
18

19
20
21
22
23
24
25
26
27
28
    getRegionSchools = (classActive, courseActive, reload) => {
        const { regions } = this._ngRedux.getState();
        if (reload === true || (reload === false && regions.size === 0)) {
            return this._hds.getRegionsWithSchools(classActive, courseActive).then(regions => {
                return this._ngRedux.dispatch({
                    type: REGIONSCHOOLS_RECEIVED,
                    payload: {
                        regions
                    }
                });
29
            });
30
31
        }
    };
32

33
34
35
36
37
    initRegionSchools = () => {
        return this._ngRedux.dispatch({
            type: REGIONSCHOOLS_INIT,
            payload: {
            }
38
        });
39
    };
40

41
42
43
44
45
46
47
48
49
50
    saveRegionSchoolsSelected = (checked, i, j) => {
        return this._ngRedux.dispatch({
            type: REGIONSCHOOLS_SELECTED_SAVE,
            payload: {
                checked: checked,
                rIndex: i,
                sIndex: j
            }
        });
    };
51

52
53
54
55
56
57
58
59
    saveRegionSchoolsOrder = (selectedSchools) => {
        return this._ngRedux.dispatch({
            type: REGIONSCHOOLS_ORDER_SAVE,
            payload: {
                selectedSchools
            }
        });
    };
60

61
}