Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Improve WP Admin UI #38

Merged
merged 36 commits into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d053407
Add author post type support
westonruter Jun 9, 2016
fbf9ff4
Remove Add New post link for snapshots; harden capabilities
westonruter Jun 9, 2016
083debb
Show only dirty settings in edit post screen; use UUID as metabox title
westonruter Jun 9, 2016
910265d
Restore UUID as heading so it is selectable
westonruter Jun 9, 2016
4e2ba3c
Fix text domain
westonruter Jun 9, 2016
fa11939
Allow non-dirty settings to be revealed
valendesigns Jun 9, 2016
7b5152c
Check that array index isset
valendesigns Jun 9, 2016
ab6ca42
Restore initial customize check
westonruter Jun 9, 2016
a8c6c20
Restore edit_published_posts and delete_published_posts caps for cust…
westonruter Jun 9, 2016
152589c
Add quick edit link to open Customizer
westonruter Jun 9, 2016
c2e9230
Add Open in Customizer button to edit snapshot screen
westonruter Jun 9, 2016
898542a
Hide Snapshot Customize links if status is publish
westonruter Jun 9, 2016
3815b26
Add missing js-doc return tags
westonruter Jun 9, 2016
4d4a1fe
Set isPreview once snapshot saved; send original _dirty state
westonruter Jun 9, 2016
ed47f1c
Make sure Published button can be re-disabled when publishing immedia…
westonruter Jun 9, 2016
8bcdce0
Move Open in Customizer button to misc publish box
westonruter Jun 9, 2016
37715bc
Move Open in Customizer button to post_submitbox_minor_actions
westonruter Jun 9, 2016
9755a6a
Remove publish metabox got published snapshots since they should be i…
westonruter Jun 9, 2016
8a4881a
Hide trash and quick edit links with view instead of edit for publish…
westonruter Jun 9, 2016
ad595a7
Disable author metabox for published snapshots
westonruter Jun 9, 2016
c55bb68
Merge branch 'bugfix/replace-state' of https://github.com/xwp/wp-cust…
westonruter Jun 9, 2016
cf6ecf8
Merge branch 'release/0.4.0' of https://github.com/xwp/wp-customize-s…
westonruter Jun 9, 2016
87c4ce6
Update wp-dev-lib 159119b...0f3058b: Merge pull request xwp/wp-dev-li…
westonruter Jun 9, 2016
390cf9c
Trim trailing question mark
westonruter Jun 9, 2016
b3ea60a
Remove publish_posts cap until #15 is implmented
westonruter Jun 10, 2016
195f4de
Introduce a submit button if user cannot publish
westonruter Jun 10, 2016
d321212
Prevent post_name from being striped when submitting for review
westonruter Jun 10, 2016
6ebf4d7
Move Open in Customizer back to metabox until publish metabox is supp…
westonruter Jun 10, 2016
5c64c5b
Hide Customize quicklink if user cannot edit post
westonruter Jun 10, 2016
3ff6158
Hide edit bulk action, quick edit, and author metabox
westonruter Jun 10, 2016
e2833a2
Restore delete quick edit link
westonruter Jun 10, 2016
6fa5ff9
Add post info from submitbox to data metabox
westonruter Jun 10, 2016
eae3c6d
Restrict editing and deleting others' posts
westonruter Jun 10, 2016
a579fa8
Merge branch 'feature/submit-for-review' into feature/wp-admin
westonruter Jun 10, 2016
f41c35d
Add test for preserving post name when submitting as pending
westonruter Jun 10, 2016
a7a4009
Fix the perms message and add new changeButton method to reduce dupli…
valendesigns Jun 10, 2016
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
2 changes: 1 addition & 1 deletion dev-lib
Submodule dev-lib updated 2 files
+65 −44 check-diff.sh
+8 −0 readme.md
119 changes: 93 additions & 26 deletions js/customize-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

/**
* Inject the functionality.
*
* @return {void}
*/
component.init = function() {
window._wpCustomizeControlsL10n.save = component.data.i18n.publish;
Expand All @@ -29,12 +31,23 @@
if ( ! api.settings.theme.active || ( component.data.theme && component.data.theme !== api.settings.theme.stylesheet ) ) {
return;
}
api.state.create( 'snapshot-saved', true);
api.state.create( 'snapshot-submitted', true );
api.bind( 'change', function () {
api.state( 'snapshot-saved' ).set( false );
api.state( 'snapshot-submitted' ).set( false );
} );

component.previewerQuery();
component.addButton();
component.addButtons();

$( '#snapshot-save' ).on( 'click', function( event ) {
event.preventDefault();
component.sendUpdateSnapshotRequest( event );
component.sendUpdateSnapshotRequest( { status: 'draft', openNewWindow: event.shiftKey } );
} );
$( '#snapshot-submit' ).on( 'click', function( event ) {
event.preventDefault();
component.sendUpdateSnapshotRequest( { status: 'pending', openNewWindow: event.shiftKey } );
} );

if ( component.data.isPreview ) {
Expand All @@ -44,6 +57,10 @@
} );

api.bind( 'save', function( request ) {

// Make sure that saved state is false so that Published button behaves as expected.
api.state( 'saved' ).set( false );

request.fail( function( response ) {
var id = 'snapshot-dialog-error',
snapshotDialogPublishError = wp.template( id );
Expand All @@ -54,7 +71,7 @@
if ( 0 === $( '#' + id ).length ) {
$( 'body' ).append( snapshotDialogPublishError( {
title: component.data.i18n.publish,
message: component.data.i18n.permsMsg
message: component.data.isPreview ? component.data.i18n.permsMsg.update : component.data.i18n.permsMsg.save
} ) );
}

Expand All @@ -77,7 +94,7 @@
urlParts;

// Set the button text back to "Save".
$( '#customize-header-actions' ).find( '#snapshot-save' ).text( component.data.i18n.saveButton );
component.changeButton( component.data.i18n.saveButton, component.data.i18n.permsMsg.save );

request = wp.ajax.post( 'customize_get_snapshot_uuid', {
nonce: component.data.nonce,
Expand All @@ -96,6 +113,7 @@
updatedUrl = urlParts[0] + '?' + _.filter( urlParts[1].split( '&' ), function( queryPair ) {
return ! /^(customize_snapshot_uuid|scope)=/.test( queryPair );
} ).join( '&' );
updatedUrl = updatedUrl.replace( /\?$/, '' );
if ( updatedUrl !== url ) {
history.replaceState( {}, document.title, updatedUrl );
}
Expand All @@ -105,6 +123,8 @@

/**
* Amend the preview query so we can update the snapshot during `customize_save`.
*
* @return {void}
*/
component.previewerQuery = function() {
var originalQuery = api.previewer.query;
Expand All @@ -119,7 +139,7 @@
api.each( function( value, key ) {
allCustomized[ key ] = {
'value': value(),
'dirty': false
'dirty': value._dirty
};
} );
retval.snapshot_customized = JSON.stringify( allCustomized );
Expand All @@ -132,32 +152,62 @@

/**
* Create the snapshot share button.
*
* @return {void}
*/
component.addButton = function() {
component.addButtons = function() {
var header = $( '#customize-header-actions' ),
publishButton = header.find( '#save' ),
snapshotButton, data;
snapshotButton, submitButton, data;

if ( header.length && 0 === header.find( '#snapshot-save' ).length ) {
snapshotButton = wp.template( 'snapshot-save' );
data = {
buttonText: component.data.isPreview ? component.data.i18n.updateButton : component.data.i18n.saveButton
};
snapshotButton = $( $.trim( snapshotButton( data ) ) );
if ( ! component.data.currentUserCanPublish ) {
snapshotButton.attr( 'title', component.data.i18n.permsMsg );
snapshotButton.addClass( 'button-primary' ).removeClass( 'button-secondary' );
}
snapshotButton.insertAfter( publishButton );
snapshotButton = wp.template( 'snapshot-save' );
data = {
buttonText: component.data.isPreview ? component.data.i18n.updateButton : component.data.i18n.saveButton
};
snapshotButton = $( $.trim( snapshotButton( data ) ) );
if ( ! component.data.currentUserCanPublish ) {
snapshotButton.attr( 'title', component.data.isPreview ? component.data.i18n.permsMsg.update : component.data.i18n.permsMsg.save );
}
snapshotButton.prop( 'disabled', true );
snapshotButton.insertAfter( publishButton );
api.state( 'snapshot-saved' ).bind( function( saved ) {
snapshotButton.prop( 'disabled', saved );
} );

if ( ! component.data.currentUserCanPublish ) {
publishButton.hide();
submitButton = wp.template( 'snapshot-submit' );
submitButton = $( $.trim( submitButton( {
buttonText: component.data.i18n.submit
} ) ) );
submitButton.prop( 'disabled', true );
submitButton.insertBefore( snapshotButton );
api.state( 'snapshot-submitted' ).bind( function( submitted ) {
submitButton.prop( 'disabled', submitted );
} );
}

header.addClass( 'button-added' );
};

/**
* Change the snapshot share button.
*
* @param {string} buttonText The button text.
* @param {string} permsMsg The permissions message.
* @return {void}
*/
component.changeButton = function( buttonText, permsMsg ) {
var snapshotButton = $( '#customize-header-actions' ).find( '#snapshot-save' );

if ( snapshotButton.length ) {
snapshotButton.text( buttonText );
if ( ! component.data.currentUserCanPublish ) {
snapshotButton.attr( 'title', permsMsg );
}
}
};

/**
* Silently update the saved state to be true without triggering the
* changed event so that the AYS beforeunload dialog won't appear
Expand All @@ -168,6 +218,8 @@
* wp.customize.state( 'saved' ).set( true );
* wp.customize.state.topics.change.enable();
* But unfortunately there is no such enable method.
*
* @return {void}
*/
component.resetSavedStateQuietly = function() {
api.state( 'saved' )._value = true;
Expand All @@ -176,12 +228,23 @@
/**
* Make the AJAX request to update/save a snapshot.
*
* @param {object} event jQuery Event object
* @param {object} options Options.
* @param {string} options.status The post status for the snapshot.
* @param {boolean} options.openNewWindow Whether to open the frontend in a new window.
* @return {void}
*/
component.sendUpdateSnapshotRequest = function( event ) {
component.sendUpdateSnapshotRequest = function( options ) {
var spinner = $( '#customize-header-actions .spinner' ),
scope = component.data.scope,
request, customized;
request, customized, args;

args = _.extend(
{
status: 'draft',
openNewWindow: false
},
options
);

spinner.addClass( 'is-active' );

Expand All @@ -199,14 +262,14 @@
snapshot_customized: JSON.stringify( customized ),
customize_snapshot_uuid: component.data.uuid,
scope: scope,
status: args.status,
preview: ( component.data.isPreview ? 'on' : 'off' )
} );

request.done( function( response ) {
var url = api.previewer.previewUrl(),
regex = new RegExp( '([?&])customize_snapshot_uuid=.*?(&|$)', 'i' ),
separator = url.indexOf( '?' ) !== -1 ? '&' : '?',
header = $( '#customize-header-actions' ),
customizeUrl = window.location.href,
customizeSeparator = customizeUrl.indexOf( '?' ) !== -1 ? '&' : '?';

Expand All @@ -226,9 +289,8 @@
}

// Change the save button text to update.
if ( header.length && 0 !== header.find( '#snapshot-save' ).length ) {
header.find( '#snapshot-save' ).text( component.data.i18n.updateButton );
}
component.changeButton( component.data.i18n.updateButton, component.data.i18n.permsMsg.update );
component.data.isPreview = true;

spinner.removeClass( 'is-active' );
component.resetSavedStateQuietly();
Expand All @@ -242,8 +304,13 @@
history.replaceState( {}, document.title, customizeUrl );
}

api.state( 'snapshot-saved' ).set( true );
if ( 'pending' === args.status ) {
api.state( 'snapshot-submitted' ).set( true );
}

// Open the preview in a new window on shift+click.
if ( event.shiftKey ) {
if ( args.openNewWindow ) {
window.open( url, '_blank' );
}

Expand Down
2 changes: 1 addition & 1 deletion js/customize-snapshots.min.js

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

Loading