diff --git a/core/app/views/refinery/admin/_continue_editing.html.erb b/core/app/views/refinery/admin/_continue_editing.html.erb index d0b8a41756..36df4d04de 100644 --- a/core/app/views/refinery/admin/_continue_editing.html.erb +++ b/core/app/views/refinery/admin/_continue_editing.html.erb @@ -1,3 +1,4 @@ <%= f.submit t('.save_and_continue_editing'), - :id => "submit_continue_button", - :class => "wymupdate button" if f.object.persisted? %> + id: 'submit_continue_button', + class: 'wymupdate button', + data: { disable_with: false } if f.object.persisted? %> diff --git a/core/app/views/refinery/admin/_form_actions.html.erb b/core/app/views/refinery/admin/_form_actions.html.erb index c5a1364985..31a9da5463 100644 --- a/core/app/views/refinery/admin/_form_actions.html.erb +++ b/core/app/views/refinery/admin/_form_actions.html.erb @@ -1,8 +1,9 @@ <% unless (hide_submit ||= false) submit_button_text ||= t('.save') - submit_button_id ||= "submit_button" + submit_button_id ||= 'submit_button' submit_button_title ||= nil + submit_button_data ||= { disable_with: false } end hide_cancel = from_dialog? unless defined?(hide_cancel).presence @@ -12,8 +13,8 @@ unless defined?(cancel_title) cancel_title = t('.cancel_lose_changes') end - cancel_button_id ||= "cancel_button" - cancel_url ||= (((back = url_for(:back)).include?('javascript') or action_name =~ /^(create|update)$/) ? refinery.send(Refinery.route_for_model(f.object.class, :plural => true)) : back) + cancel_button_id ||= 'cancel_button' + cancel_url ||= (((back = url_for(:back)).include?('javascript') or action_name =~ /^(create|update)$/) ? refinery.send(Refinery.route_for_model(f.object.class, plural: true)) : back) end continue_editing = defined?(continue_editing) ? continue_editing : (f.object.present? and f.object.persisted?) @@ -28,7 +29,7 @@ delete_button_text ||= t('.delete') delete_title ||= nil delete_confirmation ||= nil - delete_button_id ||= "delete_button" + delete_button_id ||= 'delete_button' # we have to use eval rather than refinery.send because this url may not exist for HTTP GET delete_url ||= eval("refinery.#{Refinery.route_for_model(f.object.class)}(#{f.object.id})") end @@ -38,37 +39,42 @@ <% end %> -
'> -
+<%= content_tag :div, class: "form-actions#{' form-actions-dialog' if from_dialog?}" do %> + <%= content_tag :div, class: 'form-actions-left' do %> <%= submit_tag submit_button_text, - :id => submit_button_id, - :name => nil, - :class => "wymupdate button", - :tooltip => submit_button_title unless hide_submit %> + id: submit_button_id, + name: nil, + class: 'wymupdate button', + data: submit_button_data, + tooltip: submit_button_title unless hide_submit %> - <%= render '/refinery/admin/continue_editing', :f => f if continue_editing -%> + <%= render '/refinery/admin/continue_editing', f: f if continue_editing -%> <%= hidden_field_tag :continue_editing, false if continue_editing %> <%= local_assigns[:before_cancel_button] -%> - <%= link_to(cancel_button_text, cancel_url, - :title => cancel_title, - :id => cancel_button_id, - :class => "close_dialog button") unless hide_cancel %> + <%= link_to cancel_button_text, cancel_url, + title: cancel_title, + id: cancel_button_id, + class: 'close_dialog button' unless hide_cancel %> <%= local_assigns[:after_cancel_button] -%> - -
-
+ + <%= content_tag :i, nil, id: 'spinner', class: 'loading_icon hidden_icon' %> + <% end %> + + <%= content_tag :div, class: 'form-actions-right' do %> <%= local_assigns[:before_delete_button] -%> - <%= link_to(delete_button_text, delete_url, - :title => delete_title, - :id => delete_button_id, - :method => :delete, - :data => { - :confirm => delete_confirmation + + <%= link_to delete_button_text, delete_url, + title: delete_title, + id: delete_button_id, + method: :delete, + data: { + confirm: delete_confirmation }, - :class => "button confirm-delete") unless hide_delete %> + class: 'button confirm-delete' unless hide_delete %> + <%= local_assigns[:after_delete_button] -%> -
-
+ <% end %> +<% end %> diff --git a/pages/app/views/refinery/admin/pages/_form.html.erb b/pages/app/views/refinery/admin/pages/_form.html.erb index c959c4ea84..8076e12653 100644 --- a/pages/app/views/refinery/admin/pages/_form.html.erb +++ b/pages/app/views/refinery/admin/pages/_form.html.erb @@ -18,19 +18,20 @@ <%= render 'form_advanced_options', :f => f %> - <%= render '/refinery/admin/form_actions', :f => f, - :continue_editing => true, - :delete_title => t('delete', :scope => 'refinery.admin.pages'), - :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @page.title), - :before_cancel_button => submit_tag( + <%= render '/refinery/admin/form_actions', f: f, + continue_editing: true, + delete_title: t('delete', scope: 'refinery.admin.pages'), + delete_confirmation: t('message', scope: 'refinery.admin.delete', title: @page.title), + before_cancel_button: submit_tag( t('.preview'), - :id => 'preview-button', - :title => 'Preview page', - :name => nil, - :class => "wymupdate button", - :tooltip => t('.preview_changes') + id: 'preview-button', + title: 'Preview page', + name: nil, + class: 'wymupdate button', + tooltip: t('.preview_changes'), + data: { disable_with: false } ), - :cancel_url => refinery.admin_pages_path %> + cancel_url: refinery.admin_pages_path %> <%= render 'form_new_page_parts', :f => f if Refinery::Pages.new_page_parts %> <% end %> @@ -44,17 +45,26 @@ , "<%= refinery.admin_page_parts_path %>" ); - $(document).on('click', '#preview-button', function(e) { + $( '#preview-button' ).on( 'click', function(e) { + e.preventDefault(); + var $form = $(this).parents('form'); var prev_url = $form.attr('action'); var prev_target = $form.attr('target') || ''; + $form.attr({ - 'action': '<%= @page.persisted? ? refinery.pages_admin_preview_page_path(@page.nested_url) : refinery.pages_admin_preview_pages_path %>' - , 'target': '_blank' - }); + action: '<%= @page.persisted? ? refinery.pages_admin_preview_page_path(@page.nested_url) : refinery.pages_admin_preview_pages_path %>', + target: '_blank' + }) + $form.submit(); - $form.attr({'action': prev_url, 'target': prev_target}); - e.preventDefault(); + + setTimeout(function(){ + $form.attr({ + action: prev_url, + target: prev_target + }); + }, 100); }); }); diff --git a/pages/spec/features/refinery/admin/pages_spec.rb b/pages/spec/features/refinery/admin/pages_spec.rb index 948256f205..61ef8e2e17 100644 --- a/pages/spec/features/refinery/admin/pages_spec.rb +++ b/pages/spec/features/refinery/admin/pages_spec.rb @@ -327,6 +327,30 @@ module Admin window.close end + # Regression test for save-and_continue after previewing + # https://github.com/refinery/refinerycms/issues/3328 + it 'will save-and-continue after show the preview in a new window' do + visit refinery.admin_pages_path + + find('a[tooltip^=Edit]').click + fill_in "Title", :with => "Save this" + + window = window_opened_by do + click_button "Preview" + end + + expect_window_with_content("Save this", window: window) + expect_window_without_content( + ::I18n.t('switch_to_website', :scope => 'refinery.site_bar'), + window: window + ) + + window.close + + click_button "Save & continue editing" + expect(page).to have_content("'Save this' was successfully updated") + end + it 'will show pages with inherited templates', js:true do visit refinery.admin_pages_path