Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved page specific code out of _form_actions and into the _form. Add…

…ed hooks in _form_actions to make this possible.
  • Loading branch information...
commit 094d3abeb5119b8fbf079ff3b0de82304c9b6e2f 1 parent 6bf412a
@parndt parndt authored
View
37 core/app/views/refinery/admin/_form_actions.html.erb
@@ -48,45 +48,24 @@
<%= render :partial => "/refinery/admin/continue_editing", :locals => {:f => f} if continue_editing -%>
<%= hidden_field_tag :continue_editing, false if continue_editing %>
-
- <%= submit_tag t('.preview'),
- :id => 'preview-button',
- :title => 'Preview page',
- :name => nil,
- :class => "wymupdate button",
- :tooltip => t('.checkout_your_changes') if defined?(f) && !f.nil? && f.object.is_a?(Refinery::Page) %>
-
+
+ <%= 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 %>
+
+ <%= local_assigns[:after_cancel_button] -%>
</div>
<div class='form-actions-right'>
+ <%= local_assigns[:before_delete_button] -%>
<%= link_to(delete_button_text, delete_url,
:title => delete_title,
:id => delete_button_id,
:method => :delete,
:confirm => delete_confirmation,
:class => "button confirm-delete") unless hide_delete %>
+ <%= local_assigns[:after_delete_button] -%>
</div>
-</div>
-
-<% content_for :javascripts do %>
- <script type="text/javascript" charset="utf-8">
- $(document).ready(function(){
- <% if defined?(f) && !f.nil? && f.object.is_a?(Refinery::Page) %>
- $("#preview-button").click(function(evt){
- var form = $(this).parents('form')
- var prev_url = form.attr('action');
- var prev_target = form.attr('target');
- form.attr('action', '<%= f.object.new_record? ? refinery.admin_preview_pages_path : refinery.admin_preview_page_path(f.object) %>');
- form.attr('target', '_blank');
- form.submit();
- form.attr('action', prev_url);
- form.attr('target', prev_target);
- return false;
- });
- <% end %>
- });
- </script>
-<% end %>
+</div>
View
2  core/config/locales/en.yml
@@ -38,8 +38,6 @@ en:
cancel: Cancel
cancel_lose_changes: If you cancel you will lose any changes you have made here
delete: Remove
- preview: Preview
- checkout_your_changes: Check out your changes before making them live
close: Close
image_picker:
none_selected: There is currently no image selected, please click here to add one.
View
24 pages/app/views/refinery/admin/pages/_form.html.erb
@@ -39,7 +39,13 @@
:f => f,
:continue_editing => true,
:delete_title => t('delete', :scope => 'refinery.admin.pages'),
- :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @page.title)
+ :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'))
} %>
<%= render :partial => "form_new_page_parts",
@@ -56,6 +62,22 @@
, "<%= refinery.new_admin_page_part_path %>"
, "<%= refinery.admin_page_parts_path %>"
);
+
+ $("#preview-button").click(function(e) {
+ var form = $(this).parents('form')
+ var prev_url = form.attr('action');
+ var prev_target = form.attr('target');
+ form.attr({
+ 'action': '<%= @page.persisted? ? refinery.admin_preview_page_path(@page.uncached_nested_url) : refinery.admin_preview_pages_path %>'
+ , 'target': '_blank'
+ });
+ form.submit();
+ form.attr({
+ 'action': prev_url
+ , 'target': prev_target
+ });
+ e.preventDefault();
+ });
});
</script>
<% end %>
View
3  pages/config/locales/en.yml
@@ -40,6 +40,9 @@ en:
view_live_html: View this page live <br/><em>(opens in a new window)</em>
hidden: hidden
draft: draft
+ form:
+ preview: Preview
+ preview_changes: Preview your changes before making them live
form_new_page_parts:
title: Title
form_page_parts:
View
43 pages/spec/requests/refinery/admin/pages_spec.rb
@@ -152,67 +152,66 @@ module Admin
page.should have_content("'Updated' was successfully updated.")
end
end
-
+
describe 'Previewing' do
context "an existing page" do
before(:each) { FactoryGirl.create(:page, :title => 'Preview me') }
-
+
it 'will show the preview changes in a new window', :js => true do
visit refinery.admin_pages_path
-
+
find('a[tooltip^=Edit]').click
fill_in "Title", :with => "Some changes I'm unsure what they will look like"
click_button "Preview"
-
- new_window = page.driver.browser.window_handles.last
+
+ new_window = page.driver.browser.window_handles.last
page.within_window new_window do
page.should have_content("Some changes I'm unsure what they will look like")
end
-
+
end
-
+
it 'will not save the preview changes', :js => true do
visit refinery.admin_pages_path
-
+
find('a[tooltip^=Edit]').click
fill_in "Title", :with => "Some changes I'm unsure what they will look like"
click_button "Preview"
-
- preview_page = Page.last
- preview_page.title.should_not == "Some changes I'm unsure what they will look like"
+
+ Page.last.title.should_not == "Some changes I'm unsure what they will look like"
end
-
+
end
-
+
context 'a brand new page' do
it "will not save when just previewing", :js => true do
visit refinery.admin_pages_path
-
+
click_link "Add new page"
fill_in "Title", :with => "My first page"
click_button "Preview"
-
- Page.all.should be_empty
+
+ Page.count.should == 0
end
end
-
+
context 'a nested page' do
before(:each) do
@parent = FactoryGirl.create(:page, :title => "Our Parent Page")
@nested_page = FactoryGirl.create(:page, :parent => @parent, :title => 'Preview Me')
end
-
+
it "should work like an un-nested page", :js => true do
visit refinery.admin_pages_path
-
+
within "#page_#{@nested_page.id}" do
find('a[tooltip^=Edit]').click
end
-
+
fill_in "Title", :with => "Some changes I'm unsure what they will look like"
click_button "Preview"
-
- new_window = page.driver.browser.window_handles.last
+
+ new_window = page.driver.browser.window_handles.last
page.within_window new_window do
page.should have_content("Some changes I'm unsure what they will look like")
end
Please sign in to comment.
Something went wrong with that request. Please try again.