From c4000d2bc9eef7723e957da1f9bf2824d931fd29 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Wed, 1 Dec 2021 21:35:08 -0400 Subject: [PATCH] fix: Set default values with containerManager. --- .../ADempiere/PanelDefinition/index.vue | 2 +- .../ADempiere/dictionary/window/actions.js | 80 +++++++++++++++++++ src/store/modules/ADempiere/windowManager.js | 77 ------------------ .../ADempiere/constants/actionsMenuList.js | 2 +- src/views/ADempiere/Browser/index.vue | 7 ++ src/views/ADempiere/Process/index.vue | 6 ++ src/views/ADempiere/Window/MultiTabWindow.vue | 2 +- src/views/ADempiere/Window/index.vue | 7 ++ 8 files changed, 103 insertions(+), 80 deletions(-) diff --git a/src/components/ADempiere/PanelDefinition/index.vue b/src/components/ADempiere/PanelDefinition/index.vue index 79a8f88d7af..ebcfbceb859 100644 --- a/src/components/ADempiere/PanelDefinition/index.vue +++ b/src/components/ADempiere/PanelDefinition/index.vue @@ -55,7 +55,7 @@ export default defineComponent({ const metadata = ref({}) if (root.$route.query.action === 'create-new') { - root.$store.dispatch('dataManager/setDefaultValues', { + props.containerManager.setDefaultValues({ parentUuid: props.parentUuid, containerUuid: props.containerUuid }) diff --git a/src/store/modules/ADempiere/dictionary/window/actions.js b/src/store/modules/ADempiere/dictionary/window/actions.js index 8fcf2160bf3..0da73bef85c 100644 --- a/src/store/modules/ADempiere/dictionary/window/actions.js +++ b/src/store/modules/ADempiere/dictionary/window/actions.js @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import router from '@/router' + // api request methods import { requestWindowMetadata } from '@/api/ADempiere/dictionary/window.js' @@ -113,5 +115,83 @@ export default { }) } } + }, + + /** + * Set default values to panel + * @param {string} parentUuid + * @param {string} containerUuid + * TODO: Evaluate if it is necessary to parse the default values + */ + setTabDefaultValues({ commit, dispatch, rootGetters }, { + parentUuid, + containerUuid, + isOverWriteParent = true + }) { + return new Promise(resolve => { + const tab = rootGetters.getStoredTab(parentUuid, containerUuid) + + const currentRoute = router.app._route + delete currentRoute.query.filters + // set action + router.push({ + name: currentRoute.name, + params: { + ...currentRoute.params + }, + query: { + ...currentRoute.query, + action: 'create-new' + } + }, () => {}) + + let defaultAttributes = rootGetters.getParsedDefaultValues({ + parentUuid, + containerUuid, + isSOTrxMenu: currentRoute.meta.isSalesTransaction, + fieldsList: tab.fieldsList + }) + + // set vales with permant link + if (!rootGetters['permantLink/isReadFilters'] && + containerUuid === rootGetters['permantLink/getLinkContainerUuid']) { + const parsedFilters = rootGetters['permantLink/getParsedFilters'] + if (!isEmptyValue(parsedFilters)) { + // merge values + defaultAttributes = defaultAttributes.map(attribute => { + const filterValue = parsedFilters[attribute.columnName] + return { + ...attribute, + value: filterValue + } + }) + } + + commit('permantLink/setIsReadFilters', null, { + root: true + }) + } + + defaultAttributes.forEach(attribute => { + commit('addChangeToPersistenceQueue', { + ...attribute, + containerUuid + }, { + root: true + }) + }) + + dispatch('updateValuesOfContainer', { + parentUuid, + containerUuid, + isOverWriteParent, + attributes: defaultAttributes + }, { + root: true + }) + + resolve(defaultAttributes) + }) } + } diff --git a/src/store/modules/ADempiere/windowManager.js b/src/store/modules/ADempiere/windowManager.js index 4ad770115e3..63af7543936 100644 --- a/src/store/modules/ADempiere/windowManager.js +++ b/src/store/modules/ADempiere/windowManager.js @@ -70,83 +70,6 @@ const windowManager = { }, actions: { - /** - * Set default values to panel - * @param {string} parentUuid - * @param {string} containerUuid - * TODO: Evaluate if it is necessary to parse the default values - */ - setDefaultValues({ commit, dispatch, rootGetters }, { - parentUuid, - containerUuid, - isOverWriteParent = true - }) { - return new Promise(resolve => { - const tab = rootGetters.getStoredTab(parentUuid, containerUuid) - - const currentRoute = router.app._route - delete currentRoute.query.filters - // set action - router.push({ - name: currentRoute.name, - params: { - ...currentRoute.params - }, - query: { - ...currentRoute.query, - action: 'create-new' - } - }, () => {}) - - let defaultAttributes = rootGetters.getParsedDefaultValues({ - parentUuid, - containerUuid, - isSOTrxMenu: currentRoute.meta.isSalesTransaction, - fieldsList: tab.fieldsList - }) - - // set vales with permant link - if (!rootGetters['permantLink/isReadFilters'] && - containerUuid === rootGetters['permantLink/getLinkContainerUuid']) { - const parsedFilters = rootGetters['permantLink/getParsedFilters'] - if (!isEmptyValue(parsedFilters)) { - // merge values - defaultAttributes = defaultAttributes.map(attribute => { - const filterValue = parsedFilters[attribute.columnName] - return { - ...attribute, - value: filterValue - } - }) - } - - commit('permantLink/setIsReadFilters', null, { - root: true - }) - } - - defaultAttributes.forEach(attribute => { - commit('addChangeToPersistenceQueue', { - ...attribute, - containerUuid - }, { - root: true - }) - }) - - dispatch('updateValuesOfContainer', { - parentUuid, - containerUuid, - isOverWriteParent, - attributes: defaultAttributes - }, { - root: true - }) - - resolve(defaultAttributes) - }) - }, - createEntity({ rootGetters }, { diff --git a/src/utils/ADempiere/constants/actionsMenuList.js b/src/utils/ADempiere/constants/actionsMenuList.js index 016200ba7f1..dfe9b22bea5 100644 --- a/src/utils/ADempiere/constants/actionsMenuList.js +++ b/src/utils/ADempiere/constants/actionsMenuList.js @@ -30,7 +30,7 @@ export const createNewRecord = { icon: 'el-icon-circle-plus-outline', actionName: 'createNewRecord', createNewRecord: ({ root, parentUuid, containerUuid }) => { - root.$store.dispatch('dataManager/setDefaultValues', { + root.$store.dispatch('setTabDefaultValues', { parentUuid, containerUuid }) diff --git a/src/views/ADempiere/Browser/index.vue b/src/views/ADempiere/Browser/index.vue index 4f6eabd8d8d..74775ebecd8 100644 --- a/src/views/ADempiere/Browser/index.vue +++ b/src/views/ADempiere/Browser/index.vue @@ -237,6 +237,13 @@ export default defineComponent({ }) }, + setDefaultValues: ({ parentUuid, containerUuid }) => { + root.$store.dispatch('setBrowserDefaultValues', { + parentUuid, + containerUuid + }) + }, + /** * Is displayed field in panel single record */ diff --git a/src/views/ADempiere/Process/index.vue b/src/views/ADempiere/Process/index.vue index 4d4d845a4a5..6e4a6bf655a 100644 --- a/src/views/ADempiere/Process/index.vue +++ b/src/views/ADempiere/Process/index.vue @@ -179,6 +179,12 @@ export default defineComponent({ // }) }, + setDefaultValues: ({ containerUuid }) => { + root.$store.dispatch('setProcessDefaultValues', { + containerUuid + }) + }, + isDisplayedField, isReadOnlyField({ diff --git a/src/views/ADempiere/Window/MultiTabWindow.vue b/src/views/ADempiere/Window/MultiTabWindow.vue index f56a2daf223..af6ce2e1122 100644 --- a/src/views/ADempiere/Window/MultiTabWindow.vue +++ b/src/views/ADempiere/Window/MultiTabWindow.vue @@ -104,7 +104,7 @@ export default defineComponent({ seekRecord: ({ row, tableName, parentUuid, containerUuid }) => { if (root.isEmptyValue(row)) { - root.$store.dispatch('dataManager/setDefaultValues', { + root.$store.dispatch('setTabDefaultValues', { parentUuid, containerUuid }) diff --git a/src/views/ADempiere/Window/index.vue b/src/views/ADempiere/Window/index.vue index 376d44be4c1..192f2e93a6d 100644 --- a/src/views/ADempiere/Window/index.vue +++ b/src/views/ADempiere/Window/index.vue @@ -88,6 +88,13 @@ export default defineComponent({ return new Promise() }, + setDefaultValues: ({ parentUuid, containerUuid }) => { + root.$store.dispatch('setTabDefaultValues', { + parentUuid, + containerUuid + }) + }, + seekRecord: function(eventInfo) { console.log('seekRecord: ', eventInfo) // return new Promise()