You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
willaengine/resources/js/Global/store/modules/modal/actions.js

73 lines
2.4 KiB

5 years ago
import $_can from "@Global/policy/can";
5 years ago
export default {
openModal({ state, rootState }, data) { // data: {name, rel, model, form_data, data, modal_pop_data, type}
5 years ago
let can = true;
if (data.can) {
can = $_can(data.can);
}
if (can) {
data.name = 'modal_' + data.name;
if (state.modals.findIndex(x => x.name == data.name) == -1) {
state.modals.push(data);
let module = data.name.split("_");
if (data.rel) {
rootState[module[1]].relation = data.rel;
5 years ago
state.rel.push(data.rel);
}
if (data.model) {
rootState[module[1]].current_model = data.model;
5 years ago
state.model.push(data.model);
}
rootState[module[1]].page_type = data.page_type ? data.page_type : 'modal';
}
}
},
$_closeModal({ state, rootState }) {
if (state.modals.length) {
let last_data = [...state.modals].pop();
let module = last_data.name.split("_")[1];
if (state.modals.length > 1) {
state.modals[state.modals.length - 2]['last_modal_data'] = last_data;
} else {
rootState[module].page_type = '';
}
if(last_data.rel) {
state.rel.pop();
if (state.rel.length) {
rootState[module].relation = state.rel[state.rel.length - 1];
} else {
rootState[module].relation = {};
}
}
if(last_data.model) {
state.model.pop();
if (state.model.length) {
rootState[module].current_model = state.model[state.model.length - 1];
} else {
rootState[module].current_model = {};
}
}
state.modals.pop();
}
},
$_dialog:({commit, dispatch}, properties) => {
properties['name'] = 'modal_dialog';
dispatch('openModal', properties);
commit('SET_DIALOG_TYPE', properties.type);
commit('SET_DIALOG_PROPERTIES', properties);
},
$_helper:({dispatch}, slug) => {
let data = {};
data['name'] = 'modal_helper';
data['slug'] = slug;
dispatch('openModal', data);
},
5 years ago
};