diff --git a/.gitignore b/.gitignore index 336b921..32522ff 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ spec/dummy/db/*.sqlite3 spec/dummy/log/*.log spec/dummy/tmp/ tags + +.byebug_history diff --git a/Changes.md b/Changes.md index cb4fdd8..b7af0c1 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,29 @@ +1.2.2 +----------- + +- Remove duplicated href key from config template #146 [nfilzi] +- Replace deprecated .any? with .present? #143 [AakLak] +- Development environment update #140 [mizinsky] +- Fix sanitize_params method #137 [mizinsky] +- Enable to configure global remote option and it to affects sortable helper #131 [kitabatake] +- Kaminari update [mizinsky] +- Update Readme for Rails >= 5.1 Users [mizinsky] + +1.2.1 +----------- + +- Allow to render outside of controllers [bval] +- Documentation fixes [blackcofla] +- Use id.to_json so integers and uuids will both work [sevgibson] +- Fix popover in bootstrap 4 [sevgibson] +- Fix Kaminari #num_pages deprecation warning [tylerhunt] +- Add support for Turbolinks 5 [wynksaiddestroy] +- Use #empty? for AC::Params [phoffer] +- Fix indentation in some files [boy-papan] + +1.2.0 +----------- + - Rails 5 support and Kaminari update [akostadinov] - Better handling of nested controls params - Fix controls not fading out list. Related to #51 @@ -6,6 +32,7 @@ 1.1.2 ----------- + - Some bugfixing: #20, #46, #58 1.1.0 diff --git a/Gemfile.lock b/Gemfile.lock index bf9b436..33e050e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,136 +1,216 @@ PATH remote: . specs: - smart_listing (1.1.2) + smart_listing (1.2.1) coffee-rails jquery-rails - kaminari (~> 0.17) + kaminari (>= 0.17) rails (>= 3.2) GEM remote: https://rubygems.org/ specs: - actionmailer (4.1.6) - actionpack (= 4.1.6) - actionview (= 4.1.6) + actioncable (5.1.4) + actionpack (= 5.1.4) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) mail (~> 2.5, >= 2.5.4) - actionpack (4.1.6) - actionview (= 4.1.6) - activesupport (= 4.1.6) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - actionview (4.1.6) - activesupport (= 4.1.6) + rails-dom-testing (~> 2.0) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.1.4) + activesupport (= 5.1.4) builder (~> 3.1) - erubis (~> 2.7.0) - activemodel (4.1.6) - activesupport (= 4.1.6) - builder (~> 3.1) - activerecord (4.1.6) - activemodel (= 4.1.6) - activesupport (= 4.1.6) - arel (~> 5.0.0) - activesupport (4.1.6) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.1.4) + activesupport (= 5.1.4) + globalid (>= 0.3.6) + activemodel (5.1.4) + activesupport (= 5.1.4) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) + arel (~> 8.0) + activesupport (5.1.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) minitest (~> 5.1) - thread_safe (~> 0.1) tzinfo (~> 1.1) - arel (5.0.1.20140414130214) - bootstrap-sass (3.3.0.1) - sass (~> 3.2) - builder (3.2.2) - capybara (2.4.4) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + arel (8.0.0) + autoprefixer-rails (7.2.5) + execjs + bootstrap-sass (3.3.7) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) + builder (3.2.3) + byebug (9.1.0) + capybara (2.13.0) + addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - capybara-webkit (1.3.1) - capybara (>= 2.0.2, < 2.5.0) + capybara-webkit (1.14.0) + capybara (>= 2.3.0, < 2.14.0) json - coffee-rails (4.1.0) + coderay (1.1.2) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) - coffee-script (2.3.0) + railties (>= 4.0.0) + coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.8.0) - database_cleaner (1.3.0) - diff-lcs (1.2.5) - erubis (2.7.0) - execjs (2.2.2) - hike (1.2.3) - i18n (0.6.11) - jquery-rails (3.1.2) - railties (>= 3.0, < 5.0) + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + crass (1.0.3) + database_cleaner (1.6.2) + diff-lcs (1.3) + erubi (1.7.0) + execjs (2.7.0) + ffi (1.9.18) + formatador (0.2.5) + globalid (0.4.1) + activesupport (>= 4.2.0) + guard (2.14.2) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-rspec (4.7.3) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) + i18n (0.9.3) + concurrent-ruby (~> 1.0) + jquery-rails (4.3.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.1) + json (2.1.0) kaminari (0.17.0) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - mail (2.6.3) - mime-types (>= 1.16, < 3) - mime-types (2.4.3) - mini_portile2 (2.1.0) - minitest (5.4.2) - multi_json (1.10.1) - nokogiri (1.6.8) - mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) - pkg-config (1.1.7) - rack (1.5.2) - rack-test (0.6.2) - rack (>= 1.0) - rails (4.1.6) - actionmailer (= 4.1.6) - actionpack (= 4.1.6) - actionview (= 4.1.6) - activemodel (= 4.1.6) - activerecord (= 4.1.6) - activesupport (= 4.1.6) - bundler (>= 1.3.0, < 2.0) - railties (= 4.1.6) - sprockets-rails (~> 2.0) - railties (4.1.6) - actionpack (= 4.1.6) - activesupport (= 4.1.6) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.1.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + lumberjack (1.0.12) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.2) + nenv (0.3.0) + nio4r (2.2.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + public_suffix (3.0.1) + rack (2.0.3) + rack-test (0.8.2) + rack (>= 1.0, < 3) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) + bundler (>= 1.3.0) + railties (= 5.1.4) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.3.2) - rspec-core (3.1.7) - rspec-support (~> 3.1.0) - rspec-expectations (3.1.2) + rake (12.3.0) + rb-fsevent (0.10.2) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-core (3.7.1) + rspec-support (~> 3.7.0) + rspec-expectations (3.7.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-mocks (3.1.3) - rspec-support (~> 3.1.0) - rspec-rails (3.1.0) + rspec-support (~> 3.7.0) + rspec-mocks (3.7.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.7.0) + rspec-rails (3.7.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) - rspec-support (~> 3.1.0) - rspec-support (3.1.2) - sass (3.4.7) - sprockets (2.12.3) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.2.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.9) - thor (0.19.1) - thread_safe (0.3.4) - tilt (1.4.1) - tzinfo (1.2.2) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) + rspec-support (~> 3.7.0) + rspec-support (3.7.0) + ruby_dep (1.5.0) + sass (3.5.5) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + shellany (0.0.1) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.4) thread_safe (~> 0.1) - xpath (2.0.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (2.1.0) nokogiri (~> 1.3) PLATFORMS @@ -138,12 +218,14 @@ PLATFORMS DEPENDENCIES bootstrap-sass - capybara (~> 2.4.4) - capybara-webkit (~> 1.3.1) + byebug + capybara (< 2.14) + capybara-webkit (~> 1.14) database_cleaner + guard-rspec rspec-rails smart_listing! sqlite3 BUNDLED WITH - 1.12.5 + 1.16.1 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..3215f01 --- /dev/null +++ b/Guardfile @@ -0,0 +1,70 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) \ +# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")} + +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +# Note: The cmd option is now required due to the increasing number of ways +# rspec may be run, below are examples of the most common uses. +# * bundler: 'bundle exec rspec' +# * bundler binstubs: 'bin/rspec' +# * spring: 'bin/rspec' (This will use spring if running and you have +# installed the spring binstubs per the docs) +# * zeus: 'zeus rspec' (requires the server to be started separately) +# * 'just' rspec: 'rspec' + +guard :rspec, cmd: "bundle exec rspec" do + require "guard/rspec/dsl" + dsl = Guard::RSpec::Dsl.new(self) + + # Feel free to open issues for suggestions and improvements + + # RSpec files + rspec = dsl.rspec + watch(rspec.spec_helper) { rspec.spec_dir } + watch(rspec.spec_support) { rspec.spec_dir } + watch(rspec.spec_files) + + # Ruby files + ruby = dsl.ruby + dsl.watch_spec_files_for(ruby.lib_files) + + # Rails files + rails = dsl.rails(view_extensions: %w(erb haml slim)) + dsl.watch_spec_files_for(rails.app_files) + dsl.watch_spec_files_for(rails.views) + + watch(rails.controllers) do |m| + [ + rspec.spec.call("routing/#{m[1]}_routing"), + rspec.spec.call("controllers/#{m[1]}_controller"), + rspec.spec.call("acceptance/#{m[1]}") + ] + end + + # Rails config changes + watch(rails.spec_helper) { rspec.spec_dir } + watch(rails.routes) { "#{rspec.spec_dir}/routing" } + watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } + + # Capybara features specs + watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") } + watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") } + + # Turnip features and steps + watch(%r{^spec/acceptance/(.+)\.feature$}) + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| + Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance" + end +end diff --git a/README.md b/README.md index 0eeed43..8774147 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ Also, you need to add SmartListing to your asset pipeline: //= require smart_listing ``` +__Rails >= 5.1 users__: Rails 5.1 has dropped jQuery dependency from the default stack in favour of `rails-ujs`. SmartListing still requires jQuery so make sure that you use `jquery_ujs` from `jquery-rails` gem and have following requires in your asset pipeline before `smart_listing`: +``` +//= require jquery +//= require jquery_ujs +``` + ### Initializer Optionally you can also install some configuration initializer: @@ -73,7 +79,7 @@ smart_listing_render(:users) - unless smart_listing.empty? %table %thead - %tr + %tr %th User name %th Email %tbody @@ -82,7 +88,7 @@ smart_listing_render(:users) %td= user.name %td= user.email - = smart_listing.paginate + = smart_listing.paginate - else %p.warning No records! ``` @@ -112,7 +118,7 @@ SmartListing supports two modes of sorting: implicit and explicit. Implicit mode - unless smart_listing.empty? %table %thead - %tr + %tr %th= smart_listing.sortable "User name", :name %th= smart_listing.sortable "Email", :email %tbody @@ -121,12 +127,12 @@ SmartListing supports two modes of sorting: implicit and explicit. Implicit mode %td= user.name %td= user.email - = smart_listing.paginate + = smart_listing.paginate - else %p.warning No records! ``` -In this case `:name` and `:email` are sorting column names. `Builder#sortable` renders special link containing column name and sort order (either `asc`, `desc`, or empty value). +In this case `:name` and `:email` are sorting column names. `Builder#sortable` renders special link containing column name and sort order (either `asc`, `desc`, or empty value). You can also specify default sort order in the controller: @@ -136,7 +142,7 @@ You can also specify default sort order in the controller: Implicit mode is convenient with simple data sets. In case you want to sort by joined column names, we advise you to use explicit sorting: ```ruby -@users = smart_listing_create :users, User.active.joins(:stats), partial: "users/listing", +@users = smart_listing_create :users, User.active.joins(:stats), partial: "users/listing", sort_attributes: [[:last_signin, "stats.last_signin_at"]], default_sort: {last_signin: "desc"} ``` @@ -153,7 +159,7 @@ In order to allow managing and editing list items, we need to reorganize our vie - unless smart_listing.empty? %table %thead - %tr + %tr %th= smart_listing.sortable "User name", "name" %th= smart_listing.sortable "Email", "email" %th @@ -161,9 +167,9 @@ In order to allow managing and editing list items, we need to reorganize our vie - smart_listing.collection.each do |user| %tr.editable{data: {id: user.id}} = smart_listing.render partial: 'users/user', locals: {user: user} - = smart_listing.item_new colspan: 3, link: new_user_path + = smart_listing.item_new colspan: 3, link: new_user_path - = smart_listing.paginate + = smart_listing.paginate - else %p.warning No records! ``` @@ -174,7 +180,7 @@ In order to allow managing and editing list items, we need to reorganize our vie <%= smart_listing_item :users, :new, @new_user, "users/form" %> ``` -Note that `new` action does not need to create SmartListing (via `smart_listing_create`). It just initializes `@new_user` and renders JS view. +Note that `new` action does not need to create SmartListing (via `smart_listing_create`). It just initializes `@new_user` and renders JS view. New partial for user (`users/user`) may look like this: ```haml @@ -204,10 +210,10 @@ Partial name supplied to `smart_listing_item` (`users/form`) references `@user` = form_for object, url: object.new_record? ? users_path : user_path(object), remote: true do |f| %p - Name: + Name: = f.text_field :name %p - Email: + Email: = f.text_field :email %p= f.submit "Save" ``` @@ -228,7 +234,7 @@ SmartListing controls allow you to change somehow presented data. This is typica .filter.input-append = text_field_tag :filter, '', class: "search", placeholder: "Type name here", autocomplete: "off" %button.btn.disabled{type: "submit"} - %i.icon.icon-search + %span.glyphicon.glyphicon-search ``` This gives you nice Bootstrap-enabled filter field with keychange handler. Of course you can use any other form fields in controls too. @@ -262,7 +268,7 @@ SmartListing.configure(:awesome_profile) do |config| end ``` -In order to use this profile, create helper method named `smart_listing_config_profile` returning profile name and put into your JS `SmartListing.config.merge()` function call. `merge()` function expects parameter with config attributes hash or reads body data-attribute named `smart-listing-config`. Hash of config attributes can be obtained by using helper method `SmartListing.config(:awesome_profile).to_json`. +In order to use this profile, create helper method named `smart_listing_config_profile` returning profile name and put into your JS `SmartListing.config.merge()` function call. `merge()` function expects parameter with config attributes hash or reads body data-attribute named `smart-listing-config`. Hash of config attributes can be obtained by using helper method `SmartListing.config(:awesome_profile).to_json`. ## Not enough? diff --git a/app/assets/javascripts/smart_listing.coffee.erb b/app/assets/javascripts/smart_listing.coffee.erb index 040a8dc..26313e0 100644 --- a/app/assets/javascripts/smart_listing.coffee.erb +++ b/app/assets/javascripts/smart_listing.coffee.erb @@ -1,3 +1,10 @@ +# endsWith polyfill +if !String::endsWith + String::endsWith = (search, this_len) -> + if this_len == undefined or this_len > @length + this_len = @length + @substring(this_len - (search.length), this_len) == search + # Useful when SmartListing target url is different than current one $.rails.href = (element) -> element.attr("href") || element.data("<%= SmartListing.config.data_attributes(:href) %>") || window.location.pathname @@ -24,6 +31,9 @@ class window.SmartListing @element_template: (name)-> @options["constants"]["element_templates"][name] + @bootstrap_commands: (name)-> + @options["constants"]["bootstrap_commands"][name] + @config: Config @@ -319,8 +329,8 @@ $.fn.smart_listing.observeField = (field, opts = {}) -> , 400) $.fn.smart_listing.showPopover = (elem, body) -> - elem.popover("destroy") - elem.popover(content: body, html: true, trigger: "manual", title: null) + elem.popover(SmartListing.config.bootstrap_commands("popover_destroy")) + elem.popover(content: body, html: true, trigger: "manual") elem.popover("show") $.fn.smart_listing.showConfirmation = (confirmation_elem, msg, confirm_callback) -> @@ -333,12 +343,12 @@ $.fn.smart_listing.showConfirmation = (confirmation_elem, msg, confirm_callback) editable = $(event.currentTarget).closest(SmartListing.config.class_name("editable")) confirm_callback(confirmation_elem) $(confirmation_elem).click() - $(confirmation_elem).popover("destroy") + $(confirmation_elem).popover(SmartListing.config.bootstrap_commands("popover_destroy")) ) .append(" ") .append($("").html("No").addClass("btn btn-small").click (event) => editable = $(event.currentTarget).closest(SmartListing.config.class_name("editable")) - $(confirmation_elem).popover("destroy") + $(confirmation_elem).popover(SmartListing.config.bootstrap_commands("popover_destroy")) ) ) @@ -438,4 +448,4 @@ ready = -> $(SmartListing.config.class_name("controls")).smart_listing_controls() $(document).ready ready -$(document).on "page:load", ready +$(document).on "page:load turbolinks:load", ready diff --git a/app/helpers/smart_listing/helper.rb b/app/helpers/smart_listing/helper.rb index 4266f7f..707554a 100644 --- a/app/helpers/smart_listing/helper.rb +++ b/app/helpers/smart_listing/helper.rb @@ -11,6 +11,7 @@ def smart_listing_create *args name = (args[0] || options[:name] || controller_name).to_sym collection = args[1] || options[:collection] || smart_listing_collection + view_context = self.respond_to?(:controller) ? controller.view_context : self.view_context options = {:config_profile => view_context.smart_listing_config_profile}.merge(options) list = SmartListing::Base.new(name, collection, options) @@ -32,8 +33,6 @@ def _prefixes end class Builder - # Params that should not be visible in pagination links (pages, per-page, sorting, etc.) - UNSAFE_PARAMS = {:authenticity_token => nil, :utf8 => nil} class_attribute :smart_listing_helpers @@ -47,7 +46,7 @@ def name def paginate options = {} if @smart_listing.collection.respond_to? :current_page - @template.paginate @smart_listing.collection, {:remote => @smart_listing.remote?, :param_name => @smart_listing.param_name(:page), :params => UNSAFE_PARAMS}.merge(@smart_listing.kaminari_options) + @template.paginate @smart_listing.collection, {:remote => @smart_listing.remote?, :param_name => @smart_listing.param_name(:page)}.merge(@smart_listing.kaminari_options) end end @@ -77,7 +76,7 @@ def pagination_per_page_links options = {} def pagination_per_page_link page if @smart_listing.per_page.to_i != page - url = @template.url_for(sanitize_params(@template.params.merge(@smart_listing.all_params(:per_page => page, :page => 1)))) + url = @template.url_for(@smart_listing.params.merge(@smart_listing.all_params(:per_page => page, :page => 1))) end locals = { @@ -99,10 +98,11 @@ def sortable title, attribute, options = {} locals = { :order => @smart_listing.sort_order(attribute), - :url => @template.url_for(sanitize_params(@template.params.merge(@smart_listing.all_params(:sort => sort_params)))), + :url => @template.url_for(@smart_listing.params.merge(@smart_listing.all_params(:sort => sort_params))), :container_classes => [@template.smart_listing_config.classes(:sortable)], :attribute => attribute, - :title => title + :title => title, + :remote => @smart_listing.remote? } @template.render(:partial => 'smart_listing/sortable', :locals => default_locals.merge(locals)) @@ -179,11 +179,6 @@ def max_count? private - def sanitize_params params - params = params.permit! if params.respond_to?(:permit!) - params.merge(UNSAFE_PARAMS) - end - def default_locals {:smart_listing => @smart_listing, :builder => self} end @@ -230,7 +225,7 @@ def smart_listing_for name, *args, &block end def smart_listing_render name = controller_name, *args - options = args.extract_options! + options = args.dup.extract_options! smart_listing_for(name, *args) do |smart_listing| concat(smart_listing.render_list(options[:locals])) end @@ -317,7 +312,7 @@ def smart_listing_update *args smart_listing = @smart_listings[name] # don't update list if params are missing (prevents interfering with other lists) - if params.keys.select{|k| k.include?("smart_listing")}.any? && !params[smart_listing.base_param] + if params.keys.select{|k| k.include?("smart_listing")}.present? && !params[smart_listing.base_param] return unless options[:force] end diff --git a/app/views/smart_listing/_sortable.html.erb b/app/views/smart_listing/_sortable.html.erb index 66b05ac..92e85d8 100644 --- a/app/views/smart_listing/_sortable.html.erb +++ b/app/views/smart_listing/_sortable.html.erb @@ -11,7 +11,7 @@ builder: current builder instance -%> -<%= link_to url, :class => container_classes, :data => {:attr => attribute}, :remote => true do %> +<%= link_to url, :class => container_classes, :data => {:attr => attribute}, :remote => remote do %> <%= title %> <% if order %> "> diff --git a/app/views/smart_listing/item/_create.js.erb b/app/views/smart_listing/item/_create.js.erb index b54101e..55addf2 100644 --- a/app/views/smart_listing/item/_create.js.erb +++ b/app/views/smart_listing/item/_create.js.erb @@ -1,3 +1,3 @@ var smart_listing = $('#<%= name %>').smart_listing(); smart_listing.setAutoshow(false); -smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.create(<%= (id || 0).to_json.html_safe %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); diff --git a/app/views/smart_listing/item/_create_continue.js.erb b/app/views/smart_listing/item/_create_continue.js.erb index 4d520cf..cc787b5 100644 --- a/app/views/smart_listing/item/_create_continue.js.erb +++ b/app/views/smart_listing/item/_create_continue.js.erb @@ -1,6 +1,6 @@ var smart_listing = $('#<%= name %>').smart_listing(); smart_listing.setAutoshow(true); -smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.create(<%= (id || 0).to_json.html_safe %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); <% if object.persisted? %> smart_listing.new_item("<%= escape_javascript(render(:partial => new.last, :locals => {object_key => new.first})) %>"); <% end %> diff --git a/app/views/smart_listing/item/_destroy.js.erb b/app/views/smart_listing/item/_destroy.js.erb index 31c601e..5caace4 100644 --- a/app/views/smart_listing/item/_destroy.js.erb +++ b/app/views/smart_listing/item/_destroy.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name.to_s %>').smart_listing(); -smart_listing.destroy(<%= id %>, <%= object.destroyed? %>); +smart_listing.destroy(<%= id.to_json.html_safe %>, <%= object.destroyed? %>); diff --git a/app/views/smart_listing/item/_edit.js.erb b/app/views/smart_listing/item/_edit.js.erb index 00b0625..c2873a3 100644 --- a/app/views/smart_listing/item/_edit.js.erb +++ b/app/views/smart_listing/item/_edit.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name %>').smart_listing(); -smart_listing.edit(<%= id %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.edit(<%= id.to_json.html_safe %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); diff --git a/app/views/smart_listing/item/_remove.js.erb b/app/views/smart_listing/item/_remove.js.erb index 7263d19..d876559 100644 --- a/app/views/smart_listing/item/_remove.js.erb +++ b/app/views/smart_listing/item/_remove.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name %>').smart_listing(); -smart_listing.remove(<%= id %>); +smart_listing.remove(<%= id.to_json.html_safe %>); diff --git a/app/views/smart_listing/item/_update.js.erb b/app/views/smart_listing/item/_update.js.erb index 69780d6..c8a678c 100644 --- a/app/views/smart_listing/item/_update.js.erb +++ b/app/views/smart_listing/item/_update.js.erb @@ -1,2 +1,2 @@ var smart_listing = $('#<%= name %>').smart_listing(); -smart_listing.update(<%= id %>, <%= valid.nil? ? object.valid? : valid %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); +smart_listing.update(<%= id.to_json.html_safe %>, <%= valid.nil? ? object.valid? : valid %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>"); diff --git a/lib/generators/smart_listing/install_generator.rb b/lib/generators/smart_listing/install_generator.rb index c715145..db28f84 100644 --- a/lib/generators/smart_listing/install_generator.rb +++ b/lib/generators/smart_listing/install_generator.rb @@ -5,7 +5,7 @@ class InstallGenerator < Rails::Generators::Base def self.banner #:nodoc: <<-BANNER.chomp -rails g smart_listing:install +rails g smart_listing:install Copies initializer file BANNER @@ -15,6 +15,6 @@ def self.banner #:nodoc: def copy_views template 'initializer.rb', 'config/initializers/smart_listing.rb' end - end - end + end + end end diff --git a/lib/generators/smart_listing/templates/initializer.rb b/lib/generators/smart_listing/templates/initializer.rb index 8073aae..a2ba229 100644 --- a/lib/generators/smart_listing/templates/initializer.rb +++ b/lib/generators/smart_listing/templates/initializer.rb @@ -65,7 +65,6 @@ #:inline_edit_backup => "smart-listing-edit-backup", #:params => "params", #:observed => "observed", - #:href => "href", #:autoshow => "autoshow", #:popover => "slpopover", } @@ -85,4 +84,8 @@ config.constants :element_templates, { #:row => "
Name | -<%= smart_listing.sortable "Name", "name"%> | +<%= smart_listing.sortable "Email", "email"%> | +Boolean | @@ -11,7 +12,7 @@ locals: { object: user } %> <% end %> - <%= smart_listing.item_new colspan: 3, link: new_admin_user_path %> + <%= smart_listing.item_new colspan: 4, link: new_admin_user_path %> |
---|