blob: cfa675278f33f99a958c6c0782b12a1a7c9830cb [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 */
16import {actionTypes as commonActionTypes} from 'sdc-app/common/reducers/PlainDataReducerConstants.js';
17import {actionTypes as qcommonActionTypes} from 'sdc-app/common/reducers/JSONSchemaReducerConstants.js';
18
19class ValidationHelper {
20
21 static dataChanged(dispatch, {deltaData, formName, customValidations = {}}){
22 dispatch({
23 type: commonActionTypes.DATA_CHANGED,
24 deltaData,
25 formName,
26 customValidations
27 });
28 }
29
30 static validateForm(dispatch, formName){
31 dispatch({
32 type: commonActionTypes.VALIDATE_FORM,
33 formName
34 });
35 }
36
37 static validateData(dispatch, {formName, data}) {
38 dispatch({
39 type: commonActionTypes.VALIDATE_DATA,
40 formName,
41 data
42 });
43 }
44
45 static qValidateData(dispatch, {data, qName, customValidations = {}}) {
46 dispatch({
47 type: qcommonActionTypes.VALIDATE_DATA,
48 data,
49 qName,
50 customValidations
51 });
52 }
53
az2497644017c2017-08-10 17:49:40 +030054 static qValidateForm(dispatch, qName, customValidations){
AviZi280f8012017-06-09 02:39:56 +030055 dispatch({
56 type: qcommonActionTypes.VALIDATE_FORM,
az2497644017c2017-08-10 17:49:40 +030057 qName,
58 customValidations
AviZi280f8012017-06-09 02:39:56 +030059 });
60 }
61
62 static qDataChanged(dispatch, {deltaData, qName, customValidations = {}}){
63 dispatch({
64 type: qcommonActionTypes.DATA_CHANGED,
65 deltaData,
66 qName,
67 customValidations
68 });
69 }
70
71 static qDataLoaded(dispatch, {qName, response: {qdata, qschema}}) {
72 dispatch({
73 type: qcommonActionTypes.DATA_LOADED,
74 payload: {
75 qdata,
76 qschema
77 },
78 qName
79 });
80 }
81
82 static checkFormValid(genericFieldInfo) {
83 for (let field in genericFieldInfo) {
84 if (!genericFieldInfo[field].isValid) {
85 return false;
86 }
87 }
88 return true;
89 }
90}
91
92export default ValidationHelper;