PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.5
Flex Import v2.5
2.9 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
flex-import / assets / js / template-admin.js
flex-import / assets / js Last commit date
admin-script.js 10 months ago dashboard-posts.js 10 months ago front-script.js 10 months ago jquery.notify.min.js 10 months ago license_script.js 10 months ago plugin-admin.js 10 months ago template-admin.js 10 months ago
template-admin.js
703 lines
1 document.addEventListener('DOMContentLoaded', function () {
2 let currentPage = 1;
3 let totalPages = 1;
4 let currentCategoryId = null;
5 let currentCategorySlug = null;
6 let currentSearchQuery = null;
7
8 const templatesApiEndpoint = fleximp_template_ajax_object.apiEndpoint;
9 let isFetchingTemplates = false;
10 let isFetchingCategories = false;
11
12 // new add
13 function fetchTemplates(categoryId = null, categorySlug = null, page = 1, searchQuery = null) {
14 if (isFetchingTemplates) return;
15 isFetchingTemplates = true;
16
17 // Update current category and page
18 if (categoryId && categorySlug) {
19 currentCategoryId = categoryId;
20 currentCategorySlug = categorySlug;
21 }
22 currentPage = page;
23 currentSearchQuery = searchQuery;
24
25 const requestBody = {
26 action: 'getTemplates',
27 per_page: 12,
28 page: currentPage
29 };
30
31 if (currentCategoryId && currentCategorySlug) {
32 requestBody.product_cat = currentCategoryId;
33 } else {
34 requestBody.product_cat = 15;
35 }
36
37 if (searchQuery) {
38 requestBody.search = searchQuery;
39 }
40
41 fetch(templatesApiEndpoint, {
42 method: 'POST',
43 headers: {
44 'Content-Type': 'application/json'
45 },
46 body: JSON.stringify(requestBody)
47 })
48 .then(response => response.json())
49 .then(data => {
50 if (data.success && data.data) {
51 const templates = data.data.posts || data.data.data?.posts;
52 if (Array.isArray(templates)) {
53 displayTemplates(templates);
54 // Update total pages
55 totalPages = data.data.total_pages ||
56 (data.data.data ? data.data.data.total_pages : 1);
57
58 updatePaginationControls();
59 } else {
60 console.error('Invalid templates data format:', data);
61 displayTemplates([]);
62 }
63 } else {
64 console.error('API Error:', data.message || 'Unknown error');
65 displayTemplates([]);
66 }
67 })
68 .catch(error => {
69 console.error('Network Error:', error);
70 displayTemplates([]);
71 })
72 .finally(() => {
73 isFetchingTemplates = false;
74 });
75 }
76
77 // end
78
79 // Update Pagination Controls
80 function updatePaginationControls() {
81
82 const paginationContainer = document.getElementById('pagination-controls');
83 if (!paginationContainer) {
84 console.error('Pagination container not found!');
85 return;
86 }
87
88 paginationContainer.innerHTML = '';
89
90 // Previous button
91 const prevLi = document.createElement('li');
92 prevLi.className = `page-item ${currentPage === 1 ? 'disabled' : ''}`;
93 prevLi.innerHTML = `<a class="page-link" href="#" aria-label="Previous">
94 <span aria-hidden="true">&laquo;</span>
95 </a>`;
96 prevLi.addEventListener('click', (e) => {
97 e.preventDefault();
98 if (currentPage > 1) {
99 fetchTemplates(currentCategoryId, currentCategorySlug, currentPage - 1, currentSearchQuery);
100 }
101 });
102 paginationContainer.appendChild(prevLi);
103
104 // Page numbers
105 const maxVisiblePages = 6;
106 let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
107 let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
108
109 if (endPage - startPage + 1 < maxVisiblePages) {
110 startPage = Math.max(1, endPage - maxVisiblePages + 1);
111 }
112
113 // First page
114 if (startPage > 1) {
115 const firstLi = document.createElement('li');
116 firstLi.className = 'page-item';
117 firstLi.innerHTML = `<a class="page-link" href="#">1</a>`;
118 firstLi.addEventListener('click', (e) => {
119 e.preventDefault();
120 fetchTemplates(currentCategoryId, currentCategorySlug, 1, currentSearchQuery);
121 });
122 paginationContainer.appendChild(firstLi);
123
124 if (startPage > 2) {
125 const ellipsisLi = document.createElement('li');
126 ellipsisLi.className = 'page-item disabled';
127 ellipsisLi.innerHTML = `<span class="page-link">...</span>`;
128 paginationContainer.appendChild(ellipsisLi);
129 }
130 }
131
132 // Visible page numbers
133 for (let i = startPage; i <= endPage; i++) {
134 const pageLi = document.createElement('li');
135 pageLi.className = `page-item ${i === currentPage ? 'active' : ''}`;
136 pageLi.innerHTML = `<a class="page-link" href="#">${i}</a>`;
137 pageLi.addEventListener('click', (e) => {
138 e.preventDefault();
139 fetchTemplates(currentCategoryId, currentCategorySlug, i, currentSearchQuery);
140 });
141 paginationContainer.appendChild(pageLi);
142 }
143
144 // Last page
145 if (endPage < totalPages) {
146 if (endPage < totalPages - 1) {
147 const ellipsisLi = document.createElement('li');
148 ellipsisLi.className = 'page-item disabled';
149 ellipsisLi.innerHTML = `<span class="page-link">...</span>`;
150 paginationContainer.appendChild(ellipsisLi);
151 }
152
153 const lastLi = document.createElement('li');
154 lastLi.className = 'page-item';
155 lastLi.innerHTML = `<a class="page-link" href="#">${totalPages}</a>`;
156 lastLi.addEventListener('click', (e) => {
157 e.preventDefault();
158 fetchTemplates(currentCategoryId, currentCategorySlug, totalPages);
159 });
160 paginationContainer.appendChild(lastLi);
161 }
162
163 // Next button
164 const nextLi = document.createElement('li');
165 nextLi.className = `page-item ${currentPage === totalPages ? 'disabled' : ''}`;
166 nextLi.innerHTML = `<a class="page-link" href="#" aria-label="Next">
167 <span aria-hidden="true">&raquo;</span>
168 </a>`;
169 nextLi.addEventListener('click', (e) => {
170 e.preventDefault();
171 if (currentPage < totalPages) {
172 fetchTemplates(currentCategoryId, currentCategorySlug, currentPage + 1);
173 }
174 });
175 paginationContainer.appendChild(nextLi);
176 }
177 // end
178
179 // Fetch Categories
180 function fetchCategories() {
181 if (isFetchingCategories) return;
182 isFetchingCategories = true;
183
184 fetch(templatesApiEndpoint, {
185 method: 'POST',
186 headers: {
187 'Content-Type': 'application/json'
188 },
189 body: JSON.stringify({
190 action: 'getCategories'
191 })
192 })
193 .then(response => response.json())
194 .then(data => {
195 if (data.success && Array.isArray(data.data
196 .data)) {
197 displayCategories(data.data.data);
198 } else {
199 console.error('Error fetching categories:', data);
200 }
201 })
202 .catch(error => {
203 console.error('Error:', error);
204 })
205 .finally(() => {
206 isFetchingCategories = false;
207 });
208 }
209
210 // Display Templates
211 function displayTemplates(templates) {
212 const templatesListContainer = document.getElementById('templates-list');
213 templatesListContainer.innerHTML = '';
214
215 // new add for no templates message
216 if (!templates || templates.length === 0) {
217 templatesListContainer.innerHTML = `
218 <div class="no-templates-message">
219 No templates found
220 </div>`;
221 return;
222 }
223 // end
224 templates.forEach(template => {
225 const templateSlug = template.title.toLowerCase().replace(/ /g, '-');
226 const demoUrl = template.metafields?.demo_url || '#';
227 const selectedPlugins = template.metafields?.selected_plugins || [];
228 const jsonPath = template.metafields?.json_path || '';
229 const templateMainImage = template.metafields?.template_main_image || '';
230 const templateMobileImage = template.metafields?.template_mobile_image || '';
231 const templateResponsiveImage = template.metafields?.template_responsive_image || '';
232 const contentPath = template.metafields?.content_path || '';
233 const textDomain = template.template_domain || '';
234 const templateCss = template.metafields?.template_css_path || '';
235 const templateJs = template.metafields?.template_js_path || '';
236 const templatePhp = template.metafields?.template_php_path || '';
237 const isPremium = template.metafields?.free_pro === 'Pro';
238 // const isUserPremium = fleximp_template_ajax_object.isPremiumUser === true || fleximp_template_ajax_object.isPremiumUser === '1';
239 const isUserPremium = fleximp_template_ajax_object.isPremiumUser;
240 const isImported = fleximp_template_ajax_object.imported_template;
241 const fleximpCurrentTextDomain = fleximp_template_ajax_object.fleximp_current_text_domain;
242 let buttonHTML = '';
243 // new add
244 if (isPremium && !isUserPremium) {
245 buttonHTML = `
246 <a href="https://www.flextheme.net/products/flex-pro-wordpress-theme" target="_blank" class="btn flex-template-buttons get-pro-btn">
247 <svg viewBox="0 0 64 64" width="512" xmlns="http://www.w3.org/2000/svg" id="fi_3777733"><g id="Icon"><path d="m59.45 19.31a1 1 0 0 0 -1.15.18l-12.08 11.89-13.35-23.17a1.06 1.06 0 0 0 -1.74 0l-13.35 23.17-12.08-11.89a1 1 0 0 0 -1.7.86l4 26.8a1 1 0 0 0 1 .85h46a1 1 0 0 0 1-.85l4-26.8a1 1 0 0 0 -.55-1.04z"></path></g></svg>
248 Get Pro
249 </a>`;
250 } else {
251 if (isImported === textDomain) {
252 // Show Uninstall Button
253 buttonHTML = `
254 <button
255 class="btn flex-template-buttons uninstall-btn"
256 data-template="${templateSlug}" data-title="${template.title}"
257 data-plugins='${JSON.stringify(selectedPlugins)}'
258 data-json-path="${jsonPath}"
259 data-template-main-image="${templateMainImage}"
260 data-template-mobile-image="${templateMobileImage}"
261 data-template-responsive-image="${templateResponsiveImage}"
262 data-content-path="${contentPath}"
263 data-text-domain="${textDomain}"
264 data-template-css="${templateCss}"
265 data-template-js="${templateJs}"
266 data-template-php="${templatePhp}">
267 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="15" height="15"><path d="M135.2 17.7C140.4 7.1 150.9 0 162.7 0h186.7c11.8 0 22.3 7.1 27.5 17.7L416 64h80c17.7 0 32 14.3 32 32s-14.3 32-32 32h-16v304c0 44.2-35.8 80-80 80H160c-44.2 0-80-35.8-80-80V128H64c-17.7 0-32-14.3-32-32s14.3-32 32-32h80l23.2-46.3zM160 128v304h192V128H160z"/></svg>
268 Uninstall
269 </button>
270 `;
271 } else if (fleximp_template_ajax_object.isElementorActive === '1') {
272 let isDisabled = fleximpCurrentTextDomain != textDomain && fleximpCurrentTextDomain != '' ? 'disabled title="first uninstall imported template"' : '';
273 buttonHTML = `
274 <button
275 class="btn flex-unique-import-button flex-template-buttons import-btn"
276 ${isDisabled}
277 data-template="${templateSlug}"
278 data-title="${template.title}"
279 data-plugins='${JSON.stringify(selectedPlugins)}'
280 data-json-path="${jsonPath}"
281 data-template-main-image="${templateMainImage}"
282 data-template-mobile-image="${templateMobileImage}"
283 data-template-responsive-image="${templateResponsiveImage}"
284 data-content-path="${contentPath}"
285 data-text-domain="${textDomain}"
286 data-template-css="${templateCss}"
287 data-template-js="${templateJs}"
288 data-template-php="${templatePhp}">
289 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M128 64c0-35.3 28.7-64 64-64L352 0l0 128c0 17.7 14.3 32 32 32l128 0 0 288c0 35.3-28.7 64-64 64l-256 0c-35.3 0-64-28.7-64-64l0-112 174.1 0-39 39c-9.4 9.4-9.4 24.6 0 33.9s24.6 9.4 33.9 0l80-80c9.4-9.4 9.4-24.6 0-33.9l-80-80c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l39 39L128 288l0-224zm0 224l0 48L24 336c-13.3 0-24-10.7-24-24s10.7-24 24-24l104 0zM512 128l-128 0L384 0 512 128z"/></svg>
290 Import
291 </button>
292 `;
293 } else {
294 // Elementor is NOT active, show disabled message
295 buttonHTML = `
296 <button class="btn flex-template-buttons btn-disabled" disabled title="Please install and activate Elementor to import templates.">
297 Elementor Required
298 </button>
299 `;
300 }
301 }
302
303 // end
304 const templateHTML = `
305 <div class="template-item grid-item" style="position: relative;">
306 <div class="flex-imp-temp-inner-box"><img src="${templateMainImage}" alt="${template.title}" style=""></div>
307
308 ${isPremium ? `
309 <div class="premium-badge" style="
310 position: absolute;
311 top: 10px;
312 left: 10px;
313 background-color: rgba(0, 0, 0, 0.6);
314 color: #fff;
315 padding: 4px 8px;
316 font-size: 12px;
317 border-radius: 4px;
318 display: flex;
319 align-items: center;
320 gap: 5px;">
321 <svg xmlns="http://www.w3.org/2000/svg" height="14" width="12" viewBox="0 0 448 512" fill="currentColor">
322 <path d="..."/>
323 </svg> Premium
324 </div>` : ''
325 }
326 <div class="fleximp-temp-buttons widgets-btn">
327 <div class="buttons widgets-btn">
328 <div class="btn-title">
329 <p class="template-title">${template.title}</p>
330 </div>
331 <div class="d-flex flex-gap-div">
332 <a href="${demoUrl}" target="_blank" class="btn flex-template-buttons">
333 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"> <path d="M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4C142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32zM144 256a144 144 0 1 1 288 0 144 144 0 1 1 -288 0zm144-64c0 35.3-28.7 64-64 64c-7.1 0-13.9-1.2-20.3-3.3c-5.5-1.8-11.9 1.6-11.7 7.4c.3 6.9 1.3 13.8 3.2 20.7c13.7 51.2 66.4 81.6 117.6 67.9s81.6-66.4 67.9-117.6c-11.1-41.5-47.8-69.4-88.6-71.1c-5.8-.2-9.2 6.1-7.4 11.7c2.1 6.4 3.3 13.2 3.3 20.3z"></path> </svg>Demo</a>
334 </a>
335 ${buttonHTML}
336 </div>
337 </div>
338 </div>
339 </div>
340 `;
341
342 templatesListContainer.innerHTML += templateHTML;
343 });
344 }
345
346 function displayCategories(categories) {
347 const categoriesListContainer = document.querySelector('#categories-list');
348 categoriesListContainer.innerHTML = '';
349
350 categories.forEach((category, index) => {
351 const categoryHTML = `
352 <li data-category-id="${category.id}" data-category-slug="${category.slug}" class="category-item${index === 0 ? ' active' : ''}">
353 ${category.name}
354 </li>`;
355 categoriesListContainer.innerHTML += categoryHTML;
356 });
357
358 // Auto-load templates for the first category
359 if (categories.length > 0) {
360 fetchTemplates(categories[0].id, categories[0].slug);
361 }
362 }
363
364 // for loader
365 function updateProgress(percent, message) {
366 const progressBar = document.getElementById('import-progress-bar');
367 const progressText = document.getElementById('import-progress-text');
368 if (progressBar && progressText) {
369 progressBar.style.width = percent + '%';
370 progressText.textContent = `${message} (${percent}%)`;
371 }
372 }
373 //end
374
375 document.addEventListener('click', function (event) {
376 if (event.target.classList.contains('flex-unique-import-button')) {
377
378 const templateTitle = event.target.getAttribute('data-title');
379 const templateMobileImage = event.target.getAttribute('data-template-mobile-image');
380 const textDomain = event.target.getAttribute('data-text-domain');
381 const jsonPath = event.target.getAttribute('data-json-path');
382 const contentPath = event.target.getAttribute('data-content-path');
383 const templateCss = event.target.getAttribute('data-template-css');
384 const templateJs = event.target.getAttribute('data-template-js');
385 const templatePhp = event.target.getAttribute('data-template-php');
386 const plugins = event.target.getAttribute('data-plugins');
387 const templateResponsiveImage = event.target.getAttribute('data-template-responsive-image');
388 const modal = document.getElementById('import-modal');
389 const modalTitle = document.getElementById('modal-template-title');
390 // For Step 2
391 const modalMobileTitle = document.getElementById('modal-template-mobile-title');
392 const modalMobileImage = document.getElementById('modal-template-mobile-image');
393 const modalTemplateImage = document.getElementById('modal-template-responsive-image');
394 if (modal && modalTitle && modalMobileTitle && modalMobileImage && modalTemplateImage) {
395 // Set Step 1 Data
396 modalTitle.textContent = `${templateTitle}`;
397 modalMobileTitle.textContent = `${templateTitle}`; // Set title
398 modalMobileImage.src = templateMobileImage; // Set mobile img
399 modalTemplateImage.src = templateResponsiveImage;
400 modal.style.display = 'block';
401 } else {
402 console.error('Modal or modal title/image element is missing in the DOM.');
403 }
404 const confirmBtn = document.getElementById('flex-confirm-import');
405 if (confirmBtn) {
406 // Remove existing listener if needed, or use once:true
407 confirmBtn.addEventListener('click', function () {
408 const data = {
409 textDomain: textDomain,
410 jsonPath: jsonPath,
411 contentPath: contentPath,
412 templateCss: templateCss,
413 templateJs: templateJs,
414 templatePhp: templatePhp,
415 plugins: plugins,
416 templateResponsiveImage: templateResponsiveImage,
417 };
418
419 sessionStorage.setItem('fleximp_import_data', JSON.stringify(data));
420
421 if (!textDomain) {
422 alert('Text domain not found.');
423 return;
424 }
425 fetch(fleximp_ajax_object.ajax_url, {
426 method: 'POST',
427 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
428 body: new URLSearchParams({
429 action: 'fleximp_set_text_domain',
430 text_domain: textDomain,
431 template_php: templatePhp
432 })
433 })
434 .then(res => res.json())
435 .then(response => {
436 if (response.success) {
437 sessionStorage.setItem('fleximp_auto_continue', '1');
438 location.reload();
439 } else {
440 alert('Failed to update text domain.');
441 }
442 });
443 }, { once: true });
444 }
445 }
446 });
447
448 fetchCategories();
449 fetchTemplates(15, null, 1, null);
450
451 document.addEventListener('click', function (event) {
452 const categoryItem = event.target.closest('#categories-list .category-item');
453 if (!categoryItem) return;
454
455 const categoryId = categoryItem.getAttribute('data-category-id');
456 const categorySlug = categoryItem.getAttribute('data-category-slug');
457
458 document.querySelectorAll('#categories-list .category-item').forEach(item => {
459 item.classList.remove('active');
460 });
461 categoryItem.classList.add('active');
462
463 // Reset to page 1 when changing category, but maintain search query
464 fetchTemplates(categoryId, categorySlug, 1, currentSearchQuery);
465 });
466
467 jQuery('body').on("input", "#flex-templates-search", debounce(function (event) {
468
469 const categoryId = jQuery('.category-item.active').attr('data-category-id');
470 const categorySlug = jQuery('.category-item.active').attr('data-category-slug');
471 const searchQuery = jQuery(this).val();
472 fetchTemplates(categoryId, categorySlug, 1, searchQuery);
473
474 }, 300));
475
476 });
477
478
479 function debounce(func, delay) {
480 let timeoutId;
481 return function () {
482 const context = this;
483 const args = arguments;
484 clearTimeout(timeoutId);
485 timeoutId = setTimeout(() => {
486 func.apply(context, args);
487 }, delay);
488 };
489 }
490
491 // new
492 document.addEventListener('DOMContentLoaded', function () {
493 // for uninstall
494 jQuery(document).on('click', '.uninstall-btn', function () {
495 const button = jQuery(this);
496 const templateSlug = button.data('template');
497 const textDomain = button.data('text-domain');
498 if (!confirm('Are you sure you want to uninstall this template and remove all related data?')) {
499 return;
500 }
501
502 jQuery.ajax({
503 url: ajaxurl,
504 type: 'POST',
505 data: {
506 action: 'fleximp_uninstall_template',
507 template_slug: templateSlug,
508 text_domain: textDomain,
509 },
510 success: function (response) {
511 if (response.success) {
512 alert(response.data.message);
513 location.reload();
514 } else {
515 alert('Error: ' + response.data.message);
516 }
517 },
518 });
519 });
520
521
522 });
523
524 window.addEventListener('DOMContentLoaded', function () {
525
526 if (sessionStorage.getItem('fleximp_auto_continue') === '1') {
527 const templatesTab = document.querySelector('.nav-link[href="#templates"]');
528 if (templatesTab) templatesTab.classList.add('active');
529 const templatesPane = document.querySelector('#templates');
530 if (templatesPane) templatesPane.classList.add('active', 'show');
531 const templatesTab1 = document.querySelector('.nav-link[href="#dashboard"]');
532 if (templatesTab1) templatesTab1.classList.remove('active');
533 const templatesPane1 = document.querySelector('#dashboard');
534 if (templatesPane1) templatesPane1.classList.remove('active', 'show');
535
536 sessionStorage.removeItem('fleximp_auto_continue');
537 const importData = sessionStorage.getItem('fleximp_import_data');
538 if (!importData) return;
539
540 const {
541 textDomain,
542 jsonPath,
543 contentPath,
544 templateCss,
545 templateJs,
546 templatePhp,
547 plugins,
548 templateResponsiveImage
549 } = JSON.parse(importData);
550
551 const modalTemplateImage = document.getElementById('modal-template-responsive-image');
552 modalTemplateImage.src = templateResponsiveImage;
553
554 const flexgetattributebutton = document.createElement('button');
555 flexgetattributebutton.classList.add('flex-unique-import-button');
556 flexgetattributebutton.setAttribute('data-text-domain', textDomain);
557 flexgetattributebutton.setAttribute('data-json-path', jsonPath);
558 flexgetattributebutton.setAttribute('data-content-path', contentPath);
559 flexgetattributebutton.setAttribute('data-template-css', templateCss);
560 flexgetattributebutton.setAttribute('data-template-js', templateJs);
561 flexgetattributebutton.setAttribute('data-template-php', templatePhp);
562 flexgetattributebutton.setAttribute('data-plugins', plugins);
563
564 document.body.appendChild(flexgetattributebutton);
565 runImportProcess(); // continue import
566 }
567
568 // new add for filter
569
570 });
571
572 function updateProgress(percent, message) {
573 const progressBar = document.getElementById('import-progress-bar');
574 const progressText = document.getElementById('import-progress-text');
575 if (progressBar && progressText) {
576 progressBar.style.width = percent + '%';
577 progressText.textContent = `${message} (${percent}%)`;
578 }
579 }
580
581 async function runImportProcess() {
582 document.getElementById('step-confirm-import').style.display = 'none';
583 document.getElementById('step-plugins').style.display = 'block';
584 document.getElementById('import-modal').style.display = 'block';
585
586 const pluginLoader = document.getElementById('plugin-loader');
587 const contentLoader = document.getElementById('content-loader');
588 if (pluginLoader) pluginLoader.style.display = 'inline-block';
589 if (contentLoader) contentLoader.style.display = 'none';
590
591 const importBtn = document.querySelector('.flex-unique-import-button');
592 const selectedPlugins = JSON.parse(importBtn.getAttribute('data-plugins'));
593 const jsonPath = importBtn.getAttribute('data-json-path');
594 const contentPath = importBtn.getAttribute('data-content-path');
595 const textDomain = importBtn.getAttribute('data-text-domain');
596 const templateCss = importBtn.getAttribute('data-template-css');
597 const templateJs = importBtn.getAttribute('data-template-js');
598 const templatePhp = importBtn.getAttribute('data-template-php');
599
600 const installPlugin = (plugin) => {
601 return new Promise((resolve) => {
602 jQuery.ajax({
603 url: fleximp_ajax_object.ajax_url,
604 method: 'POST',
605 data: {
606 action: 'fleximp_checked_install_plugin',
607 plugin_slug: plugin.text_domain,
608 plugin_name: plugin.name,
609 plugin_main_file: plugin.main_file
610 },
611 success: function () {
612 console.log(`Plugin ${plugin.name} installed successfully.`);
613 updateProgress(33, `Installed plugin: ${plugin.name}`);
614 },
615 error: function (xhr, status, error) {
616 console.error(`Error installing plugin ${plugin.name}: ${error}`);
617 },
618 complete: function () {
619 resolve();
620 }
621 });
622 });
623 };
624
625 const selectedPluginsObj = Object.values(selectedPlugins);
626
627 // Install plugins one by one
628 for (let i = 0; i < selectedPluginsObj.length; i++) {
629 await installPlugin(selectedPluginsObj[i]);
630 }
631
632 if (pluginLoader) pluginLoader.classList.add('loader-success');
633
634 const innerPagesLoader = document.getElementById('inner-pages-loader');
635 if (innerPagesLoader) innerPagesLoader.style.display = 'inline-block';
636
637 // Step 2: Import Inner Pages
638 await new Promise((resolve) => {
639 jQuery.ajax({
640 url: fleximp_ajax_object.ajax_url,
641 method: 'POST',
642 data: {
643 action: 'fleximp_import_inner_pages_data',
644 nonce: fleximp_ajax_object.nonce,
645 content_path: contentPath,
646 text_domain: textDomain,
647 template_css: templateCss,
648 template_js: templateJs,
649 template_php: templatePhp
650 },
651 success: function () {
652 console.log('Inner pages data imported successfully.');
653 if (innerPagesLoader) innerPagesLoader.classList.add('loader-success');
654 updateProgress(75, 'Importing inner pages success');
655 },
656 error: function (xhr, status, error) {
657 console.error(`Error importing inner pages data: ${error}`);
658 if (innerPagesLoader) innerPagesLoader.classList.add('loader-error');
659 },
660 complete: resolve
661 });
662 });
663
664 // Step 3: Import Demo Content
665 if (contentLoader) contentLoader.style.display = 'inline-block';
666 contentLoader.classList.add('loader-active');
667
668 await new Promise((resolve) => {
669 jQuery.ajax({
670 url: fleximp_ajax_object.ajax_url,
671 method: 'POST',
672 data: {
673 action: 'fleximp_import_demo_content',
674 text_domain: textDomain,
675 json_path: jsonPath
676 },
677 success: function () {
678 console.log('Content imported successfully.');
679 updateProgress(100, 'Import success');
680 },
681 error: function (xhr, status, error) {
682 console.error(`Error importing content: ${error}`);
683 },
684 complete: resolve
685 });
686 });
687
688 if (contentLoader) {
689 contentLoader.classList.remove('loader-active');
690 contentLoader.classList.add('loader-success');
691 }
692
693 const continueButton = document.getElementById('flex-continue-install');
694 if (continueButton) continueButton.style.display = 'inline-block';
695
696 document.getElementById('step-plugins').style.display = 'none';
697 document.getElementById('step-done').style.display = 'block';
698
699 setTimeout(() => location.reload(), 8000);
700 }
701
702
703