| @@ -28,48 +28,8 @@ | ||
| 28 | 28 | jQuery("#rownum_" + rownum + " td div").addClass("row-actions"); |
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -function wpda_list_table_favourite( schema_name, table_name ) { | |
| 33 | - if (jQuery('#span_favourites_'+ table_name).hasClass('dashicons-star-empty')) { | |
| 34 | - action = 'wpda_add_favourite'; | |
| 35 | - } else { | |
| 36 | - action = 'wpda_rem_favourite'; | |
| 37 | - } | |
| 38 | - url = location.pathname + '?action=' + action; | |
| 39 | - jQuery.ajax({ | |
| 40 | - method: 'POST', | |
| 41 | - url: url, | |
| 42 | - data: { | |
| 43 | - wpdaschema_name: schema_name, | |
| 44 | - table_name: table_name | |
| 45 | - } | |
| 46 | - }).done( | |
| 47 | - function (msg) { | |
| 48 | - if (msg === '1') { | |
| 49 | - if (jQuery('#span_favourites_' + table_name).hasClass('dashicons-star-empty')) { | |
| 50 | - jQuery('#span_favourites_' + table_name) | |
| 51 | - .removeClass('dashicons-star-empty') | |
| 52 | - .addClass('dashicons-star-filled') | |
| 53 | - .prop('title', 'Remove from favourites'); | |
| 54 | - } else { | |
| 55 | - jQuery('#span_favourites_' + table_name) | |
| 56 | - .removeClass('dashicons-star-filled') | |
| 57 | - .addClass('dashicons-star-empty') | |
| 58 | - .prop('title', 'Add to favourites'); | |
| 59 | - } | |
| 60 | - if (jQuery('#wpda_main_favourites_list').val()!=='') { | |
| 61 | - jQuery("#wpda_main_form :input[name='action']").val('-1'); | |
| 62 | - jQuery("#wpda_main_form :input[name='action2']").val('-1'); | |
| 63 | - jQuery('#wpda_main_form').submit(); | |
| 64 | - } | |
| 65 | - } else { | |
| 66 | - alert('Adding to favourites failed!'); | |
| 67 | - } | |
| 68 | - } | |
| 69 | - ); | |
| 70 | -} | |
| 71 | - | |
| 72 | 32 | function wpda_main_export_start() { |
| 73 | 33 | jQuery("#wpda_main_export_form").submit(); |
| 74 | 34 | jQuery("#wpda_row_export_anchor").empty(); |
| 75 | 35 | |
| @@ -631,9 +591,13 @@ | ||
| 631 | 591 | wpnonce: wpnonce, |
| 632 | 592 | } |
| 633 | 593 | }).done( |
| 634 | 594 | function(data) { |
| 635 | - msg = JSON.parse(data); | |
| 595 | + if (typeof data === "string") { | |
| 596 | + msg = JSON.parse(data); | |
| 597 | + } else { | |
| 598 | + msg = data; | |
| 599 | + } | |
| 636 | 600 | if (msg.status==="OK") { |
| 637 | 601 | jQuery.notify('Database function wpda_get_wp_user_id() created', 'success'); |
| 638 | 602 | } else { |
| 639 | 603 | console.log(msg); |
| @@ -939,5 +903,66 @@ | ||
| 939 | 903 | ); |
| 940 | 904 | |
| 941 | 905 | jQuery("#wpda-legacy-tool-settings-legacy-tool-data").val(JSON.stringify(toolStatus)); |
| 942 | 906 | jQuery("#wpda-legacy-tool-settings-form-data").submit(); |
| 907 | +} | |
| 908 | + | |
| 909 | +const submitMailCallbackOk = (response, debug) => { | |
| 910 | + if (response.code!==undefined && response.message!==undefined) { | |
| 911 | + switch(response.code) { | |
| 912 | + case "ok": | |
| 913 | + jQuery("#debugInfoContainer").parent().parent().hide() | |
| 914 | + jQuery.notify(response.message, "success"); | |
| 915 | + break; | |
| 916 | + case "error": | |
| 917 | + jQuery.notify(response.message, "error"); | |
| 918 | + break; | |
| 919 | + default: | |
| 920 | + jQuery.notify("Application error! Please contact the plugin development team.", "error"); | |
| 921 | + } | |
| 922 | + | |
| 923 | + if (debug === true) { | |
| 924 | + jQuery("#debugInfoContainer").html(response.debug) | |
| 925 | + jQuery("#debugInfoContainer").parent().parent().show() | |
| 926 | + } | |
| 927 | + } else { | |
| 928 | + submitSettingsCallbackError(response); | |
| 929 | + } | |
| 930 | + | |
| 931 | + jQuery('#mailSpinner').hide(); | |
| 932 | +} | |
| 933 | + | |
| 934 | +const submitMailCallbackError = (response) => { | |
| 935 | + if (response.code!==undefined && response.message!==undefined) { | |
| 936 | + switch(response.code) { | |
| 937 | + case "error": | |
| 938 | + jQuery.notify(response.message, "error"); | |
| 939 | + break; | |
| 940 | + default: | |
| 941 | + jQuery.notify("Application error! Please contact the plugin development team.", "error"); | |
| 942 | + } | |
| 943 | + } else { | |
| 944 | + jQuery.notify("Application error! Please contact the plugin development team.", "error"); | |
| 945 | + } | |
| 946 | + | |
| 947 | + jQuery('#mailSpinner').hide(); | |
| 948 | +} | |
| 949 | + | |
| 950 | +const sendMail = (to, subject, message, debug) => { | |
| 951 | + if (to.trim() === "" || subject.trim() === "" || message.trim() === "") { | |
| 952 | + jQuery.notify("Invalid function call! Missing arguments.", "error"); | |
| 953 | + jQuery('#mailSpinner').hide(); | |
| 954 | + } else { | |
| 955 | + wpda_rest_api( | |
| 956 | + "action/mail", | |
| 957 | + { | |
| 958 | + to: to, | |
| 959 | + subject: subject, | |
| 960 | + message: message, | |
| 961 | + }, | |
| 962 | + function(response) { | |
| 963 | + submitMailCallbackOk(response, debug) | |
| 964 | + }, | |
| 965 | + submitSettingsCallbackError | |
| 966 | + ); | |
| 967 | + } | |
| 943 | 968 | } |