Skip to content

Commit

Permalink
Use history.back() when a petition isn't moderated
Browse files Browse the repository at this point in the history
We can't redirect to the admin petition show page since it shows
the moderation form by default and attempts to lock the petition
again. In this case use window.history.back() instead.
  • Loading branch information
pixeltrix committed Sep 12, 2017
1 parent 261fc73 commit e35621d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/assets/javascripts/edit_lock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function ($) {
'use strict';

$.fn.editLock = function(id, user_id, path) {
$.fn.editLock = function(id, user_id, path, moderated) {
var $html = this;
var $message = $html.find('.edit-lock-message');
var $override = $html.find('#edit-lock-override');
Expand All @@ -12,6 +12,7 @@
var PATH = path;
var INTERVAL = 10000;
var LOCK_URL = PATH + '/' + ID + '/lock.json';
var MODERATED = moderated;

var EditLock = {
processStatus: function(data) {
Expand Down Expand Up @@ -59,7 +60,11 @@
},

cancelClicked: function(e) {
window.location = PATH + '/' + ID;
if (MODERATED) {
window.location = PATH + '/' + ID;
} else {
window.history.back();
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/admin/_edit_lock.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<script>
$(document).ready(function() {
<% if @petition.is_a?(::Archived::Petition) %>
$("#edit-lock").editLock(<%= @petition.id %>, <%= current_user.id %>, '/admin/archived/petitions');
$("#edit-lock").editLock(<%= @petition.id %>, <%= current_user.id %>, '/admin/archived/petitions', true);
<% else %>
$("#edit-lock").editLock(<%= @petition.id %>, <%= current_user.id %>, '/admin/petitions');
$("#edit-lock").editLock(<%= @petition.id %>, <%= current_user.id %>, '/admin/petitions', <%= @petition.moderated? %>);
<% end %>
});
</script>

0 comments on commit e35621d

Please sign in to comment.