Skip to content

Commit

Permalink
update common form event config.
Browse files Browse the repository at this point in the history
  • Loading branch information
wildone committed Jun 28, 2024
1 parent e752ec2 commit 75edf8a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -87,27 +87,27 @@ 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]);

//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);
Expand Down

0 comments on commit 75edf8a

Please sign in to comment.