blob: 51dfcf9a677dd1930947c9d69216f556995ee974 [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
54 static qValidateForm(dispatch, qName){
55 dispatch({
56 type: qcommonActionTypes.VALIDATE_FORM,
57 qName
58 });
59 }
60
61 static qDataChanged(dispatch, {deltaData, qName, customValidations = {}}){
62 dispatch({
63 type: qcommonActionTypes.DATA_CHANGED,
64 deltaData,
65 qName,
66 customValidations
67 });
68 }
69
70 static qDataLoaded(dispatch, {qName, response: {qdata, qschema}}) {
71 dispatch({
72 type: qcommonActionTypes.DATA_LOADED,
73 payload: {
74 qdata,
75 qschema
76 },
77 qName
78 });
79 }
80
81 static checkFormValid(genericFieldInfo) {
82 for (let field in genericFieldInfo) {
83 if (!genericFieldInfo[field].isValid) {
84 return false;
85 }
86 }
87 return true;
88 }
89}
90
91export default ValidationHelper;