diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 25babb1b055..02ad119b5e4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -79,14 +79,6 @@ function onContentLoad() { password_caps_lock_hint(); - tfm.i18n.intl.ready.then(function() { - var tz = jstz.determine(); - $.cookie('timezone', tz.name(), { - path: '/', - secure: location.protocol === 'https:', - }); - }); - $('.full-value').SelectOnClick(); activate_select2(':root'); diff --git a/package.json b/package.json index 7ae5676471f..92b453a5fdf 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/webpack/assets/javascripts/bundle.js b/webpack/assets/javascripts/bundle.js index 397994b337c..8074352d344 100644 --- a/webpack/assets/javascripts/bundle.js +++ b/webpack/assets/javascripts/bundle.js @@ -1,5 +1,6 @@ import 'core-js/shim'; import 'regenerator-runtime/runtime'; +import Cookies from 'js-cookie'; import compute from './foreman_compute_resource'; import componentRegistry from './react_app/components/componentRegistry'; @@ -56,4 +57,5 @@ window.tfm = Object.assign(window.tfm || {}, { componentRegistry, store, lookupKeys, + Cookies, }); diff --git a/webpack/assets/javascripts/hosts/tableCheckboxes.js b/webpack/assets/javascripts/hosts/tableCheckboxes.js index 5e1a1df6c85..56121c4ff69 100644 --- a/webpack/assets/javascripts/hosts/tableCheckboxes.js +++ b/webpack/assets/javascripts/hosts/tableCheckboxes.js @@ -14,6 +14,7 @@ /* eslint-disable jquery/no-in-array */ import $ from 'jquery'; +import Cookies from 'js-cookie'; import { sprintf, @@ -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(); @@ -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) { @@ -116,7 +117,7 @@ $(document).on('ContentLoad', () => { }); function removeForemanHostsCookie() { - $.removeCookie(cookieName); + Cookies.remove(cookieName); } export function resetSelection() { diff --git a/webpack/assets/javascripts/react_app/common/I18n.js b/webpack/assets/javascripts/react_app/common/I18n.js index ad2030d70a6..654caf885cb 100644 --- a/webpack/assets/javascripts/react_app/common/I18n.js +++ b/webpack/assets/javascripts/react_app/common/I18n.js @@ -2,6 +2,8 @@ /* eslint-disable import/no-dynamic-require */ import Jed from 'jed'; import { addLocaleData } from 'react-intl'; +import Cookies from 'js-cookie'; +import jstz from 'jstz'; import forceSingleton from './forceSingleton'; class IntlLoader { @@ -18,6 +20,10 @@ class IntlLoader { await this.fetchIntl(); const localeData = require(/* webpackChunkName: 'react-intl/locale/[request]' */ `react-intl/locale-data/${this.locale}`); addLocaleData(localeData); + Cookies.set('timezone', jstz.determine().name(), { + path: '/', + secure: window.location.protocol === 'https:', + }); return true; }