Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2824 Fixed event handlers new xid not displaying after saving edit form #2959

Merged
7 changes: 0 additions & 7 deletions WebContent/WEB-INF/jsp/dataSourceEdit/editModbus.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@
return messages;
}

function validateValue(htmlId, messageText, validate, value, messages) {
if(!validate(value)) {
let message = createValidationMessage(htmlId, messageText);
messages.push(message);
}
}

function createLocatorConfigTemp(){
let temp = {};
temp.slaveId = $get("test_slaveId");
Expand Down
26 changes: 16 additions & 10 deletions WebContent/WEB-INF/jsp/eventHandlers.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -456,36 +456,43 @@
var xid = $get("xid");
var alias = $get("alias");
var disabled = $get("disabled");
if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_EMAIL %>"/>) {
var messages = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messages to delete

if (!(isNotEmpty(xid)) && handlerId !== ${NEW_ID}){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!(isNotEmpty(xid)) - Instead of so many negations, it is worth creating the isEmpty method.

validateValue("xid", "<fmt:message key='validate.valueRestored'/>", isNotEmpty, xid, messages)
Copy link
Collaborator

@Limraj Limraj Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove use validateValue:
let message = createValidationMessage("xid", "<fmt:message key='validate.valueRestored'/>");

$set("xid", selectedHandlerNode.object.xid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added lines:

stopImageFader("saveImg");
showDwrMessages(message);
return;

}
if(messages.length > 0){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if to delete

stopImageFader("saveImg");
showDwrMessages(messages);
}
else {
Copy link
Collaborator

@Limraj Limraj Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What comes after ifa needs to be restored.
You only add a new if at the end of return, we do not make any other changes.

if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_EMAIL %>"/>) {
var emailList = emailRecipients.createRecipientArray();
var escalList = escalRecipients.createRecipientArray();
var inactiveList = inactiveRecipients.createRecipientArray();
EventHandlersDwr.saveEmailEventHandler(selectedEventTypeNode.object.typeId,
selectedEventTypeNode.object.typeRef1, selectedEventTypeNode.object.typeRef2, handlerId, xid, alias,
disabled, emailList, $get("sendEscalation"), $get("escalationDelayType"), $get("escalationDelay"),
escalList, $get("sendInactive"), $get("inactiveOverride"), inactiveList, saveEventHandlerCB);
}
else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_SMS %>"/>) {
} else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_SMS %>"/>) {
var smsList = smsRecipients.createRecipientArray();
EventHandlersDwr.saveSmsEventHandler(selectedEventTypeNode.object.typeId,
selectedEventTypeNode.object.typeRef1, selectedEventTypeNode.object.typeRef2, handlerId, xid, alias, disabled, smsList, saveEventHandlerCB);
}
else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_SET_POINT %>"/>) {
} else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_SET_POINT %>"/>) {
EventHandlersDwr.saveSetPointEventHandler(selectedEventTypeNode.object.typeId,
selectedEventTypeNode.object.typeRef1, selectedEventTypeNode.object.typeRef2, handlerId, xid, alias,
disabled, $get("targetPointSelect"), $get("activeAction"), $get("setPointValueActive"),
$get("activePointId"), $get("inactiveAction"), $get("setPointValueInactive"),
$get("inactivePointId"), saveEventHandlerCB);
}
else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_PROCESS %>"/>) {
} else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_PROCESS %>"/>) {
EventHandlersDwr.saveProcessEventHandler(selectedEventTypeNode.object.typeId,
selectedEventTypeNode.object.typeRef1, selectedEventTypeNode.object.typeRef2, handlerId, xid,
alias, disabled, $get("activeProcessCommand"), $get("inactiveProcessCommand"), saveEventHandlerCB);
}
else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_SCRIPT %>"/>) {
} else if (handlerType == <c:out value="<%= EventHandlerVO.TYPE_SCRIPT %>"/>) {
EventHandlersDwr.saveScriptEventHandler(selectedEventTypeNode.object.typeId,
selectedEventTypeNode.object.typeRef1, selectedEventTypeNode.object.typeRef2, handlerId, xid,
alias, disabled, $get("activeScriptCommand"), $get("inactiveScriptCommand"), saveEventHandlerCB);
}
}
}

Expand All @@ -508,7 +515,6 @@

selectedHandlerNode.object = handler;
}
$set("xid", handler.xid);
}

function deleteHandler() {
Expand Down
11 changes: 11 additions & 0 deletions WebContent/resources/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,3 +1260,14 @@ function OnListWebsocketStats() {
console.log("message[/app/websocketStats]:\n" + message.body);
} );
}

function validateValue(htmlId, messageText, validate, value, messages) {
if(!validate(value)) {
let message = createValidationMessage(htmlId, messageText);
messages.push(message);
}
}

function isNotEmpty(value) {
return !(value == null || (typeof value === "string" && value.trim() === ""))
}
7 changes: 6 additions & 1 deletion src/com/serotonin/mango/web/dwr/EventHandlersDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ private DwrResponseI18n save(int eventSourceId, int eventTypeRef1,
EventService eventService = new EventService();

vo.setId(handlerId);
vo.setXid(StringUtils.isEmpty(xid) ? eventService.generateUniqueXid() : xid);
if (StringUtils.isEmpty(xid) && handlerId == Common.NEW_ID) {
vo.setXid(StringUtils.isEmpty(xid) ? eventService.generateUniqueXid() : xid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vo.setXid(eventService.generateUniqueXid());

}
else {
vo.setXid(xid);
}
vo.setAlias(alias);
vo.setDisabled(disabled);

Expand Down
1 change: 1 addition & 0 deletions webapp-resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2989,6 +2989,7 @@ validate.required=Required value
validate.text.incompatible=Text renderer is incompatible with data type
validate.event.incompatible=Event text renderer is incompatible with data type
validate.xidUsed=This XID is already in use
validate.valueRestored=Previous value restored
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.
Need to update for each translation files.

viewEdit.addViewComponent=Add component to view
viewEdit.anonymous=Anonymous access
viewEdit.background=Background image
Expand Down
Loading