admin-script.js
3 weeks ago
dashboard-posts.js
3 months ago
free-template-admin.js
3 months ago
front-script.js
3 months ago
jquery.notify.min.js
3 months ago
license_script.js
3 weeks ago
plugin-admin.js
3 months ago
template-admin.js
3 months ago
admin-script.js
255 lines
| 1 | jQuery(document).ready(function ($) { |
| 2 | $('#fleximp-install-plugins').on('click', function () { |
| 3 | this.disabled = true; |
| 4 | this.innerText = 'Installing...'; |
| 5 | $.ajax({ |
| 6 | url: fleximp_admin_ajax_object.ajax_url, |
| 7 | method: 'POST', |
| 8 | data: { |
| 9 | action: 'fleximp_get_required_plugins', |
| 10 | _ajax_nonce: fleximp_admin_ajax_object.fleximp_nonce |
| 11 | }, |
| 12 | success: function (response) { |
| 13 | if (response.success) { |
| 14 | const plugins = response.data; |
| 15 | installPlugin(plugins, 0); |
| 16 | } else { |
| 17 | const errorMessage = response.data ? response.data : 'An unexpected error occurred while fetching plugins.'; |
| 18 | alert(errorMessage); |
| 19 | } |
| 20 | }, |
| 21 | error: function () { |
| 22 | alert('An error occurred while fetching the plugins.'); |
| 23 | } |
| 24 | }); |
| 25 | |
| 26 | function installPlugin(plugins, index) { |
| 27 | if (index >= plugins.length) { |
| 28 | $('#fleximp-install-plugins').text('All plugins installed successfully.'); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | const plugin = plugins[index]; |
| 33 | const statusElement = $(`#plugin-status-${plugin.slug}`); |
| 34 | statusElement.html('<span class="spinner is-active"></span> Installing...'); |
| 35 | |
| 36 | $.ajax({ |
| 37 | url: fleximp_admin_ajax_object.ajax_url, |
| 38 | method: 'POST', |
| 39 | data: { |
| 40 | action: 'fleximp_install_single_plugin', |
| 41 | plugin_slug: plugin.slug, |
| 42 | _ajax_nonce: fleximp_admin_ajax_object.fleximp_nonce |
| 43 | }, |
| 44 | success: function (response) { |
| 45 | const statusElement = $(`#plugin-status-${plugin.slug}`); |
| 46 | |
| 47 | if (typeof response === 'string') { |
| 48 | const jsonResponseMatch = response.match(/(\{.*\})$/); |
| 49 | |
| 50 | if (jsonResponseMatch) { |
| 51 | try { |
| 52 | const jsonResponse = JSON.parse(jsonResponseMatch[0]); |
| 53 | |
| 54 | if (jsonResponse.success) { |
| 55 | statusElement.html('<span class="dashicons dashicons-yes"></span> ' + (jsonResponse.data.message || 'success.')); |
| 56 | } else { |
| 57 | const errorMessage = jsonResponse.data.message || 'fail.'; |
| 58 | statusElement.html(`<span class="dashicons dashicons-no-alt"></span> ${errorMessage}`); |
| 59 | } |
| 60 | } catch (e) { |
| 61 | statusElement.html('<span class="dashicons dashicons-no-alt"></span> Fail.'); |
| 62 | } |
| 63 | } else { |
| 64 | statusElement.html('<span class="dashicons dashicons-no-alt"></span> Fail.'); |
| 65 | } |
| 66 | } else if (typeof response === 'object' && response !== null) { |
| 67 | if (response.success) { |
| 68 | statusElement.html('<span class="dashicons dashicons-yes"></span> ' + (response.data.message || 'success.')); |
| 69 | } else { |
| 70 | const errorMessage = response.data.message || 'An unknown error occurred during installation.'; |
| 71 | statusElement.html(`<span class="dashicons dashicons-no-alt"></span> ${errorMessage}`); |
| 72 | } |
| 73 | } else { |
| 74 | statusElement.html('<span class="dashicons dashicons-no-alt"></span> Fail.'); |
| 75 | } |
| 76 | |
| 77 | installPlugin(plugins, index + 1); |
| 78 | }, |
| 79 | |
| 80 | |
| 81 | error: function () { |
| 82 | const statusElement = $(`#plugin-status-${plugin.slug}`); |
| 83 | statusElement.html('<span class="dashicons dashicons-no-alt"></span> Installation failed.'); |
| 84 | installPlugin(plugins, index + 1); // Continue with the next plugin |
| 85 | } |
| 86 | }); |
| 87 | } |
| 88 | }); |
| 89 | }); |
| 90 | |
| 91 | |
| 92 | |
| 93 | jQuery(document).ready(function ($) { |
| 94 | $(document).on('click', '.download-btn', function (e) { |
| 95 | e.preventDefault(); |
| 96 | |
| 97 | const $button = $(this); |
| 98 | const pluginSlug = $button.data('plugin-url').split('/').pop().replace('.latest-stable.zip', ''); |
| 99 | const pluginName = $button.data('plugin-name'); |
| 100 | const pluginMainFile = $button.data('plugin-main-file'); |
| 101 | |
| 102 | $button.addClass('installing').prop('disabled', true); |
| 103 | |
| 104 | $.ajax({ |
| 105 | url: fleximp_admin_ajax_object.ajax_url, |
| 106 | type: 'POST', |
| 107 | dataType: 'json', |
| 108 | data: { |
| 109 | action: 'fleximp_install_plugin', |
| 110 | security: fleximp_admin_ajax_object.fleximp_nonce, |
| 111 | plugin_slug: pluginSlug, |
| 112 | plugin_name: pluginName, |
| 113 | plugin_main_file: pluginMainFile, |
| 114 | }, |
| 115 | success: function (response) { |
| 116 | const $status = $(`#plugin-status-${pluginSlug}`); |
| 117 | if (response.success) { |
| 118 | $button.removeClass('installing').addClass('activated').prop('disabled', true); |
| 119 | $status.text('Activated'); |
| 120 | } else { |
| 121 | alert(response.data.message || 'Failed to install the plugin.'); |
| 122 | $button.removeClass('installing').prop('disabled', false); |
| 123 | $status.text('Failed to install'); |
| 124 | } |
| 125 | }, |
| 126 | error: function () { |
| 127 | $button.removeClass('installing').addClass('activated').prop('disabled', true); |
| 128 | const $status = $(`#plugin-status-${pluginSlug}`); |
| 129 | $status.text(''); |
| 130 | |
| 131 | }, |
| 132 | }); |
| 133 | }); |
| 134 | |
| 135 | $('#install-all-btn').on('click', function () { |
| 136 | const selectedPlugins = []; |
| 137 | |
| 138 | $('.plugin-checkbox:checked').each(function () { |
| 139 | const $checkbox = $(this); |
| 140 | selectedPlugins.push({ |
| 141 | pluginSlug: $checkbox.data('plugin-url').split('/').pop().replace('.latest-stable.zip', ''), |
| 142 | pluginName: $checkbox.data('plugin-name'), |
| 143 | pluginMainFile: $checkbox.data('plugin-main-file') |
| 144 | }); |
| 145 | }); |
| 146 | |
| 147 | if (selectedPlugins.length === 0) { |
| 148 | alert('Please select at least one plugin to install.'); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | installPluginsInSequence(selectedPlugins); |
| 153 | |
| 154 | $('#install-all-btn').text('Installing All...').prop('disabled', true); |
| 155 | |
| 156 | $('#install-all-btn').text('Install All Selected').prop('disabled', false); |
| 157 | }); |
| 158 | |
| 159 | |
| 160 | // Function to install plugins sequentially |
| 161 | function installPluginsInSequence(plugins) { |
| 162 | // if (plugins.length === 0) return; |
| 163 | if (plugins.length === 0) { |
| 164 | $('#install-all-btn').text('Install All Selected').prop('disabled', false); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | const currentPlugin = plugins.shift(); |
| 169 | const $status = $(`#plugin-status-${currentPlugin.pluginSlug}`); |
| 170 | //new const $button = $(`.download-btn[data-plugin-url*="${currentPlugin.pluginSlug}"]`); |
| 171 | const $button = $(`.download-btn[data-plugin-url*="${currentPlugin.pluginSlug}"]`); |
| 172 | $status.text('Installing...'); |
| 173 | $button.addClass('installing').prop('disabled', true); |
| 174 | |
| 175 | fetch(fleximp_admin_ajax_object.ajax_url, { |
| 176 | method: 'POST', |
| 177 | headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, |
| 178 | body: `action=fleximp_install_plugin&security=${fleximp_admin_ajax_object.fleximp_nonce}&plugin_slug=${currentPlugin.pluginSlug}&plugin_name=${currentPlugin.pluginName}&plugin_main_file=${currentPlugin.pluginMainFile}` |
| 179 | }) |
| 180 | .then(response => { |
| 181 | // Check if the response is JSON |
| 182 | const contentType = response.headers.get('content-type'); |
| 183 | if (contentType && contentType.includes('application/json')) { |
| 184 | return response.json(); |
| 185 | } else { |
| 186 | return response.text(); |
| 187 | } |
| 188 | }) |
| 189 | .then(data => { |
| 190 | if (typeof data === 'object' && data.success) { |
| 191 | $status.text('Activated'); |
| 192 | $button.removeClass('installing').addClass('activated').prop('disabled', true); |
| 193 | |
| 194 | } else if (typeof data === 'string') { |
| 195 | console.log('Plugin installation message:', data); |
| 196 | $status.text('Check console for details'); |
| 197 | $button.removeClass('installing').addClass('activated').prop('disabled', true); |
| 198 | } else { |
| 199 | $status.text('Failed to install/activate'); |
| 200 | } |
| 201 | installPluginsInSequence(plugins); |
| 202 | }) |
| 203 | .catch(error => { |
| 204 | console.error('Error installing plugin:', error); |
| 205 | $status.text('Error occurred'); |
| 206 | installPluginsInSequence(plugins); |
| 207 | }); |
| 208 | } |
| 209 | }); |
| 210 | |
| 211 | // code for metafield in theme |
| 212 | jQuery(document).ready(function ($) { |
| 213 | var mediaUploader; |
| 214 | $('.custom_media_button').click(function (e) { |
| 215 | e.preventDefault(); |
| 216 | if (mediaUploader) { |
| 217 | mediaUploader.open(); |
| 218 | return; |
| 219 | } |
| 220 | mediaUploader = wp.media.frames.file_frame = wp.media({ |
| 221 | title: 'Select Image', |
| 222 | button: { text: 'Use this image' }, |
| 223 | multiple: false |
| 224 | }); |
| 225 | mediaUploader.on('select', function () { |
| 226 | var attachment = mediaUploader.state().get('selection').first().toJSON(); |
| 227 | $('#service_category_image').val(attachment.id); |
| 228 | $('#service_category_image_preview').html('<img src="' + attachment.url + '" style="max-width:100px;" />'); |
| 229 | }); |
| 230 | mediaUploader.open(); |
| 231 | }); |
| 232 | }); |
| 233 | |
| 234 | |
| 235 | jQuery(document).ready(function ($) { |
| 236 | var mediaUploader; |
| 237 | $('.custom_media_button').click(function (e) { |
| 238 | e.preventDefault(); |
| 239 | if (mediaUploader) { |
| 240 | mediaUploader.open(); |
| 241 | return; |
| 242 | } |
| 243 | mediaUploader = wp.media.frames.file_frame = wp.media({ |
| 244 | title: 'Select Image', |
| 245 | button: { text: 'Use this image' }, |
| 246 | multiple: false |
| 247 | }); |
| 248 | mediaUploader.on('select', function () { |
| 249 | var attachment = mediaUploader.state().get('selection').first().toJSON(); |
| 250 | $('#service_category_image').val(attachment.id); |
| 251 | $('#service_category_image_preview').html('<img src="' + attachment.url + '" style="max-width:100px;" />'); |
| 252 | }); |
| 253 | mediaUploader.open(); |
| 254 | }); |
| 255 | }); |