best_in_place 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +15 -16
- data/lib/assets/javascripts/best_in_place.js +30 -22
- data/lib/best_in_place/test_helpers.rb +1 -1
- data/lib/best_in_place/version.rb +1 -1
- data/spec/integration/js_spec.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84ce49122f38b9152cae6c9ce661307dd0f3d528
|
4
|
+
data.tar.gz: ad3e88ba32e9c656706661ef05e807f9fdfc7fb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1502b356495066e3c08541b068e8af62bd58bcc0c32d0ff84b5fdb570ffdd663fb9fa864ea2f78c77326ff0d359cf42b9819402a5052bf1245a5f47c19e11993
|
7
|
+
data.tar.gz: db75bf52797e26f7bb11253b4cadaaaede87ec84d46dfe736bfead6960469c76bc10fa5fb7284f211241f48da035f63d792a1197a8d2d79cb84ab458eb31d3a5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -76,7 +76,7 @@ Params:
|
|
76
76
|
|
77
77
|
Options:
|
78
78
|
|
79
|
-
- **:
|
79
|
+
- **:as** It can be only [:input, :textarea, :select, :checkbox, :date] or if undefined it defaults to :input.
|
80
80
|
- **:collection**: If you are using the :select type then you must specify the collection of values it takes as a hash where values represent the display text and keys are the option's value when selected. If you are using the :checkbox type you can specify the two values it can take, or otherwise they will default to Yes and No.
|
81
81
|
- **:url**: URL to which the updating action will be sent. If not defined it defaults to the :object path.
|
82
82
|
- **: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".
|
@@ -92,7 +92,6 @@ Options:
|
|
92
92
|
- **:display_as**: A **model** method which will be called in order to display this field. Cannot be used when using `display_with`.
|
93
93
|
- **:display_with**: A **helper** method or proc will be called in order to display this field. Cannot be used with `display_as`.
|
94
94
|
- **:helper_options**: A hash of parameters to be sent to the helper method specified by `display_with`.
|
95
|
-
- **: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.
|
96
95
|
- **:data**: Hash of custom data attributes to be added to span. Can be used to provide data to the ajax:success callback.
|
97
96
|
- **:class**: Additional classes to apply to the best_in_place span. Accepts either a string or Array of strings
|
98
97
|
- **:value**: Customize the starting value of the inline input (defaults to to the field's value)
|
@@ -120,11 +119,11 @@ condition, is satisfied. Specifically:
|
|
120
119
|
|
121
120
|
Say we have something like
|
122
121
|
|
123
|
-
<%= best_in_place_if condition, @user, :name, :
|
122
|
+
<%= best_in_place_if condition, @user, :name, :as => :input %>
|
124
123
|
|
125
124
|
In case *condition* is satisfied, the outcome will be just the same as:
|
126
125
|
|
127
|
-
<%= best_in_place @user, :name, :
|
126
|
+
<%= best_in_place @user, :name, :as => :input %>
|
128
127
|
|
129
128
|
Otherwise, we will have the same outcome as:
|
130
129
|
|
@@ -140,36 +139,36 @@ Examples (code in the views):
|
|
140
139
|
|
141
140
|
### Input
|
142
141
|
|
143
|
-
<%= best_in_place @user, :name, :
|
142
|
+
<%= best_in_place @user, :name, :as => :input %>
|
144
143
|
|
145
|
-
<%= best_in_place @user, :name, :
|
144
|
+
<%= best_in_place @user, :name, :as => :input, :nil => "Click me to add content!" %>
|
146
145
|
|
147
146
|
### Textarea
|
148
147
|
|
149
|
-
<%= best_in_place @user, :description, :
|
148
|
+
<%= best_in_place @user, :description, :as => :textarea %>
|
150
149
|
|
151
|
-
<%= best_in_place @user, :favorite_books, :
|
150
|
+
<%= best_in_place @user, :favorite_books, :as => :textarea, :ok_button => 'Save', :cancel_button => 'Cancel' %>
|
152
151
|
|
153
152
|
### Select
|
154
153
|
|
155
|
-
<%= best_in_place @user, :country, :
|
156
|
-
<%= best_in_place @user, :country, :
|
157
|
-
<%= best_in_place @user, :country, :
|
158
|
-
<%= best_in_place @user, :country, :
|
154
|
+
<%= best_in_place @user, :country, :as => :select, :collection => {"1" => "Spain", "2" => "Italy", "3" => "Germany", "4" => "France"} %>
|
155
|
+
<%= best_in_place @user, :country, :as => :select, :collection => { es: 'Spain', it: 'Italy', de: 'Germany', fr: 'France' } %>
|
156
|
+
<%= best_in_place @user, :country, :as => :select, :collection => %w(Spain Italy Germany France) %>
|
157
|
+
<%= best_in_place @user, :country, :as => :select, :collection => [[1, 'Spain'], [3, 'Germany'], [2, 'Italy'], [4, 'France']] %>
|
159
158
|
|
160
159
|
Of course it can take an instance or global variable for the collection, just remember the structure is a hash.
|
161
160
|
The value will always be converted to a string for display.
|
162
161
|
|
163
162
|
### Checkbox
|
164
163
|
|
165
|
-
<%= best_in_place @user, :receive_emails, :
|
164
|
+
<%= best_in_place @user, :receive_emails, :as => :checkbox, :collection => ["No, thanks", "Yes, of course!"] %>
|
166
165
|
|
167
166
|
The first value is always the negative boolean value and the second the positive. Structure: `["false value", "true value"]`.
|
168
167
|
If not defined, it will default to *Yes* and *No* options.
|
169
168
|
|
170
169
|
### Date
|
171
170
|
|
172
|
-
<%= best_in_place @user, :birth_date, :
|
171
|
+
<%= best_in_place @user, :birth_date, :as => :date %>
|
173
172
|
|
174
173
|
With the :date type the input field will be initialized as a datepicker input.
|
175
174
|
In order to provide custom options to the datepicker initialization you must
|
@@ -206,7 +205,7 @@ the :json format. This is a simple example showing an update action using it:
|
|
206
205
|
As of best in place 1.0.3 you can use custom methods in your model in order to
|
207
206
|
decide how a certain field has to be displayed. You can write something like:
|
208
207
|
|
209
|
-
= best_in_place @user, :description, :
|
208
|
+
= best_in_place @user, :description, :as => :textarea, :display_as => :mk_description
|
210
209
|
|
211
210
|
Then instead of using `@user.description` to show the actual value, best in
|
212
211
|
place will call `@user.mk_description`. This can be used for any kind of
|
@@ -286,7 +285,7 @@ In the view, we'd do:
|
|
286
285
|
th= size
|
287
286
|
- flavours.each do |flavour|
|
288
287
|
- v = @ice_cream.get_stock(flavour: flavour, size: size)
|
289
|
-
td= best_in_place v, :to_i,
|
288
|
+
td= best_in_place v, :to_i, as: :input, url: set_stock_ice_cream_path(flavour: flavour, size: size)
|
290
289
|
|
291
290
|
Now we need a route to which send the stock updates:
|
292
291
|
|
@@ -106,8 +106,8 @@ BestInPlaceEditor.prototype = {
|
|
106
106
|
"type": BestInPlaceEditor.defaults.ajaxMethod,
|
107
107
|
"dataType": BestInPlaceEditor.defaults.ajaxDataType,
|
108
108
|
"data": editor.requestData(),
|
109
|
-
"success": function (data) {
|
110
|
-
editor.loadSuccessCallback(data);
|
109
|
+
"success": function (data, status, xhr) {
|
110
|
+
editor.loadSuccessCallback(data, status, xhr);
|
111
111
|
},
|
112
112
|
"error": function (request, error) {
|
113
113
|
editor.loadErrorCallback(request, error);
|
@@ -120,15 +120,11 @@ BestInPlaceEditor.prototype = {
|
|
120
120
|
this.previousCollectionValue = value;
|
121
121
|
|
122
122
|
// search for the text for the span
|
123
|
-
|
124
|
-
for (_i = 0, a = this.values, _len = a.length; _i < _len; _i++) {
|
125
|
-
_ref = a[_i], key = _ref[0], val = _ref[1];
|
126
|
-
if (String(value) === String(key)) editor.element.html(val);
|
127
|
-
};
|
123
|
+
editor.element.html(this.arrayToObject(this.values)[value]);
|
128
124
|
break;
|
129
125
|
|
130
126
|
case "checkbox":
|
131
|
-
editor.element.html(this.values[value]);
|
127
|
+
editor.element.html(this.arrayToObject(this.values)[value]);
|
132
128
|
break;
|
133
129
|
|
134
130
|
default:
|
@@ -240,6 +236,19 @@ BestInPlaceEditor.prototype = {
|
|
240
236
|
alert(BestInPlaceEditor.defaults.locales[''].uninitializedForm);
|
241
237
|
},
|
242
238
|
|
239
|
+
arrayToObject: function(list, values) {
|
240
|
+
if (list == null) return {};
|
241
|
+
var result = {};
|
242
|
+
for (var i = 0, length = list.length; i < length; i++) {
|
243
|
+
if (values) {
|
244
|
+
result[list[i]] = values[i];
|
245
|
+
} else {
|
246
|
+
result[list[i][0]] = list[i][1];
|
247
|
+
}
|
248
|
+
}
|
249
|
+
return result;
|
250
|
+
},
|
251
|
+
|
243
252
|
// Trim and Strips HTML from text
|
244
253
|
sanitizeValue: function (s) {
|
245
254
|
'use strict';
|
@@ -273,7 +282,7 @@ BestInPlaceEditor.prototype = {
|
|
273
282
|
|
274
283
|
// Handlers ////////////////////////////////////////////////////////////////
|
275
284
|
|
276
|
-
loadSuccessCallback: function (data) {
|
285
|
+
loadSuccessCallback: function (data, status, xhr) {
|
277
286
|
'use strict';
|
278
287
|
data = jQuery.trim(data);
|
279
288
|
//Update original content with current text.
|
@@ -289,13 +298,11 @@ BestInPlaceEditor.prototype = {
|
|
289
298
|
this.element.data('bip-original-content', this.element.text());
|
290
299
|
this.element.html(response.display_as);
|
291
300
|
}
|
292
|
-
|
293
|
-
this.element.trigger(jQuery.Event("best_in_place:success"), data);
|
294
|
-
this.element.trigger(jQuery.Event("ajax:success"), data);
|
295
|
-
} else {
|
296
|
-
this.element.trigger(jQuery.Event("best_in_place:success"));
|
297
|
-
this.element.trigger(jQuery.Event("ajax:success"));
|
298
301
|
}
|
302
|
+
|
303
|
+
this.element.trigger(jQuery.Event("best_in_place:success"), [data, status, xhr]);
|
304
|
+
this.element.trigger(jQuery.Event("ajax:success"), [data, status, xhr]);
|
305
|
+
|
299
306
|
// Binding back after being clicked
|
300
307
|
jQuery(this.activator).bind('click', {editor: this}, this.clickHandler);
|
301
308
|
this.element.trigger(jQuery.Event("best_in_place:deactivate"));
|
@@ -392,7 +399,9 @@ BestInPlaceEditor.forms = {
|
|
392
399
|
if (this.cancelButton) {
|
393
400
|
this.element.find("input[type='button']").bind('click', {editor: this}, BestInPlaceEditor.forms.input.cancelButtonHandler);
|
394
401
|
}
|
395
|
-
this.
|
402
|
+
if (!this.okButton) {
|
403
|
+
this.element.find("input[type='text']").bind('blur', {editor: this}, BestInPlaceEditor.forms.input.inputBlurHandler);
|
404
|
+
}
|
396
405
|
this.element.find("input[type='text']").bind('keyup', {editor: this}, BestInPlaceEditor.forms.input.keyupHandler);
|
397
406
|
this.blurTimer = null;
|
398
407
|
this.userClicked = false;
|
@@ -459,15 +468,14 @@ BestInPlaceEditor.forms = {
|
|
459
468
|
select_elt = jQuery(document.createElement('select'))
|
460
469
|
.attr('class', this.inner_class !== null ? this.inner_class : ''),
|
461
470
|
currentCollectionValue = this.collectionValue,
|
462
|
-
|
463
|
-
|
464
|
-
|
471
|
+
key, value,
|
472
|
+
a = this.arrayToObject(this.values);
|
473
|
+
for (key in a) {
|
474
|
+
value = a[key];
|
465
475
|
var option_elt = jQuery(document.createElement('option'))
|
466
476
|
.val(key)
|
467
477
|
.html(value);
|
468
|
-
if (String(key) === String(currentCollectionValue))
|
469
|
-
option_elt.attr('selected', 'selected');
|
470
|
-
};
|
478
|
+
if (String(key) === String(currentCollectionValue)) option_elt.attr('selected', 'selected');
|
471
479
|
select_elt.append(option_elt);
|
472
480
|
};
|
473
481
|
output.append(select_elt);
|
data/spec/integration/js_spec.rb
CHANGED
@@ -149,6 +149,8 @@ describe "JS behaviour", :js => true do
|
|
149
149
|
|
150
150
|
bip_text @user, :email, "new@email.com"
|
151
151
|
|
152
|
+
expect(find('#email')).to have_content('new@email.com')
|
153
|
+
|
152
154
|
visit user_path(@user)
|
153
155
|
expect(find('#email')).to have_content('new@email.com')
|
154
156
|
end
|
@@ -193,6 +195,8 @@ describe "JS behaviour", :js => true do
|
|
193
195
|
|
194
196
|
bip_select @user, :country, "France"
|
195
197
|
|
198
|
+
expect(find('#country')).to have_content('France')
|
199
|
+
|
196
200
|
visit user_path(@user)
|
197
201
|
|
198
202
|
expect(find('#country')).to have_content('France')
|
@@ -215,6 +219,8 @@ describe "JS behaviour", :js => true do
|
|
215
219
|
|
216
220
|
bip_text @user, :birth_date, (today - 1.days)
|
217
221
|
|
222
|
+
expect(find('#birth_date')).to have_content(today - 1.days)
|
223
|
+
|
218
224
|
visit user_path(@user)
|
219
225
|
|
220
226
|
expect(find('#birth_date')).to have_content(today - 1.days)
|
@@ -234,6 +240,8 @@ describe "JS behaviour", :js => true do
|
|
234
240
|
JS
|
235
241
|
wait_for_ajax
|
236
242
|
|
243
|
+
expect(find('#birth_date')).to have_content(today.beginning_of_month.strftime('%d-%m-%Y'))
|
244
|
+
|
237
245
|
visit user_path(@user)
|
238
246
|
|
239
247
|
expect(find('#birth_date')).to have_content(today.beginning_of_month)
|
@@ -265,6 +273,8 @@ describe "JS behaviour", :js => true do
|
|
265
273
|
|
266
274
|
bip_bool @user, :receive_email
|
267
275
|
|
276
|
+
expect(find('#receive_email')).to have_content('Yes of course')
|
277
|
+
|
268
278
|
visit user_path(@user)
|
269
279
|
|
270
280
|
expect(find('#receive_email')).to have_content('Yes of course')
|
@@ -279,6 +289,8 @@ describe "JS behaviour", :js => true do
|
|
279
289
|
|
280
290
|
bip_bool @user, :receive_email_image
|
281
291
|
|
292
|
+
expect(find('#receive_email_image')).to have_xpath("//img[contains(@src,'yes.png')]")
|
293
|
+
|
282
294
|
visit user_path(@user)
|
283
295
|
|
284
296
|
expect(find('#receive_email_image')).to have_xpath("//img[contains(@src,'yes.png')]")
|
@@ -300,6 +312,8 @@ describe "JS behaviour", :js => true do
|
|
300
312
|
find("##{id} input[type='submit']").click
|
301
313
|
wait_for_ajax
|
302
314
|
|
315
|
+
expect(find('#favorite_color')).to have_content('Blue')
|
316
|
+
|
303
317
|
visit user_path(@user)
|
304
318
|
|
305
319
|
expect(find('#favorite_color')).to have_content('Blue')
|
@@ -350,7 +364,8 @@ describe "JS behaviour", :js => true do
|
|
350
364
|
execute_script <<-JS
|
351
365
|
$("##{id} input[name='favorite_color']").blur();
|
352
366
|
JS
|
353
|
-
|
367
|
+
sleep 0.5
|
368
|
+
expect(page).to have_css("##{id} input[type='submit']")
|
354
369
|
|
355
370
|
visit user_path(@user)
|
356
371
|
|
@@ -371,6 +386,8 @@ describe "JS behaviour", :js => true do
|
|
371
386
|
execute_script("$('##{id} input[name=\"favorite_color\"]').blur()")
|
372
387
|
wait_for_ajax
|
373
388
|
|
389
|
+
expect(find('#favorite_color')).to have_content('Blue')
|
390
|
+
|
374
391
|
visit user_path(@user)
|
375
392
|
|
376
393
|
expect(find('#favorite_color')).to have_content('Blue')
|
@@ -789,6 +806,9 @@ describe "JS behaviour", :js => true do
|
|
789
806
|
visit double_init_user_path(@user)
|
790
807
|
|
791
808
|
bip_area @user, :description, "A <a href=\"http://google.es\">link in this text</a> not sanitized."
|
809
|
+
|
810
|
+
expect(page).to have_link("link in this text", :href => "http://google.es")
|
811
|
+
|
792
812
|
visit double_init_user_path(@user)
|
793
813
|
|
794
814
|
expect(page).to have_link("link in this text", :href => "http://google.es")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: best_in_place
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernat Farrero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|