Skip to content

Commit

Permalink
#482 added predefined values to field Folder on Stateless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
planv committed May 15, 2020
1 parent 7cdbbbf commit d2d5329
Show file tree
Hide file tree
Showing 3 changed files with 870 additions and 819 deletions.
13 changes: 12 additions & 1 deletion lib/classes/class-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ public function admin_init() {
$settings = ud_get_stateless_media()->get('sm');
$settings['wildcards'] = $this->settings->wildcards;
$settings['network_admin'] = is_network_admin();
$settings['is_multisite'] = is_multisite();
if(defined('WP_STATELESS_MEDIA_JSON_KEY') && WP_STATELESS_MEDIA_JSON_KEY){
$settings['key_json'] = "Currently configured via a constant.";
}
Expand Down Expand Up @@ -1254,14 +1255,24 @@ public function admin_enqueue_scripts( $hook ) {
$data = array(
'key' => 'stateless-cache-busting',
'class' => 'notice',
'title' => sprintf( __( "Stateless mode enables and requires the Cache-Busting option.", ud_get_stateless_media()->domain ) ),
'title' => sprintf( __( "Stateless and Ephemeral modes enables and requires the Cache-Busting option.", ud_get_stateless_media()->domain ) ),
'message' => sprintf( __("WordPress looks at local files to prevent files with the same filenames.
Since Stateless mode bypasses this check, there is a potential for files to be stored with the same file name. We enforce the Cache-Busting option to prevent this.
Override with the <a href='%s' target='_blank'>%s</a> constant.", ud_get_stateless_media()->domain),"https://wp-stateless.github.io/docs/constants/#wp_stateless_media_cache_busting", "WP_STATELESS_MEDIA_CACHE_BUSTING" ),
);
echo "<script id='template-stateless-cache-busting' type='text/html'>";
include ud_get_stateless_media()->path( '/static/views/error-notice.php', 'dir' );
echo "</script>";

$data = array(
'key' => 'stateless-folder',
'class' => 'notice',
'title' => sprintf( __( "Stateless mode requires the Folder value.", ud_get_stateless_media()->domain ) ),
'message' => sprintf( __("Field Folder shoul be filled for correct work Stateless mode. ", ud_get_stateless_media()->domain) ),
);
echo "<script id='template-stateless-folder' type='text/html'>";
include ud_get_stateless_media()->path( '/static/views/error-notice.php', 'dir' );
echo "</script>";
break;
default: break;
}
Expand Down
126 changes: 69 additions & 57 deletions static/scripts/error-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,82 @@
* EVENTS
*/
jQuery( document ).ready( function ($) {

jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .button-action', function(e){
var _this = jQuery( this );
if(_this.attr('href') != '#'){
return;
}

e.preventDefault();


var data = {
action: 'stateless_enable_notice_button_action',
key: _this.data('key'),
jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .button-action', function(e){
var _this = jQuery( this );
if(_this.attr('href') != '#'){
return;
}

e.preventDefault();


var data = {
action: 'stateless_enable_notice_button_action',
key: _this.data('key'),
}

jQuery.post( ajaxurl, data, function ( result_data ) {
if( result_data.success == '1' ) {
_this.closest('.ud-admin-notice').remove();

var key = _this.attr('data-key');
key = key.replace('button_secondary_', '');
$("#" + key + " option[value=" + key +"]").attr('selected', 'selected');
$("#" + key).val('true');
} else if ( result_data.success == '0' ) {
// alert(result_data.error);
}

jQuery.post( ajaxurl, data, function ( result_data ) {
if( result_data.success == '1' ) {
_this.closest('.ud-admin-notice').remove();

var key = _this.attr('data-key');
key = key.replace('button_secondary_', '');
$("#" + key + " option[value=" + key +"]").attr('selected', 'selected');
$("#" + key).val('true');
} else if ( result_data.success == '0' ) {
// alert(result_data.error);
}
}, "json" );
return false;
});
}, "json" );
return false;
});

jQuery( '.stateless-admin-notice.ud-admin-notice' ).off( 'click', '.dismiss');
jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .dismiss-warning', function(e){
e.preventDefault();

jQuery( '.stateless-admin-notice.ud-admin-notice' ).off( 'click', '.dismiss');
jQuery( document ).on( 'click', '.stateless-admin-notice.ud-admin-notice .dismiss-warning', function(e){
e.preventDefault();
var _this = jQuery( this );

var _this = jQuery( this );
var data = {
action: 'stateless_notice_dismiss',
key: _this.data('key'),
}

var data = {
action: 'stateless_notice_dismiss',
key: _this.data('key'),
jQuery.post( ajaxurl, data, function ( result_data ) {
if( result_data.success == '1' ) {
_this.closest('.ud-admin-notice').remove();
} else if ( result_data.success == '0' ) {
// alert(result_data.error);
}
}, "json" );
return false;
});

jQuery.post( ajaxurl, data, function ( result_data ) {
if( result_data.success == '1' ) {
_this.closest('.ud-admin-notice').remove();
} else if ( result_data.success == '0' ) {
// alert(result_data.error);
}
}, "json" );
return false;
});
jQuery('#stless_settings_tab .sm-mode input[type=radio]').on('change', function(){

jQuery('#stless_settings_tab .sm-mode input[type=radio]').on('change', function(){
var $this = jQuery('#sm_mode_stateless');
if($this.is(':checked')){
var notice = jQuery('#stateless-notice-stateless-cache-busting');
if(!notice.length){
notice = jQuery(jQuery('#template-stateless-cache-busting').html());
notice.appendTo("#stateless-settings-page-title");
}
jQuery('#stateless-notice-stateless-cache-busting').show();
if($(this).val() == 'stateless' || $(this).val() == 'ephemeral'){
var notice = jQuery('#stateless-notice-stateless-cache-busting');
if(!notice.length){
notice = jQuery(jQuery('#template-stateless-cache-busting').html());
notice.appendTo("#stateless-settings-page-title");
}
else{
jQuery('#stateless-notice-stateless-cache-busting').hide();
jQuery('#stateless-notice-stateless-cache-busting').show();
}
else{
jQuery('#stateless-notice-stateless-cache-busting').hide();
}

if( $(this).val() == 'stateless' ){
var notice = jQuery('#stateless-notice-stateless-folder');
if(!notice.length){
notice = jQuery(jQuery('#template-stateless-folder').html());
notice.appendTo("#stateless-settings-page-title");
}
});

} );
jQuery('#stateless-notice-stateless-folder').show();
}
else{
jQuery('#stateless-notice-stateless-folder').hide();
}
});

} );
Loading

0 comments on commit d2d5329

Please sign in to comment.