Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow best_in_place field to specify more: #539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Options:
- **:as** It can be only [:input, :textarea, :select, :checkbox, :date] or if undefined it defaults to :input.
- **: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.
- **:url**: URL to which the updating action will be sent. If not defined it defaults to the :object path.
- **:method**: HTTP method used to submit the updating action. If not defined it defaults to :put.
- **:other_fields**: Hash of additional data fields to submit along with the updating action.
- **: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".
If not defined it will show *"-"*.
- **:activator**: Is the DOM object that can activate the field. If not defined the user will making editable by clicking on it.
Expand Down Expand Up @@ -166,7 +168,7 @@ The value will always be converted to a string for display.
If you use array as a collection, the first value is always the negative boolean value and the second the positive. Structure: `["false value", "true value"]`.
If not defined, it will default to *Yes* and *No* options.
Default true and false values are stored in locales

t(:'best_in_place.yes', default: 'Yes')
t(:'best_in_place.no', default: 'No')

Expand Down Expand Up @@ -340,7 +342,7 @@ You can configure some global options for best_in_place. Currently these options
config.container = :div
config.skip_blur = true
end


## Notification

Expand Down
10 changes: 8 additions & 2 deletions lib/assets/javascripts/best_in_place.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ BestInPlaceEditor.prototype = {
}

editor.ajax({
"type": BestInPlaceEditor.defaults.ajaxMethod,
"type": editor.ajaxMethod,
"dataType": BestInPlaceEditor.defaults.ajaxDataType,
"data": editor.requestData(),
"success": function (data, status, xhr) {
Expand Down Expand Up @@ -189,6 +189,8 @@ BestInPlaceEditor.prototype = {
self.cancelButton = self.element.data("bipCancelButton") || self.cancelButton;
self.cancelButtonClass = self.element.data("bipCancelButtonClass") || self.cancelButtonClass || BestInPlaceEditor.defaults.cancelButtonClass;
self.skipBlur = self.element.data("bipSkipBlur") || self.skipBlur || BestInPlaceEditor.defaults.skipBlur;
self.ajaxMethod = self.element.data("bipMethod") || self.ajaxMethod || BestInPlaceEditor.defaults.ajaxMethod;
self.otherFields = self.element.data("bipOtherFields") || self.otherFields || null;

// Fix for default values of 0
if (self.element.data("bipPlaceholder") == null) {
Expand Down Expand Up @@ -253,9 +255,13 @@ BestInPlaceEditor.prototype = {
var csrf_token = jQuery('meta[name=csrf-token]').attr('content'),
csrf_param = jQuery('meta[name=csrf-param]').attr('content');

var data = "_method=" + BestInPlaceEditor.defaults.ajaxMethod;
var data = "_method=" + this.ajaxMethod;
data += "&" + this.objectName + '[' + this.attributeName + ']=' + encodeURIComponent(this.getValue());

if (this.otherFields !== undefined && this.otherFields !== null) {
data += "&" + this.otherFields;
}

if (csrf_param !== undefined && csrf_token !== undefined) {
data += "&" + csrf_param + "=" + encodeURIComponent(csrf_token);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/best_in_place/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def best_in_place(object, field, opts = {})
options[:id] = opts[:id] || BestInPlace::Utils.build_best_in_place_id(real_object, field)

pass_through_html_options(opts, options)

options[:data]['bip-activator'] = opts[:activator].presence

options[:data]['bip-html-attrs'] = opts[:html_attrs].to_json unless opts[:html_attrs].blank?
Expand All @@ -49,9 +48,11 @@ def best_in_place(object, field, opts = {})
options[:data]['bip-skip-blur'] = opts.has_key?(:skip_blur) ? opts[:skip_blur].presence : BestInPlace.skip_blur

options[:data]['bip-url'] = url_for(opts[:url] || object)
options[:data]['bip-method'] = opts[:method].presence

options[:data]['bip-confirm'] = opts[:confirm].presence
options[:data]['bip-value'] = html_escape(value).presence
options[:data]['bip-other-fields'] = opts[:other_fields].to_query unless opts[:other_fields].blank?

if opts[:raw]
options[:data]['bip-raw'] = 'true'
Expand Down