inline_forms 7.11.0 → 7.13.2
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/.ruby-version +1 -1
- data/CHANGELOG.md +70 -0
- data/app/controllers/inline_forms_controller.rb +21 -0
- data/app/helpers/inline_forms_helper.rb +1 -6
- data/app/views/inline_forms/_versions_list.html.erb +16 -5
- data/archived/form_elements/README.md +1 -7
- data/inline_forms.gemspec +3 -3
- data/lib/generators/inline_forms_generator.rb +1 -1
- data/lib/inline_forms/form_element_registry.rb +46 -0
- data/lib/inline_forms/form_elements/audio_field_helper.rb +36 -0
- data/lib/inline_forms/form_elements/check_box_helper.rb +23 -0
- data/lib/inline_forms/form_elements/check_list_helper.rb +45 -0
- data/lib/inline_forms/form_elements/ckeditor_helper.rb +23 -0
- data/lib/inline_forms/form_elements/date_helper.rb +28 -0
- data/lib/inline_forms/form_elements/decimal_field_helper.rb +22 -0
- data/lib/inline_forms/form_elements/devise_password_field_helper.rb +26 -0
- data/lib/inline_forms/form_elements/dns_records_helper.rb +23 -0
- data/lib/inline_forms/form_elements/dropdown_helper.rb +58 -0
- data/lib/inline_forms/form_elements/dropdown_with_integers_helper.rb +29 -0
- data/lib/inline_forms/form_elements/dropdown_with_other_helper.rb +160 -0
- data/lib/inline_forms/form_elements/dropdown_with_values_helper.rb +40 -0
- data/lib/inline_forms/form_elements/dropdown_with_values_with_stars_helper.rb +24 -0
- data/lib/inline_forms/form_elements/file_field_helper.rb +27 -0
- data/lib/inline_forms/form_elements/header_helper.rb +24 -0
- data/lib/inline_forms/form_elements/helper_includes.rb +15 -0
- data/lib/inline_forms/form_elements/image_field_helper.rb +31 -0
- data/lib/inline_forms/form_elements/info_helper.rb +52 -0
- data/lib/inline_forms/form_elements/info_list_helper.rb +30 -0
- data/lib/inline_forms/form_elements/integer_field_helper.rb +22 -0
- data/lib/inline_forms/form_elements/money_field_helper.rb +22 -0
- data/lib/inline_forms/form_elements/month_select_helper.rb +24 -0
- data/lib/inline_forms/form_elements/month_year_picker_helper.rb +27 -0
- data/lib/inline_forms/form_elements/multi_image_field_helper.rb +31 -0
- data/lib/inline_forms/form_elements/pdf_link_helper.rb +41 -0
- data/lib/inline_forms/form_elements/plain_text_area_helper.rb +26 -0
- data/lib/inline_forms/form_elements/plain_text_helper.rb +31 -0
- data/lib/inline_forms/form_elements/question_list_helper.rb +52 -0
- data/lib/inline_forms/form_elements/radio_button_helper.rb +34 -0
- data/lib/inline_forms/form_elements/rich_text_helper.rb +44 -0
- data/lib/inline_forms/form_elements/scale_with_integers_helper.rb +30 -0
- data/lib/inline_forms/form_elements/scale_with_values_helper.rb +29 -0
- data/lib/inline_forms/form_elements/simple_file_field_helper.rb +36 -0
- data/lib/inline_forms/form_elements/slider_with_values_helper.rb +99 -0
- data/lib/inline_forms/form_elements/text_area_helper.rb +26 -0
- data/lib/inline_forms/form_elements/text_area_without_ckeditor_helper.rb +27 -0
- data/lib/inline_forms/form_elements/text_field_helper.rb +26 -0
- data/lib/inline_forms/form_elements/time_helper.rb +28 -0
- data/lib/inline_forms/form_elements.rb +27 -0
- data/lib/inline_forms/version.rb +1 -1
- data/lib/inline_forms.rb +19 -3
- data/script/migrate_form_elements.rb +62 -0
- metadata +52 -48
- data/app/helpers/form_elements/audio_field.rb +0 -28
- data/app/helpers/form_elements/check_box.rb +0 -16
- data/app/helpers/form_elements/check_list.rb +0 -37
- data/app/helpers/form_elements/ckeditor.rb +0 -15
- data/app/helpers/form_elements/date.rb +0 -20
- data/app/helpers/form_elements/decimal_field.rb +0 -15
- data/app/helpers/form_elements/devise_password_field.rb +0 -19
- data/app/helpers/form_elements/dns_records.rb +0 -15
- data/app/helpers/form_elements/dropdown.rb +0 -50
- data/app/helpers/form_elements/dropdown_with_integers.rb +0 -21
- data/app/helpers/form_elements/dropdown_with_other.rb +0 -153
- data/app/helpers/form_elements/dropdown_with_values.rb +0 -32
- data/app/helpers/form_elements/dropdown_with_values_with_stars.rb +0 -16
- data/app/helpers/form_elements/file_field.rb +0 -20
- data/app/helpers/form_elements/header.rb +0 -17
- data/app/helpers/form_elements/image_field.rb +0 -24
- data/app/helpers/form_elements/info.rb +0 -44
- data/app/helpers/form_elements/info_list.rb +0 -22
- data/app/helpers/form_elements/integer_field.rb +0 -15
- data/app/helpers/form_elements/money_field.rb +0 -15
- data/app/helpers/form_elements/month_select.rb +0 -16
- data/app/helpers/form_elements/month_year_picker.rb +0 -19
- data/app/helpers/form_elements/multi_image_field.rb +0 -24
- data/app/helpers/form_elements/pdf_link.rb +0 -33
- data/app/helpers/form_elements/plain_text.rb +0 -23
- data/app/helpers/form_elements/plain_text_area.rb +0 -18
- data/app/helpers/form_elements/question_list.rb +0 -44
- data/app/helpers/form_elements/radio_button.rb +0 -27
- data/app/helpers/form_elements/rich_text.rb +0 -36
- data/app/helpers/form_elements/scale_with_integers.rb +0 -23
- data/app/helpers/form_elements/scale_with_values.rb +0 -22
- data/app/helpers/form_elements/simple_file_field.rb +0 -28
- data/app/helpers/form_elements/slider_with_values.rb +0 -91
- data/app/helpers/form_elements/text_area.rb +0 -18
- data/app/helpers/form_elements/text_area_without_ckeditor.rb +0 -19
- data/app/helpers/form_elements/text_field.rb +0 -18
- data/app/helpers/form_elements/time.rb +0 -21
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module DropdownWithOtherHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
# dropdown
|
|
9
|
+
def dropdown_with_other_show(object, attribute)
|
|
10
|
+
attribute = attribute.to_s
|
|
11
|
+
foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym
|
|
12
|
+
id = object[foreign_key]
|
|
13
|
+
if id == 0
|
|
14
|
+
attribute_value = object[attribute + '_other']
|
|
15
|
+
attribute_value = "<i class='fi-plus'></i>".html_safe if attribute_value.nil? || attribute_value.empty?
|
|
16
|
+
else
|
|
17
|
+
attribute_value = object.send(attribute)._presentation rescue "<i class='fi-plus'></i>".html_safe
|
|
18
|
+
end
|
|
19
|
+
link_to_inline_edit object, attribute, attribute_value, from_callee: __callee__
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def dropdown_with_other_edit(object, attribute)
|
|
23
|
+
attribute = attribute.to_s
|
|
24
|
+
foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym
|
|
25
|
+
o = attribute.camelcase.constantize
|
|
26
|
+
values = o.all
|
|
27
|
+
values = o.accessible_by(current_ability) if cancan_enabled?
|
|
28
|
+
values.each do |v|
|
|
29
|
+
v.name = v._presentation
|
|
30
|
+
end
|
|
31
|
+
# values.sort_by(&:name)
|
|
32
|
+
|
|
33
|
+
collection = values.map {|v|[v.name, v.id]}
|
|
34
|
+
collection << [object[attribute + '_other'], 0] unless object[attribute + '_other'].nil? || object[attribute + '_other'].empty?
|
|
35
|
+
out = '<div class="ui-widget">'
|
|
36
|
+
out << select('_' + object.class.to_s.underscore, foreign_key.to_sym, collection, {selected: object[foreign_key.to_sym]}, {id: '_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + foreign_key.to_s})
|
|
37
|
+
out << '</div>
|
|
38
|
+
<script>
|
|
39
|
+
(function( $ ) {
|
|
40
|
+
$.widget( "custom.combobox", {
|
|
41
|
+
_create: function() {
|
|
42
|
+
this.wrapper = $( "<span>" )
|
|
43
|
+
.addClass( "custom-combobox" )
|
|
44
|
+
.insertAfter( this.element );
|
|
45
|
+
|
|
46
|
+
this.element.hide();
|
|
47
|
+
this._createAutocomplete();
|
|
48
|
+
this._createShowAllButton();
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
_createAutocomplete: function() {
|
|
52
|
+
var selected = this.element.children( ":selected" ),
|
|
53
|
+
value = selected.val() ? selected.text() : "";
|
|
54
|
+
|
|
55
|
+
this.input = $( "<input name=\''
|
|
56
|
+
|
|
57
|
+
out << '_' + object.class.to_s.underscore + '[' + attribute + '_other]'
|
|
58
|
+
|
|
59
|
+
out << '\'>" )
|
|
60
|
+
.appendTo( this.wrapper )
|
|
61
|
+
.val( value )
|
|
62
|
+
.attr( "title", "" )
|
|
63
|
+
.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
|
|
64
|
+
.autocomplete({
|
|
65
|
+
delay: 0,
|
|
66
|
+
minLength: 0,
|
|
67
|
+
source: $.proxy( this, "_source" )
|
|
68
|
+
})
|
|
69
|
+
.tooltip({
|
|
70
|
+
tooltipClass: "ui-state-highlight"
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
this._on( this.input, {
|
|
74
|
+
autocompleteselect: function( event, ui ) {
|
|
75
|
+
ui.item.option.selected = true;
|
|
76
|
+
this._trigger( "select", event, {
|
|
77
|
+
item: ui.item.option
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
_createShowAllButton: function() {
|
|
84
|
+
var input = this.input,
|
|
85
|
+
wasOpen = false;
|
|
86
|
+
|
|
87
|
+
$( "<a>" )
|
|
88
|
+
.attr( "tabIndex", -1 )
|
|
89
|
+
.attr( "title", "Show All Items" )
|
|
90
|
+
.tooltip()
|
|
91
|
+
.appendTo( this.wrapper )
|
|
92
|
+
.button({
|
|
93
|
+
icons: {
|
|
94
|
+
primary: "ui-icon-triangle-1-s"
|
|
95
|
+
},
|
|
96
|
+
text: false
|
|
97
|
+
})
|
|
98
|
+
.removeClass( "ui-corner-all" )
|
|
99
|
+
.addClass( "custom-combobox-toggle ui-corner-right" )
|
|
100
|
+
.mousedown(function() {
|
|
101
|
+
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
|
|
102
|
+
})
|
|
103
|
+
.click(function() {
|
|
104
|
+
input.focus();
|
|
105
|
+
|
|
106
|
+
// Close if already visible
|
|
107
|
+
if ( wasOpen ) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Pass empty string as value to search for, displaying all results
|
|
112
|
+
input.autocomplete( "search", "" );
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
_source: function( request, response ) {
|
|
117
|
+
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
|
|
118
|
+
response( this.element.children( "option" ).map(function() {
|
|
119
|
+
var text = $( this ).text();
|
|
120
|
+
if ( this.value && ( !request.term || matcher.test(text) ) )
|
|
121
|
+
return {
|
|
122
|
+
label: text,
|
|
123
|
+
value: text,
|
|
124
|
+
option: this
|
|
125
|
+
};
|
|
126
|
+
}) );
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
})( jQuery );
|
|
130
|
+
|
|
131
|
+
$(function() {
|
|
132
|
+
$( "'
|
|
133
|
+
out << '#_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.foreign_key.to_s
|
|
134
|
+
out << '" ).combobox();
|
|
135
|
+
});
|
|
136
|
+
</script>'
|
|
137
|
+
out.html_safe
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def dropdown_with_other_update(object, attribute)
|
|
143
|
+
attribute = attribute.to_s
|
|
144
|
+
foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.foreign_key.to_sym
|
|
145
|
+
# if there is an attribute attr, then there must be an attribute attr_other
|
|
146
|
+
other = params[('_' + object.class.to_s.underscore).to_sym][(attribute + "_other").to_sym]
|
|
147
|
+
# see if it matches anything (but we need to look at I18n too!
|
|
148
|
+
lookup_model = attribute.camelcase.constantize
|
|
149
|
+
name_field = 'name_' + I18n.locale.to_s
|
|
150
|
+
name_field = 'name' unless lookup_model.new.respond_to? name_field
|
|
151
|
+
puts 'XXXXXXXXXXXXXXXXXXXX ' + name_field.inspect
|
|
152
|
+
match = lookup_model.where(name_field.to_sym => other).first # problem if there are dupes!
|
|
153
|
+
puts 'XXXXXXXXXXXXXXXXXXXX ' + match.inspect
|
|
154
|
+
match.nil? ? object[foreign_key] = 0 : object[foreign_key] = match.id # problem if there is a record with id: 0 !
|
|
155
|
+
match.nil? ? object[attribute + '_other'] = other : object[attribute + '_other'] = nil
|
|
156
|
+
end
|
|
157
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module DropdownWithValuesHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
# dropdown_with_values
|
|
9
|
+
def dropdown_with_values_show(object, attribute)
|
|
10
|
+
values = attribute_values(object, attribute)
|
|
11
|
+
link_to_inline_edit object, attribute, object.send(attribute) ? t(values.assoc(object.send(attribute))[1]) : "<i class='fi-plus'></i>".html_safe, from_callee: __callee__
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def dropdown_with_values_edit(object, attribute)
|
|
15
|
+
# the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
|
|
16
|
+
values = attribute_values(object, attribute)
|
|
17
|
+
|
|
18
|
+
attributes = @inline_forms_attribute_list || object.inline_forms_attribute_list
|
|
19
|
+
options_disabled = attributes.assoc(attribute.to_sym)[4]
|
|
20
|
+
|
|
21
|
+
collection_select( ('_' + object.class.to_s.underscore).to_sym,
|
|
22
|
+
attribute.to_sym,
|
|
23
|
+
values, 'first', 'last',
|
|
24
|
+
:selected => object.send(attribute),
|
|
25
|
+
disabled: options_disabled,
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def dropdown_with_values_update(object, attribute)
|
|
30
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dropdown_with_values_info(object, attribute)
|
|
34
|
+
values = attribute_values(object, attribute)
|
|
35
|
+
t(values.assoc(object.send(attribute))[1]) rescue '-'
|
|
36
|
+
end
|
|
37
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module DropdownWithValuesWithStarsHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
# dropdown_with_values_with_stars
|
|
9
|
+
def dropdown_with_values_with_stars_show(object, attribute)
|
|
10
|
+
values = attribute_values(object, attribute)
|
|
11
|
+
link_to_inline_edit object, attribute, (object[attribute].nil? || object[attribute] == 0) ? "<i class='fi-plus'></i>".html_safe : image_tag(object[attribute].to_s + 'stars.png'), from_callee: __callee__
|
|
12
|
+
end
|
|
13
|
+
def dropdown_with_values_with_stars_edit(object, attribute)
|
|
14
|
+
# the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
|
|
15
|
+
values = attribute_values(object, attribute)
|
|
16
|
+
collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
|
|
17
|
+
end
|
|
18
|
+
def dropdown_with_values_with_stars_update(object, attribute)
|
|
19
|
+
object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
|
|
20
|
+
end
|
|
21
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module FileFieldHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def file_field_show(object, attribute)
|
|
9
|
+
o = object.send(attribute)
|
|
10
|
+
msg = o.to_s
|
|
11
|
+
if o.send(:present?)
|
|
12
|
+
msg = "replace | <a href='#{o.send(:url)}'>#{o.send(:path).gsub(/^.*\//,'')}</a>".html_safe
|
|
13
|
+
end
|
|
14
|
+
link_to_inline_edit object, attribute, msg, from_callee: __callee__
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def file_field_edit(object, attribute)
|
|
18
|
+
file_field_tag attribute, :class => 'input_text_field'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def file_field_update(object, attribute)
|
|
22
|
+
object.send(attribute.to_s + '=', params[attribute.to_sym])
|
|
23
|
+
end
|
|
24
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module HeaderHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def header_show(object, attribute)
|
|
9
|
+
# show the header which is the translated fake attribute
|
|
10
|
+
attribute
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def header_edit(object, attribute)
|
|
14
|
+
# just show the header
|
|
15
|
+
attribute
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def header_update(object, attribute)
|
|
19
|
+
# do absolutely nothing
|
|
20
|
+
end
|
|
21
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InlineForms
|
|
4
|
+
module FormElements
|
|
5
|
+
# Mixes every form-element helper module into InlineFormsHelper so views
|
|
6
|
+
# keep calling `text_field_show`, etc. (see name_list.html.erb).
|
|
7
|
+
module HelperIncludes
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do
|
|
11
|
+
InlineForms::FormElements.helper_modules.each { |mod| include mod }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module ImageFieldHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def image_field_show(object, attribute)
|
|
9
|
+
o = object.send(attribute)
|
|
10
|
+
msg = "<i class='fi-plus'></i>".html_safe
|
|
11
|
+
if o.send(:present?)
|
|
12
|
+
if o.respond_to? :palm
|
|
13
|
+
msg = image_tag(o.send(:palm).send(:url))
|
|
14
|
+
else
|
|
15
|
+
msg = image_tag(o.send(:url))
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
link_to_inline_edit object, attribute, msg, from_callee: __callee__
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def image_field_edit(object, attribute)
|
|
22
|
+
file_field_tag attribute, class: 'input_text_field'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def image_field_update(object, attribute)
|
|
26
|
+
object.send(attribute.to_s + '=', params[attribute.to_sym])
|
|
27
|
+
end
|
|
28
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module InfoHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def info_show(object, attribute)
|
|
9
|
+
# show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
|
|
10
|
+
o = object.send(attribute)
|
|
11
|
+
o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
|
|
12
|
+
o = o._presentation if o.respond_to?(:_presentation)
|
|
13
|
+
o
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def info_edit(object, attribute)
|
|
17
|
+
o = object.send(attribute)
|
|
18
|
+
o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
|
|
19
|
+
o = o._presentation if o.respond_to?(:_presentation)
|
|
20
|
+
o
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def info_update(object, attribute)
|
|
24
|
+
# do absolutely nothing
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def info_info(object, attribute)
|
|
28
|
+
# show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
|
|
29
|
+
o = object.send(attribute)
|
|
30
|
+
o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
|
|
31
|
+
o = o._presentation if o.respond_to?(:_presentation)
|
|
32
|
+
o
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
#module ActionView::Helpers::DateHelper
|
|
37
|
+
#
|
|
38
|
+
# def distance_of_time_in_words_to_now_with_future(from_time, include_seconds = false)
|
|
39
|
+
# if from_time > Time.now()
|
|
40
|
+
# 'in ' + distance_of_time_in_words_to_now_without_future(from_time, include_seconds)
|
|
41
|
+
# else
|
|
42
|
+
# distance_of_time_in_words_to_now_without_future(from_time, include_seconds) + ' ago'
|
|
43
|
+
# end
|
|
44
|
+
# end
|
|
45
|
+
#
|
|
46
|
+
# alias_method_chain :distance_of_time_in_words_to_now, :future
|
|
47
|
+
#
|
|
48
|
+
#end
|
|
49
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module InfoListHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def info_list_show(object, attribute)
|
|
9
|
+
# we would expect
|
|
10
|
+
out = ''
|
|
11
|
+
out = "<div class='row #{cycle('odd', 'even')}'>--</div>" if object.send(attribute).empty?
|
|
12
|
+
object.send(attribute).sort.each do | item |
|
|
13
|
+
out << "<div class='row #{cycle('odd', 'even')}'>"
|
|
14
|
+
out << item._presentation
|
|
15
|
+
out << '</div>'
|
|
16
|
+
end
|
|
17
|
+
out.html_safe
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def info_list_edit(object, attribute)
|
|
21
|
+
# we should raise an error
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def info_list_update(object, attribute)
|
|
25
|
+
# we should raise an errror
|
|
26
|
+
end
|
|
27
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module IntegerFieldHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def integer_field_show(object, attribute)
|
|
9
|
+
link_to_inline_edit object, attribute, object[attribute].nil? ? "<i class='fi-plus'></i>".html_safe : object[attribute], from_callee: __callee__
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def integer_field_edit(object, attribute)
|
|
13
|
+
number_field_tag attribute, (object.send attribute.to_sym), :class => 'input_integer_field' # for abide: , :required => true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def integer_field_update(object, attribute)
|
|
17
|
+
object.send :write_attribute, attribute.to_sym, params[attribute.to_sym]
|
|
18
|
+
end
|
|
19
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module MoneyFieldHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def money_field_show(object, attribute)
|
|
9
|
+
link_to_inline_edit object, attribute, humanized_money_with_symbol(object.send attribute), from_callee: __callee__
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def money_field_edit(object, attribute)
|
|
13
|
+
text_field_tag attribute, (object.send attribute), :class => 'input_money_field'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def money_field_update(object, attribute)
|
|
17
|
+
object.send( "#{attribute}=", params[attribute])
|
|
18
|
+
end
|
|
19
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module MonthSelectHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
# date
|
|
9
|
+
def month_select_show(object, attribute)
|
|
10
|
+
link_to_inline_edit object, attribute, (1..12).include?(object[attribute]) ? I18n.localize(Date.new(1970,object[attribute],1), :format => '%B') : "<i class='fi-plus'></i>".html_safe, from_callee: __callee__
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def month_select_edit(object, attribute)
|
|
14
|
+
select_month( (1..12).include?(object[attribute]) ? Date.new(1970, object[attribute], 1) : Date.today, field_name: attribute )
|
|
15
|
+
# ( object.send(attribute).nil? ? "" : object.send(attribute).strftime("%d-%m-%Y") ), :id => css_id, :class =>'datepicker'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def month_select_update(object, attribute)
|
|
19
|
+
object[attribute.to_sym] = params['date'][attribute] rescue 0
|
|
20
|
+
end
|
|
21
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module MonthYearPickerHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
# date
|
|
9
|
+
def month_year_picker_show(object, attribute)
|
|
10
|
+
link_to_inline_edit object, attribute, object.send(attribute).nil? ? "<i class='fi-plus'></i>".html_safe : object.send(attribute).strftime("%B %Y"), from_callee: __callee__
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def month_year_picker_edit(object, attribute)
|
|
14
|
+
css_id = 'datepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s
|
|
15
|
+
out = text_field_tag attribute, ( object.send(attribute).nil? ? "" : object.send(attribute).strftime("%B %Y") ), :id => css_id, :class =>'datepicker datepicker-month-year'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def month_year_picker_update(object, attribute)
|
|
19
|
+
puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + object[attribute.to_sym].inspect
|
|
20
|
+
puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + Date.parse(params[attribute.to_sym].to_s).strftime("%F").to_s
|
|
21
|
+
object[attribute.to_sym] = Date.parse(params[attribute.to_sym].to_s).strftime("%F").to_s
|
|
22
|
+
puts 'XXXXXXXXXXXXXXXXXXXXXXXXXX' + object[attribute.to_sym].inspect
|
|
23
|
+
end
|
|
24
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module MultiImageFieldHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def multi_image_field_show(object, attribute)
|
|
9
|
+
o = object.send(attribute)
|
|
10
|
+
msg = "<i class='fi-plus'></i>".html_safe
|
|
11
|
+
if o.send(:present?)
|
|
12
|
+
if o.respond_to? :palm
|
|
13
|
+
msg = image_tag(o.send(:palm).send(:url))
|
|
14
|
+
else
|
|
15
|
+
msg = image_tag(o.send(:url))
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
link_to_inline_edit object, attribute, msg, from_callee: __callee__
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def multi_image_field_edit(object, attribute)
|
|
22
|
+
file_field_tag attribute, multiple: true, class: 'input_text_field multi_image_field'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def multi_image_field_update(object, attribute)
|
|
26
|
+
object.send(attribute.to_s + '=', params[attribute.to_sym])
|
|
27
|
+
end
|
|
28
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module PdfLinkHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def pdf_link_show(object, attribute)
|
|
9
|
+
# the attribute is the action
|
|
10
|
+
"#{link_to 'preview', "/#{attribute}/#{object.id}", :class => "pdf_preview"} #{link_to 'pdf', "/#{attribute}/#{object.id}.pdf", :class => "pdf_open"}".html_safe
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def pdf_link_edit(object, attribute)
|
|
14
|
+
o = object.send(attribute)
|
|
15
|
+
o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
|
|
16
|
+
o = o._presentation if o.respond_to?(:_presentation)
|
|
17
|
+
o
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def pdf_link_update(object, attribute)
|
|
21
|
+
# do absolutely nothing
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#module ActionView::Helpers::DateHelper
|
|
25
|
+
#
|
|
26
|
+
# def distance_of_time_in_words_to_now_with_future(from_time, include_seconds = false)
|
|
27
|
+
# if from_time > Time.now()
|
|
28
|
+
# 'in ' + distance_of_time_in_words_to_now_without_future(from_time, include_seconds)
|
|
29
|
+
# else
|
|
30
|
+
# distance_of_time_in_words_to_now_without_future(from_time, include_seconds) + ' ago'
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# alias_method_chain :distance_of_time_in_words_to_now, :future
|
|
35
|
+
#
|
|
36
|
+
#end
|
|
37
|
+
#
|
|
38
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module PlainTextAreaHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def plain_text_area_show(object, attribute)
|
|
9
|
+
plain_text_show(object, attribute)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def plain_text_area_edit(object, attribute)
|
|
13
|
+
plain_text_edit(object, attribute)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def plain_text_area_update(object, attribute)
|
|
17
|
+
plain_text_update(object, attribute)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def plain_text_area_info(object, attribute)
|
|
21
|
+
plain_text_info(object, attribute)
|
|
22
|
+
end
|
|
23
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
module InlineForms
|
|
3
|
+
module FormElements
|
|
4
|
+
module PlainTextHelper
|
|
5
|
+
module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
|
|
6
|
+
# -*- encoding : utf-8 -*-
|
|
7
|
+
|
|
8
|
+
def plain_text_show(object, attribute)
|
|
9
|
+
InlineForms.assert_plain_text_column!(object: object, attribute: attribute, form_element: :plain_text)
|
|
10
|
+
value = object[attribute]
|
|
11
|
+
link_to_inline_edit object, attribute, (value.nil? || value.empty?) ? "<i class='fi-plus'></i>".html_safe : value, from_callee: __callee__
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def plain_text_edit(object, attribute)
|
|
15
|
+
InlineForms.assert_plain_text_column!(object: object, attribute: attribute, form_element: :plain_text)
|
|
16
|
+
text_area_tag attribute, object[attribute], :class => 'attribute_text_area'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def plain_text_update(object, attribute)
|
|
20
|
+
InlineForms.assert_plain_text_column!(object: object, attribute: attribute, form_element: :plain_text)
|
|
21
|
+
object[attribute.to_sym] = params[attribute.to_sym]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def plain_text_info(object, attribute)
|
|
25
|
+
InlineForms.assert_plain_text_column!(object: object, attribute: attribute, form_element: :plain_text)
|
|
26
|
+
object[attribute]
|
|
27
|
+
end
|
|
28
|
+
INLINE_FORMS_FORM_ELEMENT
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|