admin-script.js
392 lines
| 1 | jQuery(document).ready(function($) { |
| 2 | |
| 3 | // Loader element |
| 4 | var loaderHtml = `<img src="${fleximp_ajax_object.plugin_url}/loader/loader5.gif" alt="Loading..." style="width: 30px; height: 30px;" /> `; |
| 5 | |
| 6 | $('#fleximp-start-import').on('click', function() { |
| 7 | var nonce = $('#fleximp_import_demo_nonce_field').val(); |
| 8 | var $button = $(this); |
| 9 | var $loader = $(loaderHtml).insertAfter($button); |
| 10 | |
| 11 | $button.prop('disabled', true); |
| 12 | |
| 13 | $.ajax({ |
| 14 | url: fleximp_ajax_object.ajax_url, |
| 15 | type: 'POST', |
| 16 | data: { |
| 17 | action: 'fleximp_import_demo_content', |
| 18 | nonce: nonce |
| 19 | }, |
| 20 | beforeSend: function() { |
| 21 | $loader.show(); |
| 22 | }, |
| 23 | success: function(response) { |
| 24 | if (response.success) { |
| 25 | alert(response.data); |
| 26 | $('#fleximp-next-card-6').show(); |
| 27 | $button.prop('disabled', true); |
| 28 | } else { |
| 29 | alert(response.data); |
| 30 | $button.prop('disabled', false); |
| 31 | } |
| 32 | }, |
| 33 | error: function() { |
| 34 | alert('Error occurred during the import process.'); |
| 35 | $button.prop('disabled', false); |
| 36 | }, |
| 37 | complete: function() { |
| 38 | $loader.remove(); |
| 39 | } |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | $('#fleximp-next-card-6').on('click', function() { |
| 44 | $('.fleximp-card-content').hide(); |
| 45 | $('#card-6').show(); |
| 46 | updateActiveCard(6); |
| 47 | }); |
| 48 | |
| 49 | $('#fleximp-import-pages-data').on('click', function() { |
| 50 | var nonce = $('#fleximp_import_pages_nonce_field').val(); |
| 51 | var $button = $(this); |
| 52 | var $loader = $(loaderHtml).insertAfter($button); |
| 53 | |
| 54 | // Disable button and show loader |
| 55 | $button.prop('disabled', true); |
| 56 | |
| 57 | $.ajax({ |
| 58 | url: fleximp_ajax_object.ajax_url, |
| 59 | type: 'POST', |
| 60 | data: { |
| 61 | action: 'fleximp_import_inner_pages_data', |
| 62 | nonce: nonce |
| 63 | }, |
| 64 | beforeSend: function() { |
| 65 | // Show loader before the request starts |
| 66 | $loader.show(); |
| 67 | }, |
| 68 | success: function(response) { |
| 69 | if (response.success) { |
| 70 | alert(response.data); |
| 71 | $('#fleximp-next-card-6').show(); |
| 72 | } else { |
| 73 | alert(response.data); |
| 74 | } |
| 75 | }, |
| 76 | error: function() { |
| 77 | // Handle any errors in the request |
| 78 | alert('Error occurred while importing pages data.'); |
| 79 | }, |
| 80 | complete: function() { |
| 81 | $loader.remove(); |
| 82 | } |
| 83 | }); |
| 84 | }); |
| 85 | |
| 86 | |
| 87 | function updateActiveCard(cardNumber) { |
| 88 | const buttons = document.querySelectorAll('.fleximp-card-button'); |
| 89 | buttons.forEach(button => { |
| 90 | button.classList.remove('active'); |
| 91 | button.disabled = false; |
| 92 | if (button.getAttribute('data-card') == cardNumber) { |
| 93 | button.classList.add('active'); |
| 94 | } |
| 95 | }); |
| 96 | } |
| 97 | }); |
| 98 | |
| 99 | |
| 100 | //end |
| 101 | |
| 102 | |
| 103 | //template js |
| 104 | |
| 105 | jQuery(document).ready(function($) { |
| 106 | const isPremiumTheme = fleximp_ajax_object.is_premium_theme; |
| 107 | |
| 108 | if (isPremiumTheme) { |
| 109 | $('#card-3').css('display', 'block'); |
| 110 | updateActiveCard(3); |
| 111 | } else { |
| 112 | $('#card-1').css('display', 'block'); |
| 113 | } |
| 114 | |
| 115 | $('#fleximp-start-now').on('click', function() { |
| 116 | $('#card-1').css('display', 'none'); |
| 117 | $('#card-5').css('display', 'block'); |
| 118 | updateActiveCard(5); |
| 119 | }); |
| 120 | |
| 121 | if ($('#fleximp-install-plugins').length) { |
| 122 | $('#fleximp-install-plugins').on('click', function() { |
| 123 | $('#card-3').css('display', 'none'); |
| 124 | $('#card-4').css('display', 'block'); |
| 125 | updateActiveCard(4); |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | if ($('#fleximp-skip-button').length) { |
| 130 | $('#fleximp-skip-button').on('click', function() { |
| 131 | $('#card-2').css('display', 'none'); |
| 132 | if (isPremiumTheme) { |
| 133 | $('#card-3').css('display', 'block'); |
| 134 | updateActiveCard(3); |
| 135 | } else { |
| 136 | // $('#card-6').css('display', 'block'); |
| 137 | // updateActiveCard(6); |
| 138 | |
| 139 | $('#card-5').css('display', 'block'); |
| 140 | updateActiveCard(5); |
| 141 | } |
| 142 | }); |
| 143 | } |
| 144 | |
| 145 | function updateActiveCard(cardNumber) { |
| 146 | $('.fleximp-card-button').each(function() { |
| 147 | $(this).removeClass('active'); |
| 148 | $(this).prop('disabled', false); |
| 149 | if ($(this).data('card') == cardNumber) { |
| 150 | $(this).addClass('active'); |
| 151 | } |
| 152 | }); |
| 153 | } |
| 154 | }); |
| 155 | |
| 156 | //end |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | //new js |
| 162 | jQuery(document).ready(function($) { |
| 163 | const isPremiumTheme = fleximp_ajax_object.is_premium_theme; |
| 164 | |
| 165 | if (isPremiumTheme) { |
| 166 | $('#card-3').show(); |
| 167 | updateActiveCard(3); |
| 168 | } else { |
| 169 | $('#card-1').show(); |
| 170 | } |
| 171 | |
| 172 | $('#fleximp-start-now').on('click', function() { |
| 173 | $('#card-1').hide(); |
| 174 | $('#card-5').show(); |
| 175 | updateActiveCard(5); |
| 176 | }); |
| 177 | |
| 178 | |
| 179 | $('#fleximp-skip-button').on('click', function() { |
| 180 | $('#card-2').hide(); |
| 181 | if (isPremiumTheme) { |
| 182 | $('#card-3').show(); |
| 183 | updateActiveCard(3); |
| 184 | } else { |
| 185 | $('#card-5').show(); |
| 186 | updateActiveCard(5); |
| 187 | } |
| 188 | |
| 189 | |
| 190 | if (isPremiumTheme) { |
| 191 | document.getElementById('card-3').style.display = 'block'; |
| 192 | updateActiveCard(3); |
| 193 | } else { |
| 194 | document.getElementById('card-5').style.display = 'block'; |
| 195 | updateActiveCard(5); |
| 196 | } |
| 197 | }); |
| 198 | |
| 199 | function updateActiveCard(cardNumber) { |
| 200 | $('.fleximp-card-button').each(function() { |
| 201 | $(this).removeClass('active'); |
| 202 | $(this).prop('disabled', false); |
| 203 | if ($(this).data('card') == cardNumber) { |
| 204 | $(this).addClass('active'); |
| 205 | } |
| 206 | }); |
| 207 | } |
| 208 | }); |
| 209 | |
| 210 | |
| 211 | |
| 212 | //end |
| 213 | |
| 214 | |
| 215 | |
| 216 | jQuery(document).ready(function ($) { |
| 217 | |
| 218 | const isPremiumTheme = fleximp_ajax_object.is_premium_theme; |
| 219 | |
| 220 | function updateActiveCard(cardNumber) { |
| 221 | const buttons = document.querySelectorAll('.fleximp-card-button'); |
| 222 | buttons.forEach(button => { |
| 223 | button.classList.remove('active'); |
| 224 | button.disabled = false; |
| 225 | if (button.getAttribute('data-card') == cardNumber) { |
| 226 | button.classList.add('active'); |
| 227 | } |
| 228 | }); |
| 229 | } |
| 230 | |
| 231 | function showCard(cardNumber) { |
| 232 | document.querySelectorAll('.fleximp-card-content').forEach(card => { |
| 233 | card.style.display = 'none'; |
| 234 | }); |
| 235 | |
| 236 | const selectedCard = document.getElementById('card-' + cardNumber); |
| 237 | if (selectedCard) { |
| 238 | selectedCard.style.display = 'block'; |
| 239 | } |
| 240 | |
| 241 | // Update the active card |
| 242 | updateActiveCard(cardNumber); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | // Step 1: Start Now button |
| 247 | $('#fleximp-start-now').on('click', function () { |
| 248 | showCard(5); |
| 249 | }); |
| 250 | |
| 251 | $('#fleximp-skip-button').on('click', function () { |
| 252 | // showCard(3); |
| 253 | // showCard(6); |
| 254 | |
| 255 | showCard(5); |
| 256 | }); |
| 257 | |
| 258 | //for change key |
| 259 | |
| 260 | // Handle "Change Key" functionality |
| 261 | $('#fleximp-change-key').on('click', function (e) { |
| 262 | e.preventDefault(); |
| 263 | |
| 264 | $.post(fleximp_ajax_object.ajax_url, { |
| 265 | action: 'fleximp_deactivate_license', |
| 266 | }, function (response) { |
| 267 | if (response.success) { |
| 268 | $('input[name="fleximp_license_key"]').val(''); |
| 269 | $('input[name="fleximp_license_key"]').prop('disabled', false); |
| 270 | $('#fleximp_license_form button[type="submit"]').prop('disabled', false).text('Activate'); |
| 271 | |
| 272 | $('#fleximp-change-key').hide(); |
| 273 | |
| 274 | $('#fleximp-next-step').remove(); |
| 275 | } else { |
| 276 | alert('Failed to deactivate the license. Please try again.'); |
| 277 | } |
| 278 | }); |
| 279 | }); |
| 280 | |
| 281 | |
| 282 | if ($('#fleximp_license_form button').is('[disabled]')) { |
| 283 | $('<button id="fleximp-next-step" class="button button-primary">Next</button>').insertAfter('#fleximp_license_form'); |
| 284 | $('#fleximp-next-step').on('click', function () { |
| 285 | showCard(4); // Move to the next card |
| 286 | }); |
| 287 | } |
| 288 | |
| 289 | }); |
| 290 | |
| 291 | |
| 292 | |
| 293 | // for required plugins |
| 294 | |
| 295 | jQuery(document).ready(function($) { |
| 296 | $.ajax({ |
| 297 | url: fleximp_ajax_object.ajax_url, |
| 298 | method: 'POST', |
| 299 | data: { |
| 300 | action: 'fleximp_get_required_plugins', |
| 301 | _ajax_nonce: fleximp_ajax_object.fleximp_nonce |
| 302 | }, |
| 303 | success: function(response) { |
| 304 | if (response.success) { |
| 305 | const plugins = response.data; |
| 306 | const pluginListContainer = $('#required-plugins-list'); |
| 307 | pluginListContainer.empty(); |
| 308 | |
| 309 | $.each(plugins, function(index, plugin) { |
| 310 | const statusText = plugin.status === 'required' ? 'Required' : 'Installed'; |
| 311 | const pluginItem = ` |
| 312 | <div class="plugin-item" id="plugin-${plugin.slug}"> |
| 313 | <h4>${plugin.name}</h4> |
| 314 | <span class="plugin-status" id="plugin-status-${plugin.slug}">${statusText}</span> |
| 315 | </div>`; |
| 316 | pluginListContainer.append(pluginItem); |
| 317 | }); |
| 318 | |
| 319 | |
| 320 | } else { |
| 321 | $('#required-plugins-list').html(`<p class="error">${response.data}</p>`); |
| 322 | } |
| 323 | }, |
| 324 | error: function() { |
| 325 | $('#required-plugins-list').html('<p class="error">An error occurred while fetching the plugins.</p>'); |
| 326 | } |
| 327 | }); |
| 328 | |
| 329 | // Plugin installation logic |
| 330 | $('#fleximp-install-plugins').on('click', function() { |
| 331 | this.disabled = true; |
| 332 | this.innerText = 'Installing...'; |
| 333 | |
| 334 | // Fetch plugins again for installation |
| 335 | $.ajax({ |
| 336 | url: fleximp_ajax_object.ajax_url, |
| 337 | method: 'POST', |
| 338 | data: { |
| 339 | action: 'fleximp_get_required_plugins', |
| 340 | _ajax_nonce: fleximp_ajax_object.fleximp_nonce |
| 341 | }, |
| 342 | success: function(response) { |
| 343 | if (response.success) { |
| 344 | const plugins = response.data; |
| 345 | installPlugin(plugins, 0); |
| 346 | } else { |
| 347 | const errorMessage = response.data ? response.data : 'An unexpected error occurred while fetching plugins.'; |
| 348 | alert(errorMessage); |
| 349 | } |
| 350 | }, |
| 351 | error: function() { |
| 352 | alert('An error occurred while fetching the plugins.'); |
| 353 | } |
| 354 | }); |
| 355 | |
| 356 | function installPlugin(plugins, index) { |
| 357 | if (index >= plugins.length) { |
| 358 | $('#fleximp-install-plugins').text('All plugins installed successfully.'); |
| 359 | setTimeout(function() { |
| 360 | $('#card-4').hide(); |
| 361 | $('#card-5').show(); |
| 362 | updateActiveCard(5); |
| 363 | }, 3000); |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | const plugin = plugins[index]; |
| 368 | const statusElement = $(`#plugin-status-${plugin.slug}`); |
| 369 | statusElement.html('<span class="spinner is-active"></span> Installing...'); |
| 370 | } |
| 371 | }); |
| 372 | |
| 373 | function updateActiveCard(cardNumber) { |
| 374 | const buttons = document.querySelectorAll('.fleximp-card-button'); |
| 375 | buttons.forEach(button => { |
| 376 | button.classList.remove('active'); |
| 377 | button.disabled = false; |
| 378 | if (button.getAttribute('data-card') == cardNumber) { |
| 379 | button.classList.add('active'); |
| 380 | } |
| 381 | }); |
| 382 | } |
| 383 | }); |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 |