Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add configuration to wysihtml5 widget #1326

Merged
merged 3 commits into from

3 participants

@ahhrrr

Hello,

I'd love to write a patch to allow configuration of the wysihtml5 widget from the rails_admin config DSL. I'd like to be able to set the first set of options here: https://github.com/jhollingworth/bootstrap-wysihtml5/#advanced

Would such a patch be accepted? If so, I'll give it a shot!

@ahhrrr

I began work on a patch, but the spec fails. Following the example of the other wysihtml5 spec, I'm checking for existence (and absence) of the button elements I'm enabling/disabling with the config options. But because they are created with javascript, capybara won't ever see them.

I'd be happy to rework the spec if you can give me an idea about how to test this feature! This is working with manual tests.

Additionally, I'm not totally thrilled with the use .to_json and $.parseJSON and am open to alternative means of data sharing.

Thanks,
Ezra

@bbenezech
Collaborator

Hello @ahhrrr

We don't have any way to test JS at the moment. Just test the JSON presence, it'll be fine.

Is it ready to be merged or do you still need some time ?

@ahhrrr

Hi @bbenezech, I've updated the spec as you requested. It failed one of the CI jobs, but it appears to be because of a bundler issue. So, I think it should be ready to merge. Let me know if there's anything else you need.

@bbenezech
Collaborator

Perfect! Thank you very much.

I'll rebase it to merge. Thanks.

@bbenezech bbenezech merged commit d883601 into sferik:master

1 check failed

Details default The Travis build failed
@RafaelMCarvalho

Awesome! Thank you @ahhrrr. But i'm having a problem.

When access directly a path (Ex. '/admin/posts/new'), it works great, like you did at the spec tests. But when access navigating (Ex. Click link 'Add post'), it doesn't load setted configurations.

Are you having the same problem?
Is it a problem with pjax?

Thank you for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
9 app/assets/javascripts/rails_admin/ra.widgets.coffee
@@ -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)
View
3  app/views/rails_admin/main/_form_text.html.haml
@@ -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
View
7 lib/rails_admin/config/fields/types/text.rb
@@ -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
View
16 spec/integration/config/edit/rails_admin_config_edit_spec.rb
@@ -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
Something went wrong with that request. Please try again.