@oxyshop/admin 1.3.32 → 1.3.36

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.js CHANGED
@@ -1884,6 +1884,26 @@ $.fn.extend({
1884
1884
  },
1885
1885
  });
1886
1886
 
1887
+ class FeedCategorySelect {
1888
+ constructor(selector) {
1889
+ this.selectSelector = selector;
1890
+ }
1891
+
1892
+ init() {
1893
+ document.querySelectorAll(this.selectSelector).forEach((selectElement) => {
1894
+ const sourceCode = selectElement.getAttribute('data-source-code');
1895
+
1896
+ $(selectElement).dropdown({
1897
+ apiSettings: {
1898
+ url: `/admin/taxon-select-options/${sourceCode}/{query}`,
1899
+ cache: false,
1900
+ },
1901
+ minCharacters: 2,
1902
+ });
1903
+ });
1904
+ }
1905
+ }
1906
+
1887
1907
  class TooltipHelpers {
1888
1908
  static init() {
1889
1909
  TooltipHelpers.initSyliusShippingMethodTooltip();
@@ -1926,6 +1946,97 @@ class TooltipHelpers {
1926
1946
  }
1927
1947
  }
1928
1948
 
1949
+ class AdminSidebarScroller {
1950
+ /**
1951
+ * @param {HTMLElement} adminMenuElement
1952
+ * @param {string} menuItemSelector
1953
+ */
1954
+ constructor(adminMenuElement, menuItemSelector) {
1955
+ this.adminMenuElement = adminMenuElement;
1956
+ this.menuItemSelector = menuItemSelector;
1957
+
1958
+ Object.freeze(this);
1959
+ }
1960
+
1961
+ scrollToActiveLink() {
1962
+ const activeMenuItem = this.getActiveMenuItem();
1963
+ if (null === activeMenuItem) {
1964
+ return // no active menu item
1965
+ }
1966
+
1967
+ this.scrollToElement(activeMenuItem);
1968
+ }
1969
+
1970
+ /**
1971
+ * @private
1972
+ * @return {HTMLElement}
1973
+ */
1974
+ getActiveMenuItem() {
1975
+ const currentPathname = location.pathname;
1976
+ const activeItemSelector = `${this.menuItemSelector}[href="${currentPathname}"]`;
1977
+ return this.adminMenuElement.querySelector(activeItemSelector)
1978
+ }
1979
+
1980
+ /**
1981
+ * @private
1982
+ * @param {HTMLElement} elementToScrollTo
1983
+ */
1984
+ scrollToElement(elementToScrollTo) {
1985
+ // 'scrollIntoViewIfNeeded' is a non-standard browser feature
1986
+ if ('undefined' !== typeof elementToScrollTo.scrollIntoViewIfNeeded) {
1987
+ elementToScrollTo.scrollIntoViewIfNeeded();
1988
+ return
1989
+ }
1990
+
1991
+ elementToScrollTo.scrollIntoView();
1992
+ }
1993
+ }
1994
+
1995
+ class CustomerGroupingRuleConfiguration {
1996
+ /**
1997
+ * @param {string} groupingRuleSelectSelector
1998
+ * @param {string} formGroupSelector
1999
+ */
2000
+ constructor(groupingRuleSelectSelector, formGroupSelector) {
2001
+ this.groupingRuleSelectSelector = groupingRuleSelectSelector;
2002
+ this.formGroupSelector = formGroupSelector;
2003
+ }
2004
+
2005
+ init() {
2006
+ // Event listener on dynamic elements
2007
+ $(document).on('change', this.groupingRuleSelectSelector, (selectEvent) => {
2008
+ this.toggleRuleConfigurationSection(selectEvent.target);
2009
+ });
2010
+
2011
+ // Show all sections with selected value
2012
+ document.querySelectorAll(this.groupingRuleSelectSelector).forEach((selectElement) => {
2013
+ this.toggleRuleConfigurationSection(selectElement);
2014
+ });
2015
+ }
2016
+
2017
+ toggleRuleConfigurationSection(selectElement) {
2018
+ const selectedRuleCode = selectElement.value;
2019
+ const configurationGroup = selectElement.parentElement.parentElement;
2020
+
2021
+ configurationGroup.querySelectorAll(this.formGroupSelector).forEach((formGroup) => {
2022
+ const groupRuleCode = formGroup.getAttribute('data-grouping-rule-code');
2023
+ const toggleFunction = groupRuleCode === selectedRuleCode ? this.showElement : this.hideElement;
2024
+
2025
+ toggleFunction(formGroup);
2026
+ });
2027
+ }
2028
+
2029
+ /** @private */
2030
+ hideElement(element) {
2031
+ element.classList.add('d-none');
2032
+ }
2033
+
2034
+ /** @private */
2035
+ showElement(element) {
2036
+ element.classList.remove('d-none');
2037
+ }
2038
+ }
2039
+
1929
2040
  /**
1930
2041
  * CKEditor config
1931
2042
  */
@@ -2233,4 +2344,18 @@ $(document).ready(() => {
2233
2344
  * Place here next components
2234
2345
  */
2235
2346
  TooltipHelpers.init();
2347
+
2348
+ const feedCategorySelect = new FeedCategorySelect('.ng-feed-category-select');
2349
+ feedCategorySelect.init();
2350
+
2351
+ const customerGroupingRuleConfiguration = new CustomerGroupingRuleConfiguration(
2352
+ 'select.ng-grouping-rule-select',
2353
+ '.ng-grouping-rule-configuration'
2354
+ );
2355
+ customerGroupingRuleConfiguration.init();
2356
+
2357
+ // Admin sidebar scroller
2358
+ const adminSidebarElement = document.getElementById('sidebar');
2359
+ const adminSidebarScroller = new AdminSidebarScroller(adminSidebarElement, 'a.item');
2360
+ adminSidebarScroller.scrollToActiveLink();
2236
2361
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyshop/admin",
3
- "version": "1.3.32",
3
+ "version": "1.3.36",
4
4
  "author": "oXy Online s.r.o. <info@oxyshop.cz>",
5
5
  "main": "lib/index.js",
6
6
  "sass": "scss/main.scss",
package/scss/main.scss CHANGED
@@ -1,3 +1,7 @@
1
1
  @import 'Form/main';
2
2
  @import 'Logo/main';
3
3
  @import 'PickupPoint/main';
4
+
5
+ .d-none {
6
+ display: none !important;
7
+ }
@@ -0,0 +1,45 @@
1
+ export default class AdminSidebarScroller {
2
+ /**
3
+ * @param {HTMLElement} adminMenuElement
4
+ * @param {string} menuItemSelector
5
+ */
6
+ constructor(adminMenuElement, menuItemSelector) {
7
+ this.adminMenuElement = adminMenuElement
8
+ this.menuItemSelector = menuItemSelector
9
+
10
+ Object.freeze(this)
11
+ }
12
+
13
+ scrollToActiveLink() {
14
+ const activeMenuItem = this.getActiveMenuItem()
15
+ if (null === activeMenuItem) {
16
+ return // no active menu item
17
+ }
18
+
19
+ this.scrollToElement(activeMenuItem)
20
+ }
21
+
22
+ /**
23
+ * @private
24
+ * @return {HTMLElement}
25
+ */
26
+ getActiveMenuItem() {
27
+ const currentPathname = location.pathname
28
+ const activeItemSelector = `${this.menuItemSelector}[href="${currentPathname}"]`
29
+ return this.adminMenuElement.querySelector(activeItemSelector)
30
+ }
31
+
32
+ /**
33
+ * @private
34
+ * @param {HTMLElement} elementToScrollTo
35
+ */
36
+ scrollToElement(elementToScrollTo) {
37
+ // 'scrollIntoViewIfNeeded' is a non-standard browser feature
38
+ if ('undefined' !== typeof elementToScrollTo.scrollIntoViewIfNeeded) {
39
+ elementToScrollTo.scrollIntoViewIfNeeded()
40
+ return
41
+ }
42
+
43
+ elementToScrollTo.scrollIntoView()
44
+ }
45
+ }
@@ -0,0 +1,44 @@
1
+ export default class CustomerGroupingRuleConfiguration {
2
+ /**
3
+ * @param {string} groupingRuleSelectSelector
4
+ * @param {string} formGroupSelector
5
+ */
6
+ constructor(groupingRuleSelectSelector, formGroupSelector) {
7
+ this.groupingRuleSelectSelector = groupingRuleSelectSelector
8
+ this.formGroupSelector = formGroupSelector
9
+ }
10
+
11
+ init() {
12
+ // Event listener on dynamic elements
13
+ $(document).on('change', this.groupingRuleSelectSelector, (selectEvent) => {
14
+ this.toggleRuleConfigurationSection(selectEvent.target)
15
+ })
16
+
17
+ // Show all sections with selected value
18
+ document.querySelectorAll(this.groupingRuleSelectSelector).forEach((selectElement) => {
19
+ this.toggleRuleConfigurationSection(selectElement)
20
+ })
21
+ }
22
+
23
+ toggleRuleConfigurationSection(selectElement) {
24
+ const selectedRuleCode = selectElement.value
25
+ const configurationGroup = selectElement.parentElement.parentElement
26
+
27
+ configurationGroup.querySelectorAll(this.formGroupSelector).forEach((formGroup) => {
28
+ const groupRuleCode = formGroup.getAttribute('data-grouping-rule-code')
29
+ const toggleFunction = groupRuleCode === selectedRuleCode ? this.showElement : this.hideElement
30
+
31
+ toggleFunction(formGroup)
32
+ })
33
+ }
34
+
35
+ /** @private */
36
+ hideElement(element) {
37
+ element.classList.add('d-none')
38
+ }
39
+
40
+ /** @private */
41
+ showElement(element) {
42
+ element.classList.remove('d-none')
43
+ }
44
+ }
@@ -0,0 +1,19 @@
1
+ export default class FeedCategorySelect {
2
+ constructor(selector) {
3
+ this.selectSelector = selector
4
+ }
5
+
6
+ init() {
7
+ document.querySelectorAll(this.selectSelector).forEach((selectElement) => {
8
+ const sourceCode = selectElement.getAttribute('data-source-code')
9
+
10
+ $(selectElement).dropdown({
11
+ apiSettings: {
12
+ url: `/admin/taxon-select-options/${sourceCode}/{query}`,
13
+ cache: false,
14
+ },
15
+ minCharacters: 2,
16
+ })
17
+ })
18
+ }
19
+ }
package/src/index.js CHANGED
@@ -6,7 +6,10 @@ import 'sylius-bundle/AdminBundle/Resources/private/js/app'
6
6
 
7
7
  // Scripts - components
8
8
  import './components/taxonAttributes'
9
+ import FeedCategorySelect from './components/feedCategorySelect'
9
10
  import TooltipHelpers from './components/tooltipHelpers'
11
+ import AdminSidebarScroller from './components/adminSidebarScroller'
12
+ import CustomerGroupingRuleConfiguration from './components/customerGroupingRuleConfiguration'
10
13
 
11
14
  // Scripts - plugin
12
15
  import './plugins/ckeditor/index'
@@ -39,4 +42,18 @@ $(document).ready(() => {
39
42
  * Place here next components
40
43
  */
41
44
  TooltipHelpers.init()
45
+
46
+ const feedCategorySelect = new FeedCategorySelect('.ng-feed-category-select')
47
+ feedCategorySelect.init()
48
+
49
+ const customerGroupingRuleConfiguration = new CustomerGroupingRuleConfiguration(
50
+ 'select.ng-grouping-rule-select',
51
+ '.ng-grouping-rule-configuration'
52
+ )
53
+ customerGroupingRuleConfiguration.init()
54
+
55
+ // Admin sidebar scroller
56
+ const adminSidebarElement = document.getElementById('sidebar')
57
+ const adminSidebarScroller = new AdminSidebarScroller(adminSidebarElement, 'a.item')
58
+ adminSidebarScroller.scrollToActiveLink()
42
59
  })