AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 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 | */ |
| 16 | import {actionTypes as commonActionTypes} from 'sdc-app/common/reducers/PlainDataReducerConstants.js'; |
| 17 | import {actionTypes as qcommonActionTypes} from 'sdc-app/common/reducers/JSONSchemaReducerConstants.js'; |
| 18 | |
| 19 | class 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 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 54 | static qValidateForm(dispatch, qName, customValidations){ |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 55 | dispatch({ |
| 56 | type: qcommonActionTypes.VALIDATE_FORM, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 57 | qName, |
| 58 | customValidations |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | }); |
| 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 | |
| 92 | export default ValidationHelper; |