2018-02-21 13:59:08 +01:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* EditPage actions
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-21 18:45:18 +01:00
|
|
|
import { get } from 'lodash';
|
|
|
|
|
import { getValidationsFromForm } from 'utils/formValidations';
|
|
|
|
|
|
2018-02-21 13:59:08 +01:00
|
|
|
import {
|
2018-02-21 15:09:33 +01:00
|
|
|
CHANGE_DATA,
|
|
|
|
|
GET_DATA,
|
|
|
|
|
GET_DATA_SUCCEEDED,
|
2018-02-21 13:59:08 +01:00
|
|
|
INIT_MODEL_PROPS,
|
2018-02-21 18:45:18 +01:00
|
|
|
ON_CANCEL,
|
2018-02-21 15:33:58 +01:00
|
|
|
RESET_PROPS,
|
2018-02-27 16:24:46 +01:00
|
|
|
SET_FILE_RELATIONS,
|
2018-03-06 09:31:44 +01:00
|
|
|
SET_LOADER,
|
2018-02-21 18:45:18 +01:00
|
|
|
SET_FORM_ERRORS,
|
2018-02-22 11:33:01 +01:00
|
|
|
SUBMIT,
|
|
|
|
|
SUBMIT_SUCCESS,
|
2018-03-06 09:31:44 +01:00
|
|
|
UNSET_LOADER,
|
2018-02-21 13:59:08 +01:00
|
|
|
} from './constants';
|
|
|
|
|
|
2018-02-21 15:09:33 +01:00
|
|
|
export function changeData({ target }) {
|
|
|
|
|
return {
|
|
|
|
|
type: CHANGE_DATA,
|
|
|
|
|
keys: target.name.split('.'),
|
|
|
|
|
value: target.value,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getData(id, source, mainField) {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_DATA,
|
|
|
|
|
id,
|
|
|
|
|
source,
|
|
|
|
|
mainField,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getDataSucceeded(id, data, pluginHeaderTitle) {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_DATA_SUCCEEDED,
|
|
|
|
|
id,
|
|
|
|
|
data,
|
|
|
|
|
pluginHeaderTitle,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 18:45:18 +01:00
|
|
|
export function initModelProps(modelName, isCreating, source, attributes) {
|
|
|
|
|
const formValidations = getValidationsFromForm(
|
|
|
|
|
Object.keys(attributes).map(attr => ({ name: attr, validations: get(attributes, attr, {}) })),
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
2018-02-21 13:59:08 +01:00
|
|
|
return {
|
|
|
|
|
type: INIT_MODEL_PROPS,
|
2018-02-21 18:45:18 +01:00
|
|
|
formValidations,
|
2018-02-21 13:59:08 +01:00
|
|
|
isCreating,
|
2018-02-21 18:45:18 +01:00
|
|
|
modelName,
|
2018-02-21 15:09:33 +01:00
|
|
|
source,
|
2018-02-21 13:59:08 +01:00
|
|
|
};
|
|
|
|
|
}
|
2018-02-21 15:33:58 +01:00
|
|
|
|
2018-02-21 18:45:18 +01:00
|
|
|
export function onCancel() {
|
|
|
|
|
return {
|
|
|
|
|
type: ON_CANCEL,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 15:33:58 +01:00
|
|
|
export function resetProps() {
|
|
|
|
|
return {
|
|
|
|
|
type: RESET_PROPS,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-02-21 18:45:18 +01:00
|
|
|
|
2018-02-27 16:24:46 +01:00
|
|
|
export function setFileRelations(fileRelations) {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_FILE_RELATIONS,
|
|
|
|
|
fileRelations,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 18:45:18 +01:00
|
|
|
export function setFormErrors(formErrors) {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_FORM_ERRORS,
|
|
|
|
|
formErrors,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-02-22 11:33:01 +01:00
|
|
|
|
2018-03-06 09:31:44 +01:00
|
|
|
export function setLoader() {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_LOADER,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 11:33:01 +01:00
|
|
|
export function submit() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function submitSuccess() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT_SUCCESS,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-03-06 09:31:44 +01:00
|
|
|
|
|
|
|
|
export function unsetLoader() {
|
|
|
|
|
return {
|
|
|
|
|
type: UNSET_LOADER,
|
|
|
|
|
};
|
|
|
|
|
}
|