x-editable-rails 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/x-editable-rails/version.rb +2 -2
- data/lib/x-editable-rails/view_helpers.rb +40 -32
- data/vendor/assets/javascripts/editable/inputs-ext/wysihtml5-editable.js +9 -1
- data/vendor/assets/javascripts/editable/rails/editable_form.js.coffee +12 -12
- data/vendor/assets/stylesheets/editable/inputs-ext/{bootstrap-typehead.css → bootstrap-typeahead.css} +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 147a7545378c08302b0aa3078eefb5b34f8cfb36
|
4
|
+
data.tar.gz: f93643c63b673cb323982194ca905a0eec38a90c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09d634d226d06a25c1ba9a13977da472744b42674969f0172fc2a14e38b20182551c15737fc996b32c92c65d0a5e3f7ddcfd04da311e31ec0243590f15bb3c9e
|
7
|
+
data.tar.gz: 0b3a64951964c9f5451ac7f5deb3954a4852657151f541eca258f9cde0b1a924295bd767d3da2e771ffd717248f4531bd0d3c6a17ccf58c85775df0376fa4a9e
|
data/README.md
CHANGED
@@ -120,7 +120,7 @@ classes = { "Active" => "label-success", "Disabled" => "label-default" }
|
|
120
120
|
editable @model, :enabled, source: source, classes: classes, class: "label"
|
121
121
|
```
|
122
122
|
|
123
|
-
* **nested** - Name of a nested attributes (such as [
|
123
|
+
* **nested** - Name of a nested attributes (such as [globalize](https://github.com/globalize/globalize)'s `translations`)
|
124
124
|
* **nid** - ID of the nested attribute
|
125
125
|
|
126
126
|
```ruby
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
1
3
|
module X
|
2
4
|
module Editable
|
3
5
|
module Rails
|
@@ -16,63 +18,69 @@ module X
|
|
16
18
|
# - enumerable shorthand ['Yes', 'No', 'Maybe'] becomes { 'Yes' => 'Yes', 'No' => 'No', 'Maybe' => 'Maybe' }
|
17
19
|
# classes: a Hash of classes to add based on the value (same format and shorthands as source)
|
18
20
|
# value: override the object's value
|
19
|
-
#
|
21
|
+
#
|
20
22
|
def editable(object, method, options = {})
|
21
23
|
options = Configuration.method_options_for(object, method).deep_merge(options).with_indifferent_access
|
22
24
|
# merge data attributes for backwards-compatibility
|
23
25
|
options.merge! options.delete(:data){ Hash.new }
|
24
|
-
|
26
|
+
|
25
27
|
url = options.delete(:url){ polymorphic_path(object) }
|
26
28
|
object = object.last if object.kind_of?(Array)
|
27
29
|
value = options.delete(:value){ object.send(method) }
|
28
30
|
source = options[:source] ? format_source(options.delete(:source), value) : default_source_for(value)
|
29
31
|
classes = format_source(options.delete(:classes), value)
|
30
32
|
error = options.delete(:e)
|
31
|
-
|
33
|
+
html_options = options.delete(:html){ Hash.new }
|
34
|
+
|
32
35
|
if xeditable?(object)
|
33
|
-
model = object.
|
36
|
+
model = object.model_name.to_s.underscore
|
34
37
|
nid = options.delete(:nid)
|
35
38
|
nested = options.delete(:nested)
|
36
39
|
title = options.delete(:title) do
|
37
40
|
klass = nested ? object.class.const_get(nested.to_s.singularize.capitalize) : object.class
|
38
41
|
klass.human_attribute_name(method)
|
39
42
|
end
|
40
|
-
|
43
|
+
|
41
44
|
output_value = output_value_for(value)
|
42
45
|
css_list = options.delete(:class).to_s.split(/\s+/).unshift('editable')
|
43
46
|
css_list << classes[output_value] if classes
|
44
|
-
|
47
|
+
type = options.delete(:type){ default_type_for(value) }
|
45
48
|
css = css_list.compact.uniq.join(' ')
|
46
49
|
tag = options.delete(:tag){ 'span' }
|
47
50
|
placeholder = options.delete(:placeholder){ title }
|
48
|
-
|
51
|
+
|
49
52
|
# any remaining options become data attributes
|
50
53
|
data = {
|
51
|
-
type:
|
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,
|
54
|
+
type: type,
|
55
|
+
model: model,
|
56
|
+
name: method,
|
57
|
+
value: ( type == 'wysihtml5' ? Base64.encode64(output_value) : output_value ),
|
58
|
+
placeholder: placeholder,
|
59
|
+
classes: classes,
|
60
|
+
source: source,
|
61
|
+
url: url,
|
62
|
+
nested: nested,
|
60
63
|
nid: nid
|
61
64
|
}.merge(options)
|
62
|
-
|
65
|
+
|
63
66
|
data.reject!{|_, value| value.nil?}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
|
68
|
+
html_options.update({
|
69
|
+
class: css,
|
70
|
+
title: title,
|
71
|
+
data: data
|
72
|
+
})
|
73
|
+
|
74
|
+
content_tag tag, html_options do
|
75
|
+
safe_join(source_values_for(value, source), tag(:br)) unless %w(select checklist).include? data[:type]
|
67
76
|
end
|
68
77
|
else
|
69
|
-
value = value.try(:html_safe) unless value.kind_of?(TrueClass) or value.kind_of?(FalseClass)
|
70
78
|
error || safe_join(source_values_for(value, source), tag(:br))
|
71
79
|
end
|
72
80
|
end
|
73
|
-
|
81
|
+
|
74
82
|
private
|
75
|
-
|
83
|
+
|
76
84
|
def output_value_for(value)
|
77
85
|
value = case value
|
78
86
|
when TrueClass
|
@@ -86,22 +94,22 @@ module X
|
|
86
94
|
else
|
87
95
|
value.to_s
|
88
96
|
end
|
89
|
-
|
97
|
+
|
90
98
|
value
|
91
99
|
end
|
92
|
-
|
100
|
+
|
93
101
|
def source_values_for(value, source = nil)
|
94
102
|
source ||= default_source_for value
|
95
|
-
|
103
|
+
|
96
104
|
values = Array.wrap(value)
|
97
|
-
|
105
|
+
|
98
106
|
if source && ( source.first.is_a?(String) || source.kind_of?(Hash) )
|
99
107
|
values.map{|item| source[output_value_for item]}
|
100
108
|
else
|
101
109
|
values
|
102
110
|
end
|
103
111
|
end
|
104
|
-
|
112
|
+
|
105
113
|
def default_type_for(value)
|
106
114
|
case value
|
107
115
|
when TrueClass, FalseClass
|
@@ -112,14 +120,14 @@ module X
|
|
112
120
|
'text'
|
113
121
|
end
|
114
122
|
end
|
115
|
-
|
123
|
+
|
116
124
|
def default_source_for(value)
|
117
125
|
case value
|
118
126
|
when TrueClass, FalseClass
|
119
127
|
{ '1' => 'Yes', '0' => 'No' }
|
120
128
|
end
|
121
129
|
end
|
122
|
-
|
130
|
+
|
123
131
|
# helper method that take some shorthand source definitions and reformats them
|
124
132
|
def format_source(source, value)
|
125
133
|
formatted_source = case value
|
@@ -134,10 +142,10 @@ module X
|
|
134
142
|
source
|
135
143
|
end
|
136
144
|
end
|
137
|
-
|
145
|
+
|
138
146
|
formatted_source || source
|
139
147
|
end
|
140
|
-
|
148
|
+
|
141
149
|
end
|
142
150
|
end
|
143
151
|
end
|
@@ -72,9 +72,12 @@ $(function(){
|
|
72
72
|
|
73
73
|
return deferred.promise();
|
74
74
|
},
|
75
|
+
|
76
|
+
valueIsEncoded: true,
|
75
77
|
|
76
78
|
value2html: function(value, element) {
|
77
79
|
$(element).html(value);
|
80
|
+
this.valueIsEncoded = false;
|
78
81
|
},
|
79
82
|
|
80
83
|
html2value: function(html) {
|
@@ -82,8 +85,13 @@ $(function(){
|
|
82
85
|
},
|
83
86
|
|
84
87
|
value2input: function(value) {
|
88
|
+
value = (this.valueIsEncoded ? this.base65decode(value) : value);
|
85
89
|
this.$input.data("wysihtml5").editor.setValue(value, true);
|
86
|
-
},
|
90
|
+
},
|
91
|
+
|
92
|
+
base65decode: function(value) {
|
93
|
+
return decodeURIComponent( escape( atob( value.replace(/\s/g, ''))));
|
94
|
+
},
|
87
95
|
|
88
96
|
activate: function() {
|
89
97
|
this.$input.data("wysihtml5").editor.focus();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
unless EditableForm
|
2
2
|
EditableForm = $.fn.editableform.Constructor
|
3
3
|
EditableForm.prototype.saveWithUrlHook = (value) ->
|
4
4
|
originalUrl = @options.url
|
@@ -6,46 +6,46 @@ jQuery ($) ->
|
|
6
6
|
nestedName = @options.nested
|
7
7
|
nestedId = @options.nid
|
8
8
|
nestedLocale = @options.locale
|
9
|
-
|
9
|
+
|
10
10
|
@options.url = (params) =>
|
11
11
|
if typeof originalUrl == 'function'
|
12
12
|
originalUrl.call(@options.scope, params)
|
13
13
|
else if originalUrl? && @options.send != 'never'
|
14
14
|
myName = params.name
|
15
15
|
myValue = params.value
|
16
|
-
|
16
|
+
|
17
17
|
# if there are no values in a list, add a blank value so Rails knows all values were removed
|
18
18
|
if Object.prototype.toString.call(params.value) == '[object Array]' && params.value.length == 0
|
19
19
|
params.value.push("")
|
20
|
-
|
20
|
+
|
21
21
|
obj = {}
|
22
|
-
|
22
|
+
|
23
23
|
if nestedName
|
24
24
|
nested = {}
|
25
25
|
nested[myName] = myValue
|
26
26
|
nested['id'] = nestedId
|
27
|
-
|
27
|
+
|
28
28
|
if nestedLocale
|
29
29
|
nested['locale'] = nestedLocale
|
30
|
-
|
30
|
+
|
31
31
|
obj[nestedName + '_attributes'] = nested
|
32
32
|
else
|
33
33
|
obj[myName] = myValue
|
34
|
-
|
34
|
+
|
35
35
|
params[model] = obj
|
36
|
-
|
36
|
+
|
37
37
|
delete params.name
|
38
38
|
delete params.value
|
39
39
|
delete params.pk
|
40
|
-
|
40
|
+
|
41
41
|
$.ajax($.extend({
|
42
42
|
url: originalUrl
|
43
43
|
data: params
|
44
44
|
type: 'PUT'
|
45
45
|
dataType: 'json'
|
46
46
|
}, @options.ajaxOptions))
|
47
|
-
|
47
|
+
|
48
48
|
@saveWithoutUrlHook(value)
|
49
|
-
|
49
|
+
|
50
50
|
EditableForm.prototype.saveWithoutUrlHook = EditableForm.prototype.save
|
51
51
|
EditableForm.prototype.save = EditableForm.prototype.saveWithUrlHook
|
File without changes
|
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.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jiri Kolarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- vendor/assets/stylesheets/editable/bootstrap-editable.scss
|
87
87
|
- vendor/assets/stylesheets/editable/bootstrap2-editable.scss
|
88
88
|
- vendor/assets/stylesheets/editable/inputs-ext/address.css
|
89
|
-
- vendor/assets/stylesheets/editable/inputs-ext/bootstrap-
|
89
|
+
- vendor/assets/stylesheets/editable/inputs-ext/bootstrap-typeahead.css
|
90
90
|
- vendor/assets/stylesheets/editable/inputs-ext/bootstrap-wysihtml5.css
|
91
91
|
- vendor/assets/stylesheets/editable/inputs-ext/wysiwyg-color.css
|
92
92
|
- vendor/assets/stylesheets/editable/jquery-editable.scss
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.4.8
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: X-editable for Rails
|