diff --git a/comp/media/js/lib.js b/comp/media/js/lib.js index 0590e7baf..ac6e666ac 100644 --- a/comp/media/js/lib.js +++ b/comp/media/js/lib.js @@ -1239,7 +1239,11 @@ var Desk = { onSuccess: onSuccess, onFailure: Bricolage.handleError, on403: Bricolage.handleForbidden, - on409: Bricolage.handleConflict + on409: Bricolage.handleConflict, + on202: function(req) { + Bricolage.handleConflict(req); + onSuccess(req); + } } ); }, diff --git a/lib/Bric/App/Callback.pm b/lib/Bric/App/Callback.pm index d922de8b9..441990fa7 100644 --- a/lib/Bric/App/Callback.pm +++ b/lib/Bric/App/Callback.pm @@ -6,8 +6,8 @@ __PACKAGE__->register_subclass; use constant CLASS_KEY => 'Callback'; use HTML::Entities; use Bric::App::Cache; -use Bric::App::Util qw(get_pref add_msg); -use Bric::Util::ApacheConst qw(HTTP_CONFLICT HTTP_FORBIDDEN); +use Bric::App::Util qw(get_pref add_msg get_msg clear_msg); +use Bric::Util::ApacheConst qw(HTTP_CONFLICT HTTP_FORBIDDEN HTTP_ACCEPTED); use Bric::Util::DBI qw(begin rollback); use Bric::Util::Language; @@ -24,34 +24,49 @@ sub add_message { sub raise_status { my ($self, $status) = (shift, shift); - my $r = $self->apache_req or return $self->add_message(@_); + $self->add_message(@_); + my $r = $self->apache_req or return; # If it's not an Ajax request, it's just a message. - return $self->add_message(@_) - if ($r->headers_in->{'X-Requested-With'} || '') ne 'XMLHttpRequest'; + return if ($r->headers_in->{'X-Requested-With'} || '') ne 'XMLHttpRequest'; # Abort the database transaction. rollback(1); begin(1); - # Prep the error message. - my $txt = Bric::Util::Language->instance->maketext(@_); - if ($txt =~ /(.*)(.*)<\/span>(.*)/) { - $txt = encode_entities($1) . '' - . encode_entities($2) . '' . encode_entities($3); - } else { - $txt = encode_entities($txt); - } - # Send the status to the browser and abort. - $r->status($status); - $r->print(qq{
$txt
}); + $self->_print_messages($r, $status); $self->abort; } sub raise_conflict { shift->raise_status( HTTP_CONFLICT, @_ ) } sub raise_forbidden { shift->raise_status( HTTP_FORBIDDEN, @_ ) } +sub show_accepted { + my $self = shift; + $self->add_message(@_); + my $r = $self->apache_req or return; + + # If it's not an Ajax request, it's just a message. + return if ($r->headers_in->{'X-Requested-With'} || '') ne 'XMLHttpRequest'; + + $self->_print_messages($r, HTTP_ACCEPTED); +} + +sub _print_messages { + my ($self, $r, $status) = @_; + # Prep the error message(s). + my $txt = join '

', map { + /(.*)(.*)<\/span>(.*)/ + ? encode_entities($1) . '' + . encode_entities($2) . '' . encode_entities($3) + : encode_entities($_) + } get_msg; + clear_msg; + $r->status($status); + $r->print(qq{
$txt
}); +} + 1; =head1 Name diff --git a/lib/Bric/App/Callback/Desk.pm b/lib/Bric/App/Callback/Desk.pm index 82399245c..d8d2eeb96 100644 --- a/lib/Bric/App/Callback/Desk.pm +++ b/lib/Bric/App/Callback/Desk.pm @@ -366,16 +366,15 @@ sub publish : Callback { # By this point we now know if we're going to fail this publish # if we set the fail behaviour to fail rather than warn if (PUBLISH_RELATED_ASSETS && @messages) { + $self->add_message(@$_) for @messages; if (PUBLISH_RELATED_FAIL_BEHAVIOR eq 'fail') { - $self->add_message(@$_) for @messages; - my $msg = 'Publish aborted due to errors above. Please fix the ' - . ' above problems and try again.'; - throw_error error => $msg, - maketext => $msg; + $self->raise_conflict( + ['Publish aborted due to errors above. Please fix the above problems and try again.']); } else { # we are set to warn, should we add a further warning to the msg ? - $self->raise_conflict(@$_) for @messages, - 'Some of the related assets were not published.'; + $self->show_accepted( + ['Some of the related assets were not published.'] + ); } } else { $self->raise_conflict(@$_) for @messages; @@ -408,6 +407,10 @@ sub publish : Callback { } else { $self->set_redirect('/workflow/profile/publish'); } + + # Don't render anything for Ajax requests. + my $r = $self->apache_req or return; + $self->abort if ($r->headers_in->{'X-Requested-With'} || '') eq 'XMLHttpRequest'; } sub deploy : Callback {