crest_in_place 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +36 -0
- data/Gemfile +9 -0
- data/README.md +440 -0
- data/Rakefile +8 -0
- data/crest_in_place-2.1.0.gem +0 -0
- data/crest_in_place.gemspec +28 -0
- data/lib/assets/javascripts/best_in_place.js +740 -0
- data/lib/assets/javascripts/best_in_place.purr.js +10 -0
- data/lib/assets/javascripts/jquery.purr.js +135 -0
- data/lib/crest_in_place.rb +12 -0
- data/lib/crest_in_place/check_version.rb +8 -0
- data/lib/crest_in_place/controller_extensions.rb +28 -0
- data/lib/crest_in_place/display_methods.rb +44 -0
- data/lib/crest_in_place/engine.rb +8 -0
- data/lib/crest_in_place/helper.rb +132 -0
- data/lib/crest_in_place/railtie.rb +7 -0
- data/lib/crest_in_place/test_helpers.rb +42 -0
- data/lib/crest_in_place/utils.rb +21 -0
- data/lib/crest_in_place/version.rb +3 -0
- data/spec/helpers/best_in_place_spec.rb +429 -0
- data/spec/integration/double_init_spec.rb +34 -0
- data/spec/integration/js_spec.rb +1041 -0
- data/spec/integration/live_spec.rb +40 -0
- data/spec/integration/text_area_spec.rb +40 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/retry_on_timeout.rb +10 -0
- data/test_app/Gemfile +16 -0
- data/test_app/README +256 -0
- data/test_app/Rakefile +7 -0
- data/test_app/app/assets/images/no.png +0 -0
- data/test_app/app/assets/images/red_pen.png +0 -0
- data/test_app/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/test_app/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/test_app/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/test_app/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/test_app/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/test_app/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/test_app/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/test_app/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/test_app/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/test_app/app/assets/images/ui-icons_222222_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/test_app/app/assets/images/yes.png +0 -0
- data/test_app/app/assets/javascripts/application.js +35 -0
- data/test_app/app/assets/stylesheets/.gitkeep +0 -0
- data/test_app/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb +357 -0
- data/test_app/app/assets/stylesheets/scaffold.css +60 -0
- data/test_app/app/assets/stylesheets/style.css.erb +87 -0
- data/test_app/app/controllers/admin/users_controller.rb +14 -0
- data/test_app/app/controllers/application_controller.rb +3 -0
- data/test_app/app/controllers/cuca/cars_controller.rb +16 -0
- data/test_app/app/controllers/users_controller.rb +99 -0
- data/test_app/app/helpers/application_helper.rb +2 -0
- data/test_app/app/helpers/users_helper.rb +29 -0
- data/test_app/app/models/cuca/car.rb +5 -0
- data/test_app/app/models/user.rb +27 -0
- data/test_app/app/views/admin/users/show.html.erb +20 -0
- data/test_app/app/views/cuca/cars/show.html.erb +13 -0
- data/test_app/app/views/layouts/application.html.erb +14 -0
- data/test_app/app/views/users/_form.html.erb +51 -0
- data/test_app/app/views/users/double_init.html.erb +72 -0
- data/test_app/app/views/users/edit.html.erb +5 -0
- data/test_app/app/views/users/email_field.html.erb +1 -0
- data/test_app/app/views/users/index.html.erb +25 -0
- data/test_app/app/views/users/new.html.erb +5 -0
- data/test_app/app/views/users/show.html.erb +141 -0
- data/test_app/app/views/users/show_ajax.html.erb +12 -0
- data/test_app/config.ru +4 -0
- data/test_app/config/application.rb +51 -0
- data/test_app/config/boot.rb +13 -0
- data/test_app/config/database.yml +22 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/environments/development.rb +25 -0
- data/test_app/config/environments/production.rb +49 -0
- data/test_app/config/environments/test.rb +35 -0
- data/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test_app/config/initializers/countries.rb +1 -0
- data/test_app/config/initializers/default_date_format.rb +2 -0
- data/test_app/config/initializers/inflections.rb +10 -0
- data/test_app/config/initializers/mime_types.rb +5 -0
- data/test_app/config/initializers/secret_token.rb +7 -0
- data/test_app/config/initializers/session_store.rb +8 -0
- data/test_app/config/locales/en.yml +5 -0
- data/test_app/config/routes.rb +20 -0
- data/test_app/db/migrate/20101206205922_create_users.rb +18 -0
- data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +9 -0
- data/test_app/db/migrate/20110115204441_add_description_to_user.rb +9 -0
- data/test_app/db/migrate/20111210084202_add_favorite_color_to_users.rb +5 -0
- data/test_app/db/migrate/20111210084251_add_favorite_books_to_users.rb +5 -0
- data/test_app/db/migrate/20111217215935_add_birth_date_to_users.rb +5 -0
- data/test_app/db/migrate/20111224181356_add_money_to_user.rb +5 -0
- data/test_app/db/migrate/20120513003308_create_cars.rb +11 -0
- data/test_app/db/migrate/20120607172609_add_favorite_movie_to_users.rb +5 -0
- data/test_app/db/migrate/20120616170454_add_money_proc_to_users.rb +6 -0
- data/test_app/db/migrate/20120620165212_add_height_to_user.rb +5 -0
- data/test_app/db/migrate/20130213224102_add_favorite_locale_to_users.rb +5 -0
- data/test_app/db/schema.rb +41 -0
- data/test_app/db/seeds.rb +19 -0
- data/test_app/doc/README_FOR_APP +2 -0
- data/test_app/lib/tasks/.gitkeep +0 -0
- data/test_app/lib/tasks/cron.rake +7 -0
- data/test_app/public/404.html +26 -0
- data/test_app/public/422.html +26 -0
- data/test_app/public/500.html +26 -0
- data/test_app/public/favicon.ico +0 -0
- data/test_app/public/robots.txt +5 -0
- data/test_app/script/rails +6 -0
- data/test_app/test/fixtures/users.yml +17 -0
- data/test_app/test/functional/users_controller_test.rb +49 -0
- data/test_app/test/performance/browsing_test.rb +9 -0
- data/test_app/test/test_helper.rb +13 -0
- data/test_app/test/unit/helpers/users_helper_test.rb +4 -0
- data/test_app/test/unit/user_test.rb +8 -0
- data/test_app/vendor/plugins/.gitkeep +0 -0
- metadata +256 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//= require jquery.purr
|
|
2
|
+
|
|
3
|
+
jQuery(document).on('best_in_place:error', function(event, request, error) {
|
|
4
|
+
// Display all error messages from server side validation
|
|
5
|
+
jQuery.each(jQuery.parseJSON(request.responseText), function(index, value) {
|
|
6
|
+
if( typeof(value) == "object") {value = index + " " + value.toString(); }
|
|
7
|
+
var container = jQuery("<span class='flash-error'></span>").html(value);
|
|
8
|
+
container.purr();
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jquery.purr.js
|
|
3
|
+
* Copyright (c) 2008 Net Perspective (net-perspective.com)
|
|
4
|
+
* Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
5
|
+
*
|
|
6
|
+
* @author R.A. Ray
|
|
7
|
+
* @projectDescription jQuery plugin for dynamically displaying unobtrusive messages in the browser. Mimics the behavior of the MacOS program "Growl."
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
*
|
|
10
|
+
* @requires jquery.js (tested with 1.2.6)
|
|
11
|
+
*
|
|
12
|
+
* @param fadeInSpeed int - Duration of fade in animation in miliseconds
|
|
13
|
+
* default: 500
|
|
14
|
+
* @param fadeOutSpeed int - Duration of fade out animationin miliseconds
|
|
15
|
+
default: 500
|
|
16
|
+
* @param removeTimer int - Timeout, in miliseconds, before notice is removed once it is the top non-sticky notice in the list
|
|
17
|
+
default: 4000
|
|
18
|
+
* @param isSticky bool - Whether the notice should fade out on its own or wait to be manually closed
|
|
19
|
+
default: false
|
|
20
|
+
* @param usingTransparentPNG bool - Whether or not the notice is using transparent .png images in its styling
|
|
21
|
+
default: false
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
(function(jQuery) {
|
|
25
|
+
|
|
26
|
+
jQuery.purr = function(notice, options)
|
|
27
|
+
{
|
|
28
|
+
// Convert notice to a jQuery object
|
|
29
|
+
notice = jQuery(notice);
|
|
30
|
+
|
|
31
|
+
// Add a class to denote the notice as not sticky
|
|
32
|
+
notice.addClass('purr');
|
|
33
|
+
|
|
34
|
+
// Get the container element from the page
|
|
35
|
+
var cont = document.getElementById('purr-container');
|
|
36
|
+
|
|
37
|
+
// If the container doesn't yet exist, we need to create it
|
|
38
|
+
if (!cont)
|
|
39
|
+
{
|
|
40
|
+
cont = '<div id="purr-container"></div>';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Convert cont to a jQuery object
|
|
44
|
+
cont = jQuery(cont);
|
|
45
|
+
|
|
46
|
+
// Add the container to the page
|
|
47
|
+
jQuery('body').append(cont);
|
|
48
|
+
|
|
49
|
+
notify();
|
|
50
|
+
|
|
51
|
+
function notify ()
|
|
52
|
+
{
|
|
53
|
+
// Set up the close button
|
|
54
|
+
var close = document.createElement('a');
|
|
55
|
+
jQuery(close).attr({
|
|
56
|
+
className: 'close',
|
|
57
|
+
href: '#close'
|
|
58
|
+
}).appendTo(notice).click(function() {
|
|
59
|
+
removeNotice();
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// If ESC is pressed remove notice
|
|
64
|
+
jQuery(document).keyup(function(e) {
|
|
65
|
+
if (e.keyCode === 27) {
|
|
66
|
+
removeNotice();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Add the notice to the page and keep it hidden initially
|
|
71
|
+
notice.appendTo(cont).hide();
|
|
72
|
+
|
|
73
|
+
//Fade in the notice we just added
|
|
74
|
+
notice.fadeIn(options.fadeInSpeed);
|
|
75
|
+
|
|
76
|
+
// Set up the removal interval for the added notice if that notice is not a sticky
|
|
77
|
+
if (!options.isSticky)
|
|
78
|
+
{
|
|
79
|
+
var topSpotInt = setInterval(function() {
|
|
80
|
+
// Check to see if our notice is the first non-sticky notice in the list
|
|
81
|
+
if (notice.prevAll('.purr').length === 0)
|
|
82
|
+
{
|
|
83
|
+
// Stop checking once the condition is met
|
|
84
|
+
clearInterval(topSpotInt);
|
|
85
|
+
|
|
86
|
+
// Call the close action after the timeout set in options
|
|
87
|
+
setTimeout(function() {
|
|
88
|
+
removeNotice();
|
|
89
|
+
}, options.removeTimer);
|
|
90
|
+
}
|
|
91
|
+
}, 200);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function removeNotice()
|
|
96
|
+
{
|
|
97
|
+
// Fade the object out before reducing its height to produce the sliding effect
|
|
98
|
+
notice.animate({ opacity: '0' },
|
|
99
|
+
{
|
|
100
|
+
duration: options.fadeOutSpeed,
|
|
101
|
+
complete: function ()
|
|
102
|
+
{
|
|
103
|
+
notice.animate({ height: '0px' },
|
|
104
|
+
{
|
|
105
|
+
duration: options.fadeOutSpeed,
|
|
106
|
+
complete: function()
|
|
107
|
+
{
|
|
108
|
+
notice.remove();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
jQuery.fn.purr = function(options)
|
|
119
|
+
{
|
|
120
|
+
options = options || {};
|
|
121
|
+
options.fadeInSpeed = options.fadeInSpeed || 500;
|
|
122
|
+
options.fadeOutSpeed = options.fadeOutSpeed || 500;
|
|
123
|
+
options.removeTimer = options.removeTimer || 4000;
|
|
124
|
+
options.isSticky = options.isSticky || false;
|
|
125
|
+
options.usingTransparentPNG = options.usingTransparentPNG || false;
|
|
126
|
+
|
|
127
|
+
this.each(function()
|
|
128
|
+
{
|
|
129
|
+
new jQuery.purr( this, options );
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return this;
|
|
134
|
+
};
|
|
135
|
+
})( jQuery );
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "crest_in_place/check_version"
|
|
2
|
+
require "crest_in_place/utils"
|
|
3
|
+
require "crest_in_place/helper"
|
|
4
|
+
require "crest_in_place/engine"
|
|
5
|
+
require "crest_in_place/railtie"
|
|
6
|
+
require "crest_in_place/controller_extensions"
|
|
7
|
+
require "crest_in_place/display_methods"
|
|
8
|
+
require "action_view"
|
|
9
|
+
|
|
10
|
+
module CrestInPlace
|
|
11
|
+
autoload :TestHelpers, "crest_in_place/test_helpers"
|
|
12
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module CrestInPlace
|
|
2
|
+
module ControllerExtensions
|
|
3
|
+
def respond_with_bip(obj)
|
|
4
|
+
obj.changed? ? respond_bip_error(obj) : respond_bip_ok(obj)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
def respond_bip_ok(obj)
|
|
9
|
+
if obj.respond_to?(:id)
|
|
10
|
+
klass = "#{obj.class}_#{obj.id}"
|
|
11
|
+
else
|
|
12
|
+
klass = obj.class.to_s
|
|
13
|
+
end
|
|
14
|
+
param_key = CrestInPlace::Utils.object_to_key(obj)
|
|
15
|
+
updating_attr = params[param_key].keys.first
|
|
16
|
+
|
|
17
|
+
if renderer = CrestInPlace::DisplayMethods.lookup(klass, updating_attr)
|
|
18
|
+
render :json => renderer.render_json(obj)
|
|
19
|
+
else
|
|
20
|
+
head :no_content
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def respond_bip_error(obj)
|
|
25
|
+
render :json => obj.errors.full_messages, :status => :unprocessable_entity
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module CrestInPlace
|
|
2
|
+
module DisplayMethods
|
|
3
|
+
extend self
|
|
4
|
+
|
|
5
|
+
class Renderer < Struct.new(:opts)
|
|
6
|
+
def render_json(object)
|
|
7
|
+
case opts[:type]
|
|
8
|
+
when :model
|
|
9
|
+
{:display_as => object.send(opts[:method])}.to_json
|
|
10
|
+
when :helper
|
|
11
|
+
value = if opts[:helper_options]
|
|
12
|
+
CrestInPlace::ViewHelpers.send(opts[:method], object.send(opts[:attr]), opts[:helper_options])
|
|
13
|
+
else
|
|
14
|
+
CrestInPlace::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
|
+
{}.to_json
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@@table = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
|
|
26
|
+
|
|
27
|
+
def lookup(klass, attr)
|
|
28
|
+
foo = @@table[klass.to_s][attr.to_s]
|
|
29
|
+
foo == {} ? nil : foo
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add_model_method(klass, attr, display_as)
|
|
33
|
+
@@table[klass.to_s][attr.to_s] = Renderer.new :method => display_as.to_sym, :type => :model
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def add_helper_method(klass, attr, helper_method, helper_options = nil)
|
|
37
|
+
@@table[klass.to_s][attr.to_s] = Renderer.new :method => helper_method.to_sym, :type => :helper, :attr => attr, :helper_options => helper_options
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_helper_proc(klass, attr, helper_proc)
|
|
41
|
+
@@table[klass.to_s][attr.to_s] = Renderer.new :type => :proc, :attr => attr, :proc => helper_proc
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
module CrestInPlace
|
|
2
|
+
module CrestInPlaceHelpers
|
|
3
|
+
|
|
4
|
+
def best_in_place(object, field, opts = {})
|
|
5
|
+
if opts[:display_as] && opts[:display_with]
|
|
6
|
+
raise ArgumentError, "Can't use both 'display_as' and 'display_with' options at the same time"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
if opts[:display_with] && !opts[:display_with].is_a?(Proc) && !ViewHelpers.respond_to?(opts[:display_with])
|
|
10
|
+
raise ArgumentError, "Can't find helper #{opts[:display_with]}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
real_object = real_object_for object
|
|
14
|
+
opts[:type] ||= :input
|
|
15
|
+
opts[:collection] ||= []
|
|
16
|
+
field = field.to_s
|
|
17
|
+
|
|
18
|
+
display_value = build_value_for(real_object, field, opts)
|
|
19
|
+
|
|
20
|
+
collection = nil
|
|
21
|
+
value = nil
|
|
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
|
|
41
|
+
|
|
42
|
+
out = "<span class='#{classes.join(" ")}'"
|
|
43
|
+
out << " id='#{CrestInPlace::Utils.build_best_in_place_id(real_object, field)}'"
|
|
44
|
+
out << " data-url='#{opts[:path].blank? ? url_for(object) : url_for(opts[:path])}'"
|
|
45
|
+
out << " data-object='#{opts[:object_name] || CrestInPlace::Utils.object_to_key(real_object)}'"
|
|
46
|
+
out << " data-collection='#{attribute_escape(collection)}'" unless collection.blank?
|
|
47
|
+
out << " data-attribute='#{field}'"
|
|
48
|
+
out << " data-activator='#{opts[:activator]}'" unless opts[:activator].blank?
|
|
49
|
+
out << " data-ok-button='#{opts[:ok_button]}'" unless opts[:ok_button].blank?
|
|
50
|
+
out << " data-ok-button-class='#{opts[:ok_button_class]}'" unless opts[:ok_button_class].blank?
|
|
51
|
+
out << " data-cancel-button='#{opts[:cancel_button]}'" unless opts[:cancel_button].blank?
|
|
52
|
+
out << " data-cancel-button-class='#{opts[:cancel_button_class]}'" unless opts[:cancel_button_class].blank?
|
|
53
|
+
out << " data-nil='#{attribute_escape(opts[:nil])}'" unless opts[:nil].blank?
|
|
54
|
+
out << " data-use-confirm='#{opts[:use_confirm]}'" unless opts[:use_confirm].nil?
|
|
55
|
+
out << " data-type='#{opts[:type]}'"
|
|
56
|
+
out << " data-inner-class='#{opts[:inner_class]}'" if opts[:inner_class]
|
|
57
|
+
out << " data-html-attrs='#{opts[:html_attrs].to_json}'" unless opts[:html_attrs].blank?
|
|
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)}"
|
|
74
|
+
end
|
|
75
|
+
out << "</span>"
|
|
76
|
+
raw out
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def best_in_place_if(condition, object, field, opts={})
|
|
80
|
+
if condition
|
|
81
|
+
best_in_place(object, field, opts)
|
|
82
|
+
else
|
|
83
|
+
build_value_for real_object_for(object), field, opts
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
def build_value_for(object, field, opts)
|
|
89
|
+
return "" if object.send(field).blank?
|
|
90
|
+
|
|
91
|
+
klass = if object.respond_to?(:id)
|
|
92
|
+
"#{object.class}_#{object.id}"
|
|
93
|
+
else
|
|
94
|
+
object.class.to_s
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
if opts[:display_as]
|
|
98
|
+
CrestInPlace::DisplayMethods.add_model_method(klass, field, opts[:display_as])
|
|
99
|
+
object.send(opts[:display_as]).to_s
|
|
100
|
+
|
|
101
|
+
elsif opts[:display_with].try(:is_a?, Proc)
|
|
102
|
+
CrestInPlace::DisplayMethods.add_helper_proc(klass, field, opts[:display_with])
|
|
103
|
+
opts[:display_with].call(object.send(field))
|
|
104
|
+
|
|
105
|
+
elsif opts[:display_with]
|
|
106
|
+
CrestInPlace::DisplayMethods.add_helper_method(klass, field, opts[:display_with], opts[:helper_options])
|
|
107
|
+
if opts[:helper_options]
|
|
108
|
+
CrestInPlace::ViewHelpers.send(opts[:display_with], object.send(field), opts[:helper_options])
|
|
109
|
+
else
|
|
110
|
+
CrestInPlace::ViewHelpers.send(opts[:display_with], object.send(field))
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
else
|
|
114
|
+
object.send(field).to_s
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def attribute_escape(data)
|
|
119
|
+
return unless data
|
|
120
|
+
|
|
121
|
+
data.to_s.
|
|
122
|
+
gsub("&", "&").
|
|
123
|
+
gsub("'", "'").
|
|
124
|
+
gsub(/\r?\n/, " ")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def real_object_for(object)
|
|
128
|
+
(object.is_a?(Array) && object.last.class.respond_to?(:model_name)) ? object.last : object
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module CrestInPlace
|
|
2
|
+
module TestHelpers
|
|
3
|
+
|
|
4
|
+
include ActionView::Helpers::JavaScriptHelper
|
|
5
|
+
|
|
6
|
+
def bip_area(model, attr, new_value)
|
|
7
|
+
id = CrestInPlace::Utils.build_best_in_place_id model, attr
|
|
8
|
+
page.execute_script <<-JS
|
|
9
|
+
jQuery("##{id}").click();
|
|
10
|
+
jQuery("##{id} form textarea").val('#{escape_javascript new_value.to_s}');
|
|
11
|
+
jQuery("##{id} form textarea").blur();
|
|
12
|
+
jQuery("##{id} form textarea").blur();
|
|
13
|
+
JS
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def bip_text(model, attr, new_value)
|
|
17
|
+
id = CrestInPlace::Utils.build_best_in_place_id model, attr
|
|
18
|
+
page.execute_script <<-JS
|
|
19
|
+
jQuery("##{id}").click();
|
|
20
|
+
jQuery("##{id} input[name='#{attr}']").val('#{escape_javascript new_value.to_s}');
|
|
21
|
+
jQuery("##{id} form").submit();
|
|
22
|
+
JS
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def bip_bool(model, attr)
|
|
26
|
+
id = CrestInPlace::Utils.build_best_in_place_id model, attr
|
|
27
|
+
page.execute_script("jQuery('##{id}').click();")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def bip_select(model, attr, name)
|
|
31
|
+
id = CrestInPlace::Utils.build_best_in_place_id model, attr
|
|
32
|
+
page.execute_script <<-JS
|
|
33
|
+
(function() {
|
|
34
|
+
jQuery("##{id}").click();
|
|
35
|
+
var opt_value = jQuery("##{id} select option:contains('#{name}')").attr('value');
|
|
36
|
+
jQuery("##{id} select option[value='" + opt_value + "']").attr('selected', true);
|
|
37
|
+
jQuery("##{id} select").change();
|
|
38
|
+
})();
|
|
39
|
+
JS
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module CrestInPlace
|
|
2
|
+
module Utils
|
|
3
|
+
extend self
|
|
4
|
+
|
|
5
|
+
def build_best_in_place_id(object, field)
|
|
6
|
+
if object.is_a?(Symbol) || object.is_a?(String)
|
|
7
|
+
return "best_in_place_#{object}_#{field}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
id = "best_in_place_#{object_to_key(object)}"
|
|
11
|
+
id << "_#{object.id}" if object.class.ancestors.include?(ActiveModel::Serializers::JSON)
|
|
12
|
+
id << "_#{field}"
|
|
13
|
+
id
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def object_to_key(object)
|
|
17
|
+
return object.class.to_s.underscore unless object.class.respond_to?(:model_name)
|
|
18
|
+
ActiveModel::Naming.param_key(object.class)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|