Skip to content

Commit 4b904cf

Browse files
committed
bug fix to popup messages to allow for non json
1 parent 5180a5d commit 4b904cf

2 files changed

Lines changed: 63 additions & 30 deletions

File tree

src/js/api.library.js

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -549,18 +549,26 @@ api.modal.confirm = function (pMessage, pCallbackMethod, pCallbackParams, pIconT
549549
try {
550550
msgObj = JSON.parse(pMessage);
551551
} catch (ex) {
552-
//cant convert to json as is a string
553-
msgObj = { 'title': pMessage };
552+
//leave the message as it is
553+
msgObj = pMessage;
554554
}
555555
} else {
556+
//leave the message as it is
556557
msgObj = pMessage;
557558
}
558559

559-
$("#modal-confirm").find('[name=message-content]').empty();
560-
$("#modal-confirm").find('[name=message-text]').empty().html(msgObj.title);
560+
if (msgObj.hasOwnProperty('title')) {
561+
//for alternative modal
562+
$("#modal-confirm").find('[name=message-text]').empty().html(msgObj.title);
563+
}
564+
else {
565+
$("#modal-confirm").find('[name=message-text]').empty().html(msgObj);
566+
}
561567

562568
if (msgObj.hasOwnProperty('message')) {
563569
$("#modal-confirm").find('[name=message-content]').empty().html(msgObj.message);
570+
} else {
571+
$("#modal-confirm").find('[name=message-content]').empty();
564572
}
565573

566574
let iconType = "";
@@ -576,7 +584,7 @@ api.modal.confirm = function (pMessage, pCallbackMethod, pCallbackParams, pIconT
576584
$("#modal-confirm").find("[name=confirm]").removeClass().addClass("btn btn-warning");
577585
}
578586

579-
$("#modal-confirm").find('[name=icon-type]').removeClass().addClass(iconType + " fa-5x");//.html(iconType);
587+
$("#modal-confirm").find('[name=icon-type]').removeClass().addClass(iconType + " fa-5x");
580588

581589
$("#modal-confirm").find("[name=confirm]").once("click", function () {
582590
// Must wait for the async transition to finsh before invoking the callback function that may be a cascade confirm
@@ -612,19 +620,26 @@ api.modal.success = function (pMessage) {
612620
try {
613621
msgObj = JSON.parse(pMessage);
614622
} catch (ex) {
615-
//cant convert to json as is a string
616-
msgObj = { 'title': pMessage };
623+
//leave the message as it is
624+
msgObj = pMessage;
617625
}
618626
} else {
627+
//leave the message as it is
619628
msgObj = pMessage;
620629
}
621630

622-
$("#modal-success").find('[name=message-content]').empty();
623-
624-
$("#modal-success").find('[name=message-text]').empty().html(msgObj.title);
631+
if (msgObj.hasOwnProperty('title')) {
632+
//for alternative modal
633+
$("#modal-success").find('[name=message-text]').empty().html(msgObj.title);
634+
}
635+
else {
636+
$("#modal-success").find('[name=message-text]').empty().html(msgObj);
637+
}
625638

626639
if (msgObj.hasOwnProperty('message')) {
627640
$("#modal-success").find('[name=message-content]').empty().html(msgObj.message);
641+
} else {
642+
$("#modal-success").find('[name=message-content]').empty();
628643
}
629644

630645
$("#modal-success").find("[name=success]").once("click", function () {
@@ -699,20 +714,26 @@ api.modal.information = function (pMessage) {
699714
try {
700715
msgObj = JSON.parse(pMessage);
701716
} catch (ex) {
702-
//cant convert to json as is a string
703-
msgObj = { 'title': pMessage };
717+
//leave the message as it is
718+
msgObj = pMessage;
704719
}
705720
} else {
721+
//leave the message as it is
706722
msgObj = pMessage;
707723
}
708724

709-
710-
$("#modal-information").find('[name=message-content]').empty();
711-
712-
$("#modal-information").find('[name=message-text]').empty().html(msgObj.title);
725+
if (msgObj.hasOwnProperty('title')) {
726+
//for alternative modal
727+
$("#modal-information").find('[name=message-text]').empty().html(msgObj.title);
728+
}
729+
else {
730+
$("#modal-information").find('[name=message-text]').empty().html(msgObj);
731+
}
713732

714733
if (msgObj.hasOwnProperty('message')) {
715734
$("#modal-information").find('[name=message-content]').empty().html(msgObj.message);
735+
} else {
736+
$("#modal-information").find('[name=message-content]').empty();
716737
}
717738

718739
$("#modal-information").find("[name=information]").once("click", function () {
@@ -724,7 +745,6 @@ api.modal.information = function (pMessage) {
724745
$('.modal-hidden').removeClass('d-none');
725746
});
726747

727-
728748
// Display the Modal
729749
$("#modal-information").modal("show");
730750
};
@@ -739,19 +759,26 @@ api.modal.warning = function (pMessage) {
739759
try {
740760
msgObj = JSON.parse(pMessage);
741761
} catch (ex) {
742-
//cant convert to json as is a string
743-
msgObj = { 'title': pMessage };
762+
//leave the message as it is
763+
msgObj = pMessage;
744764
}
745765
} else {
766+
//leave the message as it is
746767
msgObj = pMessage;
747768
}
748769

749-
$("#modal-warning").find('[name=message-content]').empty();
750-
751-
$("#modal-warning").find('[name=message-text]').empty().html(msgObj.title);
770+
if (msgObj.hasOwnProperty('title')) {
771+
//for alternative modal
772+
$("#modal-warning").find('[name=message-text]').empty().html(msgObj.title);
773+
}
774+
else {
775+
$("#modal-warning").find('[name=message-text]').empty().html(msgObj);
776+
}
752777

753778
if (msgObj.hasOwnProperty('message')) {
754779
$("#modal-warning").find('[name=message-content]').empty().html(msgObj.message);
780+
} else {
781+
$("#modal-warning").find('[name=message-content]').empty();
755782
}
756783

757784
$("#modal-warning").find("[name=warning]").once("click", function () {
@@ -763,13 +790,10 @@ api.modal.warning = function (pMessage) {
763790
$('.modal-hidden').removeClass('d-none');
764791
});
765792

766-
767793
// Display the Modal
768794
$("#modal-warning").modal("show");
769795
};
770796

771-
772-
773797
/**
774798
* Pop an Error Modal in Bootstrap
775799
* @param {*} pMessage
@@ -780,19 +804,28 @@ api.modal.exception = function (pMessage) {
780804
try {
781805
msgObj = JSON.parse(pMessage);
782806
} catch (ex) {
783-
//cant convert to json as is a string
784-
msgObj = { 'title': pMessage };
807+
//leave the message as it is
808+
msgObj = pMessage;
785809
}
786810
} else {
811+
//leave the message as it is
787812
msgObj = pMessage;
788813
}
789814

790-
$("#modal-exception").find('[name=message-content]').empty();
791815

792-
$("#modal-exception").find('[name=message-text]').empty().html(msgObj.title);
816+
817+
if (msgObj.hasOwnProperty('title')) {
818+
//for alternative modal
819+
$("#modal-exception").find('[name=message-text]').empty().html(msgObj.title);
820+
}
821+
else {
822+
$("#modal-exception").find('[name=message-text]').empty().html(msgObj);
823+
}
793824

794825
if (msgObj.hasOwnProperty('message')) {
795826
$("#modal-exception").find('[name=message-content]').empty().html(msgObj.message);
827+
} else {
828+
$("#modal-exception").find('[name=message-content]').empty();
796829
}
797830

798831
$("#modal-exception").find("[name=exception]").once("click", function () {

0 commit comments

Comments
 (0)