Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR] People record editing #64

Merged
merged 6 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ module.exports = function( grunt ) {
src: "src/js/admin-card-shortcode.js",
dest: "js/admin-card-shortcode.min.js"
},
admin_edit_profile: {
src: "src/js/admin-edit-profile.js",
dest: "js/admin-edit-profile.min.js"
},
admin_edit_profile_secondary: {
src: "src/js/admin-edit-profile-secondary.js",
dest: "js/admin-edit-profile-secondary.min.js"
},
admin_page: {
src: "src/js/admin-page.js",
dest: "js/admin-page.min.js"
Expand All @@ -116,10 +124,6 @@ module.exports = function( grunt ) {
src: "src/js/admin-people-sync.js",
dest: "js/admin-people-sync.min.js"
},
admin_person: {
src: "src/js/admin-person.js",
dest: "js/admin-person.min.js"
},
admin_user_profile: {
src: "src/js/admin-user-profile.js",
dest: "js/admin-user-profile.min.js"
Expand Down
17 changes: 16 additions & 1 deletion css/admin-person.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
}

.wsuwp-profile-degrees p:hover .wsuwp-profile-button.select,
.wsuwp-profile-repeatable-field .selected:hover .wsuwp-profile-button.remove {
.wsuwp-profile-repeatable-field .selected:hover .wsuwp-profile-button.remove,
.wsuwp-profile-repeatable-field p:hover button:disabled {
display: none;
}

Expand All @@ -91,6 +92,10 @@
text-decoration: none;
}

input:disabled {
background: #eee;
}

/* "Card" display */
.profile-card {
display: table;
Expand Down Expand Up @@ -246,6 +251,16 @@
display: block;
}

.ui-tabs-panel .readonly {
color: #717171;
font-family: "Open Sans", "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
padding: 9px 10px;
}

.ui-tabs-panel .readonly p {
font-size: 14px;
}

.ui-tabs-panel[aria-hidden="true"] {
border: 0;
clip: rect(0 0 0 0);
Expand Down
57 changes: 42 additions & 15 deletions includes/class-wsuwp-people-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public function setup_hooks() {
add_filter( 'manage_taxonomies_for_' . self::$post_type_slug . '_columns', array( $this, 'manage_people_taxonomy_columns' ) );

if ( apply_filters( 'wsuwp_people_display', true ) ) {
add_action( 'wp_enqueue_editor', array( $this, 'admin_enqueue_secondary_scripts' ) );
add_filter( 'manage_' . self::$post_type_slug . '_posts_columns', array( $this, 'add_people_bio_column' ) );
add_action( 'manage_posts_custom_column', array( $this, 'bio_column' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'display_bio_edit' ), 10, 2 );
Expand Down Expand Up @@ -415,32 +416,58 @@ public function admin_enqueue_scripts( $hook_suffix ) {
'nid_nonce' => wp_create_nonce( 'wsu-people-nid-lookup' ),
'post_id' => $post->ID,
'request_from' => ( apply_filters( 'wsuwp_people_display', true ) ) ? 'rest' : 'ad',
'rest_url' => WSUWP_People_Directory::REST_URL(),
);

// Make a REST request for data from people.wsu.edu when editing a person.
if ( 'post.php' === $hook_suffix && apply_filters( 'wsuwp_people_display', true ) ) {
$profile_vars['make_request'] = true;
}

wp_enqueue_style( 'wsuwp-people-admin', plugins_url( 'css/admin-person.css', dirname( __FILE__ ) ), array(), WSUWP_People_Directory::$version );
wp_enqueue_script( 'wsuwp-people-admin', plugins_url( 'js/admin-person.min.js', dirname( __FILE__ ) ), array( 'jquery-ui-tabs', 'underscore' ), WSUWP_People_Directory::$version, true );
wp_localize_script( 'wsuwp-people-admin', 'wsupeople', $profile_vars );
}
wp_enqueue_style( 'wsuwp-people-edit-profile', plugins_url( 'css/admin-person.css', dirname( __FILE__ ) ), array(), WSUWP_People_Directory::$version );
wp_enqueue_script( 'wsuwp-people-edit-profile', plugins_url( 'js/admin-edit-profile.min.js', dirname( __FILE__ ) ), array( 'jquery-ui-tabs', 'underscore' ), WSUWP_People_Directory::$version, true );
wp_localize_script( 'wsuwp-people-edit-profile', 'wsuwp_people_edit_profile', $profile_vars );

// Disable autosaving on new people posts if this isn't people.wsu.edu.
if ( 'post-new.php' === $hook_suffix && apply_filters( 'wsuwp_people_display', true ) ) {
wp_dequeue_script( 'autosave' );
// Disable autosaving for sites other than the primary directory.
if ( apply_filters( 'wsuwp_people_display', true ) ) {
wp_dequeue_script( 'autosave' );
}
}

if ( 'edit.php' === $hook_suffix ) {
if ( 'edit.php' === $hook_suffix && apply_filters( 'wsuwp_people_display', true ) ) {
wp_enqueue_style( 'wsuwp-people-admin', plugins_url( 'css/admin-people.css', dirname( __FILE__ ) ), array(), WSUWP_People_Directory::$version );
wp_enqueue_script( 'wsuwp-people-admin', plugins_url( 'js/admin-people.min.js', dirname( __FILE__ ) ), array( 'jquery' ), WSUWP_People_Directory::$version );
wp_localize_script( 'wsuwp-people-admin', 'wsupeople', array(
'nonce' => wp_create_nonce( 'person-meta' ),
) );
}
}

/**
* Enqueue the scripts and styles used in the admin for sites other than the primary directory.
*
* @since 0.3.0
*
* @param array $to_load Contains boolean values whether TinyMCE and Quicktags are being loaded.
*/
public function admin_enqueue_secondary_scripts( $to_load ) {
$screen = get_current_screen();

if ( self::$post_type_slug !== $screen->post_type ) {
return;
}

// Make sure TinyMCE is loaded before loading the script.
if ( empty( $to_load['tinymce'] ) ) {
return;
}

$profile_vars = array(
'rest_url' => WSUWP_People_Directory::REST_URL(),
);

if ( 'add' !== $screen->action ) {
$profile_vars['load_data'] = true;
$profile_vars['nonce'] = WSUWP_People_Directory::create_rest_nonce();
$profile_vars['uid'] = wp_get_current_user()->ID;
}

wp_enqueue_script( 'wsuwp-people-edit-profile-secondary', plugins_url( 'src/js/admin-edit-profile-secondary.js', dirname( __FILE__ ) ), array( 'jquery', 'underscore' ), WSUWP_People_Directory::$version, true );
wp_localize_script( 'wsuwp-people-edit-profile-secondary', 'wsuwp_people_edit_profile_secondary', $profile_vars );
}

/**
Expand Down Expand Up @@ -563,7 +590,7 @@ public function edit_form_after_editor( $post ) {
<div id="<?php echo esc_attr( $key ); ?>" class="wsuwp-profile-panel">
<?php
if ( '_wsuwp_profile_bio_university' === $args['meta_key'] && ! current_user_can( 'create_sites' ) ) {
echo wp_kses_post( apply_filters( 'the_content', $value ) );
echo '<div class="readonly">' . wp_kses_post( apply_filters( 'the_content', $value ) ) . '</div>';
} else {
wp_editor( $value, $args['meta_key'] );
}
Expand Down
1 change: 1 addition & 0 deletions js/admin-edit-profile-secondary.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/admin-edit-profile.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading