Skip to content
Open
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
21 changes: 19 additions & 2 deletions js/zoninator.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var zoninator = {}
post_id = $this.val();
if ( post_id ) {
zoninator.addPost( post_id );
$this.find( '[value="' + post_id + '"]' ).remove();
}
});

Expand Down Expand Up @@ -136,11 +135,13 @@ var zoninator = {}
zoninator.ajax('add_post', {
zone_id: zoninator.getZoneId()
, post_id: postId
}, zoninator.addPostSuccessCallback);
}, zoninator.addPostSuccessCallback
, zoninator.addPostErrorCallback );

}

zoninator.addPostSuccessCallback = function(returnData) {
var post_id = zoninator.$zonePostLatest.val();

zoninator.$zonePostSearch.trigger('loading.end');

Expand All @@ -152,10 +153,26 @@ var zoninator = {}
;

zoninator.initZonePost($post);

//Update list only if a post was actually added to the zone
zoninator.$zonePostLatest.find( '[value="' + post_id + '"]' ).remove();

// Reorder Posts
zoninator.updatePostOrder(true);
}

/* Override the callback so specific addPostError related functionality
* can be added. (ie: reset selectedIndex and trigger load.end). A user
* shouldn't be given too many errors if they didn't do anything "technically wrong."
*/
zoninator.addPostErrorCallback = function(returnData) {
if( typeof(returnData.content) === 'undefined' || !returnData.content )
returnData.content = zoninatorOptions.errorGeneral;
alert(returnData.content);

zoninator.$zonePostLatest.val( zoninator.$zonePostLatest.prop( 'selectedIndex', 0 ) );
zoninator.$zonePostSearch.trigger('loading.end');
}

zoninator.initZonePost = function($elem) {
$elem.bind('loading.start', function(e) {
Expand Down
9 changes: 8 additions & 1 deletion zoninator.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,21 @@ function ajax_return( $status, $content = '', $action = '' ) {
function ajax_add_post() {
$zone_id = $this->_get_post_var( 'zone_id', 0, 'absint' );
$post_id = $this->_get_post_var( 'post_id', 0, 'absint' );

//Filter to limit depending on $zone_id passed (or not passed to filter all)
$num_posts = 0;
$num_posts = apply_filters( 'zoninator_post_count_limit', $num_posts, $zone_id );

// Verify nonce
$this->verify_nonce( $this->zone_ajax_nonce_action );
$this->verify_access( '', $zone_id );

// Validate
if( ! $zone_id || ! $post_id )
$this->ajax_return( 0 );

//Check number of posts allowed
if($num_posts > 0 && $num_posts <= count( $this->get_zone_posts( $zone_id ) ) )
$this->ajax_return(0, __( 'Sorry, another item cannot be added to this zone.', 'zoninator' ) );

$result = $this->add_zone_posts( $zone_id, $post_id, true );

Expand Down