langcoursesfields.actions.ts 1.72 KB
Newer Older
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 55 56 57 58
import { NgRedux } from "@angular-redux/store";
import { Injectable } from "@angular/core";

import { LANGCOURSEFIELDS_INIT, LANGCOURSEFIELDS_RECEIVED, LANGCOURSEFIELDS_SELECTED_SAVE, LANGCOURSES_ORDER_SAVE } from "../constants";
import { HelperDataService } from "../services/helper-data-service";
import { IAppState } from "../store";

@Injectable()
export class LangCourseFieldsActions {
    constructor(
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService) { }

    getLangCourseFields = (reload) => {
        const { langcourseFields } = this._ngRedux.getState();

        if (reload === true || (reload === false && langcourseFields.size === 0)) {
            return this._hds.getLangCourseFields().then(langcourseFields => {
                return this._ngRedux.dispatch({
                    type: LANGCOURSEFIELDS_RECEIVED,
                    payload: {
                        langcourseFields
                    }
                });
            });
        }
    };

    initLangCourseFields = () => {
        return this._ngRedux.dispatch({
            type: LANGCOURSEFIELDS_INIT,
            payload: {
            }
        });
    };


    saveLangCourseFieldsSelected = (newChoice: number, isSelected: number, orderId: number) => {
        return this._ngRedux.dispatch({
            type: LANGCOURSEFIELDS_SELECTED_SAVE,
            payload: {
                newChoice: newChoice,
                isSelected: isSelected,
                orderId: orderId,
            }
        });
    };

    saveCoursesOrder = (selectedCourses) => {
        return this._ngRedux.dispatch({
            type: LANGCOURSES_ORDER_SAVE,
            payload: {
                selectedCourses
            }
        });
    };

}