inline_forms 8.1.80 → 8.1.81
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/CHANGELOG.md +24 -0
- data/app/assets/stylesheets/inline_forms/inline_forms.scss +3 -12
- data/app/controllers/inline_forms_controller.rb +13 -5
- data/app/helpers/inline_forms_helper.rb +32 -11
- data/app/validators/is_curacao_phone_validator.rb +1 -1
- data/app/validators/is_email_address_validator.rb +1 -1
- data/app/validators/must_be_a_value_validator.rb +1 -1
- data/app/views/inline_forms/_header.html.erb +2 -1
- data/app/views/inline_forms/_list.html.erb +1 -1
- data/app/views/inline_forms/_new.html.erb +2 -3
- data/app/views/inline_forms/_versions_list.html.erb +2 -2
- data/app/views/layouts/application.html.erb +4 -2
- data/app/views/layouts/inline_forms.html.erb +4 -2
- data/archived/README.md +12 -0
- data/lib/inline_forms/archived_form_elements.rb +15 -2
- data/lib/inline_forms/form_elements/date_helper.rb +2 -2
- data/lib/inline_forms/form_elements/info_helper.rb +3 -0
- data/lib/inline_forms/version.rb +1 -1
- data/lib/inline_forms.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72335aa9872d9bdb812e7cafa30ce3b9644c15b13332c845124e02f0a1f63b85
|
|
4
|
+
data.tar.gz: 5482bf68736408019e5a8a4c1143a7194ce13d68edac743d6ad18dab52a07a0a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35072c3e64464f5a93e3d6b24507f37109d01f80c3e64b76b2f216bddda9dccabb962841af1374faa09c2a5e8f30eef44622338d3d2a144716fcdb693bf1d272
|
|
7
|
+
data.tar.gz: a1fd57eb92afec824df4da51f05362db8508f3132a8e03d895bfae9493443dfeaec80c99cab10cfee2e71717d330a8a55e975969af3ecf3429be58f12a8e6584
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,30 @@ All notable changes to this project are documented in this file.
|
|
|
8
8
|
|
|
9
9
|
- Known issues, parked (local note `stuff/2026-10-31-dropdown-rule-3-parked.md`) with dropdown order rule 3: `includes`, `group` or `select` in `inline_forms_list` make `dropdown` and `dropdown_with_other` raise while `/index` works, so 8.1.65's fix for a list order on a joined table holds only for `joins`, `left_joins` and `eager_load`; a has_many join gives duplicate options. Present since 8.1.60. No host's list scope has these today. Parked; not changed.
|
|
10
10
|
|
|
11
|
+
## [8.1.81] - 2026-11-24
|
|
12
|
+
|
|
13
|
+
From the RACVS / yavetracker Rails ladder (`ladder/inline_forms-PROMPT-2026-11-24.md`).
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **Three validators added no error since Rails 7.0.** `is_email_address`, `is_curacao_phone` and `must_be_a_value` did `record.errors[attribute] << …`, which Rails 7.0 and later throw away: the record stayed valid and every value was saved. They now call `errors.add`. **An app that uses them will see validation errors on values it used to accept**, including on records already stored with such values (they fail on their next save). Scouting, StProject, Papiamentu and PapCWScrabble do not use them.
|
|
18
|
+
- **An app's own list filter survives `index`.** An index override or `before_action` that sets a filtered `@objects` (a relation of the list's model) before the engine's `index` runs keeps its filter; with CanCan it is narrowed to what the ability allows (`@objects.merge(accessible_by)`), so it never shows more than before. Until now CanCan's collection replaced it, and the app's search and filters were silently lost (apps worked around it, e.g. RACVS's `sync_cancan_collection!`). Anything else in `@objects` (an Array, another model) is replaced as before.
|
|
19
|
+
- **The versions panel and the undo of a delete in an app without the Action Text table.** They asked only whether `ActionText::RichText` is defined, which it is under `rails/all`, and then queried `action_text_rich_texts`. They now ask `InlineForms.action_text_table?` (the class and its table).
|
|
20
|
+
- **Dates read dd-mm-yyyy everywhere the engine shows them.** `date_select_info`, the `info` element (for a Date) and the old and new values in the versions panel printed a bare Date, which is ISO (`2026-01-13`) since Rails 7.1; `date_select_show` already printed `13-01-2026`. New: `InlineForms::DATE_FORMAT` (`"%d-%m-%Y"`) and the view helper `inline_forms_value_text` (a Date as that, a time as `inline_forms_time_text`, anything else unchanged).
|
|
21
|
+
- **`new` and a successful `create` inside a Turbo frame answer with the frame layout** (`turbo_rails/frame`), as `index` and `destroy` do, instead of the full layout: an app's header and menus no longer run there (partials that expect a list's data crashed). A full page load keeps the `inline_forms` layout. This undoes 7.5.1's choice of the full layout for nested new forms "so the swapped frame is styled": Turbo inserts only the frame, which the page already styles (checked in a browser: the nested Photo new form, its Trix editor, cancel and ok).
|
|
22
|
+
- **Logout works without rails-ujs.** The header's link carries `data-turbo-method="delete"` (Turbo sends the DELETE) besides `data-method`; it was a GET, which Devise refuses. The same in the installer's example-app header. Apps with a header of their own (Scouting, StProject, Papiamentu) check theirs.
|
|
23
|
+
- **Trix loads once, in `<head>`,** in both layouts. In `<body>` Turbo ran it again on every visit and it threw on the second definition of `trix-toolbar`.
|
|
24
|
+
- **The cancel buttons are links styled as buttons.** The field cancel and the new form's cancel were an `<input type="button">` inside an `<a>` (invalid HTML). Now `<a class="… button alert" role="button">cancel</a>` (`inline_forms-field-cancel`, `inline_forms-new-cancel`); the CSS follows. An app that styles or selects `input[name=cancel]` must follow.
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- **Page links of a top-level list advance the address bar** (`data-turbo-action="advance"`, renderer `inline_forms_advancing_link_renderer`): back, reload and a shared link keep the page. Nested lists keep the plain links.
|
|
29
|
+
- **An app may vendor an archived form element.** The boot check skips an archived symbol when the app's helpers define `<name>_show` (`InlineForms.vendored_form_element?`); `archived/README.md` says how. Before, vendoring did not stop the raise although the message suggested it.
|
|
30
|
+
|
|
31
|
+
### Upgrade notes
|
|
32
|
+
|
|
33
|
+
- **`:text_area` is rich text (Action Text) since 7.3.1, and `:ckeditor` is archived (8.1.21).** HTML that CKEditor stored in the model's own text column is not shown by `:text_area`, which reads `action_text_rich_texts`. Either declare the column `:plain_text_area` (shows the column as plain text), or move the HTML into Action Text once: rename the old column (say `body` to `body_html`) in a migration, declare `has_rich_text :body`, copy with `Model.find_each { |r| r.update!(body: r.body_html) if r.body_html.present? }` (a runner or a data migration), check the result on a copy of production data, and drop `body_html` later.
|
|
34
|
+
|
|
11
35
|
## [8.1.80] - 2026-11-24
|
|
12
36
|
|
|
13
37
|
From the notes of the apps' move to 8.1.79's suggestions.
|
|
@@ -325,28 +325,19 @@ turbo-frame {
|
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
// Field edit cancel:
|
|
328
|
+
// Field edit cancel: the <a> itself is the button, the same height as ok.
|
|
329
329
|
.edit_form .row.collapse {
|
|
330
330
|
input[type="submit"].postfix.button,
|
|
331
|
-
a.inline_forms-field-cancel
|
|
331
|
+
a.inline_forms-field-cancel.postfix.button {
|
|
332
332
|
margin: 2px 0 !important;
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
.edit_form a.inline_forms-field-cancel {
|
|
337
337
|
display: inline-block;
|
|
338
|
-
|
|
339
|
-
border: 0;
|
|
340
|
-
background: transparent;
|
|
341
|
-
line-height: 0;
|
|
338
|
+
width: auto;
|
|
342
339
|
vertical-align: top;
|
|
343
340
|
text-decoration: none;
|
|
344
|
-
|
|
345
|
-
input[type="button"] {
|
|
346
|
-
pointer-events: none;
|
|
347
|
-
cursor: pointer;
|
|
348
|
-
width: auto;
|
|
349
|
-
}
|
|
350
341
|
}
|
|
351
342
|
|
|
352
343
|
.object_presentation {
|
|
@@ -52,10 +52,16 @@ class InlineFormsController < ApplicationController
|
|
|
52
52
|
fk_conditions = [ "#{foreign_key} = ?", @parent_id ]
|
|
53
53
|
end
|
|
54
54
|
# CanCan's load_and_authorize_resource sets @apartments (etc.); keep @objects in sync.
|
|
55
|
+
# An app's index override or before_action may already have set a filtered
|
|
56
|
+
# @objects (a relation) before this runs: keep its filter, narrowed to what
|
|
57
|
+
# the ability allows, instead of replacing it with the whole collection.
|
|
55
58
|
collection_ivar = :"@#{controller_name}"
|
|
56
59
|
if instance_variable_defined?(collection_ivar)
|
|
57
60
|
loaded = instance_variable_get(collection_ivar)
|
|
58
|
-
|
|
61
|
+
unless loaded.nil?
|
|
62
|
+
app_filtered = @objects.is_a?(ActiveRecord::Relation) && @objects.model == @Klass
|
|
63
|
+
@objects = app_filtered ? @objects.merge(loaded) : loaded
|
|
64
|
+
end
|
|
59
65
|
end
|
|
60
66
|
@objects ||= @Klass.accessible_by(current_ability) if cancan_enabled?
|
|
61
67
|
@objects ||= @Klass.all
|
|
@@ -582,7 +588,7 @@ class InlineFormsController < ApplicationController
|
|
|
582
588
|
# row already exists. Only the newest destroy version per attribute name is
|
|
583
589
|
# applied (repeat delete/undo leaves multiple RT destroy versions in the table).
|
|
584
590
|
def restore_rich_texts_for_reverted_parent!(parent)
|
|
585
|
-
return unless
|
|
591
|
+
return unless InlineForms.action_text_table?
|
|
586
592
|
|
|
587
593
|
record_type = parent.class.base_class.name
|
|
588
594
|
record_id = parent.id
|
|
@@ -775,9 +781,11 @@ class InlineFormsController < ApplicationController
|
|
|
775
781
|
end
|
|
776
782
|
|
|
777
783
|
def associated_list_frame_layout
|
|
778
|
-
#
|
|
779
|
-
#
|
|
780
|
-
|
|
784
|
+
# A Turbo frame request gets the bare frame layout: Turbo takes only the
|
|
785
|
+
# matching <turbo-frame id="…"> from the answer, and the full layout would
|
|
786
|
+
# run the app's header and menus (partials that may expect a list's data)
|
|
787
|
+
# for nothing. A full page load keeps the inline_forms layout.
|
|
788
|
+
turbo_frame_request? ? "turbo_rails/frame" : "inline_forms"
|
|
781
789
|
end
|
|
782
790
|
|
|
783
791
|
def render_turbo_new
|
|
@@ -70,7 +70,7 @@ module InlineFormsHelper
|
|
|
70
70
|
{ version: v, kind: :primary, rich_text_name: nil }
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
if
|
|
73
|
+
if InlineForms.action_text_table?
|
|
74
74
|
ActionText::RichText
|
|
75
75
|
.where(record_type: object.class.base_class.name, record_id: object.id)
|
|
76
76
|
.each do |rich_text|
|
|
@@ -94,6 +94,23 @@ module InlineFormsHelper
|
|
|
94
94
|
# requests +text/vnd.turbo-stream.html+ so Turbo does not expect a single matching
|
|
95
95
|
# frame in the response — POSTs from nested +…_versions+ frames otherwise send
|
|
96
96
|
# +Turbo-Frame: …_versions+ while the server returns the row frame (+Content missing+).
|
|
97
|
+
# will_paginate renderer for a top-level list: each page link carries
|
|
98
|
+
# data-turbo-action="advance", so a page change inside the list's
|
|
99
|
+
# <turbo-frame> also updates the address bar (back, reload and a shared
|
|
100
|
+
# link keep the page). Nested lists keep the plain renderer: their pages
|
|
101
|
+
# change one panel, not the page.
|
|
102
|
+
def inline_forms_advancing_link_renderer
|
|
103
|
+
InlineFormsHelper.advancing_link_renderer
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def self.advancing_link_renderer
|
|
107
|
+
@advancing_link_renderer ||= Class.new(WillPaginate::ActionView::LinkRenderer) do
|
|
108
|
+
def link(text, target, attributes = {})
|
|
109
|
+
super(text, target, attributes.merge("data-turbo-action": "advance"))
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
97
114
|
def inline_forms_turbo_link_data(update_span, method: :get, turbo_stream: false)
|
|
98
115
|
data = { turbo: true, turbo_frame: update_span }
|
|
99
116
|
data[:turbo_method] = method.to_s.downcase unless method == :get
|
|
@@ -268,22 +285,15 @@ module InlineFormsHelper
|
|
|
268
285
|
form_element: form_element,
|
|
269
286
|
sub_id: sub_id
|
|
270
287
|
)
|
|
271
|
-
|
|
288
|
+
# The link itself is the button (an <input> inside an <a> is invalid HTML).
|
|
289
|
+
opts = { class: "inline_forms-field-cancel postfix button alert", role: "button", tabindex: "-1" }
|
|
272
290
|
if turbo_frame
|
|
273
291
|
# Inside a <turbo-frame>: plain GET link; no data-method (legacy ujs fought Turbo).
|
|
274
292
|
opts[:data] = { turbo: true, turbo_frame: "_self" }
|
|
275
293
|
else
|
|
276
294
|
opts[:data] = { turbo: true, turbo_frame: update_span }
|
|
277
295
|
end
|
|
278
|
-
link_to path, opts
|
|
279
|
-
tag.input(
|
|
280
|
-
type: "button",
|
|
281
|
-
name: "cancel",
|
|
282
|
-
value: "cancel",
|
|
283
|
-
class: "postfix button alert",
|
|
284
|
-
tabindex: "-1"
|
|
285
|
-
)
|
|
286
|
-
end
|
|
296
|
+
link_to "cancel", path, opts
|
|
287
297
|
end
|
|
288
298
|
|
|
289
299
|
# link_to_inline_edit
|
|
@@ -394,6 +404,17 @@ module InlineFormsHelper
|
|
|
394
404
|
values
|
|
395
405
|
end
|
|
396
406
|
|
|
407
|
+
# A value as text for the screen: a Date as dd-mm-yyyy (since Rails 7.1 a
|
|
408
|
+
# bare Date prints ISO), a time as inline_forms_time_text, anything else
|
|
409
|
+
# as it is. Used by the info elements and the versions panel.
|
|
410
|
+
def inline_forms_value_text(value)
|
|
411
|
+
case value
|
|
412
|
+
when DateTime, Time, ActiveSupport::TimeWithZone then inline_forms_time_text(value)
|
|
413
|
+
when Date then value.strftime(InlineForms::DATE_FORMAT)
|
|
414
|
+
else value
|
|
415
|
+
end
|
|
416
|
+
end
|
|
417
|
+
|
|
397
418
|
# A version or file timestamp: the date with its year
|
|
398
419
|
# (time.formats.inline_forms; rails-i18n's :short has none, so edits years
|
|
399
420
|
# apart read the same), the exact ISO 8601 time on hover.
|
|
@@ -16,7 +16,7 @@ class IsCuracaoPhoneValidator < ActiveModel::EachValidator
|
|
|
16
16
|
|
|
17
17
|
def validate_each(record, attribute, value)
|
|
18
18
|
unless value =~ /[4-8][0-9]{6}/
|
|
19
|
-
record.errors
|
|
19
|
+
record.errors.add(attribute, options[:message] || error_message)
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -29,7 +29,7 @@ class IsEmailAddressValidator < ActiveModel::EachValidator
|
|
|
29
29
|
|
|
30
30
|
def validate_each(record, attribute, value)
|
|
31
31
|
unless value =~ EmailAddress
|
|
32
|
-
record.errors
|
|
32
|
+
record.errors.add(attribute, options[:message] || error_message)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|
|
@@ -16,7 +16,7 @@ class MustBeAValueValidator < ActiveModel::EachValidator
|
|
|
16
16
|
def validate_each(record, attribute, value)
|
|
17
17
|
values = attribute_values(record, attribute)
|
|
18
18
|
if values.assoc(value).nil?
|
|
19
|
-
record.errors
|
|
19
|
+
record.errors.add(attribute, options[:message] || error_message)
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
<li><%= trash_link %></li>
|
|
34
34
|
<% end %>
|
|
35
35
|
<li>
|
|
36
|
-
|
|
36
|
+
<%# data-turbo-method: Turbo sends the DELETE (the engine loads no rails-ujs); data-method for an app that does. %>
|
|
37
|
+
<%= link_to(t("common.logout"), destroy_user_session_path, method: :delete, data: { turbo_method: :delete }) if current_user %>
|
|
37
38
|
</li>
|
|
38
39
|
</ul>
|
|
39
40
|
</li>
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
test/integration/list_params_test.rb covers both.
|
|
128
128
|
-%>
|
|
129
129
|
<% paginate_params = { update: update_span, ul_needed: true } %>
|
|
130
|
-
<% pagination = will_paginate objects, params: paginate_params %>
|
|
130
|
+
<% pagination = will_paginate objects, params: paginate_params, renderer: inline_forms_advancing_link_renderer %>
|
|
131
131
|
<% else %>
|
|
132
132
|
<% if pagination %>
|
|
133
133
|
<%#
|
|
@@ -75,9 +75,8 @@
|
|
|
75
75
|
parent_id: @parent_id,
|
|
76
76
|
ul_needed: true) %>
|
|
77
77
|
<% cancel_opts = @update_span.present? ? inline_forms_turbo_link_data(@update_span) : {} %>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
<% end %>
|
|
78
|
+
<%# The link itself is the button (an <input> inside an <a> is invalid HTML). %>
|
|
79
|
+
<%= link_to "cancel", cancel_path, cancel_opts.merge(class: "button alert inline_forms-new-cancel", role: "button") %>
|
|
81
80
|
<%= submit_tag "ok", :class => "button "-%>
|
|
82
81
|
</div>
|
|
83
82
|
</div>
|
|
@@ -126,8 +126,8 @@
|
|
|
126
126
|
<td><%= sanitize value[0].to_s %></td>
|
|
127
127
|
<td><%= sanitize value[1].to_s %></td>
|
|
128
128
|
<% else %>
|
|
129
|
-
<td><%= value[0] %></td>
|
|
130
|
-
<td><%= value[1] %></td>
|
|
129
|
+
<td><%= inline_forms_value_text(value[0]) %></td>
|
|
130
|
+
<td><%= inline_forms_value_text(value[1]) %></td>
|
|
131
131
|
<% end %>
|
|
132
132
|
</tr>
|
|
133
133
|
</table>
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
<%# Publishes the CSP nonce (nothing without a nonce generator) for the %>
|
|
15
15
|
<%# scripts Turbo inserts. %>
|
|
16
16
|
<%= csp_meta_tag %>
|
|
17
|
+
<%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
|
|
18
|
+
<%# In <head>, so Turbo Drive loads it once: a body copy ran again on each %>
|
|
19
|
+
<%# visit and threw on the second definition of trix-toolbar. %>
|
|
20
|
+
<%= javascript_include_tag "trix.min" %>
|
|
17
21
|
</head>
|
|
18
22
|
|
|
19
23
|
<body class="<%= inline_forms_body_theme_class %>">
|
|
@@ -30,7 +34,5 @@
|
|
|
30
34
|
import { Turbo } from "<%= asset_path('turbo.min.js') %>"
|
|
31
35
|
window.Turbo = Turbo
|
|
32
36
|
<% end %>
|
|
33
|
-
<%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
|
|
34
|
-
<%= javascript_include_tag "trix.min" %>
|
|
35
37
|
</body>
|
|
36
38
|
</html>
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
<%= javascript_include_tag 'popper.min' %>
|
|
32
32
|
<%= javascript_include_tag 'tippy-bundle.umd.min' %>
|
|
33
33
|
<%= javascript_include_tag 'inline_forms/inline_forms' %>
|
|
34
|
+
<%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
|
|
35
|
+
<%# In <head>, so Turbo Drive loads it once: a body copy ran again on each %>
|
|
36
|
+
<%# visit and threw on the second definition of trix-toolbar. %>
|
|
37
|
+
<%= javascript_include_tag "trix.min" %>
|
|
34
38
|
</head>
|
|
35
39
|
|
|
36
40
|
<body class="<%= inline_forms_body_theme_class %>">
|
|
@@ -60,7 +64,5 @@
|
|
|
60
64
|
import { Turbo } from "<%= asset_path('turbo.min.js') %>"
|
|
61
65
|
window.Turbo = Turbo
|
|
62
66
|
<% end %>
|
|
63
|
-
<%# Trix 2 (vendored; no CDN). Self-registers its custom elements on load. %>
|
|
64
|
-
<%= javascript_include_tag "trix.min" %>
|
|
65
67
|
</body>
|
|
66
68
|
</html>
|
data/archived/README.md
CHANGED
|
@@ -39,6 +39,18 @@ Active form elements load from `app/helpers/form_elements/*.rb` only (top-level
|
|
|
39
39
|
4. Remove the symbol from `InlineForms::ARCHIVED_FORM_ELEMENTS` (or leave it and remove the model reference only in your app).
|
|
40
40
|
5. Bump your app/gem as needed; run tests.
|
|
41
41
|
|
|
42
|
+
## Vendoring an archived form element into an app
|
|
43
|
+
|
|
44
|
+
An app can keep using an archived element without changing the gem: put its
|
|
45
|
+
helper methods (`<name>_show`, `<name>_edit`, `<name>_update`, and `_info` if it
|
|
46
|
+
has one) in a module under the app's own `app/helpers/`, plus the models,
|
|
47
|
+
controllers, views, routes and assets its README lists. Since 8.1.81 the boot
|
|
48
|
+
check (`InlineForms.validate_no_archived_form_elements_for!`) skips an archived
|
|
49
|
+
symbol when the app's helpers (`ApplicationController.helpers`) answer
|
|
50
|
+
`<name>_show`, so the element is then the app's. The archived files are
|
|
51
|
+
written in the old top-level `def` style; wrap them in a helper module
|
|
52
|
+
(`module GeoCodeCuracaoHelper … end`) and replace any jQuery/UJS they use.
|
|
53
|
+
|
|
42
54
|
## Adding a new archive entry
|
|
43
55
|
|
|
44
56
|
When retiring a form element:
|
|
@@ -70,17 +70,23 @@ module InlineForms
|
|
|
70
70
|
}
|
|
71
71
|
}.freeze
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
# An app that vendors an archived element (copies its helper into its own
|
|
74
|
+
# app/helpers, see archived/README.md) defines `<element>_show` itself: the
|
|
75
|
+
# element is then the app's, and allowed. `helpers` is the view helper
|
|
76
|
+
# proxy to ask (default: ApplicationController's, with all app helpers).
|
|
77
|
+
def self.validate_no_archived_form_elements_for!(klass, helpers: nil)
|
|
74
78
|
return unless klass.instance_methods.include?(:inline_forms_attribute_list)
|
|
75
79
|
|
|
76
80
|
klass.new.inline_forms_attribute_list.each do |attribute, form_element|
|
|
77
81
|
key = form_element.to_sym
|
|
78
82
|
next unless ARCHIVED_FORM_ELEMENTS.key?(key)
|
|
83
|
+
next if vendored_form_element?(key, helpers)
|
|
79
84
|
|
|
80
85
|
meta = ARCHIVED_FORM_ELEMENTS[key]
|
|
81
86
|
version = meta[:archived_in_version] || meta[:removed_in_version]
|
|
82
87
|
hint = if meta[:archive_path]
|
|
83
|
-
"
|
|
88
|
+
"Vendor it into your app: define #{key}_show (and _edit, _update) in an app helper " \
|
|
89
|
+
"(#{meta[:archive_path]}/README.md, archived/README.md)."
|
|
84
90
|
else
|
|
85
91
|
"See archived/README.md and CHANGELOG #{version}."
|
|
86
92
|
end
|
|
@@ -90,4 +96,11 @@ module InlineForms
|
|
|
90
96
|
"which was retired in inline_forms #{version} (#{meta[:summary]}). #{hint}"
|
|
91
97
|
end
|
|
92
98
|
end
|
|
99
|
+
|
|
100
|
+
def self.vendored_form_element?(key, helpers = nil)
|
|
101
|
+
helpers ||= ::ApplicationController.helpers if defined?(::ApplicationController)
|
|
102
|
+
!!helpers&.respond_to?(:"#{key}_show")
|
|
103
|
+
rescue StandardError
|
|
104
|
+
false
|
|
105
|
+
end
|
|
93
106
|
end
|
|
@@ -7,7 +7,7 @@ module InlineForms
|
|
|
7
7
|
|
|
8
8
|
# date
|
|
9
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(
|
|
10
|
+
link_to_inline_edit object, attribute, object.send(attribute).nil? ? "<i class='fi-plus'></i>".html_safe : object.send(attribute).to_date.strftime(InlineForms::DATE_FORMAT), from_callee: __callee__
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
# Native <input type="date"> (8.1.25; replaces jQuery UI datepicker).
|
|
@@ -23,7 +23,7 @@ module InlineForms
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def date_select_info(object, attribute)
|
|
26
|
-
object.send(attribute).nil? ? "-" : object.send(attribute).to_date
|
|
26
|
+
object.send(attribute).nil? ? "-" : object.send(attribute).to_date.strftime(InlineForms::DATE_FORMAT)
|
|
27
27
|
end
|
|
28
28
|
INLINE_FORMS_FORM_ELEMENT
|
|
29
29
|
end
|
|
@@ -9,6 +9,7 @@ module InlineForms
|
|
|
9
9
|
# show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
|
|
10
10
|
o = object.send(attribute)
|
|
11
11
|
o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
|
|
12
|
+
o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
|
|
12
13
|
o = o._presentation if o.respond_to?(:_presentation)
|
|
13
14
|
o
|
|
14
15
|
end
|
|
@@ -16,6 +17,7 @@ module InlineForms
|
|
|
16
17
|
def info_edit(object, attribute)
|
|
17
18
|
o = object.send(attribute)
|
|
18
19
|
o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
|
|
20
|
+
o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
|
|
19
21
|
o = o._presentation if o.respond_to?(:_presentation)
|
|
20
22
|
o
|
|
21
23
|
end
|
|
@@ -28,6 +30,7 @@ module InlineForms
|
|
|
28
30
|
# show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
|
|
29
31
|
o = object.send(attribute)
|
|
30
32
|
o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
|
|
33
|
+
o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
|
|
31
34
|
o = o._presentation if o.respond_to?(:_presentation)
|
|
32
35
|
o
|
|
33
36
|
end
|
data/lib/inline_forms/version.rb
CHANGED
data/lib/inline_forms.rb
CHANGED
|
@@ -70,6 +70,14 @@ module InlineForms
|
|
|
70
70
|
# Is this user the superadmin? An app that has its own answer
|
|
71
71
|
# (`User#superadmin?`, e.g. only user 1) is asked first; otherwise it is
|
|
72
72
|
# whoever holds the role. A user class with neither is not a superadmin.
|
|
73
|
+
# True when the app has Action Text and its table. An app may load the
|
|
74
|
+
# Action Text railtie (rails/all) without ever installing it, and then has
|
|
75
|
+
# no action_text_rich_texts table: the versions panel and the undo of a
|
|
76
|
+
# delete look for rich text versions only when the table is there.
|
|
77
|
+
def self.action_text_table?
|
|
78
|
+
defined?(ActionText::RichText) ? ActionText::RichText.table_exists? : false
|
|
79
|
+
end
|
|
80
|
+
|
|
73
81
|
def self.superadmin?(user)
|
|
74
82
|
return !!user.superadmin? if user.respond_to?(:superadmin?)
|
|
75
83
|
|
|
@@ -201,6 +209,8 @@ module InlineForms
|
|
|
201
209
|
# Version and file timestamps: time.formats.inline_forms in the gem's en
|
|
202
210
|
# and nl locales, and the default where a locale lacks it.
|
|
203
211
|
TIME_FORMAT = "%d %b %Y %H:%M"
|
|
212
|
+
# A date as the engine shows it (date_select, info, the versions panel).
|
|
213
|
+
DATE_FORMAT = "%d-%m-%Y"
|
|
204
214
|
|
|
205
215
|
# The application's name for the gem's titles and the Devise pages: the
|
|
206
216
|
# host's `application_name` translation, else its
|