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
@@ -1,10 +1,20 @@
|
|
1
|
-
|
1
|
+
/*
|
2
|
+
* BestInPlace 3.0.0.alpha (2014)
|
3
|
+
*
|
4
|
+
* Depends:
|
5
|
+
* best_in_place.js
|
6
|
+
* jquery.purr.js
|
7
|
+
*/
|
8
|
+
/*global BestInPlaceEditor */
|
2
9
|
|
3
|
-
|
10
|
+
BestInPlaceEditor.defaults.purrErrorContainer = "<span class='bip-flash-error'></span>";
|
11
|
+
|
12
|
+
jQuery(document).on('best_in_place:error', function (event, request, error) {
|
13
|
+
'use strict';
|
4
14
|
// Display all error messages from server side validation
|
5
|
-
jQuery.each(jQuery.parseJSON(request.responseText), function(index, value) {
|
6
|
-
|
7
|
-
|
8
|
-
|
15
|
+
jQuery.each(jQuery.parseJSON(request.responseText), function (index, value) {
|
16
|
+
if (typeof value === "object") {value = index + " " + value.toString(); }
|
17
|
+
var container = jQuery(BestInPlaceEditor.defaults.purrErrorContainer).html(value);
|
18
|
+
container.purr();
|
9
19
|
});
|
10
20
|
});
|
data/lib/best_in_place.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require "best_in_place/engine"
|
5
|
-
require "best_in_place/railtie"
|
6
|
-
require "best_in_place/controller_extensions"
|
7
|
-
require "best_in_place/display_methods"
|
8
|
-
require "action_view"
|
1
|
+
require 'rails/railtie'
|
2
|
+
require 'action_view/railtie'
|
3
|
+
require 'action_controller/railtie'
|
9
4
|
|
10
5
|
module BestInPlace
|
11
|
-
|
6
|
+
def self.configure
|
7
|
+
@configuration ||= Configuration.new
|
8
|
+
yield @configuration if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.method_missing(method_name, *args, &block)
|
12
|
+
@configuration.respond_to?(method_name) ?
|
13
|
+
@configuration.send(method_name, *args, &block) : super
|
14
|
+
end
|
15
|
+
|
16
|
+
class Configuration
|
17
|
+
attr_accessor :container
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@container = :span
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
configure
|
12
25
|
end
|
26
|
+
|
27
|
+
require 'best_in_place/engine'
|
28
|
+
require 'best_in_place/utils'
|
29
|
+
require 'best_in_place/helper'
|
30
|
+
require 'best_in_place/railtie'
|
31
|
+
require 'best_in_place/controller_extensions'
|
32
|
+
require 'best_in_place/display_methods'
|
@@ -1,28 +1,25 @@
|
|
1
1
|
module BestInPlace
|
2
2
|
module ControllerExtensions
|
3
|
-
def respond_with_bip(obj)
|
4
|
-
obj.
|
3
|
+
def respond_with_bip(obj, options = {})
|
4
|
+
obj.errors.any? ? respond_bip_error(obj) : respond_bip_ok(obj, options)
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
klass = obj.class.to_s
|
13
|
-
end
|
14
|
-
param_key = BestInPlace::Utils.object_to_key(obj)
|
7
|
+
private
|
8
|
+
|
9
|
+
def respond_bip_ok(obj, options = {})
|
10
|
+
param_key = options[:param] ||= BestInPlace::Utils.object_to_key(obj)
|
11
|
+
|
15
12
|
updating_attr = params[param_key].keys.first
|
16
13
|
|
17
|
-
if renderer = BestInPlace::DisplayMethods.lookup(
|
18
|
-
render :
|
14
|
+
if renderer = BestInPlace::DisplayMethods.lookup(obj.class, updating_attr)
|
15
|
+
render json: renderer.render_json(obj)
|
19
16
|
else
|
20
17
|
head :no_content
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
24
21
|
def respond_bip_error(obj)
|
25
|
-
render :
|
22
|
+
render json: obj.errors.full_messages, status: :unprocessable_entity
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
@@ -1,44 +1,49 @@
|
|
1
1
|
module BestInPlace
|
2
|
-
module DisplayMethods
|
3
|
-
|
2
|
+
module DisplayMethods #:nodoc:
|
3
|
+
module_function
|
4
4
|
|
5
5
|
class Renderer < Struct.new(:opts)
|
6
6
|
def render_json(object)
|
7
7
|
case opts[:type]
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
when :model
|
9
|
+
{ display_as: object.send(opts[:method]) }.to_json
|
10
|
+
when :helper
|
11
|
+
value = if opts[:helper_options]
|
12
|
+
BestInPlace::ViewHelpers.send(opts[:method], object.send(opts[:attr]), opts[:helper_options])
|
13
|
+
else
|
14
|
+
BestInPlace::ViewHelpers.send(opts[:method], object.send(opts[:attr]))
|
15
|
+
end
|
16
|
+
{ display_as: value }.to_json
|
17
|
+
when :proc
|
18
|
+
{ display_as: opts[:proc].call(object.send(opts[:attr])) }.to_json
|
19
|
+
else
|
20
|
+
'{}'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
@@table = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
|
25
|
+
@@table = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
26
26
|
|
27
27
|
def lookup(klass, attr)
|
28
|
-
foo =
|
28
|
+
foo = model_attributes(klass)[attr.to_s]
|
29
29
|
foo == {} ? nil : foo
|
30
30
|
end
|
31
31
|
|
32
32
|
def add_model_method(klass, attr, display_as)
|
33
|
-
|
33
|
+
model_attributes(klass)[attr.to_s] = Renderer.new method: display_as.to_sym, type: :model
|
34
34
|
end
|
35
35
|
|
36
36
|
def add_helper_method(klass, attr, helper_method, helper_options = nil)
|
37
|
-
|
37
|
+
model_attributes(klass)[attr.to_s] = Renderer.new method: helper_method.to_sym, type: :helper, attr: attr, helper_options: helper_options
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def add_helper_proc(klass, attr, helper_proc)
|
41
|
-
|
41
|
+
model_attributes(klass)[attr.to_s] = Renderer.new type: :proc, attr: attr, proc: helper_proc
|
42
|
+
end
|
43
|
+
|
44
|
+
def model_attributes(klass)
|
45
|
+
key = Utils.object_to_key(klass)
|
46
|
+
@@table[key]
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
data/lib/best_in_place/engine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module BestInPlace
|
2
2
|
class Engine < Rails::Engine
|
3
|
-
initializer
|
4
|
-
ActionView::Base.send(:include, BestInPlace::
|
3
|
+
initializer 'best_in_place' do
|
4
|
+
ActionView::Base.send(:include, BestInPlace::Helper)
|
5
5
|
ActionController::Base.send(:include, BestInPlace::ControllerExtensions)
|
6
6
|
end
|
7
7
|
end
|
data/lib/best_in_place/helper.rb
CHANGED
@@ -1,99 +1,90 @@
|
|
1
1
|
module BestInPlace
|
2
|
-
module
|
3
|
-
|
2
|
+
module Helper
|
4
3
|
def best_in_place(object, field, opts = {})
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
best_in_place_assert_arguments(opts)
|
5
|
+
type = opts[:as] || :input
|
6
|
+
field = field.to_s
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
options = {}
|
9
|
+
options[:data] = HashWithIndifferentAccess.new(opts[:data])
|
10
|
+
options[:data]['bip-type'] = type
|
11
|
+
options[:data]['bip-attribute'] = field
|
12
|
+
|
13
|
+
real_object = best_in_place_real_object_for object
|
14
|
+
|
15
|
+
display_value = best_in_place_build_value_for(real_object, field, opts)
|
16
|
+
|
17
|
+
value = real_object.send(field)
|
18
|
+
|
19
|
+
if opts[:collection] or type == :checkbox
|
20
|
+
collection = opts[:collection]
|
21
|
+
case type
|
22
|
+
when :checkbox
|
23
|
+
value = value.to_s
|
24
|
+
if collection.blank?
|
25
|
+
collection = best_in_place_default_collection
|
26
|
+
else
|
27
|
+
collection = best_in_place_collection_builder(collection)
|
28
|
+
end
|
29
|
+
display_value = collection[value]
|
30
|
+
collection = collection.to_json
|
31
|
+
else # :select
|
32
|
+
value = value.to_s
|
33
|
+
collection = best_in_place_collection_builder(collection)
|
34
|
+
display_value = collection[value]
|
35
|
+
collection = collection.to_json
|
36
|
+
end
|
37
|
+
options[:data]['bip-collection'] = html_escape(collection)
|
11
38
|
end
|
12
39
|
|
13
|
-
|
14
|
-
opts[:
|
15
|
-
opts[:collection] ||= []
|
16
|
-
field = field.to_s
|
40
|
+
options[:class] = ['best_in_place'] + Array(opts[:class] || opts[:classes])
|
41
|
+
options[:id] = opts[:id] || BestInPlace::Utils.build_best_in_place_id(real_object, field)
|
17
42
|
|
18
|
-
|
43
|
+
options[:data]['bip-activator'] = opts[:activator].presence
|
19
44
|
|
20
|
-
|
21
|
-
|
22
|
-
if opts[:type] == :select && !opts[:collection].blank?
|
23
|
-
value = real_object.send(field)
|
24
|
-
display_value = Hash[opts[:collection]].stringify_keys[value.to_s]
|
25
|
-
collection = opts[:collection].to_json
|
26
|
-
end
|
27
|
-
if opts[:type] == :checkbox
|
28
|
-
value = !!real_object.send(field)
|
29
|
-
if opts[:collection].blank? || opts[:collection].size != 2
|
30
|
-
opts[:collection] = ["No", "Yes"]
|
31
|
-
end
|
32
|
-
display_value = value ? opts[:collection][1] : opts[:collection][0]
|
33
|
-
collection = opts[:collection].to_json
|
34
|
-
end
|
35
|
-
classes = ["best_in_place"]
|
36
|
-
unless opts[:classes].nil?
|
37
|
-
# the next three lines enable this opt to handle both a stings and a arrays
|
38
|
-
classes << opts[:classes]
|
39
|
-
classes.flatten!
|
40
|
-
end
|
45
|
+
options[:data]['bip-html-attrs'] = opts[:html_attrs].to_json unless opts[:html_attrs].blank?
|
46
|
+
options[:data]['bip-inner-class'] = opts[:inner_class].presence
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
out << " data-original-content='#{attribute_escape(real_object.send(field))}'" if opts[:display_as] || opts[:display_with]
|
59
|
-
out << " data-value='#{attribute_escape(value)}'" if value
|
60
|
-
|
61
|
-
if opts[:data] && opts[:data].is_a?(Hash)
|
62
|
-
opts[:data].each do |k, v|
|
63
|
-
if !v.is_a?(String) && !v.is_a?(Symbol)
|
64
|
-
v = v.to_json
|
65
|
-
end
|
66
|
-
out << %( data-#{k.to_s.dasherize}="#{v}")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
if !opts[:sanitize].nil? && !opts[:sanitize]
|
70
|
-
out << " data-sanitize='false'>"
|
71
|
-
out << display_value.to_s
|
72
|
-
else
|
73
|
-
out << ">#{h(display_value.to_s)}"
|
48
|
+
options[:data]['bip-placeholder'] = html_escape(opts[:place_holder]).presence
|
49
|
+
|
50
|
+
options[:data]['bip-object'] = opts[:param] || BestInPlace::Utils.object_to_key(real_object)
|
51
|
+
options[:data]['bip-ok-button'] = opts[:ok_button].presence
|
52
|
+
options[:data]['bip-ok-button-class'] = opts[:ok_button_class].presence
|
53
|
+
options[:data]['bip-cancel-button'] = opts[:cancel_button].presence
|
54
|
+
options[:data]['bip-cancel-button-class'] = opts[:cancel_button_class].presence
|
55
|
+
options[:data]['bip-original-content'] = html_escape(opts[:value] || value).presence
|
56
|
+
|
57
|
+
options[:data]['bip-url'] = url_for(opts[:url] || object)
|
58
|
+
|
59
|
+
options[:data]['bip-confirm'] = opts[:confirm].presence
|
60
|
+
options[:data]['bip-value'] = html_escape(value).presence
|
61
|
+
|
62
|
+
if opts[:raw]
|
63
|
+
options[:data]['bip-raw'] = 'true'
|
74
64
|
end
|
75
|
-
|
76
|
-
|
65
|
+
|
66
|
+
# delete nil keys only
|
67
|
+
options[:data].delete_if { |_, v| v.nil? }
|
68
|
+
container = opts[:container] || BestInPlace.container
|
69
|
+
content_tag(container, display_value, options, opts[:raw].blank?)
|
77
70
|
end
|
78
71
|
|
79
|
-
def best_in_place_if(condition, object, field, opts={})
|
72
|
+
def best_in_place_if(condition, object, field, opts = {})
|
80
73
|
if condition
|
81
74
|
best_in_place(object, field, opts)
|
82
75
|
else
|
83
|
-
|
76
|
+
best_in_place_build_value_for best_in_place_real_object_for(object), field, opts
|
84
77
|
end
|
85
78
|
end
|
86
79
|
|
87
|
-
|
88
|
-
|
89
|
-
|
80
|
+
def best_in_place_unless(condition, object, field, opts = {})
|
81
|
+
best_in_place_if(!condition, object, field, opts)
|
82
|
+
end
|
90
83
|
|
91
|
-
|
92
|
-
"#{object.class}_#{object.id}"
|
93
|
-
else
|
94
|
-
object.class.to_s
|
95
|
-
end
|
84
|
+
private
|
96
85
|
|
86
|
+
def best_in_place_build_value_for(object, field, opts)
|
87
|
+
klass = object.class
|
97
88
|
if opts[:display_as]
|
98
89
|
BestInPlace::DisplayMethods.add_model_method(klass, field, opts[:display_as])
|
99
90
|
object.send(opts[:display_as]).to_s
|
@@ -107,7 +98,15 @@ module BestInPlace
|
|
107
98
|
if opts[:helper_options]
|
108
99
|
BestInPlace::ViewHelpers.send(opts[:display_with], object.send(field), opts[:helper_options])
|
109
100
|
else
|
110
|
-
|
101
|
+
field_value = object.send(field)
|
102
|
+
|
103
|
+
if field_value.blank?
|
104
|
+
''
|
105
|
+
else
|
106
|
+
|
107
|
+
|
108
|
+
BestInPlace::ViewHelpers.send(opts[:display_with], field_value)
|
109
|
+
end
|
111
110
|
end
|
112
111
|
|
113
112
|
else
|
@@ -115,18 +114,77 @@ module BestInPlace
|
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
118
|
-
def
|
119
|
-
|
117
|
+
def best_in_place_real_object_for(object)
|
118
|
+
(object.is_a?(Array) && object.last.class.respond_to?(:model_name)) ? object.last : object
|
119
|
+
end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
def best_in_place_assert_arguments(args)
|
122
|
+
args.assert_valid_keys(:id, :type, :nil, :classes, :collection, :data,
|
123
|
+
:activator, :cancel_button, :cancel_button_class, :html_attrs, :inner_class, :nil,
|
124
|
+
:object_name, :ok_button, :ok_button_class, :display_as, :display_with, :path, :value,
|
125
|
+
:use_confirm, :confirm, :sanitize, :raw, :helper_options, :url, :place_holder, :class,
|
126
|
+
:as, :param, :container)
|
127
|
+
|
128
|
+
best_in_place_deprecated_options(args)
|
129
|
+
|
130
|
+
if args[:display_as] && args[:display_with]
|
131
|
+
fail ArgumentError, 'Can`t use both `display_as`` and `display_with` options at the same time'
|
132
|
+
end
|
133
|
+
|
134
|
+
if args[:display_with] && !args[:display_with].is_a?(Proc) && !ViewHelpers.respond_to?(args[:display_with])
|
135
|
+
fail ArgumentError, "Can't find helper #{args[:display_with]}"
|
136
|
+
end
|
125
137
|
end
|
126
138
|
|
127
|
-
def
|
128
|
-
|
139
|
+
def best_in_place_deprecated_options(args)
|
140
|
+
if deprecated_option = args.delete(:path)
|
141
|
+
args[:url] = deprecated_option
|
142
|
+
ActiveSupport::Deprecation.warn('[Best_in_place] :path is deprecated in favor of :url ')
|
143
|
+
end
|
144
|
+
|
145
|
+
if deprecated_option = args.delete(:object_name)
|
146
|
+
args[:param] = deprecated_option
|
147
|
+
ActiveSupport::Deprecation.warn('[Best_in_place] :object_name is deprecated in favor of :param ')
|
148
|
+
end
|
149
|
+
|
150
|
+
if deprecated_option = args.delete(:type)
|
151
|
+
args[:as] = deprecated_option
|
152
|
+
ActiveSupport::Deprecation.warn('[Best_in_place] :type is deprecated in favor of :as ')
|
153
|
+
end
|
154
|
+
|
155
|
+
if deprecated_option = args.delete(:classes)
|
156
|
+
args[:class] = deprecated_option
|
157
|
+
ActiveSupport::Deprecation.warn('[Best_in_place] :classes is deprecated in favor of :class ')
|
158
|
+
end
|
159
|
+
|
160
|
+
if deprecated_option = args.delete(:nil)
|
161
|
+
args[:place_holder] = deprecated_option
|
162
|
+
ActiveSupport::Deprecation.warn('[Best_in_place] :nil is deprecated in favor of :place_holder ')
|
163
|
+
end
|
164
|
+
|
165
|
+
if deprecated_option = args.delete(:use_confirm)
|
166
|
+
args[:confirm] = deprecated_option
|
167
|
+
ActiveSupport::Deprecation.warn('[Best_in_place] :use_confirm is deprecated in favor of :confirm ')
|
168
|
+
end
|
169
|
+
|
170
|
+
if deprecated_option = args.delete(:sanitize)
|
171
|
+
args[:raw] = !deprecated_option
|
172
|
+
ActiveSupport::Deprecation.warn('[Best_in_place] :sanitize is deprecated in favor of :raw ')
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def best_in_place_collection_builder(collection)
|
177
|
+
case collection
|
178
|
+
when Array
|
179
|
+
Hash[collection.map { |x| [x.to_s, x.to_s] }]
|
180
|
+
else
|
181
|
+
collection.stringify_keys
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def best_in_place_default_collection
|
186
|
+
{'true' => t(:'best_in_place.yes', default: 'Yes'),
|
187
|
+
'false' => t(:'best_in_place.no', default: 'No')}
|
129
188
|
end
|
130
189
|
end
|
131
190
|
end
|
132
|
-
|