Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/jet-elements   php

Repository URL to install this package:

Version: 2.5.6 

/ modules / jet-dashboard / assets / js / license-page.js

(function () {

	'use strict';

	Vue.component( 'license-item', {
		template: '#jet-dashboard-license-item',

		props: {
			licenseData: Object,
			type: String
		},

		data: function() {
			return {
				licenseKey: this.licenseData.licenseKey,
				licenseStatus: this.licenseData.licenseStatus,
				licenseDetails: this.licenseData.licenseDetails,
				activationStatus: false,
				ajaxLicenseAction: null,
			}
		},

		computed: {

			isLicenseActive: function() {
				return 'active' === this.licenseStatus ? true : false;
			},

			licenseActionType: function() {
				return ! this.isLicenseActive ? 'activate' : 'deactivate';
			},

			maskedLicenseKey: function() {
				let licenseKey      = this.licenseKey,
					licenseKeyArray = licenseKey.split(''),
					maskerLicenseArray = [];

				maskerLicenseArray = licenseKeyArray.map( ( item, index ) => {

					if ( index > 4 && index < licenseKeyArray.length - 4 ) {
						return '*';
					}

					return item;
				} );

				return maskerLicenseArray.join('');
			},

			/*licenseStatus: function() {
				return this.isLicenseActive ? 'activated' : 'not-activated';
			},*/

			licenseType: function() {
				return this.licenseDetails.type ? this.licenseDetails.type : '';
			},

			productName: function() {
				return this.licenseDetails.product_name ? this.licenseDetails.product_name : '';
			},

			isLicenseExpired: function() {
				return 'expired' === this.licenseStatus ? true : false;
			},

			expireDate: function() {

				let expireCases = [
					'0000-00-00 00:00:00',
					'1000-01-01 00:00:00',
					'lifetime'
				];

				if ( expireCases.includes( this.licenseDetails.expire ) ) {
					return 'Lifetime';
				}

				return this.licenseDetails.expire;
			},

			licensePlugins: function() {
				return this.licenseDetails.plugins ? this.licenseDetails.plugins : [];
			},
		},

		methods: {
			showLicenseManager: function() {
				window.JetDashboardEventBus.$emit( 'showLicenseManager' );
			},

			licenseAction: function() {
				var self       = this,
					actionType = self.licenseActionType;

				self.activationStatus = true;

				self.ajaxLicenseAction = jQuery.ajax( {
					type: 'POST',
					url: window.JetDashboardConfig.ajaxUrl,
					dataType: 'json',
					data: {
						action: 'jet_license_action',
						data: {
							license: self.licenseKey,
							action: actionType
						}
					},
					beforeSend: function( jqXHR, ajaxSettings ) {

						if ( null !== self.ajaxLicenseAction ) {
							self.ajaxLicenseAction.abort();
						}
					},
					success: function( responce, textStatus, jqXHR ) {
						self.activationStatus = false;

						self.$CXNotice.add( {
							message: responce.message,
							type: responce.status,
							duration: 4000,
						} );

						let licenseStatus  = responce.status,
							licenseDetails = responce.data;

						if ( 'success' === licenseStatus ) {

							if ( 'activate' === actionType ) {

								self.licenseStatus = 'active';
								self.licenseDetails = licenseDetails;

								window.JetDashboardEventBus.$emit( 'addLicenseItem', {
									'licenseKey': self.licenseKey,
									'licenseStatus': 'active',
									'licenseDetails': licenseDetails,
								} );
							}

							if ( 'deactivate' === actionType ) {
								window.JetDashboardEventBus.$emit( 'removeLicenseItem', self.licenseKey );
							}
						}

						if ( 'error' === licenseStatus ) {
							if ( 'limit_exceeded' === responce.code ) {
								window.JetDashboardEventBus.$emit( 'showResponcePopup', responce );
							}
						}
					}
				} );
			}
		}
	} );

	Vue.component( 'plugin-item-installed', {
		template: '#jet-dashboard-plugin-item-installed',

		props: {
			pluginData: Object
		},

		data: function() {
			return {
				actionPlugin: false,
				actionPluginRequest: null,
				actionPluginProcessed: false,
				licenseActionProcessed: false,
				updatePluginProcessed: false,
				rollbackPluginProcessed: false,
				licenseKey: '',
				ajaxLicenseAction: null,
				rollbackPopupVisible: false,
				rollbackVersion: this.pluginData['version']
			}
		},

		computed: {

			deactivateAvaliable: function() {
				return ( this.pluginData['isInstalled'] && this.pluginData['isActivated'] ) ? true : false;
			},

			activateAvaliable: function() {
				return ( this.pluginData['isInstalled'] && !this.pluginData['isActivated'] ) ? true : false;
			},

			updateAvaliable: function() {
				return ( this.pluginData['updateAvaliable'] ) ? true : false;
			},

			updateActionAvaliable: function() {
				return ( this.pluginData['licenseActivated'] && this.pluginData['updateAvaliable'] ) ? true : false;
			},

			activateLicenseVisible: function() {
				return ( this.pluginData['licenseControl'] && !this.pluginData['licenseActivated'] ) ? true : false;
			},

			deactivateLicenseVisible: function() {
				return ( this.pluginData['licenseActivated'] ) ? true : false;
			},

			versionRollbackAvaliable: function() {
				return ( 0 < this.pluginData['versions'].length ) && this.pluginData['licenseActivated'] && this.deactivateAvaliable ? true : false;
			},

			rollbackButtonVisible: function() {
				return this.rollbackVersion !== this.pluginData['currentVersion'];
			},

			proccesingState: function() {
				return this.actionPluginProcessed || this.updatePluginProcessed || this.rollbackPluginProcessed;
			},

			rollbackOptions: function() {

				return this.pluginData['versions'].map( ( version ) => {
					let label = version;

					if ( label === this.pluginData['currentVersion'] ) {
						label = label + ' - Current Version';
					}

					if ( label === this.pluginData['version'] ) {
						label = label + ' - Latest Version';
					}

					return {
						label: label,
						value: version,
					}
				} );
			}
		},

		methods: {

			deactivatePlugin: function() {
				this.actionPlugin = 'deactivate';
				this.pluginAction();
			},

			activatePlugin: function() {
				this.actionPlugin = 'activate';
				this.pluginAction();
			},

			updatePlugin: function() {

				if ( this.updateActionAvaliable ) {

					this.actionPlugin = 'update';
					this.pluginAction();
				} else {
					window.JetDashboardEventBus.$emit( 'showPopupUpdateCheck' );
				}

			},

			showPopupActivation: function() {
				window.JetDashboardEventBus.$emit( 'showPopupActivation', this.pluginData['slug'] );
			},

			showRollbackPopup: function() {
				this.rollbackPopupVisible = true;
			},

			rollbackPluginVersion: function() {
				this.actionPlugin = 'rollback';
				this.pluginAction();
			},

			pluginAction: function() {
				let self = this;

				self.actionPluginRequest = jQuery.ajax( {
					type: 'POST',
					url: window.JetDashboardConfig.ajaxUrl,
					dataType: 'json',
					data: {
						action: 'jet_dashboard_plugin_action',
						data: {
							action: self.actionPlugin,
							plugin: self.pluginData['slug'],
							version: self.rollbackVersion,
						}
					},
					beforeSend: function( jqXHR, ajaxSettings ) {

						if ( null !== self.actionPluginRequest ) {
							self.actionPluginRequest.abort();
						}

						switch( self.actionPlugin ) {

							case 'activate':
							case 'deactivate':
								self.actionPluginProcessed = true;
							break;

							case 'update':
								self.updatePluginProcessed = true;
							break;

							case 'rollback':
								self.rollbackPluginProcessed = true;
							break;
						}
					},
					success: function( responce, textStatus, jqXHR ) {

						switch(  self.actionPlugin ) {

							case 'activate':
							case 'deactivate':
								self.actionPluginProcessed = false;
							break;

							case 'update':
								self.updatePluginProcessed = false;
							break;

							case 'rollback':
								self.rollbackPluginProcessed = false;
							break;
						}

						self.$CXNotice.add( {
							message: responce.message,
							type: responce.status,
							duration: 3000,
						} );

						if ( 'success' === responce.status ) {
							self.rollbackPopupVisible = false;

							window.JetDashboardEventBus.$emit( 'updateUserPluginData', {
								'slug': self.pluginData['slug'],
								'pluginData': responce.data,
							} );
						}
					}
				} );
			},
Loading ...