| @@ -631,9 +631,13 @@ | ||
| 631 | 631 | wpnonce: wpnonce, |
| 632 | 632 | } |
| 633 | 633 | }).done( |
| 634 | 634 | function(data) { |
| 635 | - msg = JSON.parse(data); | |
| 635 | + if (typeof data === "string") { | |
| 636 | + msg = JSON.parse(data); | |
| 637 | + } else { | |
| 638 | + msg = data; | |
| 639 | + } | |
| 636 | 640 | if (msg.status==="OK") { |
| 637 | 641 | jQuery.notify('Database function wpda_get_wp_user_id() created', 'success'); |
| 638 | 642 | } else { |
| 639 | 643 | console.log(msg); |
| @@ -939,5 +943,66 @@ | ||
| 939 | 943 | ); |
| 940 | 944 | |
| 941 | 945 | jQuery("#wpda-legacy-tool-settings-legacy-tool-data").val(JSON.stringify(toolStatus)); |
| 942 | 946 | jQuery("#wpda-legacy-tool-settings-form-data").submit(); |
| 947 | +} | |
| 948 | + | |
| 949 | +const submitMailCallbackOk = (response, debug) => { | |
| 950 | + if (response.code!==undefined && response.message!==undefined) { | |
| 951 | + switch(response.code) { | |
| 952 | + case "ok": | |
| 953 | + jQuery("#debugInfoContainer").parent().parent().hide() | |
| 954 | + jQuery.notify(response.message, "success"); | |
| 955 | + break; | |
| 956 | + case "error": | |
| 957 | + jQuery.notify(response.message, "error"); | |
| 958 | + break; | |
| 959 | + default: | |
| 960 | + jQuery.notify("Application error! Please contact the plugin development team.", "error"); | |
| 961 | + } | |
| 962 | + | |
| 963 | + if (debug === true) { | |
| 964 | + jQuery("#debugInfoContainer").html(response.debug) | |
| 965 | + jQuery("#debugInfoContainer").parent().parent().show() | |
| 966 | + } | |
| 967 | + } else { | |
| 968 | + submitSettingsCallbackError(response); | |
| 969 | + } | |
| 970 | + | |
| 971 | + jQuery('#mailSpinner').hide(); | |
| 972 | +} | |
| 973 | + | |
| 974 | +const submitMailCallbackError = (response) => { | |
| 975 | + if (response.code!==undefined && response.message!==undefined) { | |
| 976 | + switch(response.code) { | |
| 977 | + case "error": | |
| 978 | + jQuery.notify(response.message, "error"); | |
| 979 | + break; | |
| 980 | + default: | |
| 981 | + jQuery.notify("Application error! Please contact the plugin development team.", "error"); | |
| 982 | + } | |
| 983 | + } else { | |
| 984 | + jQuery.notify("Application error! Please contact the plugin development team.", "error"); | |
| 985 | + } | |
| 986 | + | |
| 987 | + jQuery('#mailSpinner').hide(); | |
| 988 | +} | |
| 989 | + | |
| 990 | +const sendMail = (to, subject, message, debug) => { | |
| 991 | + if (to.trim() === "" || subject.trim() === "" || message.trim() === "") { | |
| 992 | + jQuery.notify("Invalid function call! Missing arguments.", "error"); | |
| 993 | + jQuery('#mailSpinner').hide(); | |
| 994 | + } else { | |
| 995 | + wpda_rest_api( | |
| 996 | + "action/mail", | |
| 997 | + { | |
| 998 | + to: to, | |
| 999 | + subject: subject, | |
| 1000 | + message: message, | |
| 1001 | + }, | |
| 1002 | + function(response) { | |
| 1003 | + submitMailCallbackOk(response, debug) | |
| 1004 | + }, | |
| 1005 | + submitSettingsCallbackError | |
| 1006 | + ); | |
| 1007 | + } | |
| 943 | 1008 | } |