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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +70 -0
  4. data/app/controllers/inline_forms_controller.rb +21 -0
  5. data/app/helpers/inline_forms_helper.rb +1 -6
  6. data/app/views/inline_forms/_versions_list.html.erb +16 -5
  7. data/archived/form_elements/README.md +1 -7
  8. data/inline_forms.gemspec +3 -3
  9. data/lib/generators/inline_forms_generator.rb +1 -1
  10. data/lib/inline_forms/form_element_registry.rb +46 -0
  11. data/lib/inline_forms/form_elements/audio_field_helper.rb +36 -0
  12. data/lib/inline_forms/form_elements/check_box_helper.rb +23 -0
  13. data/lib/inline_forms/form_elements/check_list_helper.rb +45 -0
  14. data/lib/inline_forms/form_elements/ckeditor_helper.rb +23 -0
  15. data/lib/inline_forms/form_elements/date_helper.rb +28 -0
  16. data/lib/inline_forms/form_elements/decimal_field_helper.rb +22 -0
  17. data/lib/inline_forms/form_elements/devise_password_field_helper.rb +26 -0
  18. data/lib/inline_forms/form_elements/dns_records_helper.rb +23 -0
  19. data/lib/inline_forms/form_elements/dropdown_helper.rb +58 -0
  20. data/lib/inline_forms/form_elements/dropdown_with_integers_helper.rb +29 -0
  21. data/lib/inline_forms/form_elements/dropdown_with_other_helper.rb +160 -0
  22. data/lib/inline_forms/form_elements/dropdown_with_values_helper.rb +40 -0
  23. data/lib/inline_forms/form_elements/dropdown_with_values_with_stars_helper.rb +24 -0
  24. data/lib/inline_forms/form_elements/file_field_helper.rb +27 -0
  25. data/lib/inline_forms/form_elements/header_helper.rb +24 -0
  26. data/lib/inline_forms/form_elements/helper_includes.rb +15 -0
  27. data/lib/inline_forms/form_elements/image_field_helper.rb +31 -0
  28. data/lib/inline_forms/form_elements/info_helper.rb +52 -0
  29. data/lib/inline_forms/form_elements/info_list_helper.rb +30 -0
  30. data/lib/inline_forms/form_elements/integer_field_helper.rb +22 -0
  31. data/lib/inline_forms/form_elements/money_field_helper.rb +22 -0
  32. data/lib/inline_forms/form_elements/month_select_helper.rb +24 -0
  33. data/lib/inline_forms/form_elements/month_year_picker_helper.rb +27 -0
  34. data/lib/inline_forms/form_elements/multi_image_field_helper.rb +31 -0
  35. data/lib/inline_forms/form_elements/pdf_link_helper.rb +41 -0
  36. data/lib/inline_forms/form_elements/plain_text_area_helper.rb +26 -0
  37. data/lib/inline_forms/form_elements/plain_text_helper.rb +31 -0
  38. data/lib/inline_forms/form_elements/question_list_helper.rb +52 -0
  39. data/lib/inline_forms/form_elements/radio_button_helper.rb +34 -0
  40. data/lib/inline_forms/form_elements/rich_text_helper.rb +44 -0
  41. data/lib/inline_forms/form_elements/scale_with_integers_helper.rb +30 -0
  42. data/lib/inline_forms/form_elements/scale_with_values_helper.rb +29 -0
  43. data/lib/inline_forms/form_elements/simple_file_field_helper.rb +36 -0
  44. data/lib/inline_forms/form_elements/slider_with_values_helper.rb +99 -0
  45. data/lib/inline_forms/form_elements/text_area_helper.rb +26 -0
  46. data/lib/inline_forms/form_elements/text_area_without_ckeditor_helper.rb +27 -0
  47. data/lib/inline_forms/form_elements/text_field_helper.rb +26 -0
  48. data/lib/inline_forms/form_elements/time_helper.rb +28 -0
  49. data/lib/inline_forms/form_elements.rb +27 -0
  50. data/lib/inline_forms/version.rb +1 -1
  51. data/lib/inline_forms.rb +19 -3
  52. data/script/migrate_form_elements.rb +62 -0
  53. metadata +52 -48
  54. data/app/helpers/form_elements/audio_field.rb +0 -28
  55. data/app/helpers/form_elements/check_box.rb +0 -16
  56. data/app/helpers/form_elements/check_list.rb +0 -37
  57. data/app/helpers/form_elements/ckeditor.rb +0 -15
  58. data/app/helpers/form_elements/date.rb +0 -20
  59. data/app/helpers/form_elements/decimal_field.rb +0 -15
  60. data/app/helpers/form_elements/devise_password_field.rb +0 -19
  61. data/app/helpers/form_elements/dns_records.rb +0 -15
  62. data/app/helpers/form_elements/dropdown.rb +0 -50
  63. data/app/helpers/form_elements/dropdown_with_integers.rb +0 -21
  64. data/app/helpers/form_elements/dropdown_with_other.rb +0 -153
  65. data/app/helpers/form_elements/dropdown_with_values.rb +0 -32
  66. data/app/helpers/form_elements/dropdown_with_values_with_stars.rb +0 -16
  67. data/app/helpers/form_elements/file_field.rb +0 -20
  68. data/app/helpers/form_elements/header.rb +0 -17
  69. data/app/helpers/form_elements/image_field.rb +0 -24
  70. data/app/helpers/form_elements/info.rb +0 -44
  71. data/app/helpers/form_elements/info_list.rb +0 -22
  72. data/app/helpers/form_elements/integer_field.rb +0 -15
  73. data/app/helpers/form_elements/money_field.rb +0 -15
  74. data/app/helpers/form_elements/month_select.rb +0 -16
  75. data/app/helpers/form_elements/month_year_picker.rb +0 -19
  76. data/app/helpers/form_elements/multi_image_field.rb +0 -24
  77. data/app/helpers/form_elements/pdf_link.rb +0 -33
  78. data/app/helpers/form_elements/plain_text.rb +0 -23
  79. data/app/helpers/form_elements/plain_text_area.rb +0 -18
  80. data/app/helpers/form_elements/question_list.rb +0 -44
  81. data/app/helpers/form_elements/radio_button.rb +0 -27
  82. data/app/helpers/form_elements/rich_text.rb +0 -36
  83. data/app/helpers/form_elements/scale_with_integers.rb +0 -23
  84. data/app/helpers/form_elements/scale_with_values.rb +0 -22
  85. data/app/helpers/form_elements/simple_file_field.rb +0 -28
  86. data/app/helpers/form_elements/slider_with_values.rb +0 -91
  87. data/app/helpers/form_elements/text_area.rb +0 -18
  88. data/app/helpers/form_elements/text_area_without_ckeditor.rb +0 -19
  89. data/app/helpers/form_elements/text_field.rb +0 -18
  90. data/app/helpers/form_elements/time.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62c8598afcb5052d9869391009bbf364b8711ed1a9c2f15c3c3ff8d8b6c25e17
4
- data.tar.gz: 2eced24a18c335754a0199525a49a724af9bc000c0003f0230c7558af096139a
3
+ metadata.gz: 51e2a1ebb89510ad07098cd4bddbae4b312e8dba44deeae17a6594b9a78e7625
4
+ data.tar.gz: ab154d4f32670f0dc27cd2fb34a55f9799fe0ca6e31f18b669eb278b6295a6c7
5
5
  SHA512:
6
- metadata.gz: 6436dd214a36bf76c78a38d69aed44d993f50f4c66610baed8372d2e43b9f0ec7700e6203c26a4530bc9c898fb9e4f0879eb5584a9f3c58ca24f9c654155553d
7
- data.tar.gz: be9f7b3f9df5f3ff938a2ed6d65cab6f23668d067d01e30c10afd780b2dd8b3f9a1e1b1ed87695f431b2138fb82993989c9746d7f11d9a8c26e36364606c50b8
6
+ metadata.gz: bda0f225b64be4393f4de458a0757c563ec0ca9b769b106c071cfb18f9723965ad9cea96423f3fefa41f0a72104dda4212ae3b503bddf440cc0f16b6a6363f54
7
+ data.tar.gz: 5d6f660d7c86a30c20a4030ae637f8dcf1fb14075c00cdbd0c3e9b542ef00f1261f231267e16bb1deb4948f020a943dfb3edcf2ee161f853b18b0992c7965c2a
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.2.1
1
+ ruby-4.0.4
data/CHANGELOG.md CHANGED
@@ -4,6 +4,76 @@ All notable changes to this project are documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [7.13.2] - 2026-05-19
8
+
9
+ ### Fixed
10
+
11
+ - **Versions panel — `Restore` on a `create` event no longer 500s.** `PaperTrail::Version#reify` returns `nil` for `create` events (no prior state), so the old `revert` action fell through to `@parent.save!` on `nil` and raised `NoMethodError: undefined method 'save!' for nil` — most visibly when reverting an ActionText (`rich_text`) `create` version in the description column, which was the first `create` row most apps encountered for rich text.
12
+ - **`app/views/inline_forms/_versions_list.html.erb`**: hide the `Restore` link for `version.event == "create"` rows (covers both `:primary` and `:rich_text` entries). Reverting a `create` is semantically a destroy; primary records keep their dedicated Destroy button, and rich-text content can still be cleared by editing.
13
+ - **`app/controllers/inline_forms_controller.rb#revert`**: defensive nil-reify guard. If the request still arrives (bookmarked / replayed URL), short-circuit to the existing turbo-stream row-close response keyed off `@version.item` (its parent for `ActionText::RichText`) instead of calling `save!` on nil.
14
+
15
+ ### Added
16
+
17
+ - **`test/integration/example_app_apartment_versions_turbo_test.rb`** (installer template): two new regression tests that pin the fix above — `revert on rich_text create version no-ops via turbo-stream instead of NoMethodError` (replays the failing POST and asserts the parent body is preserved) and `versions list hides Restore link on create rows but keeps it on update rows` (asserts the view-side link gating).
18
+
19
+ ### Fixed (also)
20
+
21
+ - **`test/integration/example_app_apartment_photos_pagination_test.rb`** (installer template): `refute_match(/UnknownFormat|406/, …)` is flaky because CarrierWave's seeded image URL contains a random UUID that can include the substring `406`. Tightened to `/UnknownFormat|406 Not Acceptable/`, which still catches the original `ActionController::UnknownFormat` / `406` error-page regression but no longer matches harmless hex inside the upload path.
22
+
23
+ ### Changed (also)
24
+
25
+ - **`InlineFormsInstaller::VERSION`** bumped to `7.13.2` in lockstep (the installer's `INLINE_FORMS_VERSION = VERSION` constant is what `installer_core.rb` writes into generated `Gemfile`s as the `gem "inline_forms", "~> X.Y.Z"` pin).
26
+
27
+ ### Verified
28
+
29
+ - `gem build inline_forms.gemspec` → `inline_forms-7.13.2.gem`; `gem build inline_forms_installer.gemspec` → `inline_forms_installer-7.13.2.gem`.
30
+ - `inline_forms create MyApp -d sqlite --example` → `bundle exec rails test` — **79 runs, 441 assertions, 0 failures, 0 errors, 0 skips** (Ruby 4.0.4 / Rails 7.2.3.1).
31
+
32
+ ## [7.13.1] - 2026-05-19
33
+
34
+ ### Fixed
35
+
36
+ - **Generated app Gemfile:** add **`puma`** in `:development` so plain **`rails s`** works on Rails 7.2 (rackup default handler is puma/falcon/webrick; `thin` and `unicorn` are not auto-selected).
37
+
38
+ ### Verified
39
+
40
+ - **`inline_forms create MyApp -d sqlite --example`** → **`bundle exec rails s`** boots Puma → **`bundle exec rails test`** — **77 runs, 427 assertions, 0 failures**.
41
+
42
+ ## [7.13.0] - 2026-05-19
43
+
44
+ ### Changed
45
+
46
+ - **Track B — Zeitwerk / form elements:** ~37 form elements moved from `app/helpers/form_elements/*.rb` (top-level `def` + `Dir[]` require) to namespaced `InlineForms::FormElements::*Helper` modules under `lib/inline_forms/form_elements/*_helper.rb`.
47
+ - **`InlineForms::FormElementRegistry`:** central `SPECIAL_COLUMN_TYPES` registration (replaces per-file side effects).
48
+ - **`InlineFormsHelper` / `InlineFormsController`:** both include `InlineForms::FormElements::HelperIncludes` so views still call `text_field_show`, etc., and controllers still dispatch `*_update` (e.g. `name_list.html.erb` unchanged).
49
+ - **Loading:** form-element helpers are explicitly `require`d at boot; `lib/inline_forms/form_elements/` is ignored by Zeitwerk (avoids `_helper.rb` constant mismatches during `zeitwerk:check`).
50
+ - **`inline_forms_generator`:** requires `inline_forms` only (no full helper preload).
51
+ - **`validation_hints`:** requires `~> 7.13`.
52
+
53
+ ### Verified
54
+
55
+ - **`inline_forms create MyApp -d sqlite --example`** on Ruby 4.0.4 / Rails 7.2.3.1 → **`bundle exec rails zeitwerk:check`** — clean → **`bundle exec rails test`** — **77 runs, 427 assertions, 0 failures**.
56
+
57
+ ## [7.12.0] - 2026-05-19
58
+
59
+ ### Changed
60
+
61
+ - **Rails 7.2:** engine gemspec and installer Gemfile pin `rails ~> 7.2.3`, `config.load_defaults 7.2`, migrations `ActiveRecord::Migration[7.2]`.
62
+ - **Ruby 4.0:** gemspecs require Ruby `>= 4.0.0`; generated apps write `.ruby-version` `ruby-4.0.4` (`InlineFormsInstaller::TARGET_RUBY_VERSION`).
63
+ - **`validation_hints`:** requires `~> 7.12` (Active Record 7.2).
64
+ - **`rails-i18n`:** `~> 7.0` in generated Gemfile (7.0.x is the published line for Rails 7.2); engine dependency `>= 7.0`, `< 8.0`.
65
+ - **`bin/inline_forms`:** prefers locally installed `rails` 7.2.x for `rails new`.
66
+ - **`.ruby-version`:** written from the app template after `rails new` (avoids Thor conflict with Rails’ own file).
67
+ - **`config.autoload_lib`:** no longer stripped from generated `application.rb` (Rails 7.2 expects it).
68
+
69
+ ### Fixed
70
+
71
+ - **Example app test:** `example_app_photos_test` — standalone `GET /photos` asserts non-success (403), not `UnknownFormat`.
72
+
73
+ ### Verified
74
+
75
+ - **`inline_forms create MyApp -d sqlite --example`** on Ruby 4.0.4 / Rails 7.2.3.1 → **`bundle exec rails test`** — **77 runs, 427 assertions, 0 failures**.
76
+
7
77
  ## [7.11.0] - 2026-05-19
8
78
 
9
79
  ### Changed
@@ -22,6 +22,7 @@
22
22
  # @Klass is used in the InlineFormsHelper
23
23
  #
24
24
  class InlineFormsController < ApplicationController
25
+ include InlineForms::FormElements::HelperIncludes
25
26
  include CancanConcern
26
27
  include VersionsConcern
27
28
 
@@ -269,6 +270,26 @@ class InlineFormsController < ApplicationController
269
270
  if current_user.role? :superadmin
270
271
  @version = PaperTrail::Version.find(params[:id])
271
272
  @object = @version.reify
273
+ # PaperTrail::Version#reify returns nil for `create` events because
274
+ # there is no prior state to roll back to. The versions list view
275
+ # hides the Restore link for `create` rows, but guard here too in
276
+ # case a request was bookmarked or replayed: render close on the
277
+ # current parent without mutating anything.
278
+ if @object.nil?
279
+ item = @version.item
280
+ @parent = if defined?(ActionText::RichText) && item.is_a?(ActionText::RichText)
281
+ item.record
282
+ else
283
+ item
284
+ end
285
+ return unless @parent
286
+ authorize!(:revert, @parent) if cancan_enabled?
287
+ return unless row_html_turbo_allowed?
288
+ respond_to do |format|
289
+ format.turbo_stream { render_revert_turbo_streams }
290
+ end
291
+ return
292
+ end
272
293
  if defined?(ActionText::RichText) && @object.is_a?(ActionText::RichText)
273
294
  @rich_text_record = @object
274
295
  @parent = @rich_text_record.record
@@ -1,11 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineFormsHelper
3
- # Load active form elements (top-level *.rb only). Retired elements live under
4
- # archived/form_elements/ — see archived/README.md.
5
- INLINE_FORMS_PATH = File.dirname(__FILE__) + "/form_elements/"
6
- Dir[INLINE_FORMS_PATH + "*.rb"].each do |form_element|
7
- require form_element
8
- end
3
+ include InlineForms::FormElements::HelperIncludes
9
4
 
10
5
  def inline_forms_version
11
6
  InlineForms::VERSION
@@ -48,11 +48,22 @@
48
48
  <%# Restore is enabled for both :primary (object itself) and :rich_text
49
49
  (ActionText::RichText hanging off @object). The revert route is
50
50
  keyed by PaperTrail::Version id (global) and always targets the
51
- parent's controller, so the same path works for both kinds. -%>
52
- <% row_id = inline_forms_row_turbo_frame_id(@object) %>
53
- <%= link_to t("inline_forms.view.restore"),
54
- send("revert_#{@object.class.to_s.underscore}_path", version, update: row_id),
55
- inline_forms_turbo_link_data(row_id, method: :post, turbo_stream: true) %>
51
+ parent's controller, so the same path works for both kinds.
52
+
53
+ PaperTrail's `reify` returns nil for `create` versions (no prior
54
+ state to roll back to). Reverting a `create` would mean destroying
55
+ the record primary records already have a dedicated Destroy
56
+ button (superadmin), and rich_text content can be cleared by
57
+ editing. Omitting the link here keeps the UI consistent and
58
+ avoids a NoMethodError in the controller's `save!`. -%>
59
+ <% if version.event == "create" %>
60
+ &nbsp;
61
+ <% else %>
62
+ <% row_id = inline_forms_row_turbo_frame_id(@object) %>
63
+ <%= link_to t("inline_forms.view.restore"),
64
+ send("revert_#{@object.class.to_s.underscore}_path", version, update: row_id),
65
+ inline_forms_turbo_link_data(row_id, method: :post, turbo_stream: true) %>
66
+ <% end %>
56
67
  </div>
57
68
  <div class="small-1 column">
58
69
  <%= version.event -%><% if entry[:kind] == :rich_text %> <em>(rich text)</em><% end %>
@@ -1,12 +1,6 @@
1
1
  # Archived form elements
2
2
 
3
- Form elements are Ruby files that define `#{name}_show`, `#{name}_edit`, and `#{name}_update` helpers. The engine loads them from:
4
-
5
- ```ruby
6
- Dir[File.dirname(__FILE__) + "/form_elements/*.rb"].each { |f| require f }
7
- ```
8
-
9
- Only **top-level** `app/helpers/form_elements/*.rb` files are loaded. Subdirectories (including this `archived/` tree) are ignored.
3
+ Form elements live under `lib/inline_forms/form_elements/*_helper.rb` as `InlineForms::FormElements::*Helper` modules, included into `InlineFormsHelper` (views still call `text_field_show`, etc.). Subdirectories under `archived/` are not loaded.
10
4
 
11
5
  ## Why archive instead of delete?
12
6
 
data/inline_forms.gemspec CHANGED
@@ -13,14 +13,14 @@ Gem::Specification.new do |s|
13
13
  s.summary = %q{Inline editing of forms. Versions after 6.2.14 are currently broken.}
14
14
  s.description = %q{Inline Forms aims to ease the setup of forms that provide inline editing. The field list can be specified in the model. Versions after 6.2.14 are currently broken, and we will post a notice when the gem is good again.}
15
15
  s.licenses = ["MIT"]
16
- s.required_ruby_version = ">= 3.2.0"
16
+ s.required_ruby_version = ">= 4.0.0"
17
17
 
18
18
  s.files = InlineFormsGemFiles.gem_files(include_installer: false)
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency("validation_hints", ">= 6.3", "< 7.0")
23
- s.add_dependency("rails", ">= 7.1.5", "< 7.2")
22
+ s.add_dependency("validation_hints", ">= 7.13", "< 8.0")
23
+ s.add_dependency("rails", ">= 7.2.3.1", "< 7.3")
24
24
  s.add_dependency("rails-i18n", ">= 7.0", "< 8.0")
25
25
 
26
26
  s.add_development_dependency("minitest", "~> 5.0")
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require File.expand_path(File.join(File.dirname(__FILE__),'../../app/helpers/inline_forms_helper.rb'))
2
+ require "inline_forms"
3
3
  module InlineForms
4
4
  # == Usage
5
5
  # This generator generates a migration, a model and a controller.
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InlineForms
4
+ module FormElementRegistry
5
+ ENTRIES = {
6
+ :audio_field => :string,
7
+ :check_box => :boolean,
8
+ :check_list => :no_migration,
9
+ :ckeditor => :text,
10
+ :date_select => :date,
11
+ :decimal_field => :string,
12
+ :devise_password_field => :string,
13
+ :dropdown => :belongs_to,
14
+ :dropdown_with_integers => :integer,
15
+ :dropdown_with_other => :belongs_to,
16
+ :dropdown_with_values => :integer,
17
+ :dropdown_with_values_with_stars => :integer,
18
+ :file_field => :string,
19
+ :header => :string,
20
+ :image_field => :string,
21
+ :info => :string,
22
+ :integer_field => :integer,
23
+ :money_field => :integer,
24
+ :month_select => :integer,
25
+ :month_year_picker => :date,
26
+ :multi_image_field => :string,
27
+ :plain_text => :text,
28
+ :plain_text_area => :text,
29
+ :question_list => :no_migration,
30
+ :radio_button => :integer,
31
+ :rich_text => :no_migration,
32
+ :scale_with_integers => :integer,
33
+ :scale_with_values => :integer,
34
+ :simple_file_field => :string,
35
+ :slider_with_values => :integer,
36
+ :text_area => :text,
37
+ :text_area_without_ckeditor => :text,
38
+ :text_field => :string,
39
+ :time_select => :time,
40
+ }.freeze
41
+
42
+ def self.apply!
43
+ SPECIAL_COLUMN_TYPES.merge!(ENTRIES)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module AudioFieldHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ def audio_field_show(object, attribute)
9
+ o = object.send(attribute)
10
+ msg = "<i class='fi-pencil' title='Edit #{attribute.to_s}'></i>".html_safe
11
+ if o.send(:present?)
12
+ if o.respond_to? :palm
13
+ audio_html = audio_tag(o.send(:palm).send(:url), autoplay: false, controls: true)
14
+ else
15
+ audio_html = audio_tag(o.send(:url), autoplay: false, controls: true)
16
+ end
17
+ end
18
+ link_to_edit = link_to_inline_edit object, attribute, msg, from_callee: __callee__
19
+ if cancan_disabled? || ( can? :update, object, attribute )
20
+ "#{audio_html} #{link_to_edit}".html_safe
21
+ else
22
+ audio_html.html_safe
23
+ end
24
+ end
25
+
26
+ def audio_field_edit(object, attribute)
27
+ file_field_tag attribute, class: 'input_text_field'
28
+ end
29
+
30
+ def audio_field_update(object, attribute)
31
+ object.send(attribute.to_s + '=', params[attribute.to_sym])
32
+ end
33
+ INLINE_FORMS_FORM_ELEMENT
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module CheckBoxHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+ # boolean, bit unaptly named check_box
8
+ def check_box_show(object, attribute)
9
+ values = attribute_values(object, attribute)
10
+ link_to_inline_edit object, attribute, values[object.send(attribute) ? 1 : 0 ][1], from_callee: __callee__
11
+ end
12
+
13
+ def check_box_edit(object, attribute)
14
+ check_box_tag attribute.to_s, 1, object.send(attribute)
15
+ end
16
+
17
+ def check_box_update(object, attribute)
18
+ object[attribute.to_s.to_sym] = params[attribute.to_s.to_sym].nil? ? 0 : 1
19
+ end
20
+ INLINE_FORMS_FORM_ELEMENT
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module CheckListHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # checklist
9
+ def check_list_show(object, attribute)
10
+ out = ''
11
+ out = link_to_inline_edit(object, attribute, "<i class='fi-plus'></i>".html_safe, from_callee: __callee__) if object.send(attribute).empty?
12
+ object.send(attribute).sort.each do | item |
13
+ out << "<div class='row #{cycle('odd', 'even')}'>"
14
+ out << link_to_inline_edit(object, attribute, item._presentation, from_callee: __callee__ )
15
+ out << '</div>'
16
+ end
17
+ out.html_safe
18
+ end
19
+
20
+ def check_list_edit(object, attribute)
21
+ object.send(attribute).build if object.send(attribute).empty?
22
+ if cancan_enabled?
23
+ values = object.send(attribute).first.class.name.constantize.accessible_by(current_ability).order(attribute.to_s.singularize.camelcase.constantize.order_by_clause)
24
+ else
25
+ values = object.send(attribute).first.class.name.constantize.order(attribute.to_s.singularize.camelcase.constantize.order_by_clause)
26
+ end
27
+ out = ''
28
+ values.each do | item |
29
+ out << "<div class='row #{cycle('odd', 'even')}'>"
30
+ out << check_box_tag( attribute.to_s + '[' + item.id.to_s + ']', 1, object.send(attribute.to_s.singularize + "_ids").include?(item.id) )
31
+ out << "<label for=#{attribute.to_s + '[' + item.id.to_s + ']'}>#{h(item._presentation)}</label>"
32
+ out << '</div>'
33
+ end
34
+ out.html_safe
35
+ end
36
+
37
+ def check_list_update(object, attribute)
38
+ params[attribute] ||= {}
39
+ object.send(attribute.to_s.singularize + '_ids=', params[attribute].keys)
40
+ object.touch unless object.new_record? # Check for new_record needed for Rails > 3; TODO we should have a flag to turn this on or of.
41
+ end
42
+ INLINE_FORMS_FORM_ELEMENT
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module CkeditorHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+ # Legacy type name: CKEditor is removed; behaves like :rich_text.
8
+
9
+ def ckeditor_show(object, attribute)
10
+ rich_text_show(object, attribute)
11
+ end
12
+
13
+ def ckeditor_edit(object, attribute)
14
+ rich_text_edit(object, attribute)
15
+ end
16
+
17
+ def ckeditor_update(object, attribute)
18
+ rich_text_update(object, attribute)
19
+ end
20
+ INLINE_FORMS_FORM_ELEMENT
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module DateHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # date
9
+ def date_select_show(object, attribute)
10
+ link_to_inline_edit object, attribute, object.send(attribute).nil? ? "<i class='fi-plus'></i>".html_safe : object.send(attribute).to_date.strftime("%d-%m-%Y"), from_callee: __callee__
11
+ end
12
+
13
+ def date_select_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).to_date.strftime("%d-%m-%Y") ), :id => css_id, :class =>'datepicker'
16
+ end
17
+
18
+ def date_select_update(object, attribute)
19
+ object[attribute.to_sym] = params[attribute.to_sym]
20
+ end
21
+
22
+ def date_select_info(object, attribute)
23
+ object.send(attribute).nil? ? "-" : object.send(attribute).to_date
24
+ end
25
+ INLINE_FORMS_FORM_ELEMENT
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module DecimalFieldHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ def decimal_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 decimal_field_edit(object, attribute)
13
+ text_field_tag attribute, (object.send attribute.to_sym), :class => 'input_decimal_field' # for abide: , :required => true
14
+ end
15
+
16
+ def decimal_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,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module DevisePasswordFieldHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ def devise_password_field_show(object, attribute)
9
+ link_to_inline_edit object, attribute, '', from_callee: __callee__
10
+ end
11
+
12
+ def devise_password_field_edit(object, attribute)
13
+ password_field_tag attribute, '', :class => 'input_devise_password_field'
14
+ end
15
+
16
+ def devise_password_field_update(object, attribute)
17
+ if params[attribute.to_sym].blank?
18
+ # nothing happens
19
+ else
20
+ object.password = params[attribute.to_sym]
21
+ end
22
+ end
23
+ INLINE_FORMS_FORM_ELEMENT
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module DnsRecordsHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+ def dnsrecords_show(object, attribute)
8
+ out = ""
9
+ [object.a_records,object.template_a_records].flatten.collect do |r|
10
+ out << r.djbdns_line(object.name) + "<br/>"
11
+ end
12
+ raw out
13
+ end
14
+
15
+ def dnsrecords_edit(object, attribute)
16
+ end
17
+
18
+ def dnsrecords_update(object, attribute)
19
+ end
20
+ INLINE_FORMS_FORM_ELEMENT
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,58 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module DropdownHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # dropdown
9
+ def dropdown_show(object, attribute)
10
+ attr = object.send attribute
11
+ presentation = "_presentation"
12
+ presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation"
13
+ attribute_value = object.send(attribute).send(presentation) rescue "<i class='fi-plus'></i>".html_safe
14
+ link_to_inline_edit object, attribute, attribute_value, from_callee: __callee__
15
+ end
16
+
17
+ def dropdown_edit(object, attribute)
18
+ object.send('build_' + attribute.to_s) unless object.send(attribute) # we really need this!
19
+ attr = object.send attribute
20
+ presentation = "_presentation"
21
+ presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation"
22
+ klass = object.send(attribute).class
23
+ if cancan_enabled?
24
+ values = klass.accessible_by(current_ability)
25
+ else
26
+ values = klass.all
27
+ end
28
+ options_disabled = nil
29
+ if klass.method_defined? :disabled_for_dropdown?
30
+ options_disabled = values.map{|v| v.id if v.disabled_for_dropdown?}.compact
31
+ end
32
+ values.sort_by {|v|v.send presentation}
33
+ # 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!
34
+ collection_select( ('_' + object.class.to_s.underscore).to_sym,
35
+ attribute.to_s.foreign_key.to_sym,
36
+ values,
37
+ 'id',
38
+ presentation,
39
+ selected: (object.send(attribute).id rescue nil),
40
+ disabled: options_disabled,
41
+ )
42
+ end
43
+
44
+ def dropdown_update(object, attribute)
45
+ foreign_key = object.class.reflect_on_association(attribute.to_sym).options[:foreign_key] || attribute.to_s.foreign_key.to_sym
46
+ object[foreign_key] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_s.foreign_key.to_sym]
47
+ end
48
+
49
+ def dropdown_info(object, attribute)
50
+ attr = object.send attribute
51
+ presentation = "_presentation"
52
+ presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation"
53
+ object.send(attribute).send(presentation) rescue "-"
54
+ end
55
+ INLINE_FORMS_FORM_ELEMENT
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module DropdownWithIntegersHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # dropdown_with_integers generates a dropdown menu
9
+ # with the given list of integers as options
10
+ #
11
+ # values must be a Range or a one-dimensional array of Integers
12
+ def dropdown_with_integers_show(object, attribute)
13
+ values = attribute_values(object, attribute)
14
+ link_to_inline_edit object, attribute, values[object.send(attribute)][1], from_callee: __callee__
15
+ end
16
+
17
+ def dropdown_with_integers_edit(object, attribute)
18
+ # 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!
19
+ values = attribute_values(object, attribute)
20
+ collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
21
+ end
22
+
23
+ def dropdown_with_integers_update(object, attribute)
24
+ object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
25
+ end
26
+ INLINE_FORMS_FORM_ELEMENT
27
+ end
28
+ end
29
+ end