Skip to content

Commit

Permalink
CKEditor implementation finished
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Jul 2, 2014
1 parent 223d2e8 commit d4ae861
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 78 deletions.
Expand Up @@ -55,7 +55,9 @@ jQuery(function()
{
return;
}
tinyMCE.execCommand( 'mceRemoveControl', false, textarea.attr('id') );

CKEDITOR.instances[ textarea.attr('id') ].destroy();
textarea.hide();
textarea.data('richtext-suspended', true);
});

Expand All @@ -65,7 +67,9 @@ jQuery(function()
{
return;
}
tinyMCE.execCommand( 'mceAddControl', false, textarea.attr('id') );

textarea.show();
textarea.trigger('richtextinit');
textarea.data('richtext-suspended', false);
});
});
Expand All @@ -85,7 +89,7 @@ jQuery(function()

body.on('contentbeforeremove', function(e)
{
// remove tinymce instances when removing fields
// remove ckeditor instances when removing fields

var removable_item = jQuery(e.target);
var textareas = removable_item.is('textarea.richtext') ? removable_item : removable_item.find( 'textarea.richtext' );
Expand All @@ -98,7 +102,7 @@ jQuery(function()
});


// to avoid losing content tinymce needs to be disabled and reenabled when used inside a sortable list
// to avoid losing content ckeditor needs to be disabled and reenabled when used inside a sortable list
body.on('sortablestart', function( event )
{
jQuery(event.target).find('textarea.richtext').each(function()
Expand All @@ -109,15 +113,15 @@ jQuery(function()

body.on('sortablestop sortableupdate', function( event )
{
// restore tinymce on either sortablestop or sortableupdate, whichever comes first
// restore ckeditor on either sortablestop or sortableupdate, whichever comes first
// (sortable plugin actually calls update before stop)
jQuery(event.target).find('textarea.richtext').each(function()
{
jQuery(this).trigger('richtextresume');
});
});

// if id of the textarea gets changed, tinymce needs to be reinitialized
// if id of the textarea gets changed, ckeditor needs to be reinitialized
body.on('beforeattributechange', 'textarea.richtext', function(event, event_params)
{
if (event_params.attribute != 'id')
Expand Down
66 changes: 0 additions & 66 deletions releaf-core/app/views/releaf/base/new_attachment.html.haml

This file was deleted.

Expand Up @@ -4,7 +4,7 @@ def fields_to_display
if %w[show index].include? params[:action]
super
else
super + [{chapters: %w[title text]}]
super + [{chapters: %w[title text sample_html]}]
end
end

Expand All @@ -14,7 +14,7 @@ def setup
end

def resource_params
super + [{chapters_attributes: [:title, :text, :id, :_destroy]}]
super + [{chapters_attributes: [:title, :text, :sample_html, :id, :_destroy, :item_position]}]
end
end

Expand Up @@ -3,7 +3,9 @@ def change
create_table :chapters do |t|
t.string :title, :null => false
t.text :text
t.text :sample_html
t.integer :book_id
t.integer :item_position
t.timestamps
end
add_index :chapters, :book_id
Expand Down
3 changes: 2 additions & 1 deletion releaf-core/lib/generators/dummy/templates/models/chapter.rb
@@ -1,5 +1,6 @@
class Chapter < ActiveRecord::Base
validates_presence_of :title, :text, :book
validates_presence_of :title, :text, :book, :sample_html
belongs_to :book
alias_attribute :to_text, :title
default_scope { order('chapters.item_position ASC') }
end
10 changes: 8 additions & 2 deletions releaf-core/spec/features/edit_actions_spec.rb
Expand Up @@ -22,6 +22,10 @@
expect(page).to have_css('.delete-restricted-dialog.dialog .content .restricted-relations .relations li', :count => 2)
end

scenario "drag and drop nested items with ckeditors" do
skip "implement drag and drop test"
end

scenario "when clicking on delete restriction relation, it opens edit for related object" do
visit edit_admin_author_path @author
open_toolbox("Delete")
Expand Down Expand Up @@ -59,13 +63,14 @@

fill_in 'resource_chapters_attributes_0_title', :with => 'Chapter 1'
fill_in 'resource_chapters_attributes_0_text', :with => 'todo'
fill_in_richtext 'resource_chapters_attributes_0_sample_html', "xx"

find('button.primary[type="submit"]').click
save_and_check_response "Update succeeded"
expect(page).to_not have_css('.remove-nested-item')
expect(page).to have_css('#resource_chapters_attributes_0_title[value="Chapter 1"]')
end

scenario "adding newsted objects" do
scenario "adding nested objects" do
visit new_admin_book_path
within "form.new_resource" do
fill_in "Title", with: "Master and Margarita"
Expand All @@ -79,6 +84,7 @@

fill_in "Title", with: "Chapter 1"
fill_in "Text", with: "some text"
fill_in_richtext 'resource_chapters_attributes_0_sample_html', "xx"
end
end
save_and_check_response "Create succeeded"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/chapter.rb
Expand Up @@ -2,5 +2,6 @@
factory :chapter do
sequence(:title) { |n| "Chapter #{n}" }
text 'Some awesome text for great test'
sample_html '<strong>heavy</strong> words'
end
end
2 changes: 1 addition & 1 deletion spec/support/helpers.rb
Expand Up @@ -55,7 +55,7 @@ def open_toolbox item_name, resource = nil, content_controller = false
end

def fill_in_richtext html_element_id, content
expect(page).to have_css("#cke_#{html_element_id}") # wait for tinymce appearance
expect(page).to have_css("#cke_#{html_element_id}") # wait for ckeditor appearance
page.execute_script("$('##{html_element_id}').val(\"#{content}\")")
end
end

0 comments on commit d4ae861

Please sign in to comment.