x-editable-rails 1.4.0 → 1.5.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.
- checksums.yaml +4 -4
- data/README.md +130 -48
- data/lib/x-editable-rails.rb +1 -0
- data/lib/x-editable-rails/configuration.rb +68 -0
- data/lib/x-editable-rails/version.rb +1 -1
- data/lib/x-editable-rails/view_helpers.rb +132 -20
- data/vendor/assets/javascripts/editable/rails.js.coffee +2 -37
- data/vendor/assets/javascripts/editable/rails/data_classes.js.coffee +23 -0
- data/vendor/assets/javascripts/editable/rails/editable_form.js.coffee +40 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 658565005fa676f034fc99c545ba7e60158b983b
|
4
|
+
data.tar.gz: 67c484363471f28a725164ffbdbb8476ac9268d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb098d43de97de7c8a9b71495a79f8d7ace85d76792f0476a55381da194491e25d74bf6ae4236de79948b15ca65aa907616bb3fa00e23b38416947ccb3ca1a73
|
7
|
+
data.tar.gz: f40ec85577f7b1d4cb6ce0d36123918a1b77c4e4f7a56d1394bbb5d17a7356e028bf377da90513cd40e5768425c83d9a47876ae9426b358f443b38352622fa1f
|
data/README.md
CHANGED
@@ -18,96 +18,178 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Assets
|
22
|
+
|
23
|
+
Choose between the following javascripts:
|
24
|
+
|
25
|
+
* bootstrap-editable
|
26
|
+
* bootstrap2-editable
|
27
|
+
* jqueryui-editable
|
28
|
+
* jquery-editable-poshytip
|
29
|
+
|
30
|
+
You'll also need to include editable/rails in your scripts for this to work.
|
22
31
|
|
23
32
|
```coffee
|
24
33
|
#= require editable/bootstrap-editable
|
34
|
+
#= require editable/rails
|
25
35
|
```
|
26
|
-
|
36
|
+
|
37
|
+
Choose the corresponding stylesheets:
|
38
|
+
|
39
|
+
* bootstrap-editable
|
40
|
+
* bootstrap2-editable
|
41
|
+
* jqueryui-editable
|
42
|
+
* jquery-editable
|
27
43
|
|
28
44
|
```scss
|
45
|
+
// as CSS
|
29
46
|
*= require editable/bootstrap-editable
|
47
|
+
|
48
|
+
// or SCSS
|
49
|
+
@import "editable/bootstrap-editable";
|
30
50
|
```
|
31
|
-
You can choose between bootstrap-editable/bootstrap2-editable/jqueryui-editable/jquery-editable
|
32
51
|
|
52
|
+
Enable editing with jQuery:
|
33
53
|
|
34
|
-
You can also insert this file
|
35
54
|
```coffee
|
55
|
+
$('.editable').editable()
|
56
|
+
```
|
57
|
+
|
58
|
+
For custom inputs like the Wysihtml5 editor, add these dependencies:
|
59
|
+
|
60
|
+
```coffee
|
61
|
+
#= require editable/bootstrap-editable
|
62
|
+
#= require editable/inputs-ext/wysihtml5
|
63
|
+
#= require editable/inputs-ext/bootstrap-wysihtml5
|
64
|
+
#= require editable/inputs-ext/wysihtml5-editable
|
36
65
|
#= require editable/rails
|
37
66
|
```
|
38
67
|
|
39
|
-
|
68
|
+
And related stylesheets:
|
40
69
|
|
41
|
-
|
70
|
+
```css
|
71
|
+
//= require editable/bootstrap-editable
|
72
|
+
//= require editable/inputs-ext/bootstrap-wysihtml5
|
73
|
+
//= require editable/inputs-ext/wysiwyg-color
|
74
|
+
```
|
75
|
+
|
76
|
+
### Making Things Editable
|
77
|
+
|
78
|
+
`x-editable-rails` provides a helper method in your view to make your model values editable.
|
79
|
+
By default, you need to specify the model and property that should be editable.
|
80
|
+
A `span` element is rendered with `data-*` attributes used by `x-editable`.
|
42
81
|
|
43
82
|
```ruby
|
44
|
-
|
45
|
-
|
46
|
-
end
|
83
|
+
# the editable object and the attribute to edit
|
84
|
+
%h1= editable @model, :name
|
47
85
|
```
|
48
86
|
|
49
|
-
|
87
|
+
The helper method automatically adds these `data-*` attributes used by [x-editable](http://vitalets.github.io/x-editable/docs.html).
|
88
|
+
|
89
|
+
* **url** - Uses the `polymorphic_path(model)` helper method.
|
90
|
+
* **source** - Only populated if the value is a boolean to convert `true` or `false` to "Yes" and "No".
|
91
|
+
* **value** - Uses `model.name`. If `model.name` were a boolean value or if a `source` is specified, the `source` text would be displayed rather than the raw value. (Presumably the value is an ID and the source would have the text associated with that value.)
|
92
|
+
* **title** - The model and attribute name are used to create a capitalized title
|
93
|
+
* **placeholder** - Uses the `title` value by default
|
50
94
|
|
51
95
|
```ruby
|
52
|
-
%h1= editable @page, :name, e: @page.name
|
53
96
|
# editable object, what_you_want_update, e: exception - when is xeditable? false or can? :edit, object is false
|
97
|
+
%h1= editable @model, :name, url: model_path, value: @model.name.upcase
|
54
98
|
```
|
55
99
|
|
56
|
-
|
100
|
+
Here are some special features to enhance what's baked into [x-editable](http://vitalets.github.io/x-editable/docs.html):
|
101
|
+
|
102
|
+
* **type** - The type of input is automatically detected. By default, if the value is a boolean, the `type` is "select" with a built-in `source` that outputs "Yes" and "No" (unless another `source` is specified).
|
103
|
+
* **source** - In addition to hashes or arrays of hashes, you can also use an array of strings for a simpler structure if the name and value are the same:
|
104
|
+
|
57
105
|
```ruby
|
58
|
-
|
59
|
-
|
106
|
+
source = [ "Active", "Disabled" ]
|
107
|
+
editable @model, :enabled, source: source
|
60
108
|
```
|
61
109
|
|
62
|
-
|
110
|
+
* **value** - This option will override the `model.name` value
|
111
|
+
* **classes** - This is a custom option for `x-editable-rails` that will change the editable element's CSS class based on the selected value. Use the `source` hash structure to map a CSS class name to a value. (This [functionality](vendor/assets/javascripts/editable/rails/data_classes.js.coffee) is toggled when the value changes and the "save" event is triggered.)
|
112
|
+
|
63
113
|
```ruby
|
64
|
-
|
114
|
+
source = [ "Active", "Disabled" ]
|
115
|
+
classes = { "Active" => "label-success", "Disabled" => "label-default" }
|
116
|
+
editable @model, :enabled, source: source, classes: classes, class: "label"
|
65
117
|
```
|
66
118
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
```
|
71
|
-
|
72
|
-
|
73
|
-
|
119
|
+
* **nested** - Name of a nested attributes (such as [gobalize](https://github.com/globalize/globalize)'s `translations`)
|
120
|
+
* **nid** - ID of the nested attribute
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
%h1= editable @model, :name, nested: :translations, nid: @model.translation.id
|
124
|
+
|
125
|
+
# example of nested resource
|
126
|
+
%h1= editable [picture.gallery, picture], :name, nested: :translations, nid: picture.translation.id
|
74
127
|
```
|
75
128
|
|
76
|
-
|
77
|
-
1. data-model
|
78
|
-
2. data-name
|
79
|
-
3. data-url
|
129
|
+
### Authorization
|
80
130
|
|
81
|
-
|
82
|
-
1. data-nested
|
83
|
-
2. data-nid
|
131
|
+
Add a helper method to your controllers to indicate if `x-editable` should be enabled.
|
84
132
|
|
85
|
-
|
86
|
-
|
87
|
-
|
133
|
+
```ruby
|
134
|
+
def xeditable?
|
135
|
+
true # Or something like current_user.xeditable?
|
136
|
+
end
|
88
137
|
```
|
89
138
|
|
90
|
-
|
139
|
+
This gem requires [CanCan](https://github.com/ryanb/cancan) and checks the `:edit` permission for the model being edited.
|
91
140
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
#= require editable/inputs-ext/wysihtml5-editable
|
99
|
-
#= require editable/rails
|
141
|
+
```ruby
|
142
|
+
if xeditable? && can?(:edit, model)
|
143
|
+
... output x-editable HTML ...
|
144
|
+
else
|
145
|
+
... output uneditable value ...
|
146
|
+
end
|
100
147
|
```
|
101
148
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
149
|
+
* **e** - Specify a custom (error) message to display if the value isn't editable
|
150
|
+
|
151
|
+
### "Don't Repeat Yourself" Templates
|
152
|
+
|
153
|
+
To make your views cleaner, you can specify all your options for each class and attribute in a YAML configuration file.
|
154
|
+
Attributes where the `title` or `placeholder` are not different except maybe capitalized can be left out because they are automatically capitalized when rendered (see above).
|
155
|
+
|
156
|
+
This example uses the `MailingList` class and its attributes.
|
157
|
+
The attribute value can be a string, which is used as the `title` and `placeholder`.
|
158
|
+
If you want to specify other options, create a hash of options.
|
159
|
+
|
160
|
+
Save your YAML file in: `config/x-editable.yml`. Here is an example [example](config/x-editable.yml).
|
161
|
+
|
162
|
+
```yaml
|
163
|
+
class_options:
|
164
|
+
MailingList:
|
165
|
+
# Specify placeholder text for each attribute or a Hash of options
|
166
|
+
name: Mailing list name
|
167
|
+
enabled:
|
168
|
+
type: select
|
169
|
+
source:
|
170
|
+
- Active
|
171
|
+
- Disabled
|
172
|
+
reply_email:
|
173
|
+
type: email
|
174
|
+
title: Reply-to email
|
175
|
+
User:
|
176
|
+
email:
|
177
|
+
type: email
|
178
|
+
password:
|
179
|
+
type: password
|
180
|
+
mailing_lists:
|
181
|
+
type: select
|
182
|
+
# specify a URL to get source via AJAX (see x-editable docs)
|
183
|
+
source: <%= ::Rails.application.routes.url_helpers.mailing_lists_source_path %>
|
107
184
|
```
|
108
185
|
|
186
|
+
Now you can specify your editable fields without options because they will be inherited from your YAML config.
|
187
|
+
|
109
188
|
```ruby
|
110
|
-
=
|
189
|
+
model = MailingList.new
|
190
|
+
|
191
|
+
editable model, :name # type: "text", title: "Mailing list name"
|
192
|
+
editable model, :enabled # type: "select", title: "Enabled", source: [ "Active", "Disabled" ]
|
111
193
|
```
|
112
194
|
|
113
195
|
## Contributing
|
data/lib/x-editable-rails.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
module X
|
2
|
+
module Editable
|
3
|
+
module Rails
|
4
|
+
module Configuration
|
5
|
+
|
6
|
+
def method_options_for(object, method)
|
7
|
+
class_options_for(object).fetch(method, {})
|
8
|
+
end
|
9
|
+
|
10
|
+
def class_options_for(object)
|
11
|
+
class_options = options.fetch(:class_options, {})
|
12
|
+
class_options.fetch(object.class.name, {})
|
13
|
+
end
|
14
|
+
|
15
|
+
def class_options
|
16
|
+
options.fetch(:class_options, {})
|
17
|
+
end
|
18
|
+
|
19
|
+
def options
|
20
|
+
default_options.deep_merge custom_options
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_options
|
24
|
+
@defaults ||= begin
|
25
|
+
options = load_yaml_file File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "x-editable.yml"))
|
26
|
+
format_class_options! options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def custom_options
|
31
|
+
@custom_options ||= begin
|
32
|
+
options = load_yaml_file ::Rails.root.join("config", "x-editable.yml")
|
33
|
+
format_class_options! options
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_yaml_file(path)
|
38
|
+
source = File.read path
|
39
|
+
source = ERB.new(source).result
|
40
|
+
|
41
|
+
result = YAML.load(source)
|
42
|
+
result = {} if result.blank?
|
43
|
+
|
44
|
+
result.with_indifferent_access
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# if the specified options are a string, convert to Hash and make the string the title
|
50
|
+
def format_class_options!(options)
|
51
|
+
if class_options = options[:class_options]
|
52
|
+
class_options.each do |class_name, methods|
|
53
|
+
methods.each do |method, method_options|
|
54
|
+
unless method_options.is_a? Hash
|
55
|
+
methods[method] = { title: method_options }.with_indifferent_access
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
options
|
62
|
+
end
|
63
|
+
|
64
|
+
extend self
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,30 +1,142 @@
|
|
1
1
|
module X
|
2
2
|
module Editable
|
3
3
|
module Rails
|
4
|
-
module ViewHelpers
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
4
|
+
module ViewHelpers
|
5
|
+
#
|
6
|
+
# Options determine how the HTML tag is rendered and the remaining options are converted to data-* attributes.
|
7
|
+
#
|
8
|
+
# options:
|
9
|
+
# tag: tag name of element returned
|
10
|
+
# class: "class" attribute on element
|
11
|
+
# placeholder: "placeholder" attribute on element
|
12
|
+
# title: "title" attribute on element (defaults to placeholder)
|
13
|
+
# data: "data-*" attributes on element
|
14
|
+
# source: a Hash of friendly display values used by input elements based on (object) value
|
15
|
+
# - boolean shorthand ['Enabled', 'Disabled'] becomes { '1' => 'Enabled', '0' => 'Disabled' }
|
16
|
+
# - enumerable shorthand ['Yes', 'No', 'Maybe'] becomes { 'Yes' => 'Yes', 'No' => 'No', 'Maybe' => 'Maybe' }
|
17
|
+
# classes: a Hash of classes to add based on the value (same format and shorthands as source)
|
18
|
+
# value: override the object's value
|
19
|
+
#
|
20
|
+
def editable(object, method, options = {})
|
21
|
+
options = Configuration.method_options_for(object, method).deep_merge(options).with_indifferent_access
|
22
|
+
# merge data attributes for backwards-compatibility
|
23
|
+
options.merge! options.delete(:data){ Hash.new }
|
24
|
+
|
25
|
+
url = options.delete(:url){ polymorphic_path(object) }
|
26
|
+
object = object.last if object.kind_of?(Array)
|
27
|
+
value = options.delete(:value){ object.send(method) }
|
28
|
+
source = options[:source] ? format_source(options.delete(:source), value) : default_source_for(value)
|
29
|
+
classes = format_source(options.delete(:classes), value)
|
30
|
+
error = options.delete(:e)
|
31
|
+
|
32
|
+
if xeditable? and can?(:edit, object)
|
33
|
+
model = object.class.name.split('::').last.underscore
|
34
|
+
nid = options.delete(:nid)
|
35
|
+
nested = options.delete(:nested)
|
36
|
+
title = options.delete(:title) do
|
37
|
+
klass = nested ? object.class.const_get(nested.to_s.singularize.capitalize) : object.class
|
38
|
+
klass.human_attribute_name(method)
|
22
39
|
end
|
40
|
+
|
41
|
+
output_value = output_value_for(value)
|
42
|
+
css_list = options.delete(:class).to_s.split(/s+/).unshift('editable')
|
43
|
+
css_list << classes[output_value] if classes
|
44
|
+
|
45
|
+
css = css_list.compact.uniq.join(' ')
|
46
|
+
tag = options.delete(:tag){ 'span' }
|
47
|
+
placeholder = options.delete(:placeholder){ title }
|
48
|
+
|
49
|
+
# any remaining options become data attributes
|
50
|
+
data = {
|
51
|
+
type: options.delete(:type){ default_type_for(value) },
|
52
|
+
model: model,
|
53
|
+
name: method,
|
54
|
+
value: output_value,
|
55
|
+
placeholder: placeholder,
|
56
|
+
classes: classes,
|
57
|
+
source: source,
|
58
|
+
url: url,
|
59
|
+
nested: nested,
|
60
|
+
nid: nid
|
61
|
+
}.merge(options)
|
62
|
+
|
63
|
+
data.reject!{|_, value| value.nil?}
|
64
|
+
|
65
|
+
content_tag tag, class: css, title: title, data: data do
|
66
|
+
source_values_for(value, source).join('<br/>').html_safe
|
67
|
+
end
|
68
|
+
else
|
69
|
+
# create a friendly value using the source to display a default value (if no error message given)
|
70
|
+
error || source_values_for(value, source).join('<br/>').html_safe
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def output_value_for(value)
|
77
|
+
value = case value
|
78
|
+
when TrueClass
|
79
|
+
'1'
|
80
|
+
when FalseClass
|
81
|
+
'0'
|
82
|
+
when NilClass
|
83
|
+
''
|
84
|
+
when Array
|
85
|
+
value.map{|item| output_value_for item}.join(',')
|
86
|
+
else
|
87
|
+
value.to_s
|
88
|
+
end
|
89
|
+
|
90
|
+
value.html_safe
|
91
|
+
end
|
92
|
+
|
93
|
+
def source_values_for(value, source = nil)
|
94
|
+
source ||= default_source_for value
|
95
|
+
|
96
|
+
values = Array.wrap(value)
|
97
|
+
|
98
|
+
if source
|
99
|
+
values.map{|item| source[output_value_for item]}
|
23
100
|
else
|
24
|
-
|
101
|
+
values
|
25
102
|
end
|
26
103
|
end
|
104
|
+
|
105
|
+
def default_type_for(value)
|
106
|
+
case value
|
107
|
+
when TrueClass, FalseClass
|
108
|
+
'select'
|
109
|
+
when Array
|
110
|
+
'checklist'
|
111
|
+
else
|
112
|
+
'text'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def default_source_for(value)
|
117
|
+
case value
|
118
|
+
when TrueClass, FalseClass
|
119
|
+
{ '1' => 'Yes', '0' => 'No' }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# helper method that take some shorthand source definitions and reformats them
|
124
|
+
def format_source(source, value)
|
125
|
+
formatted_source = case value
|
126
|
+
when TrueClass, FalseClass
|
127
|
+
if source.is_a?(Array) && source.first.is_a?(String) && source.size == 2
|
128
|
+
{ '1' => source[0], '0' => source[1] }
|
129
|
+
end
|
130
|
+
when String
|
131
|
+
if source.is_a?(Array) && source.first.is_a?(String)
|
132
|
+
source.inject({}){|hash, key| hash.merge(key => key)}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
formatted_source || source
|
137
|
+
end
|
138
|
+
|
27
139
|
end
|
28
140
|
end
|
29
141
|
end
|
30
|
-
end
|
142
|
+
end
|
@@ -1,37 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
EditableForm.prototype.saveWithUrlHook = (value) ->
|
4
|
-
originalUrl = @options.url
|
5
|
-
model = @options.model
|
6
|
-
nestedName = @options.nested
|
7
|
-
nestedId = @options.nid
|
8
|
-
nestedLocale = @options.locale
|
9
|
-
@options.url = (params) =>
|
10
|
-
if typeof originalUrl == 'function'
|
11
|
-
originalUrl.call(@options.scope, params)
|
12
|
-
else if originalUrl? && @options.send != 'never'
|
13
|
-
myName = params.name
|
14
|
-
myValue = params.value.replace(/(\r\n|\n|\r)/gm,"<br/>")
|
15
|
-
obj = {}
|
16
|
-
if nestedName
|
17
|
-
nested = {}
|
18
|
-
nested[myName] = myValue
|
19
|
-
nested['id'] = nestedId
|
20
|
-
if nestedLocale
|
21
|
-
nested['locale'] = nestedLocale
|
22
|
-
obj[nestedName + '_attributes'] = nested
|
23
|
-
else
|
24
|
-
obj[myName] = myValue
|
25
|
-
params[model] = obj
|
26
|
-
delete params.name
|
27
|
-
delete params.value
|
28
|
-
delete params.pk
|
29
|
-
$.ajax($.extend({
|
30
|
-
url : originalUrl
|
31
|
-
data : params
|
32
|
-
type : 'PUT'
|
33
|
-
dataType: 'json'
|
34
|
-
}, @options.ajaxOptions))
|
35
|
-
@saveWithoutUrlHook(value)
|
36
|
-
EditableForm.prototype.saveWithoutUrlHook = EditableForm.prototype.save
|
37
|
-
EditableForm.prototype.save = EditableForm.prototype.saveWithUrlHook
|
1
|
+
#= require ./rails/editable_form
|
2
|
+
#= require ./rails/data_classes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
# make things editable that can be edited
|
3
|
+
|
4
|
+
# $('.editable').editable(
|
5
|
+
# success: (response, value) ->
|
6
|
+
# element = $(this)
|
7
|
+
# css = element.data('classes') || {}
|
8
|
+
# element.removeClass(class_name) for key, class_name of css
|
9
|
+
# element.addClass(css[value])
|
10
|
+
# element.css('background-color', '')
|
11
|
+
# )
|
12
|
+
|
13
|
+
# swap CSS classes when the value changes
|
14
|
+
|
15
|
+
jQuery ($) ->
|
16
|
+
$("[data-classes]").on "save", (e, data) ->
|
17
|
+
value = data.newValue
|
18
|
+
element = $(this)
|
19
|
+
css = element.data('classes') || {}
|
20
|
+
element.removeClass(class_name) for key, class_name of css
|
21
|
+
element.addClass(css[value])
|
22
|
+
element.css('background-color', '')
|
23
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
jQuery ($) ->
|
2
|
+
EditableForm = $.fn.editableform.Constructor
|
3
|
+
EditableForm.prototype.saveWithUrlHook = (value) ->
|
4
|
+
originalUrl = @options.url
|
5
|
+
model = @options.model
|
6
|
+
nestedName = @options.nested
|
7
|
+
nestedId = @options.nid
|
8
|
+
nestedLocale = @options.locale
|
9
|
+
@options.url = (params) =>
|
10
|
+
if typeof originalUrl == 'function'
|
11
|
+
originalUrl.call(@options.scope, params)
|
12
|
+
else if originalUrl? && @options.send != 'never'
|
13
|
+
myName = params.name
|
14
|
+
if typeof params.value == 'string'
|
15
|
+
myValue = params.value.replace(/(\r\n|\n|\r)/gm,"<br/>")
|
16
|
+
else
|
17
|
+
myValue = params.value
|
18
|
+
obj = {}
|
19
|
+
if nestedName
|
20
|
+
nested = {}
|
21
|
+
nested[myName] = myValue
|
22
|
+
nested['id'] = nestedId
|
23
|
+
if nestedLocale
|
24
|
+
nested['locale'] = nestedLocale
|
25
|
+
obj[nestedName + '_attributes'] = nested
|
26
|
+
else
|
27
|
+
obj[myName] = myValue
|
28
|
+
params[model] = obj
|
29
|
+
delete params.name
|
30
|
+
delete params.value
|
31
|
+
delete params.pk
|
32
|
+
$.ajax($.extend({
|
33
|
+
url : originalUrl
|
34
|
+
data : params
|
35
|
+
type : 'PUT'
|
36
|
+
dataType: 'json'
|
37
|
+
}, @options.ajaxOptions))
|
38
|
+
@saveWithoutUrlHook(value)
|
39
|
+
EditableForm.prototype.saveWithoutUrlHook = EditableForm.prototype.save
|
40
|
+
EditableForm.prototype.save = EditableForm.prototype.saveWithUrlHook
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: x-editable-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jiri Kolarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cancan
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: X-editable for Rails
|
56
70
|
email:
|
57
71
|
- jiri.kolarik@imin.cz
|
@@ -59,6 +73,7 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- lib/x-editable-rails/configuration.rb
|
62
77
|
- lib/x-editable-rails/version.rb
|
63
78
|
- lib/x-editable-rails/view_helpers.rb
|
64
79
|
- lib/x-editable-rails.rb
|
@@ -74,6 +89,8 @@ files:
|
|
74
89
|
- vendor/assets/javascripts/editable/inputs-ext/wysihtml5.js
|
75
90
|
- vendor/assets/javascripts/editable/jquery-editable-poshytip.js
|
76
91
|
- vendor/assets/javascripts/editable/jqueryui-editable.js
|
92
|
+
- vendor/assets/javascripts/editable/rails/data_classes.js.coffee
|
93
|
+
- vendor/assets/javascripts/editable/rails/editable_form.js.coffee
|
77
94
|
- vendor/assets/javascripts/editable/rails.js.coffee
|
78
95
|
- vendor/assets/stylesheets/editable/bootstrap-editable.scss
|
79
96
|
- vendor/assets/stylesheets/editable/bootstrap2-editable.scss
|
@@ -110,3 +127,4 @@ signing_key:
|
|
110
127
|
specification_version: 4
|
111
128
|
summary: X-editable for Rails
|
112
129
|
test_files: []
|
130
|
+
has_rdoc:
|