blob: aa578c6692c02bdc52e25510f8f9f25fdb503b8d [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { actionTypes as commonActionTypes } from 'sdc-app/common/reducers/PlainDataReducerConstants.js';
17import { actionTypes as qcommonActionTypes } from 'sdc-app/common/reducers/JSONSchemaReducerConstants.js';
AviZi280f8012017-06-09 02:39:56 +030018
19class ValidationHelper {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020020 static dataChanged(
21 dispatch,
22 { deltaData, formName, customValidations = {} }
23 ) {
24 dispatch({
25 type: commonActionTypes.DATA_CHANGED,
26 deltaData,
27 formName,
28 customValidations
29 });
30 }
AviZi280f8012017-06-09 02:39:56 +030031
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020032 static validateForm(dispatch, formName) {
33 dispatch({
34 type: commonActionTypes.VALIDATE_FORM,
35 formName
36 });
37 }
AviZi280f8012017-06-09 02:39:56 +030038
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020039 static validateData(dispatch, { formName, data }) {
40 dispatch({
41 type: commonActionTypes.VALIDATE_DATA,
42 formName,
43 data
44 });
45 }
AviZi280f8012017-06-09 02:39:56 +030046
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020047 static qValidateData(dispatch, { data, qName, customValidations = {} }) {
48 dispatch({
49 type: qcommonActionTypes.VALIDATE_DATA,
50 data,
51 qName,
52 customValidations
53 });
54 }
AviZi280f8012017-06-09 02:39:56 +030055
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020056 static qValidateForm(dispatch, qName, customValidations) {
57 dispatch({
58 type: qcommonActionTypes.VALIDATE_FORM,
59 qName,
60 customValidations
61 });
62 }
AviZi280f8012017-06-09 02:39:56 +030063
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020064 static qDataChanged(
65 dispatch,
66 { deltaData, qName, customValidations = {} }
67 ) {
68 dispatch({
69 type: qcommonActionTypes.DATA_CHANGED,
70 deltaData,
71 qName,
72 customValidations
73 });
74 }
AviZi280f8012017-06-09 02:39:56 +030075
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020076 static qDataLoaded(dispatch, { qName, response: { qdata, qschema } }) {
77 dispatch({
78 type: qcommonActionTypes.DATA_LOADED,
79 payload: {
80 qdata,
81 qschema
82 },
83 qName
84 });
85 }
AviZi280f8012017-06-09 02:39:56 +030086
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020087 static checkFormValid(genericFieldInfo) {
88 for (let field in genericFieldInfo) {
89 if (!genericFieldInfo[field].isValid) {
90 return false;
91 }
92 }
93 return true;
94 }
AviZi280f8012017-06-09 02:39:56 +030095}
96
97export default ValidationHelper;