deactivate.php
158 lines
| 1 | <div id="analyst-deactivate-modal" class="analyst-modal" style="display: none"> |
| 2 | <div class="analyst-modal-content" style="width: 500px"> |
| 3 | <div class="analyst-disable-modal-mask" id="analyst-disable-deactivate-modal-mask" style="display: none"></div> |
| 4 | <div style="display: flex"> |
| 5 | <div class="analyst-install-image-block" style="width: 80px"> |
| 6 | <img src="<?php echo $pencilImage; ?>"/> |
| 7 | </div> |
| 8 | <div class="analyst-install-description-block" style="padding-left: 20px"> |
| 9 | <strong class="analyst-modal-header">Why do you deactivate?</strong> |
| 10 | <div class="analyst-install-description-text" style="padding-top: 2px"> |
| 11 | Please let us know, so we can improve it! Thank you <img class="analyst-smile-image" src="<?php echo $smileImage; ?>" alt=""> |
| 12 | </div> |
| 13 | </div> |
| 14 | </div> |
| 15 | <div> |
| 16 | <ul id="analyst-deactivation-reasons"> |
| 17 | <li> |
| 18 | <label> |
| 19 | <span> |
| 20 | <input type="radio" name="deactivation-reason"> |
| 21 | </span> |
| 22 | <span class="question" data-question="I couldn't understand how to make it work">I couldn't understand how to make it work</span> |
| 23 | </label> |
| 24 | </li> |
| 25 | <li data-input-type="textarea" data-input-placeholder="What should have worked, but didn’t?"> |
| 26 | <label> |
| 27 | <span> |
| 28 | <input type="radio" name="deactivation-reason"> |
| 29 | </span> |
| 30 | <span class="question" data-question="The plugin didn't work as expected">The plugin didn't work as expected</span> |
| 31 | </label> |
| 32 | <div class="question-answer"></div> |
| 33 | </li> |
| 34 | <li data-input-type="input" data-input-placeholder="What is the plugin name?"> |
| 35 | <label> |
| 36 | <span> |
| 37 | <input type="radio" name="deactivation-reason"> |
| 38 | </span> |
| 39 | <span class="question" data-question="I found a better plugin">I found a better plugin</span> |
| 40 | </label> |
| 41 | <div class="question-answer"></div> |
| 42 | </li> |
| 43 | <li> |
| 44 | <label> |
| 45 | <span> |
| 46 | <input type="radio" name="deactivation-reason"> |
| 47 | </span> |
| 48 | <span class="question" data-question="It's a temporary deactivation">It's a temporary deactivation</span> |
| 49 | </label> |
| 50 | <div class="question-answer"></div> |
| 51 | </li> |
| 52 | <li data-input-type="textarea" data-input-placeholder="Please provide the reason of deactivation"> |
| 53 | <label> |
| 54 | <span> |
| 55 | <input type="radio" name="deactivation-reason"> |
| 56 | </span> |
| 57 | <span class="question" data-question="Other">Other</span> |
| 58 | </label> |
| 59 | <div class="question-answer"></div> |
| 60 | </li> |
| 61 | </ul> |
| 62 | <p id="analyst-deactivation-error" style="color: #dc3232; font-size: 16px; display: none">Please let us know the reason for de-activation. Thank you!</p> |
| 63 | </div> |
| 64 | <div> |
| 65 | <button class="analyst-btn-grey" id="analyst-disabled-plugin-action">Deactivate</button> |
| 66 | </div> |
| 67 | <div class="" style="text-align: center; font-size: 18px; padding-top: 10px"> |
| 68 | <button class="analyst-btn-secondary-ghost analyst-deactivate-modal-close" style="color: #cccccc">Cancel</button> |
| 69 | </div> |
| 70 | </div> |
| 71 | </div> |
| 72 | |
| 73 | <script type="text/javascript"> |
| 74 | (function ($) { |
| 75 | $('.deactivate').click(function (e) { |
| 76 | var anchor = $(this).find('[analyst-plugin-id]') |
| 77 | var pluginId = anchor.attr('analyst-plugin-id') |
| 78 | var isOptedIn = anchor.attr('analyst-plugin-opted-in') === '1' |
| 79 | |
| 80 | // Do not ask for reason if not opted in |
| 81 | if (!isOptedIn) { |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | e.preventDefault() |
| 86 | |
| 87 | $('#analyst-deactivate-modal') |
| 88 | .attr({ |
| 89 | 'analyst-plugin-id': pluginId, |
| 90 | 'analyst-redirect-url': $(this).find('a').attr('href') |
| 91 | }) |
| 92 | .show() |
| 93 | }) |
| 94 | |
| 95 | $('.analyst-deactivate-modal-close').click(function () { |
| 96 | $('#analyst-deactivate-modal').hide() |
| 97 | }) |
| 98 | |
| 99 | $('#analyst-deactivation-reasons input[name="deactivation-reason"]').change(function () { |
| 100 | $('.question-answer').empty() |
| 101 | |
| 102 | var root = $('#analyst-deactivation-reasons input[name="deactivation-reason"]:checked').parents('li') |
| 103 | |
| 104 | $('#analyst-deactivation-error').hide() |
| 105 | |
| 106 | if (!root.attr('data-input-type')) return |
| 107 | |
| 108 | var reasonInput = $('<' + root.attr('data-input-type') + '/>').attr({placeholder: root.attr('data-input-placeholder'), class: 'reason-answer'}) |
| 109 | |
| 110 | root.find('.question-answer').append(reasonInput) |
| 111 | }) |
| 112 | |
| 113 | $('#analyst-disabled-plugin-action').click(function () { |
| 114 | var pluginId = $('#analyst-deactivate-modal').attr('analyst-plugin-id') |
| 115 | var pluginDeactivationUrl = $('#analyst-deactivate-modal').attr('analyst-redirect-url') |
| 116 | |
| 117 | var root = $('#analyst-deactivation-reasons input[name="deactivation-reason"]:checked').parents('li'); |
| 118 | |
| 119 | var reason = root.find('.question-answer .reason-answer').val(); |
| 120 | |
| 121 | var question = root.find('.question').attr('data-question').trim() |
| 122 | |
| 123 | var $errorBlock = $('#analyst-deactivation-error') |
| 124 | |
| 125 | if (!question) { |
| 126 | return $errorBlock.show() |
| 127 | } |
| 128 | |
| 129 | $errorBlock.hide() |
| 130 | |
| 131 | var data = { |
| 132 | action: 'analyst_plugin_deactivate_' + pluginId, |
| 133 | question: question, |
| 134 | nonce: analyst_opt_localize.nonce |
| 135 | } |
| 136 | |
| 137 | if (reason) { |
| 138 | data['reason'] = reason.trim(); |
| 139 | } |
| 140 | |
| 141 | $(this).attr('disabled', true).text('Deactivating...'); |
| 142 | |
| 143 | $('#analyst-disable-deactivate-modal-mask').show(); |
| 144 | |
| 145 | $.ajax({ |
| 146 | url: ajaxurl, |
| 147 | method: 'POST', |
| 148 | data: data |
| 149 | }).done(function () { |
| 150 | window.location.href = pluginDeactivationUrl |
| 151 | |
| 152 | $('#analyst-disable-deactivate-modal-mask').hide(); |
| 153 | }) |
| 154 | }) |
| 155 | |
| 156 | })(jQuery) |
| 157 | </script> |
| 158 |