Hi,
I have (mostly working) code for FCKeditor (
http://www.fckeditor.net/ ) integration and I'd like to discuss here
what Ive done.
First of all, my aim is to not reinvent the wheel, so I'm using the FCKeditor plugin (
http://rubyforge.org/projects/fckeditorp/
) .
It provides some helpers to substitute textarea with rich editors (in
ajax way or not) and in _form.rhtml one can write something like:
[...]
<% elsif controller.fckeditor_column?
column.name %>
<%=
fckeditor_textarea(@model_underscore,
column.name, :ajax => true,
:toolbarSet => 'Basic', :rows => '20', :cols => '70') %>
<% else %>
[...]
Moreover, form should be prepared for FCKeditor, in _edit.rhtml:
<%
editors = { :series => ['description', 'comment1'] }
before = ""
editors.keys.each do |e|
editors[e].each do |f|
before += fckeditor_before_js(e, f)
end
end
remote_form_for @model_underscore.to_sym, @streamlined_item,
:url
=> { :action => "update", :id=>@streamlined_item, :from_window
=> true},
:before => before do |form|
%>
(here we can write a patch for FCKeditor plugin which doesn't have a
fckeditor_remote_form_for helper, hence the work for constructing
:before parameter copied from the fckeditor_remote_form_tag helper)
Unfortunately there is an issue. When the edit Prototype windows is
opened, it takes its content from an url and _doesn't_ evaluate scripts
and I haven't found an option to change this behaviour (this doesn't
mean that this option actually exists :-) ). This is, in fact, very
similar to the problems Nelson Silvan had integrating TinyMCE (
http://wiki.streamlinedframework.org/streamlined/show/TinyMCE ).
Anyway, observing that everything works well when one clicks on "Edit" in a show windows, I've found a workaround:
managing the windows opening in the same way of the windows update.
In streamlined.js, open_window_from_url becomes:
open_local_window_from_url: function(title_prefix, url, model) {
if (model == null) {
model = "new"
}
// create an empty window
Streamlined.Windows.open_local_window(title_prefix, '', model);
// update its content
new Ajax.Request(url, {
method: "get",
evalScripts: true
});
}
Consequently, in _list.rhtml (around line 37):
<%= link_to_function image_tag('edit_16.png',
{:alt => 'Edit', :title => 'Edit', :border => '0'}),
"Streamlined.Windows.open_local_window_from_url('Edit',
'#{url_for(:action => 'edit', :id =>
item.id, :from_window =>
true)}', #{
item.id})" %>
with a "fake" :from_window param. The same change should be done for the 'Show' icon.
These modifications could potentially simplify the
streamlined_controller because there is no need to distinguish
rendering depending on request.xhr? &&
params[:from_window] condition but I don't know how this scales when
more window/transition types will be added (
http://groups.google.com/group/streamlined/browse_frm/thread/6298ed8f41c7c1f9/19e644408a25a439#19e644408a25a439
). By the way: when?
I prefer FCKeditor to TinyMCE because, as far as I know, with TinyMCE there isn't an open/Ruby file browser.
FCKeditor file browser (
http://wiki.fckeditor.net/Developer%27s_Guide/Configuration/Built_in_File_Browser
) integrates with streamlined naturally (without "core" changes).
Any comments will be appreciated, best regards
--
Nicola Piccinini --
http://superfluo.org