very_best_in_place 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +14 -0
  5. data/CHANGELOG.md +36 -0
  6. data/Gemfile +8 -0
  7. data/README.md +438 -0
  8. data/Rakefile +8 -0
  9. data/best_in_place.gemspec +26 -0
  10. data/lib/assets/javascripts/best_in_place.js +722 -0
  11. data/lib/assets/javascripts/best_in_place.purr.js +10 -0
  12. data/lib/assets/javascripts/jquery.purr.js +161 -0
  13. data/lib/best_in_place.rb +12 -0
  14. data/lib/best_in_place/check_version.rb +8 -0
  15. data/lib/best_in_place/controller_extensions.rb +28 -0
  16. data/lib/best_in_place/display_methods.rb +44 -0
  17. data/lib/best_in_place/engine.rb +8 -0
  18. data/lib/best_in_place/helper.rb +128 -0
  19. data/lib/best_in_place/railtie.rb +7 -0
  20. data/lib/best_in_place/test_helpers.rb +41 -0
  21. data/lib/best_in_place/utils.rb +21 -0
  22. data/lib/best_in_place/version.rb +3 -0
  23. data/spec/helpers/best_in_place_spec.rb +407 -0
  24. data/spec/integration/double_init_spec.rb +34 -0
  25. data/spec/integration/js_spec.rb +959 -0
  26. data/spec/integration/live_spec.rb +40 -0
  27. data/spec/integration/text_area_spec.rb +40 -0
  28. data/spec/spec_helper.rb +23 -0
  29. data/spec/support/retry_on_timeout.rb +10 -0
  30. data/test_app/Gemfile +16 -0
  31. data/test_app/README +256 -0
  32. data/test_app/Rakefile +7 -0
  33. data/test_app/app/assets/images/no.png +0 -0
  34. data/test_app/app/assets/images/red_pen.png +0 -0
  35. data/test_app/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  36. data/test_app/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  37. data/test_app/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
  38. data/test_app/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  39. data/test_app/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  40. data/test_app/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  41. data/test_app/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  42. data/test_app/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  43. data/test_app/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  44. data/test_app/app/assets/images/ui-icons_222222_256x240.png +0 -0
  45. data/test_app/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
  46. data/test_app/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
  47. data/test_app/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
  48. data/test_app/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
  49. data/test_app/app/assets/images/yes.png +0 -0
  50. data/test_app/app/assets/javascripts/application.js +35 -0
  51. data/test_app/app/assets/stylesheets/.gitkeep +0 -0
  52. data/test_app/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb +357 -0
  53. data/test_app/app/assets/stylesheets/scaffold.css +60 -0
  54. data/test_app/app/assets/stylesheets/style.css.erb +79 -0
  55. data/test_app/app/controllers/admin/users_controller.rb +14 -0
  56. data/test_app/app/controllers/application_controller.rb +3 -0
  57. data/test_app/app/controllers/cuca/cars_controller.rb +16 -0
  58. data/test_app/app/controllers/users_controller.rb +99 -0
  59. data/test_app/app/helpers/application_helper.rb +2 -0
  60. data/test_app/app/helpers/users_helper.rb +29 -0
  61. data/test_app/app/models/cuca/car.rb +5 -0
  62. data/test_app/app/models/user.rb +27 -0
  63. data/test_app/app/views/admin/users/show.html.erb +20 -0
  64. data/test_app/app/views/cuca/cars/show.html.erb +13 -0
  65. data/test_app/app/views/layouts/application.html.erb +14 -0
  66. data/test_app/app/views/users/_form.html.erb +51 -0
  67. data/test_app/app/views/users/double_init.html.erb +72 -0
  68. data/test_app/app/views/users/email_field.html.erb +1 -0
  69. data/test_app/app/views/users/index.html.erb +25 -0
  70. data/test_app/app/views/users/new.html.erb +5 -0
  71. data/test_app/app/views/users/show.html.erb +135 -0
  72. data/test_app/app/views/users/show_ajax.html.erb +12 -0
  73. data/test_app/config.ru +4 -0
  74. data/test_app/config/application.rb +51 -0
  75. data/test_app/config/boot.rb +13 -0
  76. data/test_app/config/database.yml +22 -0
  77. data/test_app/config/environment.rb +5 -0
  78. data/test_app/config/environments/development.rb +25 -0
  79. data/test_app/config/environments/production.rb +49 -0
  80. data/test_app/config/environments/test.rb +35 -0
  81. data/test_app/config/initializers/backtrace_silencers.rb +7 -0
  82. data/test_app/config/initializers/countries.rb +1 -0
  83. data/test_app/config/initializers/default_date_format.rb +2 -0
  84. data/test_app/config/initializers/inflections.rb +10 -0
  85. data/test_app/config/initializers/mime_types.rb +5 -0
  86. data/test_app/config/initializers/secret_token.rb +7 -0
  87. data/test_app/config/initializers/session_store.rb +8 -0
  88. data/test_app/config/locales/en.yml +5 -0
  89. data/test_app/config/routes.rb +20 -0
  90. data/test_app/db/migrate/20101206205922_create_users.rb +18 -0
  91. data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +9 -0
  92. data/test_app/db/migrate/20110115204441_add_description_to_user.rb +9 -0
  93. data/test_app/db/migrate/20111210084202_add_favorite_color_to_users.rb +5 -0
  94. data/test_app/db/migrate/20111210084251_add_favorite_books_to_users.rb +5 -0
  95. data/test_app/db/migrate/20111217215935_add_birth_date_to_users.rb +5 -0
  96. data/test_app/db/migrate/20111224181356_add_money_to_user.rb +5 -0
  97. data/test_app/db/migrate/20120513003308_create_cars.rb +11 -0
  98. data/test_app/db/migrate/20120607172609_add_favorite_movie_to_users.rb +5 -0
  99. data/test_app/db/migrate/20120616170454_add_money_proc_to_users.rb +6 -0
  100. data/test_app/db/migrate/20120620165212_add_height_to_user.rb +5 -0
  101. data/test_app/db/schema.rb +40 -0
  102. data/test_app/db/seeds.rb +19 -0
  103. data/test_app/doc/README_FOR_APP +2 -0
  104. data/test_app/lib/tasks/.gitkeep +0 -0
  105. data/test_app/lib/tasks/cron.rake +7 -0
  106. data/test_app/public/404.html +26 -0
  107. data/test_app/public/422.html +26 -0
  108. data/test_app/public/500.html +26 -0
  109. data/test_app/public/favicon.ico +0 -0
  110. data/test_app/public/robots.txt +5 -0
  111. data/test_app/script/rails +6 -0
  112. data/test_app/test/fixtures/users.yml +17 -0
  113. data/test_app/test/functional/users_controller_test.rb +49 -0
  114. data/test_app/test/performance/browsing_test.rb +9 -0
  115. data/test_app/test/test_helper.rb +13 -0
  116. data/test_app/test/unit/helpers/users_helper_test.rb +4 -0
  117. data/test_app/test/unit/user_test.rb +8 -0
  118. data/test_app/vendor/plugins/.gitkeep +0 -0
  119. metadata +241 -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,161 @@
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
+ if (jQuery.browser.msie && options.usingTransparentPNG)
74
+ {
75
+ // IE7 and earlier can't handle the combination of opacity and transparent pngs, so if we're using transparent pngs in our
76
+ // notice style, we'll just skip the fading in.
77
+ notice.show();
78
+ }
79
+ else
80
+ {
81
+ //Fade in the notice we just added
82
+ notice.fadeIn(options.fadeInSpeed);
83
+ }
84
+
85
+ // Set up the removal interval for the added notice if that notice is not a sticky
86
+ if (!options.isSticky)
87
+ {
88
+ var topSpotInt = setInterval(function() {
89
+ // Check to see if our notice is the first non-sticky notice in the list
90
+ if (notice.prevAll('.purr').length == 0)
91
+ {
92
+ // Stop checking once the condition is met
93
+ clearInterval(topSpotInt);
94
+
95
+ // Call the close action after the timeout set in options
96
+ setTimeout(function() {
97
+ removeNotice();
98
+ }, options.removeTimer);
99
+ }
100
+ }, 200);
101
+ }
102
+ }
103
+
104
+ function removeNotice()
105
+ {
106
+ // IE7 and earlier can't handle the combination of opacity and transparent pngs, so if we're using transparent pngs in our
107
+ // notice style, we'll just skip the fading out.
108
+ if (jQuery.browser.msie && options.usingTransparentPNG)
109
+ {
110
+ notice.css({ opacity: 0 }).animate({ height: '0px'},
111
+ {
112
+ duration: options.fadeOutSpeed,
113
+ complete: function ()
114
+ {
115
+ notice.remove();
116
+ }
117
+ }
118
+ );
119
+ }
120
+ else
121
+ {
122
+ // Fade the object out before reducing its height to produce the sliding effect
123
+ notice.animate({ opacity: '0' },
124
+ {
125
+ duration: options.fadeOutSpeed,
126
+ complete: function ()
127
+ {
128
+ notice.animate({ height: '0px' },
129
+ {
130
+ duration: options.fadeOutSpeed,
131
+ complete: function()
132
+ {
133
+ notice.remove();
134
+ }
135
+ }
136
+ );
137
+ }
138
+ }
139
+ );
140
+ }
141
+ };
142
+ };
143
+
144
+ jQuery.fn.purr = function(options)
145
+ {
146
+ options = options || {};
147
+ options.fadeInSpeed = options.fadeInSpeed || 500;
148
+ options.fadeOutSpeed = options.fadeOutSpeed || 500;
149
+ options.removeTimer = options.removeTimer || 4000;
150
+ options.isSticky = options.isSticky || false;
151
+ options.usingTransparentPNG = options.usingTransparentPNG || false;
152
+
153
+ this.each(function()
154
+ {
155
+ new jQuery.purr( this, options );
156
+ }
157
+ );
158
+
159
+ return this;
160
+ };
161
+ })( jQuery );
@@ -0,0 +1,12 @@
1
+ require "best_in_place/check_version"
2
+ require "best_in_place/utils"
3
+ require "best_in_place/helper"
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"
9
+
10
+ module BestInPlace
11
+ autoload :TestHelpers, "best_in_place/test_helpers"
12
+ end
@@ -0,0 +1,8 @@
1
+ module BestInPlace
2
+ module CheckVersion
3
+ if Rails::VERSION::STRING < "3.1"
4
+ raise "This version of Best in Place is intended to be used for Rails >= 3.1. If you want to use it with Rails 3.0 or lower, please use the rails-3.0 branch."
5
+ return
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ module BestInPlace
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 = BestInPlace::Utils.object_to_key(obj)
15
+ updating_attr = params[param_key].keys.first
16
+
17
+ if renderer = BestInPlace::DisplayMethods.lookup(klass, updating_attr)
18
+ render :json => renderer.render_json(obj)
19
+ else
20
+ head :ok
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 BestInPlace
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
+ 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
+ {}.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,8 @@
1
+ module BestInPlace
2
+ class Engine < Rails::Engine
3
+ initializer "setup for rails" do
4
+ ActionView::Base.send(:include, BestInPlace::BestInPlaceHelpers)
5
+ ActionController::Base.send(:include, BestInPlace::ControllerExtensions)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,128 @@
1
+ module BestInPlace
2
+ module BestInPlaceHelpers
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='#{BestInPlace::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] || BestInPlace::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-cancel-button='#{opts[:cancel_button]}'" unless opts[:cancel_button].blank?
51
+ out << " data-nil='#{attribute_escape(opts[:nil])}'" unless opts[:nil].blank?
52
+ out << " data-use-confirm='#{opts[:use_confirm]}'" unless opts[:use_confirm].nil?
53
+ out << " data-type='#{opts[:type]}'"
54
+ out << " data-inner-class='#{opts[:inner_class]}'" if opts[:inner_class]
55
+ out << " data-html-attrs='#{opts[:html_attrs].to_json}'" unless opts[:html_attrs].blank?
56
+ out << " data-original-content='#{attribute_escape(real_object.send(field))}'" if opts[:display_as] || opts[:display_with]
57
+ out << " data-value='#{attribute_escape(value)}'" if value
58
+
59
+ if opts[:data] && opts[:data].is_a?(Hash)
60
+ opts[:data].each do |k, v|
61
+ if !v.is_a?(String) && !v.is_a?(Symbol)
62
+ v = v.to_json
63
+ end
64
+ out << %( data-#{k.to_s.dasherize}="#{v}")
65
+ end
66
+ end
67
+ if !opts[:sanitize].nil? && !opts[:sanitize]
68
+ out << " data-sanitize='false'>"
69
+ out << display_value.to_s
70
+ else
71
+ out << ">#{h(display_value.to_s)}"
72
+ end
73
+ out << "</span>"
74
+ raw out
75
+ end
76
+
77
+ def best_in_place_if(condition, object, field, opts={})
78
+ if condition
79
+ best_in_place(object, field, opts)
80
+ else
81
+ build_value_for real_object_for(object), field, opts
82
+ end
83
+ end
84
+
85
+ private
86
+ def build_value_for(object, field, opts)
87
+ return "" if object.send(field).blank?
88
+
89
+ if (object.respond_to?(:id))
90
+ klass = "#{object.class}_#{object.id}"
91
+ else
92
+ klass = object.class.to_s
93
+ end
94
+ if opts[:display_as]
95
+ BestInPlace::DisplayMethods.add_model_method(klass, field, opts[:display_as])
96
+ object.send(opts[:display_as]).to_s
97
+
98
+ elsif opts[:display_with].try(:is_a?, Proc)
99
+ BestInPlace::DisplayMethods.add_helper_proc(klass, field, opts[:display_with])
100
+ opts[:display_with].call(object.send(field))
101
+ elsif opts[:display_with]
102
+ BestInPlace::DisplayMethods.add_helper_method(klass, field, opts[:display_with], opts[:helper_options])
103
+ if opts[:helper_options]
104
+ BestInPlace::ViewHelpers.send(opts[:display_with], object.send(field), opts[:helper_options])
105
+ else
106
+ BestInPlace::ViewHelpers.send(opts[:display_with], object.send(field))
107
+ end
108
+
109
+ else
110
+ object.send(field).to_s.presence || ""
111
+ end
112
+ end
113
+
114
+ def attribute_escape(data)
115
+ return unless data
116
+
117
+ data.to_s.
118
+ gsub("&", "&amp;").
119
+ gsub("'", "&apos;").
120
+ gsub(/\r?\n/, "&#10;")
121
+ end
122
+
123
+ def real_object_for(object)
124
+ (object.is_a?(Array) && object.last.class.respond_to?(:model_name)) ? object.last : object
125
+ end
126
+ end
127
+ end
128
+
@@ -0,0 +1,7 @@
1
+ module BestInPlace
2
+ class Railtie < Rails::Railtie
3
+ initializer "set view helpers" do
4
+ BestInPlace::ViewHelpers = ActionView::Base.new
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ module BestInPlace
2
+ module TestHelpers
3
+
4
+ include ActionView::Helpers::JavaScriptHelper
5
+
6
+ def bip_area(model, attr, new_value)
7
+ id = BestInPlace::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
+ JS
13
+ end
14
+
15
+ def bip_text(model, attr, new_value)
16
+ id = BestInPlace::Utils.build_best_in_place_id model, attr
17
+ page.execute_script <<-JS
18
+ jQuery("##{id}").click();
19
+ jQuery("##{id} input[name='#{attr}']").val('#{escape_javascript new_value.to_s}');
20
+ jQuery("##{id} form").submit();
21
+ JS
22
+ end
23
+
24
+ def bip_bool(model, attr)
25
+ id = BestInPlace::Utils.build_best_in_place_id model, attr
26
+ page.execute_script("jQuery('##{id}').click();")
27
+ end
28
+
29
+ def bip_select(model, attr, name)
30
+ id = BestInPlace::Utils.build_best_in_place_id model, attr
31
+ page.execute_script <<-JS
32
+ (function() {
33
+ jQuery("##{id}").click();
34
+ var opt_value = jQuery("##{id} select option:contains('#{name}')").attr('value');
35
+ jQuery("##{id} select option[value='" + opt_value + "']").attr('selected', true);
36
+ jQuery("##{id} select").change();
37
+ })();
38
+ JS
39
+ end
40
+ end
41
+ end