inline_forms 1.6.53 → 1.6.54

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDVlNzZmNmE5NTQ0YTNlMDJhYjVhNjY4ZjVhZDg5MjAyMjE5MDYwOQ==
4
+ NjA1YTU5ZDE2NzU2NTU3Zjk4ZDlhNGI4ZjA5ZjMyYTQ5NzkwM2UyOQ==
5
5
  data.tar.gz: !binary |-
6
- MWI0YjI5MzdmODViM2NlM2I2NGNkOTliN2ViY2M4ODJhYzhhYmM3MA==
6
+ YTU3YmI4NzQ3NTdiMjEzOTMyNWEyMjIyOTI5NzRlOGVlNjhlYWEyNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGZkMjg1NmI1YjY3Y2EyZGNhMWUzN2I5YzQ5NWQ2MmY2ZmFkZjgzNzFmMzQ3
10
- NmU1ZTJlNTZmNDAyYzk2NDI3MjI0MGY2NjQxNDE0NmY0NDFlMGE5YWE3NjRh
11
- YjljNGEyMTBjZmQ5ZmM2ZWM3OGIwNTAwODkzNzc5NTRjYWI2OWE=
9
+ YWViZWNlMzVjMjI5NDJlODg0M2FjYWYxNDZmMTcwYjVjOTY0OTY3MWU1YTI5
10
+ ZTE4ZGFiNjZlY2JhOGJkZWNjN2RiZDliNjZiMjRlNzhkMzcwMGQ5YTg2ZDQ4
11
+ N2IwMTlhYmE4ZTJlYTY4ZTI3MjgzMDY4YjljNGRlMTA3MjI3NWI=
12
12
  data.tar.gz: !binary |-
13
- YmUwNmI0Nzg2Nzc0Yzk1MDhjYzA1YjIwMDIyMDU1N2FmZDYyODg0ODI0YWU0
14
- MWU5MTA1MDI3YzQyNmI3OTU1MjUxMjhmZDQ0MTE3MjllYmQzNmRiMjkxMzU5
15
- NjM3NmE2YWU0YmZjMTA5YzAwNGMyZTJiYzljYjBlNmU3ZjlmMTA=
13
+ NDgxMDNmNTk3ZGJmNDNiOTJiODYxMmIyY2U0NDhkMjk2Yzg3MGUwNjJiMTcy
14
+ NzUxNGM0MTUyYjJhNDIzYmVjZGQ4NzA5ZDRmOGQ2MTY3ZmNiNjU3NGIxNzRl
15
+ NzM2MGU3MmI0NTE2NjMzNjFhYmYwMGNmODgyOWUzODQ5ZGQ0NGM=
@@ -0,0 +1,149 @@
1
+ # -*- encoding : utf-8 -*-
2
+ InlineForms::SPECIAL_COLUMN_TYPES[:dropdown_with_other]=:belongs_to
3
+
4
+ # dropdown
5
+ def dropdown_with_other_show(object, attribute)
6
+ foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym
7
+ id = object[foreign_key]
8
+ if id == 0
9
+ attribute_value = object[attribute.to_s + '_other']
10
+ attribute_value = "<i class='fi-plus'></i>".html_safe if attribute_value.empty? || attribute_value.nil?
11
+ else
12
+ attribute_value = object.send(attribute)._presentation rescue "<i class='fi-plus'></i>".html_safe
13
+ end
14
+ link_to_inline_edit object, attribute, attribute_value
15
+ end
16
+
17
+ def dropdown_with_other_edit(object, attribute)
18
+ foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym
19
+ # object.send('build_' + attribute.to_s) unless object.send(attribute)
20
+ o = attribute.capitalize.constantize
21
+ if cancan_enabled?
22
+ values = o.accessible_by(current_ability).order(o.order_by_clause)
23
+ else
24
+ values = o.order(o.order_by_clause)
25
+ end
26
+ values.each do |v|
27
+ v.name = v._presentation
28
+ end
29
+ values.sort_by! &:name
30
+ collection = values.map {|v|[v.name, v.id]}
31
+ collection << [object[attribute.to_s + '_other'], 0] unless object[attribute.to_s + '_other'].nil? || object[attribute.to_s + '_other'].empty?
32
+ out = '<div class="ui-widget">'
33
+ out << select('_' + object.class.to_s.underscore, foreign_key.to_sym, collection, {selected: object[foreign_key.to_sym], prompt: 'maake een keuze', id: '_' + object.class.to_s.underscore + '_' + foreign_key.to_s})
34
+ # collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_s.foreign_key.to_sym, values, 'id', 'name', :selected => object.send(attribute).id)
35
+ out << '</div>
36
+ <script>
37
+ (function( $ ) {
38
+ $.widget( "custom.combobox", {
39
+ _create: function() {
40
+ this.wrapper = $( "<span>" )
41
+ .addClass( "custom-combobox" )
42
+ .insertAfter( this.element );
43
+
44
+ this.element.hide();
45
+ this._createAutocomplete();
46
+ this._createShowAllButton();
47
+ },
48
+
49
+ _createAutocomplete: function() {
50
+ var selected = this.element.children( ":selected" ),
51
+ value = selected.val() ? selected.text() : "";
52
+
53
+ this.input = $( "<input name=\''
54
+
55
+ out << '_' + object.class.to_s.underscore + '[' + attribute.to_s + '_other]'
56
+
57
+ out << '\'>" )
58
+ .appendTo( this.wrapper )
59
+ .val( value )
60
+ .attr( "title", "" )
61
+ .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
62
+ .autocomplete({
63
+ delay: 0,
64
+ minLength: 0,
65
+ source: $.proxy( this, "_source" )
66
+ })
67
+ .tooltip({
68
+ tooltipClass: "ui-state-highlight"
69
+ });
70
+
71
+ this._on( this.input, {
72
+ autocompleteselect: function( event, ui ) {
73
+ ui.item.option.selected = true;
74
+ this._trigger( "select", event, {
75
+ item: ui.item.option
76
+ });
77
+ }
78
+ });
79
+ },
80
+
81
+ _createShowAllButton: function() {
82
+ var input = this.input,
83
+ wasOpen = false;
84
+
85
+ $( "<a>" )
86
+ .attr( "tabIndex", -1 )
87
+ .attr( "title", "Show All Items" )
88
+ .tooltip()
89
+ .appendTo( this.wrapper )
90
+ .button({
91
+ icons: {
92
+ primary: "ui-icon-triangle-1-s"
93
+ },
94
+ text: false
95
+ })
96
+ .removeClass( "ui-corner-all" )
97
+ .addClass( "custom-combobox-toggle ui-corner-right" )
98
+ .mousedown(function() {
99
+ wasOpen = input.autocomplete( "widget" ).is( ":visible" );
100
+ })
101
+ .click(function() {
102
+ input.focus();
103
+
104
+ // Close if already visible
105
+ if ( wasOpen ) {
106
+ return;
107
+ }
108
+
109
+ // Pass empty string as value to search for, displaying all results
110
+ input.autocomplete( "search", "" );
111
+ });
112
+ },
113
+
114
+ _source: function( request, response ) {
115
+ var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
116
+ response( this.element.children( "option" ).map(function() {
117
+ var text = $( this ).text();
118
+ if ( this.value && ( !request.term || matcher.test(text) ) )
119
+ return {
120
+ label: text,
121
+ value: text,
122
+ option: this
123
+ };
124
+ }) );
125
+ },
126
+ });
127
+ })( jQuery );
128
+
129
+ $(function() {
130
+ $( "'
131
+ out << '#_' + object.class.to_s.underscore + '_' + attribute.to_s.foreign_key.to_s
132
+ out << '" ).combobox();
133
+ });
134
+ </script>'
135
+ out.html_safe
136
+
137
+
138
+ end
139
+
140
+ def dropdown_with_other_update(object, attribute)
141
+ foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym
142
+ # if there is an attribute attr, then there must be an attribute attr_other
143
+ other = params[('_' + object.class.to_s.underscore).to_sym][(attribute.to_s + "_other").to_sym]
144
+ # see if it matches anything
145
+ match = attribute.capitalize.constantize.where(name: other).first # problem if there are dupes!
146
+ match.nil? ? object[foreign_key] = 0 : object[foreign_key] = match.id # problem if there is a record with id: 0 !
147
+ match.nil? ? object[attribute.to_s + '_other'] = other : object[attribute.to_s + '_other'] = nil
148
+ end
149
+
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineForms
3
- VERSION = "1.6.53"
3
+ VERSION = "1.6.54"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.53
4
+ version: 1.6.54
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rvm
@@ -189,6 +189,7 @@ files:
189
189
  - lib/app/helpers/form_elements/dns_records.rb
190
190
  - lib/app/helpers/form_elements/dropdown.rb
191
191
  - lib/app/helpers/form_elements/dropdown_with_integers.rb
192
+ - lib/app/helpers/form_elements/dropdown_with_other.rb
192
193
  - lib/app/helpers/form_elements/dropdown_with_values.rb
193
194
  - lib/app/helpers/form_elements/file_field.rb
194
195
  - lib/app/helpers/form_elements/geo_code_curacao.rb