8 changed files with 152 additions and 22 deletions
@ -0,0 +1,48 @@
|
||||
/** |
||||
* catalog-admin.js |
||||
*/ |
||||
|
||||
( function ( $ ) { |
||||
$( document ).ready( function () { |
||||
$( '.wrap' ).on( 'click', '.notice-dismiss', function () { |
||||
$( this ).parent( '#message' ).fadeOut( 500, function () { |
||||
$( this ).remove(); |
||||
} ); |
||||
} ); |
||||
$( 'input.in-catalog' ).on( 'change', function () { |
||||
let book_id = $( this ).parent( 'td' ).siblings( 'th' ).children( 'input' ).val(); |
||||
let in_catalog = $( this ).prop( 'checked' ); |
||||
$.ajax( { |
||||
url: ajaxurl, |
||||
type: 'POST', |
||||
data: { |
||||
action: 'pressbooks_aldine_update_catalog', |
||||
book_id: book_id, |
||||
in_catalog: in_catalog, |
||||
_ajax_nonce: PB_Aldine_Admin.aldineAdminNonce, |
||||
}, |
||||
success: function (){ |
||||
if ( $( '#message' ).length < 1 ) { |
||||
$( '<div id="message" class="updated notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 ); |
||||
} else { |
||||
$( '#message' ).fadeOut( 500, function () { |
||||
$( this ).remove(); |
||||
$( '<div id="message" class="updated notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 ); |
||||
} ); |
||||
} |
||||
|
||||
}, |
||||
error: function ( jqXHR, textStatus, errorThrown ) { |
||||
if ( $( '#message' ).length < 1 ) { |
||||
$( '<div id="message" class="error notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_not_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 ); |
||||
} else { |
||||
$( '#message' ).fadeOut( 500, function () { |
||||
$( this ).remove(); |
||||
$( '<div id="message" class="error notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_not_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 ); |
||||
} ); |
||||
} |
||||
}, |
||||
} ); |
||||
} ); |
||||
} ); |
||||
} )( jQuery ); |
||||
@ -1,6 +1,7 @@
|
||||
{ |
||||
"/scripts/aldine.js": "/scripts/aldine.js?id=a166171314fdc227903c", |
||||
"/scripts/aldine.js": "/scripts/aldine.js?id=1f58027f7de9942caf57", |
||||
"/styles/aldine.css": "/styles/aldine.css?id=00b0c10d93f464c01cc5", |
||||
"/styles/editor.css": "/styles/editor.css?id=10e3f4b144847aa8d75e", |
||||
"/scripts/customizer.js": "/scripts/customizer.js?id=decf119933e3b2d4b210" |
||||
"/scripts/customizer.js": "/scripts/customizer.js?id=1b0d3cfc1d85f460af53", |
||||
"/scripts/catalog-admin.js": "/scripts/catalog-admin.js?id=d25f1240496bd3607338" |
||||
} |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,71 @@
|
||||
<?php |
||||
/** |
||||
* @package Aldine |
||||
*/ |
||||
|
||||
namespace Aldine\Admin; |
||||
|
||||
use PressbooksMix\Assets; |
||||
|
||||
/** |
||||
* @param string $hook |
||||
*/ |
||||
function admin_scripts( $hook ) { |
||||
if ( 'sites.php' !== $hook ) { |
||||
return; |
||||
} |
||||
|
||||
$assets = new Assets( 'pressbooks-aldine', 'theme' ); |
||||
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' ); |
||||
wp_enqueue_script( 'pressbooks-aldine-admin', $assets->getPath( 'scripts/catalog-admin.js' ), [ 'jquery' ] ); |
||||
|
||||
wp_localize_script( |
||||
'pressbooks-aldine-admin', 'PB_Aldine_Admin', [ |
||||
'aldineAdminNonce' => wp_create_nonce( 'pressbooks-aldine-admin' ), |
||||
'catalog_updated' => __( 'Catalog updated.', 'pressbooks-aldine' ), |
||||
'catalog_not_updated' => __( 'Sorry, but your catalog was not updated. Please try again.', 'pressbooks-aldine' ), |
||||
'dismiss_notice' => __( 'Dismiss this notice.', 'pressbooks-aldine' ), |
||||
] |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
function update_catalog() { |
||||
if ( ! current_user_can( 'manage_network' ) || ! check_ajax_referer( 'pressbooks-aldine-admin' ) ) { |
||||
return; |
||||
} |
||||
|
||||
$blog_id = absint( $_POST['book_id'] ); |
||||
$in_catalog = $_POST['in_catalog']; |
||||
|
||||
if ( $in_catalog == 'true' ) { |
||||
update_blog_option( $blog_id, 'in_catalog', 1 ); |
||||
} else { |
||||
delete_blog_option( $blog_id, 'in_catalog' ); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param array $columns |
||||
* |
||||
* @return array |
||||
*/ |
||||
function catalog_columns( $columns ) { |
||||
$columns['in_catalog'] = __( 'In Catalog', 'pressbooks-aldine' ); |
||||
return $columns; |
||||
} |
||||
|
||||
/** |
||||
* @param string $column |
||||
* @param int $blog_id |
||||
*/ |
||||
function catalog_column( $column, $blog_id ) { |
||||
|
||||
if ( 'in_catalog' == $column && ! is_main_site( $blog_id ) ) { ?> |
||||
<input class="in-catalog" type="checkbox" name="in_catalog" value="1" <?php checked( get_blog_option( $blog_id, 'in_catalog' ), 1 ); ?> <?php |
||||
if ( ! get_blog_option( $blog_id, 'blog_public' ) ) { ?>disabled="disabled" title="<?php _e( 'This book is private, so you can’t display it in your catalog.', 'pressbooks-aldine' ); ?>"<?php } ?> />
|
||||
<?php } |
||||
|
||||
} |
||||
Loading…
Reference in new issue