Skip to content

Commit

Permalink
Frontend Editor: When creating a new event with multiple groups attac…
Browse files Browse the repository at this point in the history
…hed, default the post status to public if at least one public group is attached.

Previously, if at least one private group was attached to an event, the
event's post status would default to private (see #28).

This commit does the opposite.

See #55.
  • Loading branch information
r-a-y committed Oct 23, 2016
1 parent 4fa2287 commit cfcdcfc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
44 changes: 30 additions & 14 deletions assets/js/group-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ var bpeoGroupMsg = BpEventOrganiserSettings.group_privacy_message,
jQuery(function($){
var select2obj;

bpeoCurrStatus = $('#post-status-display').text();
bpeoCurrVisibility = $('#post-visibility-display').text();
bpeoSelect = $('#bp_event_organiser_metabox select');
bpeoPrivateFlag = bpeoSelect.find('[title]').length;
bpeoSubmit = $('#submitdiv .inside');

bpeoPublicFlag = bpeoSelect.find('[title]').length;
bpeoIsPrivate = !!bpeoPublicFlag; // convert to boolean
bpeoIsPrivate = !bpeoPublicFlag; // flip the boolean

bpeoToggle = function() {
var notice = bpeoSubmit.find('.updated');

if ( false === $.isEmptyObject( bpeoSelect.val() ) ) {
bpeoToggleFlag = true;

if ( bpeoPrivateFlag === 1 ) {
$("#visibility-radio-private").prop("checked", true);
if ( bpeoIsPrivate ) {
$("#visibility-radio-private" ).prop("checked", true);
$('#post-status-display').fadeOut('fast').text( postL10n.privatelyPublished ).fadeIn('fast');
$('#post-visibility-display').fadeOut('fast').text( postL10n.private ).fadeIn('fast');
} else {
$("#visibility-radio-public" ).prop("checked", true);
$('#post-status-display').fadeOut('fast').text( postL10n.published ).fadeIn('fast');
$('#post-visibility-display').fadeOut('fast').text( postL10n.public ).fadeIn('fast');
}
bpeoGroupMsg = BpEventOrganiserSettings.group_privacy_message;

$('.misc-pub-post-status, .misc-pub-visibility').hide();
$('#save-post').hide();
Expand All @@ -31,21 +35,33 @@ jQuery(function($){
if ( ! notice.length && typeof adminpage === 'undefined' ) {
bpeoSubmit.prepend('<div class="updated"><p>' + bpeoGroupMsg + '</p></div>');
} else {
notice.fadeOut('fast');
notice.find('p').html( bpeoGroupMsg );
notice.fadeIn('fast');
}

} else if ( bpeoPrivateFlag === 0 && bpeoToggleFlag === true ) {
} else if ( bpeoPublicFlag === 0 && bpeoToggleFlag === true ) {
bpeoToggleFlag = false;
$("#visibility-radio-public").prop("checked", true);

if ( bpeoIsPrivate ) {
$("#visibility-radio-private" ).prop("checked", true);
$('#post-status-display').fadeOut('fast').text( postL10n.privatelyPublished ).fadeIn('fast');
$('#post-visibility-display').fadeOut('fast').text( postL10n.private ).fadeIn('fast');
} else {
$("#visibility-radio-public" ).prop("checked", true);
$('#post-status-display').fadeOut('fast').text( postL10n.published ).fadeIn('fast');
$('#post-visibility-display').fadeOut('fast').text( postL10n.public ).fadeIn('fast');
}
bpeoGroupMsg = BpEventOrganiserSettings.group_privacy_message;

$('.misc-pub-post-status, .misc-pub-visibility').show();
$('#post-status-display').fadeOut('fast').text( bpeoCurrStatus ).fadeIn('fast');
$('.edit-post-status').show();
$('#post-visibility-display').fadeOut('fast').text( bpeoCurrVisibility ).fadeIn('fast');
$('#save-post').show();
$('#submitdiv .inside .error').hide();

if ( notice.length ) {
notice.fadeOut('fast');
notice.find('p').html( bpeoGroupMsg );
}
}
}
Expand Down Expand Up @@ -113,14 +129,14 @@ jQuery(function($){
});

bpeoSelect.on("select2:unselecting", function (e) {
if ( 'Private' == e.params.args.data.title || true === e.params.args.data.private ) {
bpeoPrivateFlag--;
if ( 'Public' == e.params.args.data.title || true === e.params.args.data.public ) {
bpeoPublicFlag--;
}
});

bpeoSelect.on("select2:selecting", function (e) {
if ( 'Private' == e.params.args.data.title || true === e.params.args.data.private ) {
bpeoPrivateFlag++;
if ( 'Public' == e.params.args.data.title || true === e.params.args.data.public ) {
bpeoPublicFlag++;
}
});

Expand Down
6 changes: 3 additions & 3 deletions bp-event-organiser-eo.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ public function event_meta_box_render( $event ) {
<?php
foreach( $this->group_ids as $gid ) {
$group = groups_get_group( array( 'group_id' => $gid ) );
$private = 'public' !== $group->status ? 'title="Private"' : '';
echo "<option value='{$gid}' selected='selected' {$private}>{$group->name}</option>";
$public = 'public' === $group->status ? 'title="Public"' : '';
echo "<option value='{$gid}' selected='selected' {$public}>{$group->name}</option>";
}
?>
</select>
Expand Down Expand Up @@ -320,7 +320,7 @@ public function ajax_get_groups() {
) ),
'avatar' => bp_get_group_avatar_mini(),
'total_member_count' => $group->total_member_count,
'private' => $group->status !== 'public'
'public' => $group->status === 'public'
);
}

Expand Down
4 changes: 4 additions & 0 deletions bp-event-organiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ public function enqueue_scripts( $admin_hook = '' ) {
wp_enqueue_script( 'bpeo-group-select' );

$vars['group_privacy_message'] = __( 'You have added a group to this event. Since groups have their own privacy settings, we have removed the ability to set the status for this event.', 'bp-event-organiser' );
$vars['group_public_message'] = sprintf( __( 'You have added a %1$s to this event. Since the added group is %2$s, be aware that your event will also be publicized on the sitewide event calendar.', 'bp-event-organiser' ),
'<strong>' . __( 'public group', 'bp-event-organiser' ) . '</strong>',
'<strong>' . __( 'public', 'bp-event-organiser' ) . '</strong>'
);

wp_localize_script( 'bpeo-group-select', 'BpEventOrganiserSettings', $vars );
}
Expand Down

0 comments on commit cfcdcfc

Please sign in to comment.