Browse Source
* Widgets not supported @see pressbooks-aldine/inc/intervention.php * Catalog page: restore network admin controls (issue #65) * Connect functionality to get_catalog_data * Better, strong, faster, ...sort-y-er? (issue #65) * Fix accessibility issue, handle the old option from networks that have been using Pressbooks Publisher * Fix eslint failure * Fix sorting. Fix coding standards. * Let phpcbf fix things for me. * Remove odd leftover comment.pull/70/head
Dac Chartrand
7 years ago
committed by
Ned Zimmerman
11 changed files with 239 additions and 72 deletions
@ -0,0 +1,45 @@ |
|||||||
|
/* global ajaxurl, PB_Aldine_Admin */ |
||||||
|
( 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=1210a93b205df58a9afb", |
"/styles/aldine.css": "/styles/aldine.css?id=00b0c10d93f464c01cc5", |
||||||
"/styles/editor.css": "/styles/editor.css?id=d96762ab5918cde0c2e1", |
"/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,76 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* @package Aldine |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace Aldine\Admin; |
||||||
|
|
||||||
|
use PressbooksMix\Assets; |
||||||
|
|
||||||
|
/** |
||||||
|
* Uses old option to provide a simpler upgrade path from pressbooks-publisher theme |
||||||
|
*/ |
||||||
|
const BLOG_OPTION = 'pressbooks_publisher_in_catalog'; |
||||||
|
|
||||||
|
/** |
||||||
|
* @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, \Aldine\Admin\BLOG_OPTION, 1 ); |
||||||
|
} else { |
||||||
|
delete_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @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" aria-label="<?php echo esc_attr_x( 'Show in Catalog', 'pressbooks-aldine' ); ?>" <?php checked( get_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION ), 1 ); ?> <?php |
||||||
|
if ( ! get_blog_option( $blog_id, 'blog_public' ) ) { ?>disabled="disabled" title="<?php echo esc_attr_x( 'This book is private, so you can’t display it in your catalog.', 'pressbooks-aldine' ); ?>"<?php } ?> />
|
||||||
|
<?php } |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue