Add configuration to wysihtml5 widget #1326

Merged
merged 3 commits into from Oct 12, 2012
@@ -191,19 +191,20 @@ $(document).live 'rails_admin.dom_ready', ->
# bootstrap_wysihtml5
- goBootstrapWysihtml5s = (array) =>
+ goBootstrapWysihtml5s = (array, config_options) =>
array.each ->
$(@).addClass('bootstrap-wysihtml5ed')
$(@).closest('.controls').addClass('well')
- $(@).wysihtml5()
+ $(@).wysihtml5(config_options)
array = $('form [data-richtext=bootstrap-wysihtml5]').not('.bootstrap-wysihtml5ed')
if array.length
@array = array
if not window.wysihtml5
options = $(array[0]).data('options')
+ config_options = $.parseJSON(options['config_options'])
$('head').append('<link href="' + options['csspath'] + '" rel="stylesheet" media="all" type="text\/css">')
$.getScript options['jspath'], (script, textStatus, jqXHR) =>
- goBootstrapWysihtml5s(@array)
+ goBootstrapWysihtml5s(@array, config_options)
else
- goBootstrapWysihtml5s(@array)
+ goBootstrapWysihtml5s(@array, config_options)
@@ -20,7 +20,8 @@
richtext = 'bootstrap-wysihtml5'
js_data = {
:csspath => field.bootstrap_wysihtml5_css_location,
- :jspath => field.bootstrap_wysihtml5_js_location
+ :jspath => field.bootstrap_wysihtml5_js_location,
+ :config_options => field.bootstrap_wysihtml5_config_options.to_json
}
else
richtext = false
@@ -65,6 +65,13 @@ class Text < RailsAdmin::Config::Fields::Base
false
end
+ # If you want to have a different toolbar configuration for wysihtml5
+ # you can use a Ruby hash to configure these options:
+ # https://github.com/jhollingworth/bootstrap-wysihtml5/#advanced
+ register_instance_option(:bootstrap_wysihtml5_config_options) do
+ nil
+ end
+
register_instance_option(:bootstrap_wysihtml5_css_location) do
'/assets/bootstrap-wysihtml5.css'
end
@@ -793,6 +793,22 @@ class HelpTest < Tableless
visit new_path(:model_name => "draft")
should have_selector('textarea#draft_notes[data-richtext="bootstrap-wysihtml5"]')
end
+
+ it "should include custom wysihtml5 configuration" do
+ RailsAdmin.config Draft do
+ edit do
+ field :notes do
+ bootstrap_wysihtml5 true
+ bootstrap_wysihtml5_config_options :image => false
+ bootstrap_wysihtml5_css_location 'stub_css.css'
+ bootstrap_wysihtml5_js_location 'stub_js.js'
+ end
+ end
+ end
+
+ visit new_path(:model_name => "draft")
+ should have_selector("textarea#draft_notes[data-richtext=\"bootstrap-wysihtml5\"][data-options]")
+ end
end
describe "Paperclip Support" do