Skip to content

Commit

Permalink
Fixes #37664 - switch to using js-cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Jul 18, 2024
1 parent f824a88 commit cca3247
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//= require hidden_values
//= require select_on_click
//= require lookup_keys
//= require js.cookie

$(function() {
if(window.allJsLoaded){
Expand Down Expand Up @@ -81,7 +82,7 @@ function onContentLoad() {

tfm.i18n.intl.ready.then(function() {
var tz = jstz.determine();
$.cookie('timezone', tz.name(), {
Cookies.set('timezone', tz.name(), {
path: '/',
secure: location.protocol === 'https:',
});
Expand Down
1 change: 1 addition & 0 deletions bundler.d/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
gem 'execjs', '>= 1.4.0', '< 3.0'
gem 'terser', '~> 1.1'
gem 'sass-rails', '~> 6.0'
gem 'js_cookie_rails', '~> 2.2'
end
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"graphql-tag": "^2.11.0",
"intl": "~1.2.5",
"jed": "^1.1.1",
"js-cookie": "^3.0.5",
"os-browserify": "^0.3.0",
"react-intl": "^2.8.0"
},
Expand Down
7 changes: 4 additions & 3 deletions webpack/assets/javascripts/hosts/tableCheckboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/* eslint-disable jquery/no-in-array */

import $ from 'jquery';
import Cookies from 'js-cookie';

import {
sprintf,
Expand Down Expand Up @@ -43,7 +44,7 @@ export function hostChecked({ id, checked }) {
multipleAlert.data('multiple', false);
}
}
$.cookie(cookieName, JSON.stringify(foremanSelectedHosts), {
Cookies.set(cookieName, JSON.stringify(foremanSelectedHosts), {
secure: window.location.protocol === 'https:',
});
toggleActions();
Expand All @@ -62,7 +63,7 @@ function rmHostId(id) {

function readFromCookie() {
try {
const r = $.cookie(cookieName);
const r = Cookies.get(cookieName);
if (r) return $.parseJSON(r);
return [];
} catch (err) {
Expand Down Expand Up @@ -116,7 +117,7 @@ $(document).on('ContentLoad', () => {
});

function removeForemanHostsCookie() {
$.removeCookie(cookieName);
Cookies.remove(cookieName);
}

export function resetSelection() {
Expand Down

0 comments on commit cca3247

Please sign in to comment.