Plugin Directory

Changeset 3296226


Ignore:
Timestamp:
05/19/2025 07:21:19 AM (11 months ago)
Author:
scaleflex
Message:

Add option keep data when deactivate plugin

Location:
filerobot-digital-asset-management-and-acceleration
Files:
31 added
4 edited

Legend:

Unmodified
Added
Removed
  • filerobot-digital-asset-management-and-acceleration/trunk/README.txt

    r3294556 r3296226  
    55Tested up to: 6.8
    66Requires at least: 4.8
    7 Stable tag: 4.0.11
     7Stable tag: 4.0.12
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    224224= 4.0.11 =
    225225* Fix bug sync assets
     226= 4.0.12 =
     227* Add option keep data when deactivate plugin
    226228
    227229== Upgrade Notice ==
  • filerobot-digital-asset-management-and-acceleration/trunk/assets/scripts/fmaw.js

    r3174729 r3296226  
    5050
    5151jQuery(document).ready(function($) {
     52    $('.deactivate a').click(function(e) {
     53        if ($(this).attr('id') === 'deactivate-filerobot-digital-asset-management-and-acceleration') {
     54            e.preventDefault();
     55            showModal();
     56            return false;
     57
     58        }
     59    });
     60
    5261    // event resize image in classic editor
    5362    let isClassicEditor = ($('#wp-content-wrap').length > 0 && $('#wp-content-wrap').hasClass('tmce-active')) ? true : false;
     
    465474    }
    466475}
     476
     477function showModal() {
     478    // Check if modal is already exists
     479    if (document.getElementById("modalOverlay")) return;
     480
     481    // Create overlay
     482    let overlay = document.createElement("div");
     483    overlay.id = "modalOverlay";
     484    overlay.style.position = "fixed";
     485    overlay.style.top = "0";
     486    overlay.style.left = "0";
     487    overlay.style.width = "100%";
     488    overlay.style.height = "100%";
     489    overlay.style.background = "rgba(0, 0, 0, 0.5)";
     490    overlay.style.display = "flex";
     491    overlay.style.justifyContent = "center";
     492    overlay.style.alignItems = "center";
     493    overlay.style.zIndex = "1000";
     494
     495    // Create modal
     496    let modal = document.createElement("div");
     497    modal.style.background = "white";
     498    modal.style.padding = "20px";
     499    modal.style.borderRadius = "8px";
     500    modal.style.width = "400px";
     501    modal.style.textAlign = "center";
     502    modal.style.boxShadow = "0 4px 10px rgba(0, 0, 0, 0.2)";
     503
     504    // Modal header
     505    let title = document.createElement("h3");
     506    title.innerText = "Scaleflex DAM";
     507
     508    // Content
     509    let message = document.createElement("p");
     510    message.setAttribute("id", "sfxMessage");
     511    message.innerText = "";
     512
     513    // Question
     514    let question = document.createElement("p");
     515    question.innerText = "Are you sure you want to deactivate the plugin?";
     516
     517    // Select option text
     518    let optionText = document.createElement("p");
     519    optionText.innerText = "Please select an option below to deactivate the plugin:";
     520
     521    // Radio button
     522    let radioContainer = document.createElement("div");
     523    radioContainer.style.marginTop = "15px";
     524    radioContainer.style.textAlign = "left";
     525
     526    let radioWrapper0 = document.createElement("div");
     527
     528    let radio0 = document.createElement("input");
     529    radio0.type = "radio";
     530    radio0.name = "keep_data";
     531    radio0.value = "0";
     532    radio0.id = "keep_data_0";
     533
     534    let label0 = document.createElement("label");
     535    label0.htmlFor = "keep_data_0";
     536    label0.innerText = "Delete all plugin data.";
     537
     538    radioWrapper0.appendChild(radio0);
     539    radioWrapper0.appendChild(label0);
     540
     541    let radioWrapper1 = document.createElement("div");
     542    radioWrapper1.style.marginTop = "5px";
     543
     544    let radio1 = document.createElement("input");
     545    radio1.type = "radio";
     546    radio1.name = "keep_data";
     547    radio1.value = "1";
     548    radio1.id = "keep_data_1";
     549    radio1.defaultChecked = true;
     550
     551    let label1 = document.createElement("label");
     552    label1.htmlFor = "keep_data_1";
     553    label1.innerText = "Keep all plugin data.";
     554
     555    radioWrapper1.appendChild(radio1);
     556    radioWrapper1.appendChild(label1);
     557
     558    radioContainer.appendChild(radioWrapper0);
     559    radioContainer.appendChild(radioWrapper1);
     560
     561    // Submit
     562    let submitBtn = document.createElement("button");
     563    submitBtn.innerText = "Yes";
     564    submitBtn.style.background = "#d891ef";
     565    submitBtn.style.padding = "10px";
     566    submitBtn.style.border = "none";
     567    submitBtn.style.cursor = "pointer";
     568    submitBtn.style.marginTop = "15px";
     569    submitBtn.onclick = closeModalAndSendRequest;
     570
     571    // Cancel
     572    let skipBtn = document.createElement("button");
     573    skipBtn.innerText = "No";
     574    skipBtn.style.background = "#ddd";
     575    skipBtn.style.padding = "10px";
     576    skipBtn.style.border = "none";
     577    skipBtn.style.cursor = "pointer";
     578    skipBtn.style.marginLeft = "15px";
     579    skipBtn.onclick = closeModal;
     580
     581    modal.appendChild(title);
     582    modal.appendChild(message);
     583    modal.appendChild(question);
     584    modal.appendChild(optionText);
     585    modal.appendChild(radioContainer);
     586    modal.appendChild(submitBtn);
     587    modal.appendChild(skipBtn);
     588    overlay.appendChild(modal);
     589    document.body.appendChild(overlay);
     590}
     591
     592function closeModalAndSendRequest() {
     593    let keep_data = jQuery('input[name="keep_data"]:checked').val();
     594    const data = {
     595        action: 'filerobot_deactivate_plugin',
     596        keep_data: keep_data
     597    };
     598
     599    let overlay = document.getElementById("modalOverlay");
     600    if (overlay) {
     601        overlay.remove();
     602    }
     603
     604    jQuery.ajax({
     605        type: 'POST',
     606        url: ajaxurl,
     607        data: data,
     608        dataType: 'json'
     609    }).done(function (res) {
     610        if (res.success) {
     611            window.location.href = jQuery('#deactivate-filerobot-digital-asset-management-and-acceleration').attr('href');
     612        } else {
     613            return false;
     614        }
     615    });
     616    return true;
     617}
     618
     619function closeModal() {
     620    let overlay = document.getElementById("modalOverlay");
     621    if (overlay) {
     622        overlay.remove();
     623    }
     624}
Note: See TracChangeset for help on using the changeset viewer.