Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove page JS #889

Merged
merged 13 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ source "https://rubygems.org"

gem "bootstrap-datepicker-rails"
gem "chartkick"
gem "coffee-rails"
gem "devise", "~> 4.7"
gem "devise-bootstrap-views", "~> 0.0.7"
gem "google-api-client", "~> 0.9"
Expand Down
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ GEM
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.1)
tilt (2.3.0)
tilt (2.4.0)
timeout (0.4.1)
trailblazer-option (0.1.2)
turbolinks (2.5.4)
Expand Down Expand Up @@ -496,7 +496,6 @@ DEPENDENCIES
capybara
chartkick
climate_control (~> 1.2)
coffee-rails
devise (~> 4.7)
devise-bootstrap-views (~> 0.0.7)
dotenv
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ def external_link(object, prefix: nil)
external_id
end
end

def showing_tab?(tab_id)
params[:show_tab] == tab_id || @show_tab == tab_id
end
end
5 changes: 0 additions & 5 deletions app/javascript/stockaid/all_or_none.coffee

This file was deleted.

8 changes: 8 additions & 0 deletions app/javascript/stockaid/all_or_none.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
$(document).on("click", ".js-select-all", ev => $("input:checkbox").prop("checked", true));

$(document).on("click", ".js-select-none", ev => $("input:checkbox").prop("checked", false));
2 changes: 0 additions & 2 deletions app/javascript/stockaid/auto_submit.coffee

This file was deleted.

6 changes: 6 additions & 0 deletions app/javascript/stockaid/auto_submit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
$(document).on("change", ".auto-submit", e => $(e.target).closest("form").submit());
54 changes: 0 additions & 54 deletions app/javascript/stockaid/bins.coffee

This file was deleted.

68 changes: 68 additions & 0 deletions app/javascript/stockaid/bins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
$.guards.name("binLocationUnique").grouped().target("#bin-location-error-target").message("Location must be unique.").using(function(values) {
const rack = values[0];
const shelf = values[1];
if ((rack === "") && (shelf === "")) { return true; }

for (var x of Array.from($("#bin-location-selector option[data-rack][data-shelf]"))) {
var xRack = $(x).data("rack");
var xShelf = $(x).data("shelf");
if ((rack === xRack) && (shelf === xShelf)) { return false; }
}

return true;
});

$.guards.name("binitemdupes").message("You have duplicate items selected.").using(function(value) {
const values = [];
$(".item-selector").each(function() {
return values.push($(this).val());
});
let count = 0;

for (var x of Array.from(values)) {
if (x === value) { count += 1; }
}

return count <= 1;
});

$(document).on("change", "#bin-location-selector", function(event) {
const option = $("option:selected", this);
const value = option.val();
$("#existing-bin-location-fields, #new-bin-location-fields").empty();

switch (value) {
case "": // Do nothing
case "new":
var content = tmpl("new-bin-location-template", {});
return $("#new-bin-location-fields").html(content).show();
default:
content = tmpl("existing-bin-location-template", option.data());
return $("#existing-bin-location-fields").html(content).show();
}
});

expose("eachBin", callback => Array.from(embedded.bins()).map((bin) => callback(bin)));

$(document).on("turbolinks:load", () => {
if ($("#bin-items-table").length > 0) {
let numRows = 1;
let selectedItems = embedded.binSelectedItems();

if (selectedItems.length > 0) {
numRows = selectedItems.length;
}

$.tableEditable("bin-items-table").initialize(numRows, (rows) => {
for (let i = 0; i < selectedItems.length; i++) {
rows[i].find("select").val(selectedItems[i]).trigger("change");
}
});
}
});
13 changes: 0 additions & 13 deletions app/javascript/stockaid/check_uncheck_all.coffee

This file was deleted.

20 changes: 20 additions & 0 deletions app/javascript/stockaid/check_uncheck_all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
$(document).on("click", ".check-all", function(e) {
e.preventDefault();
e.stopPropagation();

const selector = $(this).data("check-all-target");
return $(selector).find(":checkbox").prop("checked", true).change();
});

$(document).on("click", ".uncheck-all", function(e) {
e.preventDefault();
e.stopPropagation();

const selector = $(this).data("uncheck-all-target");
return $(selector).find(":checkbox").prop("checked", false).change();
});
28 changes: 0 additions & 28 deletions app/javascript/stockaid/cookies.coffee

This file was deleted.

42 changes: 42 additions & 0 deletions app/javascript/stockaid/cookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const createCookie = function(name, value, days) {
if (!days || (days < 1)) { days = 365 * 10; }
name = encodeURIComponent(name);
value = encodeURIComponent(`${value}`);
const expires = new Date();
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
return document.cookie = `${name}=${value}; expires=${expires.toGMTString()}; path=/`;
};

const readCookie = function(name, defaultValue) {
const namePrefix = `${encodeURIComponent(name)}=`;
const jar = document.cookie.split(";");

for (var cookie of Array.from(jar)) {
cookie = cookie.trim();

if (cookie.indexOf(namePrefix) === 0) {
return decodeURIComponent(cookie.substring(namePrefix.length, cookie.length));
}
}

return defaultValue;
};

const readCookieInt = function(name, defaultValue) {
if (defaultValue == null) { defaultValue = 0; }
const result = readCookie(name, `${defaultValue}`);
return parseInt(result, 10);
};

$.cookies = {
create: createCookie,
read: readCookie,
readInt: readCookieInt
};
69 changes: 0 additions & 69 deletions app/javascript/stockaid/count_sheets.coffee

This file was deleted.

Loading