Skip to content

Commit

Permalink
[#556] [BUG FIX] Same block can appear twice.
Browse files Browse the repository at this point in the history
* Issue: CKeditor would not work if the same block appeared twice, meaning you couldn't remove, edit or move either block.
* Fix: Generate unique ids for each block, so CKeditor could bind to them. Their ids are meaningless anyway, as data attributes are used.
  • Loading branch information
peakpg committed Mar 19, 2013
1 parent 7743061 commit e8b9205
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 9 additions & 1 deletion app/helpers/cms/rendering_helper.rb
Expand Up @@ -24,7 +24,7 @@ def show(method, options={})
value.respond_to?(:html_safe) ? value.html_safe : value
else
content_tag 'div',
id: "#{@content_block.content_block_type}-#{@content_block.id}-#{method}",
id: random_unique_identifier(),
class: 'content-block',
contenteditable: true,
data: {
Expand Down Expand Up @@ -90,5 +90,13 @@ def render_connectable(content_block)
def render_cms_toolbar(tab=:dashboard)
render :partial => 'layouts/cms_toolbar', :locals => {:tab => tab}
end

private

# Each block needs a unique id on the page so CKeditor can attach to it. Doesn't matter what it is though.
# This ensure that if the same block is add twice, it will still work.
def random_unique_identifier
SecureRandom.urlsafe_base64
end
end
end
14 changes: 8 additions & 6 deletions app/views/cms/pages/_edit_content.html.erb
@@ -1,9 +1,11 @@
<%= content_tag 'div', class: 'connector',
data: { move_up: cms.move_up_connector_path(connector, format: :json),
move_down: cms.move_down_connector_path(connector, format: :json),
remove: cms.connector_path(connector, format: :json),
edit_path: edit_cms_connectable_path(connectable, :_redirect_to => @page.path)
data: {move_up: cms.move_up_connector_path(connector, format: :json),
move_down: cms.move_down_connector_path(connector, format: :json),
remove: cms.connector_path(connector, format: :json),
edit_path: edit_cms_connectable_path(connectable, :_redirect_to => @page.path)
} do %>
<%= link_to(image_tag('cms/pencil.png', class: 'cms-edit-content-link'), edit_cms_connectable_path(connectable, :_redirect_to => @page.path), title: "Edit this content.") %>
<%= render_connectable connectable %>
<%= link_to(image_tag('cms/pencil.png', class: 'cms-edit-content-link'),
edit_cms_connectable_path(connectable, :_redirect_to => @page.path),
title: "Edit this content.") %>
<%= render_connectable connectable %>
<% end %>
2 changes: 1 addition & 1 deletion task_ckeditor.md
Expand Up @@ -23,7 +23,7 @@
* [BUG] Can't move portlets up/down.
* [BUG][Minor] Inline (i.e. product.name) fields display have a <p> tag added by ckeditor, so they display as block elements. This might go away if we don't embed content blocks.
* [Improvement][Minor] Block Orders - Disable button based on position (i.e. Can't move first block up, last block down)
* [BUG][Major] Adding the same block twice to a page screws things up.
* [BUG][Trivial] If the same block appears twice on the same page, inline editing one will not cause the other to immediately show the update. (This is probably so rare as to be a non-issue anyway.)

### General UI issues

Expand Down

0 comments on commit e8b9205

Please sign in to comment.