Skip to content

Commit

Permalink
fix(rubyforgood#3556): remove all cocoon code
Browse files Browse the repository at this point in the history
Removes all cocoon code. Depends on rubyforgood#4182.

Needs to clear precompiled assets to work.
  • Loading branch information
elasticspoon authored and dorner committed Apr 2, 2024
1 parent dcbc4e5 commit e0457da
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 252 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ gem "stimulus-rails"

##### VIEWS/CONTROLLERS #####

# Adds easy links to add or remove associations in a form (e.g. line items)
gem "cocoon"
# Adds filter support to models and views.
gem "filterrific"
# Generates JSON structures via a builder interface.
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ GEM
clockwork (3.0.2)
activesupport
tzinfo
cocoon (1.2.15)
coderay (1.1.3)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
Expand Down Expand Up @@ -679,7 +678,6 @@ DEPENDENCIES
capybara (~> 3.40)
capybara-screenshot
clockwork
cocoon
coverband
cuprite
database_cleaner-active_record (~> 2.1)
Expand Down
49 changes: 0 additions & 49 deletions app/helpers/ui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,6 @@ def remove_element_button(label, container_selector:, soft: false, **html_attrs)
end
end

def add_line_item_button(form, node, options = {})
text = options[:text] || "Add another item"
size = options[:size] || "md"
type = options[:type] || "primary"
partial = options[:partial] || "line_items/line_item_fields"
link_to_add_association form, :line_items,
data: {
association_insertion_node: node,
association_insertion_method: "append"
}, id: "__add_line_item", class: "btn btn-#{size} btn-#{type}", partial: partial do
fa_icon "plus", text: text
end
end

def delete_line_item_button(form, options = {})
text = options[:text] || "Remove"
size = options[:text] || "sm"
type = options[:type] || "danger"

link_to_remove_association form, class: "btn btn-#{size} btn-#{type}", style: "width: 100px;" do
fa_icon "trash", text: text
end
end

def delete_button_to(link, options = {})
# Delete has a few extra options we have to consider to ensure the button works right
data = options[:no_confirm] ? {} : { data: { confirm: options[:confirm] || "Are you sure?" } }
Expand Down Expand Up @@ -225,29 +201,4 @@ def optional_data_text(field)
tag.span("Not-Provided", class: "text-muted font-weight-light")
end
end

def add_served_area_button(form, node, options = {})
text = options[:text] || "Add another county"
size = options[:size] || "md"
type = options[:type] || "primary"
partial = options[:partial] || "served_areas/served_area_fields"
link_to_add_association form, :served_areas,
data: {
association_insertion_node: node,
association_insertion_method: "append"
}, id: "__add_partner_served_area", class: "btn btn-#{size} btn-#{type} add-partner-served_area", partial: partial do
fa_icon "plus", text: text
end
end

def delete_served_area_button(form, options = {})
text = options[:text] || "Remove"
size = options[:text] || "sm"
type = options[:type] || "danger"

link_to_remove_association form, class: "btn btn-#{size} btn-#{type} remove_served_area", style: "width: 100px;",
"data-action": "click->served-area#zeroShareValue click->area-served#calculateClientShareTotal" do
fa_icon "trash", text: text
end
end
end
1 change: 0 additions & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ window.$ = jQuery
import "startup"
import "jquery-ui"
import 'admin-lte'
import "cocoon-js-vanilla";
import 'filterrific'
import { Turbo } from "@hotwired/turbo-rails"
import "trix"
Expand Down
187 changes: 0 additions & 187 deletions app/javascript/cocoon-js-vanilla.js

This file was deleted.

21 changes: 15 additions & 6 deletions app/javascript/controllers/form_input_controller.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
import { Controller } from "@hotwired/stimulus"
import { Controller } from "@hotwired/stimulus";

// Connects to data-controller="form-input"
export default class extends Controller {
static targets = ["addButton", "addTemplate", "removeContainer", "addContainer"];
static targets = [
"addButton",
"addTemplate",
"removeContainer",
"addContainer",
];

// requires data-add-dest-selector to be set on the add button OR
// data-form-input-target="addContainer" to be set on the add container
addItem(event) {
const template = this.addTemplateTarget.content.firstElementChild.outerHTML;
const dest = document.querySelector(event.target.dataset.addDestSelector) ||
const dest =
document.querySelector(event.target.dataset.addDestSelector) ||
this.addContainerTarget;

const uniqId = new Date().getTime();
const rendered = this.setUniqIds(template, uniqId);

dest.insertAdjacentHTML("beforeend", rendered);

var afterInsert = new CustomEvent('cocoon:after-insert',
{ bubbles: true, detail: [rendered, event, dest.lastElementChild] });
var afterInsert = new CustomEvent("form-input-after-insert", {
bubbles: true,
detail: dest.lastElementChild,
});

dest.dispatchEvent(afterInsert);
}

// requires data-remove-parent-selector to be set on the remove button OR
// data-form-input-target="removeContainer" to be set on the container to remove
removeItem(event) {
const wrapper = event.target.closest(event.target.dataset.removeParentSelector) ||
const wrapper =
event.target.closest(event.target.dataset.removeParentSelector) ||
this.removeContainerTarget;
const removeSoft = event.target.dataset.removeSoft === "false";

Expand Down
4 changes: 2 additions & 2 deletions app/javascript/utils/distributions_and_transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ $(function() {
});

$(document).on(
"cocoon:after-insert",
"form-input-after-insert",
"form.storage-location-required",
function(e) {
const insertedItem = $(e.detail[2]);
const insertedItem = $(e.detail);
request_storage_location_and_populate_item($("select", insertedItem));
insertedItem
.find("input.__barcode_item_lookup")
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/utils/donations.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ $(function() {
});

$(document).on(
"cocoon:after-insert",
"form-input-after-insert",
"#donation_line_items",
(e) => {
const insertedItem = $(e.detail[2]);
const insertedItem = $(e.detail);
insertedItem
.find("input.__barcode_item_lookup")
.attr("id", `_barcode-lookup-${$(".nested-fields").length - 1}`)
Expand Down
1 change: 0 additions & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pin "jquery", to: "https://ga.jspm.io/npm:[email protected]/dist/jquery.js", preload: true
pin "admin-lte", to: "adminlte.js", preload: true
pin "cocoon-js-vanilla", to: "cocoon-js-vanilla.js"
pin "application", preload: true
pin "startup", to: "startup.js", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
Expand Down

0 comments on commit e0457da

Please sign in to comment.