diff options
Diffstat (limited to 'plugins/CorePluginsAdmin/vue/src/Plugins/PluginUpload.ts')
-rw-r--r-- | plugins/CorePluginsAdmin/vue/src/Plugins/PluginUpload.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/plugins/CorePluginsAdmin/vue/src/Plugins/PluginUpload.ts b/plugins/CorePluginsAdmin/vue/src/Plugins/PluginUpload.ts new file mode 100644 index 0000000000..9c620fd556 --- /dev/null +++ b/plugins/CorePluginsAdmin/vue/src/Plugins/PluginUpload.ts @@ -0,0 +1,40 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +import { Matomo, translate } from 'CoreHome'; + +const { $ } = window; + +function onUploadPlugin(event: MouseEvent) { + event.preventDefault(); + Matomo.helper.modalConfirm('#installPluginByUpload', {}); +} + +function onSubmitPlugin(event: MouseEvent) { + const $zipFile = $('[name=pluginZip]'); + const fileName = $zipFile.val(); + + if (!fileName || fileName.slice(-4) !== '.zip') { + event.preventDefault(); + // eslint-disable-next-line no-alert + alert(translate('CorePluginsAdmin_NoZipFileSelected')); + } else if ($zipFile.data('maxSize') > 0 + && $zipFile[0].files[0].size > $zipFile.data('maxSize') * 1048576 + ) { + event.preventDefault(); + // eslint-disable-next-line no-alert + alert(translate('CorePluginsAdmin_FileExceedsUploadLimit')); + } +} + +export default { + mounted(): void { + setTimeout(() => { + $('.uploadPlugin').click(onUploadPlugin); + $('#uploadPluginForm').submit(onSubmitPlugin); + }); + }, +}; |