Skip to content

Commit

Permalink
Created a page template for Submit Resource page. Minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbohacek committed May 12, 2018
1 parent a7a663f commit bbdda93
Show file tree
Hide file tree
Showing 9 changed files with 646 additions and 10 deletions.
2 changes: 1 addition & 1 deletion includes/post-types/bots.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function add_pending_bots_link($wp_admin_bar) {
if ( $pending_count > 0 ){
$args = array(
'id' => 'review-pending-bots',
'title' => 'Review Pending Bots (' . $pending_count . ')',
'title' => 'New Bots (' . $pending_count . ')',
'href' => '/wp-admin/edit.php?post_status=pending&post_type=bot',
'meta' => array(
'class' => 'review-pending-bots',
Expand Down
28 changes: 28 additions & 0 deletions includes/post-types/resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function post_type_setup() {
add_filter( 'enter_title_here', array( $this, 'change_post_title_placeholder' ) );
add_filter( 'post_type_link', array( $this, 'resource_page_link' ), 1, 3 );
add_filter( 'template_redirect', array( $this, 'external_resource_redirect' ) );
add_action( 'admin_bar_menu', array( $this, 'add_pending_resources_link' ), 100 );

}

Expand Down Expand Up @@ -196,6 +197,33 @@ function add_resource_info(){
);
}


function add_pending_resources_link($wp_admin_bar) {
if ( current_user_can('administrator') ){
$query = array(
'post_type' => 'resource',
'post_status' => array('pending'),
'posts_per_page' => -1
);

$pending_count = count( query_posts($query) );

if ( $pending_count > 0 ){
$args = array(
'id' => 'review-pending-resources',
'title' => 'New Resources (' . $pending_count . ')',
'href' => '/wp-admin/edit.php?post_status=pending&post_type=resource',
'meta' => array(
'class' => 'review-pending-resources',
'title' => 'Review pending resources'
)
);
$wp_admin_bar->add_node($args);
}
wp_reset_query();
}
}

function save_meta( $post_id ) {
if ( wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce') ){
return;
Expand Down
2 changes: 1 addition & 1 deletion js/scripts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/scripts.min.js.map

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions src/scripts/submit-resource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
$(function() {
var $body = $('body'),
$form_submit_button = $('#resource-form-submit');
if ($body.hasClass('page-template-template-submit-resource')){

/* Wake up the screenshot service on Glitch. */

$.get({
url: 'https://screenshot-beta.glitch.me'
}).done(function( data ) {
/* noop */
});



/* Disassociate resource author to allow logged in users to submit other people's resources. */

$('#disassociate-author').click(function(ev){
ev.preventDefault();
$('#logged-in-author').remove();
$('#disassociate-author-input').val('true');
$('#add-author-fields').click();
return false;
});


/* Test submission, only available to admins. */

$('#test').click(function(ev){
ev.preventDefault();

$('#add-author-fields').before('<div class="author-fields form-row"><div class="form-group col-md-6"><input type="text" class="form-control" id="author-2-name" name="author-names[]" placeholder="Author"></div><div class="form-group col-md-6"><input type="url" class="form-control" id="author-2-url" name="author-urls[]" placeholder="https://twitter.com/author"></div></div>');

$('#resource-name').val('One cool resource');
$('#author-1-name').val('Stefan');
$('#author-1-url').val('https://twitter.com/fourtonfish');
$('#author-2-name').val('John Doe');
// $('#author-2-url').val('https://twitter.com/jd');
var resource_description_editor = new MediumEditor('#resource-description', {});

resource_description_editor.setContent('generates random images.');

$('#resource-url').val('https://coolresource.github.com/');

$('#resource-selected-tweets').val('https://twitter.com/mycoolresource/status/123456789\nhttps://twitter.com/mycoolresource/status/987654321');
$('#resource-tagline').val('This is a cool resource.');
$('#resource-networks').val(['twitter-bots']);
$('#resource-networks').trigger('change');

$('#resource-tags').val(['generative', 'images', 'nodejs']);
$('#resource-tags').trigger('change');

$('#resource-is-opensource').click();

$('#resource-source-url').val('https://github.com/resourcewiki/resourcewiki.org');
$('#resource-source-language').val('nodejs');
$('#resource-source-language').trigger('change');

$('html, body').animate({
scrollTop: $form_submit_button.offset().top - 500
}, 450);

return false;
});

$('.js-select2').each(function(i){
$(this).select2({
tags: true,
placeholder: $(this).attr('placeholder')
});
});

$('#submit-resource-form').submit(function(){
$form_submit_button.attr('disabled', 'disabled').html('Please wait...');
setTimeout(function(){
$form_submit_button.html('Still working...');
}, 4700);
});

var $resource_type_select = $('[name="resource-type'),
$resource_type_name = $('.resource-type-name');

$resource_type_select.on('change', function(ev){
var resource_type_name = $(this).children("option").filter(":selected").text().toLowerCase();
$resource_type_name.html(resource_type_name);
$('#resource-name').attr('placeholder', `My ${resource_type_name}...`);
$('#resource-tagline').attr('placeholder', `A useful ${resource_type_name}.`);
});

$('#add-author-fields').click(function(ev){
ev.preventDefault();

var new_id = $('.author-fields').length + 1;

$(this).before(`<div class="author-fields form-row"><div class="form-group col-md-6"><input type="text" class="form-control" id="author-${new_id}-name" name="author-names[]" placeholder="Author"></div><div class="form-group col-md-6"><input type="url" class="form-control" id="author-${new_id}-url" name="author-urls[]" placeholder="https://twitter.com/author"></div></div>`);

return false;
});

var resource_info_network_select_html = $('#resource-network').html();

$('#add-resource-info-fields').click(function(ev){
ev.preventDefault();

var new_id = $('.resource-info-fields').length + 1;

$(this).before(`<div class="resource-info-fields form-row"><div class="form-group col-md-6"><select class="form-control js-select2" id="resource-info-${new_id}-network" name="resource-networks[]" placeholder="Twitter, Tumblr, Slack,...">${resource_info_network_select_html.replace('-1-', new_id)}</select></div><div class="form-group col-md-6"><input type="url" class="form-control" id="resource-${new_id}-url" name="resource-url" placeholder="https://twitter.com/onecoolresource${new_id}"></div></div>`);

$(`#resource-info-${new_id}-network`).select2({
tags: true,
placeholder: $(this).attr('placeholder')
});

enable_selected_tweets_field();

return false;
});

var $resource_source_info = $('#resource-source-info');

$('#resource-is-opensource').click(function(ev){

if ($(this).is(':checked')){
$resource_source_info.removeClass('d-none');
}
else{
$resource_source_info.addClass('d-none');
}
});

var $apply_for_botmaker_badge = $('#apply-for-botmaker-badge'),
$resourceaker_badge_application = $('#botmaker-badge-application');

$apply_for_botmaker_badge.click(function(ev){

if ($(this).is(':checked')){
$resourceaker_badge_application.removeClass('d-none');
}
else{
$resourceaker_badge_application.addClass('d-none');
}
});

var $selected_tweets_field = $('#resource-selected-tweets-field');

function enable_selected_tweets_field(){
var $resource_networks_select = $('[name="resource-networks[]');

$resource_networks_select.on('change', function(){
var show_selected_tweets_field = false;
$resource_networks_select.each(function(i){
var $this = $(this);
if ($this.children("option").filter(":selected").text().indexOf('Twitter') > -1){
show_selected_tweets_field = true;
}
});

if (show_selected_tweets_field){
$selected_tweets_field.removeClass('d-none');
}
else{
$selected_tweets_field.addClass('d-none');
}
});
}
enable_selected_tweets_field();
}
if (typeof MediumEditor !== "undefined"){
var resource_description_editor = new MediumEditor('#resource-description', {
placeholder: {
text: 'It helps you/teaches you...',
hideOnClick: true
},
toolbar: {
buttons: ['anchor', 'pre', 'quote']
}
});
}
});
2 changes: 1 addition & 1 deletion template-basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</li>
</ul>

<?php echo do_shortcode(get_post_field('post_content', $post_id) ); ?>
<?php echo do_shortcode( get_post_field( 'post_content', $post_id) ); ?>

</article>
</div>
Expand Down
Loading

0 comments on commit bbdda93

Please sign in to comment.