forked from fixin.me/fixin.me
Migrate all inline JS to Stimulus controllers
Add stimulus-rails gem and wire up 7 controllers: - measurements_view_controller: view toggle (compact/wide) via localStorage - measurements_controller: grouped rows MutationObserver - charts_controller: Plotly chart rendering - form_controller: keyboard shortcuts (Escape/Enter) and submit validation - details_controller: quantity picker state, focusout close, MutationObserver - readout_unit_controller: default unit button enable/disable + PATCH submission - drag_controller: drag-and-drop for quantity reparenting and unit rebasing Remove all inline onclick/onkeydown/ondrag*/onsubmit handlers from templates. Remove all window.* global exports from application.js. Remove bare <script> block from measurements/_form.html.erb. Remove turbo:load listeners for behavior now in controller connect(). application.js now only contains: Turbo Stream custom action definitions and the showPage visibility listener. Document Stimulus conventions in CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<%= tabular_fields_for @unit, form: form_tag do |form| %>
|
||||
<%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
|
||||
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
|
||||
<%- tag.tr id: row, class: "form",
|
||||
data: {controller: 'form', action: 'keydown->form#processKey',
|
||||
link: link, form: form_tag, hidden_row: hidden_row} do %>
|
||||
|
||||
<td style="--depth:<%= @unit.base_id? ? 1 : 0 %>">
|
||||
<%= form.text_field :symbol, required: true, autofocus: true, size: 12 %>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<%= tag.tr id: dom_id(unit),
|
||||
ondragstart: "dragStart(event)", ondragend: "dragEnd(event)",
|
||||
ondragover: "dragOver(event)", ondrop: "drop(event)",
|
||||
ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)",
|
||||
data: {drag_path: rebase_unit_path(unit),
|
||||
drop_id: dom_id(unit.base || unit),
|
||||
drop_id_param: "unit[base_id]"} do %>
|
||||
draggable: true,
|
||||
data: {controller: 'drag',
|
||||
action: 'dragstart->drag#start dragend->drag#end dragover->drag#over drop->drag#drop dragenter->drag#enter dragleave->drag#leave',
|
||||
drag_drag_path_value: rebase_unit_path(unit),
|
||||
drag_drop_id_value: dom_id(unit.base || unit),
|
||||
drag_drop_id_param_value: 'unit[base_id]'} do %>
|
||||
|
||||
<td style="--depth:<%= unit.base_id? ? 1 : 0 %>">
|
||||
<%= link_to unit, edit_unit_path(unit), class: 'link', onclick: 'this.blur();',
|
||||
|
||||
@@ -22,9 +22,10 @@
|
||||
<% end %>
|
||||
</tr>
|
||||
<%= tag.tr id: "unit_", hidden: true,
|
||||
ondragover: "dragOver(event)", ondrop: "drop(event)",
|
||||
ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)",
|
||||
data: {drop_id: "unit_", drop_id_param: "unit[base_id]"} do %>
|
||||
data: {controller: 'drag',
|
||||
action: 'dragover->drag#over drop->drag#drop dragenter->drag#enter dragleave->drag#leave',
|
||||
drag_drop_id_value: 'unit_',
|
||||
drag_drop_id_param_value: 'unit[base_id]'} do %>
|
||||
<th colspan="5"><%= t '.top_level_drop' %></th>
|
||||
<% end %>
|
||||
</thead>
|
||||
|
||||
Reference in New Issue
Block a user