From 75edf8a55f07782d6474e7932ec91a3a031776ab Mon Sep 17 00:00:00 2001 From: wildone Date: Fri, 28 Jun 2024 17:08:18 +1000 Subject: [PATCH] update common form event config. --- .../dialog/tabs/event/.content.json | 16 ++ .../forms/form/clientlibs/functions.js | 4 +- .../forms/form/dialog/.content.json | 155 ++---------------- .../clientlibs-header/events/functions.js | 10 +- 4 files changed, 39 insertions(+), 146 deletions(-) diff --git a/application/backend/src/main/resources/apps/typerefinery/components/dialog/tabs/event/.content.json b/application/backend/src/main/resources/apps/typerefinery/components/dialog/tabs/event/.content.json index 6ad9d6132..58f939012 100644 --- a/application/backend/src/main/resources/apps/typerefinery/components/dialog/tabs/event/.content.json +++ b/application/backend/src/main/resources/apps/typerefinery/components/dialog/tabs/event/.content.json @@ -12,6 +12,7 @@ }, "info": { "sling:resourceType": "typerefinery/components/dialog/label", + "ws:disallowedContext": ["edit:panel"], "appearance": "info", "iconLabel": "Info", "title": "Map component actions to events, this allows you to respond to component actions in other components.", @@ -106,6 +107,21 @@ "label": "Success", "value": "successaction" }, + "cancel": { + "sling:resourceType": "typerefinery/components/dialog/select/selectitem", + "label": "Cancel", + "value": "cancelaction" + }, + "reset": { + "sling:resourceType": "typerefinery/components/dialog/select/selectitem", + "label": "Reset", + "value": "resetaction" + }, + "submit": { + "sling:resourceType": "typerefinery/components/dialog/select/selectitem", + "label": "Submit", + "value": "submitaction" + }, "error": { "sling:resourceType": "typerefinery/components/dialog/select/selectitem", "label": "Error", diff --git a/application/backend/src/main/resources/apps/typerefinery/components/forms/form/clientlibs/functions.js b/application/backend/src/main/resources/apps/typerefinery/components/forms/form/clientlibs/functions.js index 56e83532d..40ab97f55 100644 --- a/application/backend/src/main/resources/apps/typerefinery/components/forms/form/clientlibs/functions.js +++ b/application/backend/src/main/resources/apps/typerefinery/components/forms/form/clientlibs/functions.js @@ -501,7 +501,7 @@ window.Typerefinery.Page.Files = Typerefinery.Page.Files || {}; //register events if (events) { events.forEach(event => { - const { topic, type, name, nameCustom, action } = event; + const { topic, type, name, nameCustom, action, config} = event; //if topic not set use component id as topic const topicName = topic || defaultTopic; // if type is not defined then its emitted @@ -511,7 +511,7 @@ window.Typerefinery.Page.Files = Typerefinery.Page.Files || {}; let eventName = nameCustom || name; console.log(["registerEventActionMapping", JSON.stringify(ns.eventMap), topicName, typeName, action, eventName]); - eventNs.registerEventActionMapping(ns.eventMap, topicName, typeName, action, eventName); + eventNs.registerEventActionMapping(ns.eventMap, id, topicName, typeName, action, eventName, config); console.log(["registerEventActionMapping", JSON.stringify(ns.eventMap)]); // if event type is listen then add event listener for the event diff --git a/application/backend/src/main/resources/apps/typerefinery/components/forms/form/dialog/.content.json b/application/backend/src/main/resources/apps/typerefinery/components/forms/form/dialog/.content.json index fed93aa78..e6cc5adf7 100644 --- a/application/backend/src/main/resources/apps/typerefinery/components/forms/form/dialog/.content.json +++ b/application/backend/src/main/resources/apps/typerefinery/components/forms/form/dialog/.content.json @@ -17,22 +17,12 @@ "sling:resourceType": "wcm/dialogs/components/tab", "label": "Events", "warning": { - "sling:resourceType": "typerefinery/components/dialog/label", - "ws:disallowedContext": ["edit:dialog"], - "appearance": "error", - "iconLabel": "Open Dialog", - "title": "Some fields are not editable in side-panel.", - "secondaryText": "", - "placement": "bottom-start" + "sling:resourceType": "wcm/dialogs/components/include", + "path": "/apps/typerefinery/components/dialog/tabs/event/warning" }, "info": { - "sling:resourceType": "typerefinery/components/dialog/label", - "ws:disallowedContext": ["edit:panel"], - "appearance": "info", - "iconLabel": "Info", - "title": "Map component actions to events, this allows you to respond to component actions in other components.", - "secondaryText": "", - "placement": "bottom-start" + "sling:resourceType": "wcm/dialogs/components/include", + "path": "/apps/typerefinery/components/dialog/tabs/event/info" }, "event": { "sling:resourceType": "wcm/dialogs/components/multifield", @@ -41,28 +31,12 @@ "description": "Pick generic event or specify custom event to which component action will be mapped.", "label": "Events", "topic": { - "sling:resourceType": "wcm/dialogs/components/textfield", - "name": "topic", - "label": "Topic", - "description": "The topic of the event, default is component id." + "sling:resourceType": "wcm/dialogs/components/include", + "path": "/apps/typerefinery/components/dialog/tabs/event/event/topic" }, "type": { - "sling:resourceType": "wcm/dialogs/components/select", - "name": "type", - "label": "Event Type", - "description": "How will the component interact with the event system.", - "listen": { - "sling:resourceType": "wcm/dialogs/components/select/selectitem", - "label": "Listen", - "value": "listen", - "selected": true - }, - "emit": { - "sling:resourceType": "wcm/dialogs/components/select/selectitem", - "label": "Emit", - "value": "emit", - "selected": true - } + "sling:resourceType": "wcm/dialogs/components/include", + "path": "/apps/typerefinery/components/dialog/tabs/event/event/type" }, "eventAction": { "sling:resourceType": "typerefinery/components/dialog/eventactions", @@ -71,113 +45,16 @@ "description": "Which component action to map to event." }, "eventName": { - "sling:resourceType": "typerefinery/components/dialog/select", - "name": "name", - "allowCreate": true, - "label": "Event Name", - "description": "Event Name of the even raised by the component", - "default": { - "sling:resourceType": "typerefinery/components/dialog/select/selectgroup", - "label": "Default", - "default": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Custom", - "value": "" - } - }, - "componentcrud": { - "sling:resourceType": "typerefinery/components/dialog/select/selectgroup", - "label": "Component", - "create": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Create", - "value": "createaction" - }, - "read": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Read", - "value": "readaction" - }, - "update": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Update", - "value": "updateaction" - }, - "delete": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Delete", - "value": "deleteaction" - }, - "filter": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Filter", - "value": "filteraction" - } - }, - "generic": { - "sling:resourceType": "typerefinery/components/dialog/select/selectgroup", - "label": "Generic", - "success": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Success", - "value": "successaction" - }, - "cancel": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Cancel", - "value": "cancelaction" - }, - "reset": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Reset", - "value": "resetaction" - }, - "submit": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Submit", - "value": "submitaction" - }, - "error": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Error", - "value": "erroraction" - } - }, - "itemcrud": { - "sling:resourceType": "typerefinery/components/dialog/select/selectgroup", - "label": "Item", - "create": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Create", - "value": "createitem" - }, - "read": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Read", - "value": "readitem" - }, - "update": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Update", - "value": "updateitem" - }, - "delete": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Delete", - "value": "deleteitem" - }, - "seelect": { - "sling:resourceType": "typerefinery/components/dialog/select/selectitem", - "label": "Select", - "value": "selectitem" - } - } + "sling:resourceType": "wcm/dialogs/components/include", + "path": "/apps/typerefinery/components/dialog/tabs/event/event/eventName" }, "eventNameCustom": { - "sling:resourceType": "wcm/dialogs/components/textfield", - "name": "nameCustom", - "label": "Custom Event Name", - "description": "Custom Event Name of the even raised by the component" + "sling:resourceType": "wcm/dialogs/components/include", + "path": "/apps/typerefinery/components/dialog/tabs/event/event/eventNameCustom" + }, + "eventConfig": { + "sling:resourceType": "wcm/dialogs/components/include", + "path": "/apps/typerefinery/components/dialog/tabs/event/event/eventConfig" } } }, diff --git a/application/backend/src/main/resources/apps/typerefinery/components/structure/page/clientlibs-header/events/functions.js b/application/backend/src/main/resources/apps/typerefinery/components/structure/page/clientlibs-header/events/functions.js index 6ae280fc1..b61b06c9a 100644 --- a/application/backend/src/main/resources/apps/typerefinery/components/structure/page/clientlibs-header/events/functions.js +++ b/application/backend/src/main/resources/apps/typerefinery/components/structure/page/clientlibs-header/events/functions.js @@ -63,7 +63,7 @@ Typerefinery.Page.Events = Typerefinery.Page.Events || {}; //add event mapping in eventMap local to component, maps component action to topic with event, for quick access by functions. ns.registerEventActionMapping = function(eventMap, componentId, topic, type, componentAction, eventName, config) { console.group('registerEventActionMapping'); - console.log(eventMap, topic, type, componentAction, eventName, config); + console.log(eventMap, componentId, topic, type, componentAction, eventName, config); //check if params are passed if (!topic || !componentAction || !eventMap) { console.error("missing params"); @@ -87,19 +87,19 @@ Typerefinery.Page.Events = Typerefinery.Page.Events || {}; //init event type, EMIT or LISTEN if (!eventMap[type]) { eventMap[type] = {}; - console.warn(`event type not found ${type}, creating new type ${type}`); + console.warn(`event type not found ${type} in eventMap, creating new type ${type}`); } //init component action that maps to event name if (!eventMap[type][componentAction]) { eventMap[type][componentAction] = {}; - console.warn(`event action not found ${componentAction}, creating new action ${componentAction}`); + console.warn(`event action not found ${componentAction} in eventMap[${type}], creating new action ${componentAction}`); } //init mapped event name to component id if (!eventMap[type][componentAction][componentId]) { eventMap[type][componentAction][componentId] = {}; - console.warn(`component id not found ${componentId}, creating new component id ${componentId}`); + console.warn(`component id not found ${componentId} in eventMap[${type}][${componentAction}], creating new component id ${componentId}`); } console.log(["topicAction", topicAction]); @@ -107,7 +107,7 @@ Typerefinery.Page.Events = Typerefinery.Page.Events || {}; //init mapped event name that maps to topic if (!eventMap[type][componentAction][componentId][eventName]) { eventMap[type][componentAction][componentId][eventName] = [topicAction]; - console.warn(`event name not found ${eventName}, creating new event name with topic ${topic}`); + console.warn(`event name not found ${eventName} in eventMap[${type}][${componentAction}][${componentId}], creating new event name with topic ${topic}`); } else { //add event to type eventMap[type][componentAction][componentId][eventName].push(topicAction);