@oxyshop/admin 1.3.35 → 1.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1884,11 +1884,13 @@ $.fn.extend({
1884
1884
  },
1885
1885
  });
1886
1886
 
1887
- $.fn.extend({
1888
- feedCategorySelect() {
1889
- const matchedElements = this;
1887
+ class FeedCategorySelect {
1888
+ constructor(selector) {
1889
+ this.selectSelector = selector;
1890
+ }
1890
1891
 
1891
- Object.values(matchedElements).forEach((selectElement) => {
1892
+ init() {
1893
+ document.querySelectorAll(this.selectSelector).forEach((selectElement) => {
1892
1894
  const sourceCode = selectElement.getAttribute('data-source-code');
1893
1895
 
1894
1896
  $(selectElement).dropdown({
@@ -1899,8 +1901,8 @@ $.fn.extend({
1899
1901
  minCharacters: 2,
1900
1902
  });
1901
1903
  });
1902
- },
1903
- });
1904
+ }
1905
+ }
1904
1906
 
1905
1907
  class TooltipHelpers {
1906
1908
  static init() {
@@ -1990,6 +1992,51 @@ class AdminSidebarScroller {
1990
1992
  }
1991
1993
  }
1992
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
+
1993
2040
  /**
1994
2041
  * CKEditor config
1995
2042
  */
@@ -2288,7 +2335,6 @@ vendorDescriptionElements.forEach((element) => {
2288
2335
  // Components initializations
2289
2336
  $(document).ready(() => {
2290
2337
  $('.ng-taxon-attr-dropdown').taxonAttributes();
2291
- $('.ng-feed-category-select').feedCategorySelect();
2292
2338
 
2293
2339
  $(document).previewUploadedImage('#sylius_payment_method_images');
2294
2340
  $(document).previewUploadedImage('#sylius_shipping_method_images');
@@ -2299,6 +2345,15 @@ $(document).ready(() => {
2299
2345
  */
2300
2346
  TooltipHelpers.init();
2301
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
+
2302
2357
  // Admin sidebar scroller
2303
2358
  const adminSidebarElement = document.getElementById('sidebar');
2304
2359
  const adminSidebarScroller = new AdminSidebarScroller(adminSidebarElement, 'a.item');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyshop/admin",
3
- "version": "1.3.35",
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,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
+ }
@@ -1,8 +1,10 @@
1
- $.fn.extend({
2
- feedCategorySelect() {
3
- const matchedElements = this
1
+ export default class FeedCategorySelect {
2
+ constructor(selector) {
3
+ this.selectSelector = selector
4
+ }
4
5
 
5
- Object.values(matchedElements).forEach((selectElement) => {
6
+ init() {
7
+ document.querySelectorAll(this.selectSelector).forEach((selectElement) => {
6
8
  const sourceCode = selectElement.getAttribute('data-source-code')
7
9
 
8
10
  $(selectElement).dropdown({
@@ -13,5 +15,5 @@ $.fn.extend({
13
15
  minCharacters: 2,
14
16
  })
15
17
  })
16
- },
17
- })
18
+ }
19
+ }
package/src/index.js CHANGED
@@ -6,9 +6,10 @@ import 'sylius-bundle/AdminBundle/Resources/private/js/app'
6
6
 
7
7
  // Scripts - components
8
8
  import './components/taxonAttributes'
9
- import './components/feedCategorySelect'
9
+ import FeedCategorySelect from './components/feedCategorySelect'
10
10
  import TooltipHelpers from './components/tooltipHelpers'
11
11
  import AdminSidebarScroller from './components/adminSidebarScroller'
12
+ import CustomerGroupingRuleConfiguration from './components/customerGroupingRuleConfiguration'
12
13
 
13
14
  // Scripts - plugin
14
15
  import './plugins/ckeditor/index'
@@ -32,7 +33,6 @@ import '@oxyshop/admin/images/admin-logo.svg'
32
33
  // Components initializations
33
34
  $(document).ready(() => {
34
35
  $('.ng-taxon-attr-dropdown').taxonAttributes()
35
- $('.ng-feed-category-select').feedCategorySelect()
36
36
 
37
37
  $(document).previewUploadedImage('#sylius_payment_method_images')
38
38
  $(document).previewUploadedImage('#sylius_shipping_method_images')
@@ -43,6 +43,15 @@ $(document).ready(() => {
43
43
  */
44
44
  TooltipHelpers.init()
45
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
+
46
55
  // Admin sidebar scroller
47
56
  const adminSidebarElement = document.getElementById('sidebar')
48
57
  const adminSidebarScroller = new AdminSidebarScroller(adminSidebarElement, 'a.item')