Skip to content

Commit

Permalink
Merge pull request #56 from crowdfavorite/1.4.0
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
al-esc authored May 14, 2020
2 parents 5c61226 + 630a92c commit 8654dce
Show file tree
Hide file tree
Showing 23 changed files with 14,315 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ node_modules/
build/
composer/
composer.lock
package-lock.json
/package-lock.json
!lib/ace/build/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Version 1.4.0
- added EDD licensing/updating

## Version 1.3.0
- fixed warning when editing posts in the backend
- replace icon
Expand Down
3 changes: 2 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
remove_post_type_support('post', 'post-formats');

require_once dirname(__FILE__) . '/lib/wp-taxonomy-filter/taxonomy-filter.php';
require_once dirname(__FILE__) . '/updater/updater.php';

/**
* Test if this is a Capsule server.
Expand Down Expand Up @@ -867,7 +868,7 @@ function capsule_wp_editor_warning()
<div class="capsule-editor-warning">
<h3><?php esc_html_e('Whoa Cowboy!', 'capsule'); ?></h3>
<p>
<b><?php esc_html_e('<b>Capsule is designed for front-end editing only.', 'capsule'); ?></b>
<b><?php esc_html_e('Capsule is designed for front-end editing only.', 'capsule'); ?></b>
<br>
<?php
esc_html_e(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capsule-ui",
"version": "1.3.0",
"version": "1.4.0",
"devDependencies": {},
"dependencies": {
"requirejs": "",
Expand Down
3 changes: 3 additions & 0 deletions updater/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/env", "@babel/preset-react"]
}
1 change: 1 addition & 0 deletions updater/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions updater/assets/img/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
188 changes: 188 additions & 0 deletions updater/assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/**
* Admin settings.
*
* @package capsule
*/
import axios from 'axios';
import Swal from 'sweetalert2';

let __ = wp.i18n.__;
let _n = wp.i18n._n;

jQuery(($) => {
var Capsule = {
/**
* Initialize.
*/
init() {
this.$body = $('body');
this.registerLicenseSave();
this.registerLicenseReveal();
this.registerLicenseRevoke();
this.registerLicenseCheck();
},
/**
* Send command via Ajax.
*/
sendCommand(action, data, callback, options = {}, blockUI = true) {
if (blockUI) {
$.blockUI({
message: `
<div id="capsule-sl-logo-loading" aria-label="${__('Loading', 'capsule')}">
<img src="${capsule_sl_admin.loading}" style="max-width: 200px;" /><br />
</div>`,
css: {
border: 'none',
padding: '15px',
backgroundColor: 'transparent',
},
overlayCSS: { backgroundColor: '#FFF' },
});
}

let default_options = {
json: true,
alert_on_error: false,
prefix: 'capsule_sl_',
nonce: $('#_capsule_sl').val(),
timeout: null,
async: true,
type: 'POST',
};

for (let opt in default_options) {
if (!options.hasOwnProperty(opt)) {
options[opt] = default_options[opt];
}
}

// Axios and WordPress require data as form data.
var formData = new FormData();
for (let key in data) {
if (data.hasOwnProperty(key)) {
formData.append(key, data[key]);
}
}

formData.append('action', options.prefix + action);

axios({
method: options.type,
url: ajaxurl,
data: formData,
})
.then((response) => {
$.unblockUI();
if (!response.data.success && options.alert_on_error) {
alert(response.data.data.message);
return;
}
if ('function' === typeof callback) callback(response.data);
},
(response) => {
$.unblockUI();
alert(__('Could not complete request', 'capsule'));
});
},
/**
* Register the reset button on the white label savings button.
*/
registerLicenseSave() {
this.$body.on('click', '#capsule-sl-license-save', (e) => {
e.preventDefault();
Capsule.sendCommand(
'license_save',
{
nonce: $('#_capsule_sl').val(),
license: $('#edd-license').val(),
},
(response) => this.updateContent(response)
);
});
},
/**
* Revokes a license.
*/
revokeLicense() {
Capsule.sendCommand(
'license_deactivate',
{
nonce: $('#_capsule_sl').val(),
license: $('#edd-license').val(),
},
(response) => this.updateContent(response)
);
},
/**
* Register the reset button on the white label savings button.
*/
registerLicenseRevoke() {
this.$body.on('click', '#capsule-sl-license-deactivate', (e) => {
e.preventDefault();

Swal.fire({
title: __( 'Revoke License?', 'capsule' ),
text: __( 'You can always enter your license again later.', 'capsule' ),
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#c3640f',
cancelButtonColor: '#721c24',
confirmButtonText: __( 'Revoke License', 'capsule' ),
}).then((result) => {
if (result.value) {
Capsule.revokeLicense();
}
})
});
},
/**
* Register the check button on the license check button.
*/
registerLicenseCheck() {
this.$body.on('click', '#capsule-sl-license-check', (e) => {
e.preventDefault();
Capsule.sendCommand(
'license_check',
{
nonce: $('#_capsule_sl').val(),
license: $('#edd-license').val(),
},
(response) => this.updateContent(response)
);
});
},
/**
* Reveal the license.
*/
registerLicenseReveal() {
this.$body.on('click', '#capsule-sl-field-license-reveal', (e) => {
let $license = $('#edd-license');
if ('password' === $license.prop('type')) {
$license.prop('type', 'text');
} else {
$license.prop('type', 'password');
}
});
},
/**
* Update content.
*/
updateContent(response) {
if (response.success) {
$('.license-status')
.removeClass('capsule-sl-success capsule-sl-error')
.addClass('capsule-sl-success')
.html(response.data.message)
.css('display', 'block');
$('.capsule-sl-action-buttons-wrapper').html( response.data.html );
} else {
$('.license-status')
.removeClass('capsule-sl-success capsule-sl-error')
.addClass('capsule-sl-error')
.html(response.data[0].message)
.css('display', 'block');
}
}
};
Capsule.init();
});
Loading

0 comments on commit 8654dce

Please sign in to comment.