var ajaxUrl = window.location.protocol + "//" + window.location.host + "/wp-admin/admin-post.php"; (function($) { //include bootstrap.min.js if not loaded already var bootstrapLoaded = (typeof $().emulateTransitionEnd == 'function'); if (!bootstrapLoaded) { var script = document.createElement("script") script.type = "text/javascript"; //Chrome,Firefox, Opera, Safari 3+ script.onload = function() { console.log('bootstrap is loaded'); }; script.src = "/wp-content/plugins/andropress-rest-api/assets/js/bootstrap-3.3.7.min.js"; document.getElementsByTagName("head")[0].appendChild(script); } $(document).on('click', '#btn-generate', function() { $.ajax({ url: ajaxUrl + "?action=generate_key", type: 'GET', cache: false, success: function(response) { $('#app-key').val(response); }, error: function(error) { console.log(error); } }); }); $(document).on('click', '#btn-create', function() { var appName = $('#app-name').val(); var appKey = $('#app-key').val(); if (appName && appKey) { $('.result').css({ "display": "none" }); $.ajax({ url: ajaxUrl, type: 'POST', cache: false, data: { action: 'insert_app', name: $('#app-name').val(), key: $('#app-key').val() }, success: function(response) { if (response == 'success') { $('.result').css({ "display": "block", "color": "#008000" }); $('.result').text("App Created Successfully !"); location.reload(); } else { $('.result').css({ "display": "block", "color": "#ff0000" }); $('.result').text("Something Went Wrong ! Try Again"); } $('#app-name').val(''); $('#app-key').val(''); }, error: function(error) { $('.result').css({ "display": "block", "color": "#ff0000" }); $('.result').text("Something Went Wrong ! Try Again"); $('#app-name').val(''); $('#app-key').val(''); } }); } else { $('.result').css({ "display": "block", "color": "#ff0000" }); $('.result').text("Insert App Name And App Key"); } }); })(jQuery); function deleteApp(id) { (function($) { $.ajax({ url: ajaxUrl, type: 'POST', cache: false, data: { action: "delete_app", id: id }, success: function(response) { if (response == "success") { location.reload(); } }, error: function(error) { console.log("error:" + error.Message); } }); })(jQuery); }