From 436d193a4dba20e8c36df5601ac49cf2ebb71b7d Mon Sep 17 00:00:00 2001 From: Josh Adams Date: Sun, 18 Jan 2009 14:48:35 -0600 Subject: [PATCH] did some work on the form builder page plugin --- .../initializers/fckeditor_text_area_tag.rb | 29 +++++++++++++++++++ .../admin/form_fields_controller.rb | 7 +++-- .../ansuz/j_adams/form_field_text_field.rb | 1 + .../views/admin/form_builders/_edit.html.erb | 5 ++-- .../app/views/admin/form_fields/new.html.erb | 1 + 5 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 config/initializers/fckeditor_text_area_tag.rb diff --git a/config/initializers/fckeditor_text_area_tag.rb b/config/initializers/fckeditor_text_area_tag.rb new file mode 100644 index 0000000..0642279 --- /dev/null +++ b/config/initializers/fckeditor_text_area_tag.rb @@ -0,0 +1,29 @@ +module Fckeditor + module Helper + def fckeditor_textarea_tag(name, value='', options={}) + options[:id] ||= name + cols = options[:cols].nil? ? '' : "cols='"+options[:cols]+"'" + rows = options[:rows].nil? ? '' : "rows='"+options[:rows]+"'" + + width = options[:width].nil? ? '100%' : options[:width] + height = options[:height].nil? ? '100%' : options[:height] + + toolbarSet = options[:toolbarSet].nil? ? 'Default' : options[:toolbarSet] + + if options[:ajax] + inputs = "\n" << + "\n" + else + inputs = "\n" + end + + js_path = "#{ActionController::Base.relative_url_root}/javascripts" + base_path = "#{js_path}/fckeditor/" + return inputs << + javascript_tag("jQuery(document).ready(function(){ var oFCKeditor = new FCKeditor('#{options[:id]}', '#{width}', '#{height}', '#{toolbarSet}');\n" << + "oFCKeditor.BasePath = \"#{base_path}\"\n" << + "oFCKeditor.Config['CustomConfigurationsPath'] = '#{js_path}/fckcustom.js';\n" << + "oFCKeditor.ReplaceTextarea(); });\n") + end + end +end diff --git a/vendor/plugins/ansuz_form_builder/app/controllers/admin/form_fields_controller.rb b/vendor/plugins/ansuz_form_builder/app/controllers/admin/form_fields_controller.rb index db6ada3..64a70eb 100644 --- a/vendor/plugins/ansuz_form_builder/app/controllers/admin/form_fields_controller.rb +++ b/vendor/plugins/ansuz_form_builder/app/controllers/admin/form_fields_controller.rb @@ -21,19 +21,20 @@ def new end def create + options = {:label => params[:label]} # create the appropriate stuff... case params[:type] # TODO: Split this up and provide an API for other plugins to add form field types to the builder when "Text Field" - @field = Ansuz::JAdams::FormFieldTextField.new + @field = Ansuz::JAdams::FormFieldTextField.new(options) @form_field.form_builder_id = @form_builder.id @form_field.field = @field when "Text Area" - @field = Ansuz::JAdams::FormFieldTextArea.new + @field = Ansuz::JAdams::FormFieldTextArea.new(options) @form_field.form_builder_id = @form_builder.id @form_field.field = @field when "Rich Text Area" - @field = Ansuz::JAdams::FormFieldTextArea.new + @field = Ansuz::JAdams::FormFieldTextArea.new(options) @form_field.form_builder_id = @form_builder.id @form_field.field = @field @field.settings["has_rich_content_editor"] = true diff --git a/vendor/plugins/ansuz_form_builder/app/models/ansuz/j_adams/form_field_text_field.rb b/vendor/plugins/ansuz_form_builder/app/models/ansuz/j_adams/form_field_text_field.rb index f811693..a477bc6 100644 --- a/vendor/plugins/ansuz_form_builder/app/models/ansuz/j_adams/form_field_text_field.rb +++ b/vendor/plugins/ansuz_form_builder/app/models/ansuz/j_adams/form_field_text_field.rb @@ -1,3 +1,4 @@ +# FIXME: The whole form builder should be built with inheritance, what the heck happened here? module Ansuz module JAdams class FormFieldTextField < ActiveRecord::Base diff --git a/vendor/plugins/ansuz_form_builder/app/views/admin/form_builders/_edit.html.erb b/vendor/plugins/ansuz_form_builder/app/views/admin/form_builders/_edit.html.erb index 5487cef..9efd2db 100644 --- a/vendor/plugins/ansuz_form_builder/app/views/admin/form_builders/_edit.html.erb +++ b/vendor/plugins/ansuz_form_builder/app/views/admin/form_builders/_edit.html.erb @@ -1,6 +1,3 @@ -<%= link_to famfamfam_icon("add") + " Add a field", new_admin_form_builder_form_field_path(plugin_module) %> -
- <% plugin_module.form_fields.each do |form_field| %> <% @@ -11,3 +8,5 @@ <%= render_form_field_builder_view(form_field, :locals => { :field => form_field, :admin_links => admin_links.join(" ") }) %> <% end %>
+
+<%= link_to "Add a field", new_admin_form_builder_form_field_path(plugin_module), :class => "icon button add" %> diff --git a/vendor/plugins/ansuz_form_builder/app/views/admin/form_fields/new.html.erb b/vendor/plugins/ansuz_form_builder/app/views/admin/form_fields/new.html.erb index 58bd6db..3eb8475 100644 --- a/vendor/plugins/ansuz_form_builder/app/views/admin/form_fields/new.html.erb +++ b/vendor/plugins/ansuz_form_builder/app/views/admin/form_fields/new.html.erb @@ -2,6 +2,7 @@ <% form_for :form_builder, :url => admin_form_builder_form_fields_path(@form_builder) do |f| %> + <%= form_row "Label", text_field_tag(:label) %> <%= form_row "Type", select_tag(:type, options_for_select(["Text Field", "Text Area", "Rich Text Area"])) %> <%= form_row "", submit_tag %>