best_in_place 2.1.0 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -5
- data/.rspec +1 -0
- data/.travis.yml +12 -5
- data/Appraisals +17 -0
- data/CHANGELOG.md +51 -30
- data/Gemfile +15 -2
- data/README.md +52 -105
- data/best_in_place.gemspec +13 -11
- data/config.ru +7 -0
- data/gemfiles/rails_3.2.gemfile +24 -0
- data/gemfiles/rails_4.0.gemfile +23 -0
- data/gemfiles/rails_4.1.gemfile +23 -0
- data/gemfiles/rails_edge.gemfile +25 -0
- data/lib/assets/javascripts/best_in_place.jquery-ui.js +57 -0
- data/lib/assets/javascripts/best_in_place.js +551 -650
- data/lib/assets/javascripts/best_in_place.purr.js +16 -6
- data/lib/best_in_place.rb +29 -9
- data/lib/best_in_place/controller_extensions.rb +10 -13
- data/lib/best_in_place/display_methods.rb +26 -21
- data/lib/best_in_place/engine.rb +2 -2
- data/lib/best_in_place/helper.rb +145 -87
- data/lib/best_in_place/railtie.rb +5 -2
- data/lib/best_in_place/test_helpers.rb +0 -1
- data/lib/best_in_place/utils.rb +20 -12
- data/lib/best_in_place/version.rb +1 -1
- data/spec/{helpers/best_in_place_spec.rb → helper_spec.rb} +134 -99
- data/spec/integration/double_init_spec.rb +3 -5
- data/spec/integration/js_spec.rb +193 -123
- data/spec/integration/live_spec.rb +3 -4
- data/spec/integration/text_area_spec.rb +4 -4
- data/spec/internal/app/assets/images/info.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/no.png +0 -0
- data/spec/internal/app/assets/images/purrBottom.png +0 -0
- data/spec/internal/app/assets/images/purrClose.png +0 -0
- data/spec/internal/app/assets/images/purrTop.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/red_pen.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_222222_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/yes.png +0 -0
- data/spec/internal/app/assets/javascripts/application.js +37 -0
- data/{test_app → spec/internal}/app/assets/stylesheets/.gitkeep +0 -0
- data/{test_app → spec/internal}/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb +1 -2
- data/{test_app → spec/internal}/app/assets/stylesheets/scaffold.css +1 -1
- data/{test_app → spec/internal}/app/assets/stylesheets/style.css.erb +2 -4
- data/{test_app → spec/internal}/app/controllers/admin/users_controller.rb +8 -3
- data/{test_app → spec/internal}/app/controllers/application_controller.rb +0 -0
- data/{test_app → spec/internal}/app/controllers/cuca/cars_controller.rb +0 -0
- data/{test_app → spec/internal}/app/controllers/users_controller.rb +8 -40
- data/{test_app → spec/internal}/app/helpers/application_helper.rb +0 -0
- data/spec/internal/app/helpers/users_helper.rb +29 -0
- data/{test_app → spec/internal}/app/models/cuca/car.rb +0 -0
- data/{test_app → spec/internal}/app/models/user.rb +5 -1
- data/{test_app → spec/internal}/app/views/admin/users/show.html.erb +2 -2
- data/{test_app → spec/internal}/app/views/cuca/cars/show.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/layouts/application.html.erb +1 -1
- data/{test_app → spec/internal}/app/views/users/_form.html.erb +2 -2
- data/{test_app → spec/internal}/app/views/users/double_init.html.erb +4 -10
- data/spec/internal/app/views/users/edit.html.erb +5 -0
- data/{test_app → spec/internal}/app/views/users/email_field.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/users/index.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/users/new.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/users/show.html.erb +32 -24
- data/{test_app → spec/internal}/app/views/users/show_ajax.html.erb +0 -0
- data/spec/internal/config/database.yml +5 -0
- data/{test_app → spec/internal}/config/initializers/countries.rb +0 -0
- data/{test_app → spec/internal}/config/initializers/default_date_format.rb +0 -0
- data/spec/internal/config/initializers/development.rb +8 -0
- data/{test_app → spec/internal}/config/routes.rb +1 -2
- data/spec/internal/db/schema.rb +26 -0
- data/{test_app → spec/internal}/public/favicon.ico +0 -0
- data/spec/rails_helper.rb +21 -0
- data/spec/support/retry_on_timeout.rb +4 -7
- data/spec/utils_spec.rb +21 -0
- data/vendor/assets/javascripts/jquery.autosize.js +272 -0
- data/{lib → vendor}/assets/javascripts/jquery.purr.js +1 -1
- metadata +92 -175
- data/lib/best_in_place/check_version.rb +0 -8
- data/spec/spec_helper.rb +0 -23
- data/test_app/Gemfile +0 -16
- data/test_app/README +0 -256
- data/test_app/Rakefile +0 -7
- data/test_app/app/assets/javascripts/application.js +0 -35
- data/test_app/app/helpers/users_helper.rb +0 -29
- data/test_app/config.ru +0 -4
- data/test_app/config/application.rb +0 -51
- data/test_app/config/boot.rb +0 -13
- data/test_app/config/database.yml +0 -22
- data/test_app/config/environment.rb +0 -5
- data/test_app/config/environments/development.rb +0 -25
- data/test_app/config/environments/production.rb +0 -49
- data/test_app/config/environments/test.rb +0 -35
- data/test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test_app/config/initializers/inflections.rb +0 -10
- data/test_app/config/initializers/mime_types.rb +0 -5
- data/test_app/config/initializers/secret_token.rb +0 -7
- data/test_app/config/initializers/session_store.rb +0 -8
- data/test_app/config/locales/en.yml +0 -5
- data/test_app/db/migrate/20101206205922_create_users.rb +0 -18
- data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +0 -9
- data/test_app/db/migrate/20110115204441_add_description_to_user.rb +0 -9
- data/test_app/db/migrate/20111210084202_add_favorite_color_to_users.rb +0 -5
- data/test_app/db/migrate/20111210084251_add_favorite_books_to_users.rb +0 -5
- data/test_app/db/migrate/20111217215935_add_birth_date_to_users.rb +0 -5
- data/test_app/db/migrate/20111224181356_add_money_to_user.rb +0 -5
- data/test_app/db/migrate/20120513003308_create_cars.rb +0 -11
- data/test_app/db/migrate/20120607172609_add_favorite_movie_to_users.rb +0 -5
- data/test_app/db/migrate/20120616170454_add_money_proc_to_users.rb +0 -6
- data/test_app/db/migrate/20120620165212_add_height_to_user.rb +0 -5
- data/test_app/db/migrate/20130213224102_add_favorite_locale_to_users.rb +0 -5
- data/test_app/db/schema.rb +0 -41
- data/test_app/db/seeds.rb +0 -19
- data/test_app/doc/README_FOR_APP +0 -2
- data/test_app/lib/tasks/.gitkeep +0 -0
- data/test_app/lib/tasks/cron.rake +0 -7
- data/test_app/public/404.html +0 -26
- data/test_app/public/422.html +0 -26
- data/test_app/public/500.html +0 -26
- data/test_app/public/robots.txt +0 -5
- data/test_app/script/rails +0 -6
- data/test_app/test/fixtures/users.yml +0 -17
- data/test_app/test/functional/users_controller_test.rb +0 -49
- data/test_app/test/performance/browsing_test.rb +0 -9
- data/test_app/test/test_helper.rb +0 -13
- data/test_app/test/unit/helpers/users_helper_test.rb +0 -4
- data/test_app/test/unit/user_test.rb +0 -8
- data/test_app/vendor/plugins/.gitkeep +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cd401a2aea2b0d9e1343cab79428b35ccf33074d
|
4
|
+
data.tar.gz: 1006cddfe9686ff779a3542992a1805f7564d009
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efa269229efb9b0a27b31120bdc87322d869a1cf9b8542fb3341bd7c7d6c52c4c5f1542738e29233f9b90b717e987b010c5b003221e8b2de093283f925975a34
|
7
|
+
data.tar.gz: fa3ef98b427393d8b2d7efc58a8881761baca55a0816e3eb821d8a2015840b79c81f525e8b536064fe54a24159746f894f44396c5c7090969d776e193cf49ddd
|
data/.gitignore
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
.DS_Store
|
2
2
|
.bundle
|
3
|
+
.idea
|
3
4
|
pkg/*
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
*.lock
|
7
|
+
spec/internal/.bundle
|
8
|
+
spec/internal/db/*.sqlite3
|
9
|
+
spec/internal/log/*.log
|
10
|
+
spec/internal/tmp/**/*
|
10
11
|
|
11
12
|
.rvmrc
|
13
|
+
coverage
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
+
language: ruby
|
1
2
|
rvm:
|
2
3
|
- 1.9.3
|
4
|
+
- 2.1.2
|
5
|
+
- rbx-2
|
3
6
|
|
4
7
|
env: "RAILS_ENV=test DISPLAY=:99.0"
|
8
|
+
gemfile:
|
9
|
+
- gemfiles/rails_3.2.gemfile
|
10
|
+
- gemfiles/rails_4.0.gemfile
|
11
|
+
- gemfiles/rails_4.1.gemfile
|
12
|
+
- gemfiles/rails_edge.gemfile
|
5
13
|
|
6
14
|
before_script:
|
7
|
-
- "sh -c 'cd test_app && bundle && bundle exec rake db:drop db:migrate'"
|
8
15
|
- "sh -e /etc/init.d/xvfb start"
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
-
|
13
|
-
-
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- gemfile: gemfiles/rails_edge.gemfile
|
20
|
+
- rvm: rbx-2
|
data/Appraisals
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
appraise "rails-3.2" do
|
2
|
+
gem 'rails', '3.2.19'
|
3
|
+
gem 'strong_parameters'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "rails-4.0" do
|
7
|
+
gem "rails", "~> 4.0.0"
|
8
|
+
end
|
9
|
+
|
10
|
+
appraise "rails-4.1" do
|
11
|
+
gem "rails", "~> 4.1.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
appraise "rails-edge" do
|
15
|
+
gem "rails", github: "rails/rails"
|
16
|
+
gem 'arel', github: 'rails/arel'
|
17
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,36 +1,57 @@
|
|
1
1
|
#Changelog
|
2
2
|
|
3
|
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
|
10
|
-
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
-
|
18
|
-
|
19
|
-
|
20
|
-
-
|
21
|
-
|
22
|
-
|
23
|
-
- v.
|
24
|
-
|
25
|
-
version of Rails before booting. Minor fixes.
|
26
|
-
- v.1.0.6 Fix issue with display_with. Update test_app to 3.2.
|
3
|
+
- v.3.0.0 :
|
4
|
+
- Expect syntax for spec
|
5
|
+
- Deprecated option[:path] in favor of option[:url]
|
6
|
+
- Deprecated option[:nil] in favor of option[:place_holder]
|
7
|
+
- Deprecated option[:classes] in favor of option[:class]
|
8
|
+
- Deprecated opts[:object_name] in favor of option[:as]
|
9
|
+
- Deprecated opts[:use_confirm] in favor of option[:confirm]
|
10
|
+
- Deprecated Elastic jQuery plugin in favor of jQuery Autosize
|
11
|
+
- Fixed bug in jquery.purr
|
12
|
+
- Support all supported version of actionpack/rails
|
13
|
+
- Dropped dependency on jquery gem
|
14
|
+
- Namespaced all data attributes to avoid conflict.
|
15
|
+
- Jquery-ui datepicker was extracted to best_in_place.jquery-ui.js
|
16
|
+
- Added BestInPlaceEditor.defaults
|
17
|
+
- Deprecated opts[:sanitize] in favor of option[:raw]
|
18
|
+
- You have to require jquery.purr before best_in_place.purr
|
19
|
+
- You have to require jquery-ui.datepicker before best_in_place.jquery-ui
|
20
|
+
- Added opts[:value] to set custom original-value
|
21
|
+
- You can override the default container
|
22
|
+
|
23
|
+
- v.2x : glitch in the Matrix
|
24
|
+
|
27
25
|
- v.1.1.0 Changed $ by jQuery for compatibility (thanks @tschmitz), new
|
28
26
|
events for 'deactivate' (thanks @glebtv), added new 'data' attribute
|
29
|
-
|
30
|
-
elements to the page (thanks @enriclluelles), added object detection to
|
31
|
-
|
27
|
+
the 'path' parameter and some more bugfixes.
|
28
|
+
elements to the page (thanks @enriclluelles), added object detection to
|
29
|
+
to BIP's span (thanks @straydogstudio), works with dynamically added
|
30
|
+
- v.1.0.6 Fix issue with display_with. Update test_app to 3.2.
|
31
|
+
- v.1.0.5 Fix a bug involving quotes (thanks @ygoldshtrakh). Minor fixes
|
32
|
+
version of Rails before booting. Minor fixes.
|
33
|
+
by @bfalling. Add object name option (thanks @nicholassm). Check
|
34
|
+
- v.1.0.4 Depend on ActiveModel instead of ActiveRecord (thanks,
|
35
|
+
display_with.
|
36
|
+
@skinnyfit). Added date type (thanks @taavo). Added new feature:
|
37
|
+
- v.1.0.3 replace apostrophes in collection with corresponding HTML entity,
|
38
|
+
`respond_with_bip` to be used in the controller.
|
39
|
+
thanks @taavo. Implemented `:display_as` option and adding
|
40
|
+
- v.1.0.2 New bip_area text helper to work with text areas.
|
41
|
+
- v.1.0.1 Fixing a double initialization bug
|
42
|
+
- v.1.0.0 Setting RSpec and Capybara up, and adding some utilities. Mantaining some HTML attributes. Fix a respond_with bug (thanks, @moabite). Triggering ajax:success when ajax call is complete (thanks, @indrekj). Setting up Travis CI. Updated for Rails 3.1.
|
32
43
|
|
33
|
-
##Rails 3.0 branch only
|
34
|
-
- v.0.2.0 Added RSpec and Capybara setup, and some tests. Fix countries map syntax, Allowing href and some other HTML attributes. Adding Travis CI too. Added the best_in_place_if option. Added ajax:success trigger, thanks to @indrekj.
|
35
|
-
- v.0.2.1 Fixing double initialization bug.
|
36
44
|
- v.0.2.2 New bip_area text helper.
|
45
|
+
- v.0.2.1 Fixing double initialization bug.
|
46
|
+
- v.0.2.0 Added RSpec and Capybara setup, and some tests. Fix countries map syntax, Allowing href and some other HTML attributes. Adding Travis CI too. Added the best_in_place_if option. Added ajax:success trigger, thanks to @indrekj.
|
47
|
+
|
48
|
+
- v.0.1.9 Adding elastic autogrowing textareas
|
49
|
+
- v.0.1.8 jslint compliant, sanitizing tags in the gem, getting right csrf params, controlling size of textarea (elastic script, for autogrowing textarea)
|
50
|
+
- v.0.1.6-0.1.7 Avoiding request when the input is not modified and allowing the user to not sanitize input data.
|
51
|
+
- v.0.1.5 **Attention: this release is not backwards compatible**. Changing params from list to option hash, helper's refactoring,
|
52
|
+
of key ESCAPE for destroying changes before they are made permanent (in inputs and textarea).
|
53
|
+
fixing bug with objects inside namespaces, adding feature for passing an external activator handler as param. Adding feature
|
54
|
+
- v.0.1.4 Adding two new parameters for further customization urlObject and nilValue and making input update on blur.
|
55
|
+
- v.0.1.3 Bug in Rails Helper. Key wrongly considered an Integer.
|
56
|
+
- v.0.1.2 Fixing errors in collections (taken value[0] instead of index) and fixing test_app controller responses
|
57
|
+
- v.0.1.0 Initial commit
|
data/Gemfile
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
+
source 'https://rails-assets.org'
|
2
3
|
|
3
4
|
# Specify your gem's dependencies in best_in_place.gemspec
|
4
5
|
gemspec
|
5
6
|
|
6
|
-
gem '
|
7
|
-
gem 'jquery-
|
7
|
+
gem 'rails-assets-jquery', '1.11.1'
|
8
|
+
gem 'rails-assets-jquery-ui', '1.10.4'
|
8
9
|
gem 'rdiscount'
|
10
|
+
gem 'rspec-rails'
|
11
|
+
gem 'nokogiri'
|
12
|
+
gem 'combustion'
|
13
|
+
gem 'sprockets-rails'
|
14
|
+
gem 'capybara'
|
15
|
+
gem 'selenium-webdriver'
|
16
|
+
gem 'sqlite3'
|
17
|
+
gem 'appraisal'
|
18
|
+
|
19
|
+
platforms :mri_21 do
|
20
|
+
gem 'byebug'
|
21
|
+
end
|
data/README.md
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
##Description
|
7
7
|
|
8
8
|
**Best in Place** is a jQuery based AJAX Inplace-Editor that takes profit of RESTful server-side controllers to allow users to edit stuff with
|
9
|
-
no need of forms. If the server
|
10
|
-
Javascript file to the application it
|
9
|
+
no need of forms. If the server has standard defined REST methods, particularly those to UPDATE your objects (HTTP PUT), then by adding the
|
10
|
+
Javascript file to the application it allows all the fields with the proper defined classes to become user in-place editable.
|
11
11
|
|
12
12
|
The editor works by PUTting the updated value to the server and GETting the updated record afterwards to display the updated value.
|
13
13
|
|
@@ -27,7 +27,7 @@ The editor works by PUTting the updated value to the server and GETting the upda
|
|
27
27
|
- Allows external activator
|
28
28
|
- Allows optional, configurable OK and Cancel buttons for inputs and textareas
|
29
29
|
- ESC key destroys changes (requires user confirmation)
|
30
|
-
- Autogrowing textarea
|
30
|
+
- Autogrowing textarea with **jQuery Autosize**
|
31
31
|
- Helper for generating the best_in_place field only if a condition is satisfied
|
32
32
|
- Provided test helpers to be used in your integration specs
|
33
33
|
- Custom display methods using a method from your model or an existing rails
|
@@ -48,8 +48,8 @@ Options:
|
|
48
48
|
- **:type** It can be only [:input, :textarea, :select, :checkbox, :date (>= 1.0.4)] or if undefined it defaults to :input.
|
49
49
|
- **:collection**: In case you are using the :select type then you must specify the collection of values it takes. In case you are
|
50
50
|
using the :checkbox type you can specify the two values it can take, or otherwise they will default to Yes and No.
|
51
|
-
- **:
|
52
|
-
- **:
|
51
|
+
- **:url**: URL to which the updating action will be sent. If not defined it defaults to the :object path.
|
52
|
+
- **:place_holder**: The nil param defines the content displayed in case no value is defined for that field. It can be something like "click me to edit".
|
53
53
|
If not defined it will show *"-"*.
|
54
54
|
- **:activator**: Is the DOM object that can activate the field. If not defined the user will making editable by clicking on it.
|
55
55
|
- **:ok_button**: (Inputs and textareas only) If set to a string, then an OK button will be shown with the string as its label, replacing save on blur.
|
@@ -58,15 +58,17 @@ Options:
|
|
58
58
|
- **:cancel_button_class**: (Inputs and textareas only) Specifies any extra classes to set on the Cancel button.
|
59
59
|
- **:sanitize**: True by default. If set to false the input/textarea will accept html tags.
|
60
60
|
- **:html_attrs**: Hash of html arguments, such as maxlength, default-value etc.
|
61
|
-
- **:inner_class**: Class that is set to the rendered
|
61
|
+
- **:inner_class**: Class that is set to the rendered input.
|
62
62
|
- **:display_as**: A model method which will be called in order to display
|
63
63
|
this field.
|
64
|
-
- **:
|
64
|
+
- **:as**: Used for overriding the default params key used for the object (the data-object attribute). Useful for e.g. STI scenarios where best_in_place should post to a common controller for different models.
|
65
65
|
- **:data**: Hash of custom data attributes to be added to span. Can be used to provide data to the ajax:success callback.
|
66
|
-
- **:
|
66
|
+
- **:class**: Additional classes to apply to the best_in_place span. Accepts either a string or Array of strings
|
67
|
+
- **:value**: Customize the starting value of the inline input (defaults to to the field's value)
|
67
68
|
|
68
69
|
###best_in_place_if
|
69
70
|
**best_in_place_if condition, object, field, OPTIONS**
|
71
|
+
see also **best_in_place_unless
|
70
72
|
|
71
73
|
It allows us to use best_in_place only if the first new parameter, a
|
72
74
|
condition, is satisfied. Specifically:
|
@@ -109,10 +111,10 @@ Examples (code in the views):
|
|
109
111
|
|
110
112
|
### Select
|
111
113
|
|
112
|
-
<%= best_in_place @user, :country, :type => :select, :collection =>
|
114
|
+
<%= best_in_place @user, :country, :type => :select, :collection => {{"1", "Spain"}, {"2", "Italy"}, {"3", "Germany"}, {"4", "France"}} %>
|
113
115
|
|
114
|
-
Of course it can take an instance or global variable for the collection, just remember the structure `
|
115
|
-
The key
|
116
|
+
Of course it can take an instance or global variable for the collection, just remember the structure `{{key, value}, {key, value},...}`.
|
117
|
+
The key has to be a string. *
|
116
118
|
|
117
119
|
### Checkbox
|
118
120
|
|
@@ -192,9 +194,9 @@ The 'ajax:success' event is triggered upon success. Use bind:
|
|
192
194
|
|
193
195
|
$('.best_in_place').bind("ajax:success", function () {$(this).closest('tr').effect('highlight'); });
|
194
196
|
|
195
|
-
To bind a callback that is specific to a particular field, use the 'classes' option in the helper method and
|
196
|
-
then bind to that class.
|
197
|
-
|
197
|
+
To bind a callback that is specific to a particular field, use the 'classes' option in the helper method and
|
198
|
+
then bind to that class.
|
199
|
+
|
198
200
|
<%= best_in_place @user, :name, :classes => 'highlight_on_success' %>
|
199
201
|
<%= best_in_place @user, :mail, :classes => 'bounce_on_success' %>
|
200
202
|
|
@@ -231,16 +233,16 @@ In the view, we'd do:
|
|
231
233
|
// @ice_cream is already available
|
232
234
|
- flavours = ... // get them somewhere
|
233
235
|
- sizes = ... // get them somewhere
|
234
|
-
|
235
|
-
|
236
|
-
-
|
237
|
-
|
236
|
+
table
|
237
|
+
tr
|
238
|
+
- flavours.each do |flavour|
|
239
|
+
th= flavour
|
238
240
|
- sizes.each do |size|
|
239
|
-
|
241
|
+
tr
|
240
242
|
%th= size
|
241
243
|
- flavours.each do |flavour|
|
242
|
-
- v = @ice_cream.get_stock(:
|
243
|
-
|
244
|
+
- v = @ice_cream.get_stock(flavour: flavour, size: size)
|
245
|
+
td= best_in_place v, :to_i, type: :input, url: set_stock_ice_cream_path(flavour: flavour, size: size)
|
244
246
|
|
245
247
|
Now we need a route to which send the stock updates:
|
246
248
|
|
@@ -283,35 +285,12 @@ And finally we need a controller:
|
|
283
285
|
|
284
286
|
And this is how it is done!
|
285
287
|
|
286
|
-
---
|
287
|
-
|
288
|
-
##Test Helpers
|
289
|
-
Best In Place has also some helpers that may be very useful for integration testing. Since it might very common to test some views using Best In Place, some helpers are provided to ease it.
|
290
|
-
|
291
|
-
As of now, a total of four helpers are available. There is one for each of the following BIP types: a plain text input, a textarea, a boolean input and a selector. Its function is to simulate the user's action of filling such fields.
|
292
|
-
|
293
|
-
These four helpers are listed below:
|
294
|
-
|
295
|
-
* **bip_area(model, attr, new_value)**
|
296
|
-
* **bip_text(model, attr, new_value)**
|
297
|
-
* **bip_bool(model, attr)**
|
298
|
-
* **bip_select(model, attr, name)**
|
299
|
-
|
300
|
-
The parameters are defined here (some are method-specific):
|
301
|
-
|
302
|
-
* **model**: the model to which this action applies.
|
303
|
-
* **attr**: the attribute of the model to which this action applies.
|
304
|
-
* **new_value** (only **bip_area** and **bip_text**): the new value with which to fill the BIP field.
|
305
|
-
* **name** (only **bip_select**): the name to select from the dropdown selector.
|
306
|
-
|
307
|
-
---
|
308
|
-
|
309
288
|
##Installation
|
310
289
|
|
311
|
-
###Rails
|
290
|
+
###Rails
|
312
291
|
|
313
|
-
Installing *best_in_place* is very easy and straight-forward
|
314
|
-
|
292
|
+
Installing *best_in_place* is very easy and straight-forward.
|
293
|
+
Just begin including the gem in your Gemfile:
|
315
294
|
|
316
295
|
gem "best_in_place"
|
317
296
|
|
@@ -320,9 +299,11 @@ javascripts in your application.js, and optionally specify jquery-ui if
|
|
320
299
|
you want to use jQuery UI datepickers:
|
321
300
|
|
322
301
|
//= require jquery
|
323
|
-
//= require jquery-ui
|
324
302
|
//= require best_in_place
|
325
303
|
|
304
|
+
//= require jquery-ui
|
305
|
+
//= require best_in_place.jquery-ui
|
306
|
+
|
326
307
|
If you want to use jQuery UI datepickers, you should also install and
|
327
308
|
load your preferred jquery-ui CSS file and associated assets.
|
328
309
|
|
@@ -335,61 +316,18 @@ Then, just add a binding to prepare all best in place fields when the document i
|
|
335
316
|
|
336
317
|
You are done!
|
337
318
|
|
338
|
-
###Rails 3.0 and lower
|
339
|
-
|
340
|
-
Installing *best_in_place* for Rails 3.0 or below is a little bit
|
341
|
-
different, since the master branch is specifically updated for Rails
|
342
|
-
3.1. But don't be scared, you'll be fine!
|
343
|
-
|
344
|
-
Rails 3.0 support will be held in the 0.2.X versions, but we have planned not to continue developing for this version of Rails. Nevertheless, you can by implementing what you want and sending us a pull request.
|
345
|
-
|
346
|
-
First, add the gem's 0.2 version in the Gemfile:
|
347
|
-
|
348
|
-
gem "best_in_place", "~> 0.2.0"
|
349
|
-
|
350
|
-
After that, install and load all the javascripts from the folder
|
351
|
-
**/public/javascripts** in your layouts. They have to be in the order:
|
352
|
-
|
353
|
-
* jquery
|
354
|
-
* **best_in_place**
|
355
|
-
|
356
|
-
You can automatize this installation by doing
|
357
|
-
|
358
|
-
rails g best_in_place:setup
|
359
319
|
|
360
|
-
If you want to use jQuery UI datepickers, you should also install and
|
361
|
-
load jquery-ui.js as well as your preferred jquery-ui CSS file and
|
362
|
-
associated assets.
|
363
|
-
|
364
|
-
Finally, as for Rails 3.1, just add a binding to prepare all best in place fields when the document is ready:
|
365
|
-
|
366
|
-
$(document).ready(function() {
|
367
|
-
/* Activating Best In Place */
|
368
|
-
jQuery(".best_in_place").best_in_place();
|
369
|
-
});
|
370
|
-
|
371
|
-
---
|
372
320
|
|
373
321
|
## Notification
|
374
322
|
|
375
323
|
Sometimes your in-place updates will fail due to validation or for some other reason. In such case, you'll want to notify the user somehow. **Best in Place** supports doing so through the best_in_place:error event, and has built-in support for notification via jquery.purr, right out of the box.
|
376
324
|
|
377
|
-
To opt into the jquery.purr error notification, just add best_in_place.purr to your javascripts, as described below.
|
378
|
-
|
379
|
-
###Rails 3.1 and higher
|
380
|
-
|
381
|
-
It's as simple as adding:
|
325
|
+
To opt into the jquery.purr error notification, just add best_in_place.purr to your javascripts, as described below.
|
382
326
|
|
327
|
+
//= require jquery.purr
|
383
328
|
//= require best_in_place.purr
|
384
329
|
|
385
|
-
|
386
|
-
|
387
|
-
You'll have to load the following additional javascripts, in this order, after loading jquery and **best_in_place**:
|
388
|
-
|
389
|
-
* jquery.purr
|
390
|
-
* **best_in_place.purr**
|
391
|
-
|
392
|
-
---
|
330
|
+
If you'd like to develop your own custom form of error notification, you can use best_in_place.purr as an example to guide you.
|
393
331
|
|
394
332
|
## Security
|
395
333
|
|
@@ -411,25 +349,34 @@ If the script is used with the Rails Gem no html tags will be allowed unless the
|
|
411
349
|
|
412
350
|
Fork the project on [github](https://github.com/bernat/best_in_place 'bernat / best_in_place on Github')
|
413
351
|
|
414
|
-
$ git clone
|
352
|
+
$ git clone <your fork>
|
415
353
|
$ cd best_in_place
|
416
354
|
$ bundle
|
417
355
|
|
418
|
-
###
|
356
|
+
### Run the specs
|
419
357
|
|
420
|
-
$
|
421
|
-
$ bundle
|
422
|
-
$ bundle exec rake db:test:prepare
|
423
|
-
$ cd ..
|
358
|
+
$ appraisal rspec
|
424
359
|
|
425
|
-
|
360
|
+
---
|
426
361
|
|
427
|
-
|
362
|
+
##Test Helpers
|
363
|
+
Best In Place has also some helpers that may be very useful for integration testing. Since it might very common to test some views using Best In Place, some helpers are provided to ease it.
|
428
364
|
|
429
|
-
|
365
|
+
As of now, a total of four helpers are available. There is one for each of the following BIP types: a plain text input, a textarea, a boolean input and a selector. Its function is to simulate the user's action of filling such fields.
|
430
366
|
|
431
|
-
|
432
|
-
|
367
|
+
These four helpers are listed below:
|
368
|
+
|
369
|
+
* **bip_area(model, attr, new_value)**
|
370
|
+
* **bip_text(model, attr, new_value)**
|
371
|
+
* **bip_bool(model, attr)**
|
372
|
+
* **bip_select(model, attr, name)**
|
373
|
+
|
374
|
+
The parameters are defined here (some are method-specific):
|
375
|
+
|
376
|
+
* **model**: the model to which this action applies.
|
377
|
+
* **attr**: the attribute of the model to which this action applies.
|
378
|
+
* **new_value** (only **bip_area** and **bip_text**): the new value with which to fill the BIP field.
|
379
|
+
* **name** (only **bip_select**): the name to select from the dropdown selector.
|
433
380
|
|
434
381
|
---
|
435
382
|
|