accrete 0.0.53__py3-none-any.whl → 0.0.55__py3-none-any.whl

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.
accrete/utils/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  from . import dates
2
- from .forms import save_form
3
- from .http import filter_from_querystring
2
+ from .forms import save_form, save_forms, inline_vals_from_post, extend_formset
3
+ from .http import filter_from_querystring, cast_param
4
4
  from .models import get_related_model
accrete/utils/forms.py CHANGED
@@ -1,6 +1,9 @@
1
+ import re
1
2
  import logging
2
3
  from uuid import uuid4
4
+ from typing import Type
3
5
  from django.db import transaction
6
+ from django.forms import BaseFormSet
4
7
 
5
8
  _logger = logging.getLogger(__name__)
6
9
 
@@ -22,3 +25,79 @@ def save_form(form, reraise=False):
22
25
  if reraise:
23
26
  raise e
24
27
  return form
28
+
29
+
30
+ def save_forms(form, inline_formsets: list = None, reraise: bool = False):
31
+
32
+ def handle_error(error):
33
+ form.save_error = repr(error)
34
+ error_id = str(uuid4())[:8]
35
+ _logger.exception(f'{error_id}: {error}')
36
+ form.save_error_id = error_id
37
+
38
+ form.is_saved = False
39
+ form.save_error = None
40
+ form.save_error_id = None
41
+ form.inline_forms = inline_formsets
42
+
43
+ try:
44
+ form.is_valid()
45
+ inlines_valid = all([
46
+ inline_formset.is_valid() for inline_formset in inline_formsets
47
+ ])
48
+ except Exception as e:
49
+ handle_error(e)
50
+ if reraise:
51
+ raise e
52
+ return form
53
+
54
+ if not form.is_valid() or not inlines_valid:
55
+ return form
56
+
57
+ try:
58
+ with transaction.atomic():
59
+ form.save()
60
+ for inline_formset in inline_formsets:
61
+ inline_formset.save()
62
+ except Exception as e:
63
+ handle_error(e)
64
+ if reraise:
65
+ raise e
66
+ return form
67
+
68
+ form.is_saved = True
69
+ return form
70
+
71
+
72
+ def inline_vals_from_post(post: dict, prefix: str) -> list[dict]:
73
+ post_keys = set(re.findall(f'{prefix}-[0-9]+', ', '.join(post.keys())))
74
+ initial_data = {
75
+ post_key: {}
76
+ for post_key in post_keys if not post.get(f'{post_key}-DELETE')
77
+ }
78
+ for key, val in post.items():
79
+ post_key = '-'.join(key.split('-')[:-1])
80
+ if post_key not in initial_data:
81
+ continue
82
+ field_name = key.split('-')[-1]
83
+ initial_data[post_key].update({field_name: val})
84
+ return [val for val in initial_data.values()]
85
+
86
+
87
+ def extend_formset(formset_class, post: dict, data: list[dict]|dict, **formset_kwargs) -> Type[BaseFormSet]:
88
+ formset = formset_class(post, **formset_kwargs)
89
+ if not formset.is_valid():
90
+ return formset
91
+ form_data = post.copy()
92
+ if isinstance(data, dict):
93
+ data = [data]
94
+ prefix = formset_kwargs.get('prefix', 'form')
95
+ total = int(form_data[f'{prefix}-TOTAL_FORMS']) - 1
96
+ for item in data:
97
+ total += 1
98
+ form_data.update({f'{prefix}-{total}-{key}': value for key, value in item.items()})
99
+ form_data[f'{prefix}-TOTAL_FORMS'] = total + 1
100
+ formset = formset_class(form_data, **formset_kwargs)
101
+ for form in formset:
102
+ form._errors = {}
103
+ return formset
accrete/utils/http.py CHANGED
@@ -1,13 +1,14 @@
1
1
  import logging
2
2
  import json
3
3
  import operator
4
+ from typing import Callable
4
5
  from django.db.models import Model, Q, QuerySet
5
6
  from accrete.utils.models import get_related_model
6
7
  from accrete.annotation import Annotation
7
8
 
8
9
  _logger = logging.getLogger(__name__)
9
10
 
10
- Querystring_KEY_MAP = {
11
+ QUERYSTRING_KEY_MAP = {
11
12
  'querystring': 'q',
12
13
  'order': 'order',
13
14
  'paginate_by': 'paginate_by',
@@ -19,7 +20,7 @@ def filter_from_querystring(
19
20
  model: type[Model], get_params: dict, key_map: dict = None
20
21
  ) -> QuerySet:
21
22
 
22
- key_map = key_map or Querystring_KEY_MAP
23
+ key_map = key_map or QUERYSTRING_KEY_MAP
23
24
  querystring = get_params.get(key_map['querystring'], '[]')
24
25
  order = get_params.get(key_map['order']) or model._meta.ordering
25
26
 
@@ -96,4 +97,14 @@ def parse_querystring(model: type[Model], query_string: str) -> Q:
96
97
 
97
98
  ops = {'&': operator.and_, '|': operator.or_, '^': operator.xor}
98
99
  query = parse_query_block(query_data)
99
- return query
100
+ return query
101
+
102
+
103
+ def cast_param(params: dict, param: str, cast_to: Callable, default):
104
+ if param not in params:
105
+ return default
106
+ try:
107
+ return cast_to(params.get(param, default))
108
+ except Exception as e:
109
+ _logger.exception(e)
110
+ return default
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: accrete
3
- Version: 0.0.53
3
+ Version: 0.0.55
4
4
  Summary: Django Shared Schema Multi Tenant
5
5
  Author-email: Benedikt Jilek <benedikt.jilek@pm.me>
6
6
  License: Copyright (c) 2023 Benedikt Jilek
@@ -3,8 +3,8 @@ accrete/admin.py,sha256=MUYUmCFlGYPowiXTbwl4_Q6Cq0-neiL53WW4P76JCLs,1174
3
3
  accrete/annotation.py,sha256=P85kNgf_ka3U8i5cwaiKaAiSm21U-xY9PKmXMZR2ulU,1160
4
4
  accrete/apps.py,sha256=F7ynMLHJr_6bRujWtZVUzCliY2CGKiDvyUmL4F68L2E,146
5
5
  accrete/config.py,sha256=eJUbvyBO3DvAD6xkVKjTAzlXy7V7EK9bVyb91girfUs,299
6
- accrete/forms.py,sha256=2LobDn8EjHIaqBcgE4_Xk-nbfN6CPQasey-l22cQcT0,10740
7
- accrete/managers.py,sha256=EvWURMnGadnH3d-wXwv0-sLJKD6uGY03tSCiRSGsKbo,1170
6
+ accrete/forms.py,sha256=2vUh80qNvPDD8Zl3agKBSJEQeY7bXVLOx_SAB34wf8E,1359
7
+ accrete/managers.py,sha256=CaIJLeBry4NYIXaVUrdUjp7zx4sEWgv-1-ssI1m-EOs,1156
8
8
  accrete/middleware.py,sha256=bUsvhdVdUlbqB-Hd5Y5w6WL8rO8It1VSGA5EZaEPA3o,3266
9
9
  accrete/models.py,sha256=grvRNXg0ZYAJU3KAIX-svuZXeXlfqP4qEJ00nlbV594,5145
10
10
  accrete/tenant.py,sha256=g3ZuTrQr2zqmIopNBRQeCmHEK2R3dlUme_hOV765J6U,1778
@@ -32,12 +32,12 @@ accrete/contrib/system_mail/tests.py,sha256=mrbGGRNg5jwbTJtWWa7zSKdDyeB4vmgZCRc2
32
32
  accrete/contrib/system_mail/views.py,sha256=xc1IQHrsij7j33TUbo-_oewy3vs03pw_etpBWaMYJl0,63
33
33
  accrete/contrib/system_mail/migrations/0001_initial.py,sha256=6cwkkRXGjXvwXoMjjgmWmcPyXSTlUbhW1vMiHObk9MQ,1074
34
34
  accrete/contrib/system_mail/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
- accrete/contrib/ui/__init__.py,sha256=gnU3YLT6kHCxrUm1c-Bsvh8-hpdLGbGYxdNGcNGsXlg,477
35
+ accrete/contrib/ui/__init__.py,sha256=aeRSerct2JWpztNoxWDZXi7FzJhfxptVMVAZl4Sdzqs,504
36
36
  accrete/contrib/ui/admin.py,sha256=suMo4x8I3JBxAFBVIdE-5qnqZ6JAZV0FESABHOSc-vg,63
37
37
  accrete/contrib/ui/apps.py,sha256=E0ao2ox6PQ3ldfeR17FXJUUJuGiWjm2DPCxHbPXGzls,152
38
- accrete/contrib/ui/context.py,sha256=m_QcDK9R3bMC-wB5JTaEBYVmfLGqofw9fVN7Cp5GcX8,6843
38
+ accrete/contrib/ui/context.py,sha256=jVD7w9QIIA2qh04UrO9rYDDrY-0Osr6FLggMlGxvztI,8364
39
39
  accrete/contrib/ui/elements.py,sha256=mxhNC-29YqkPei4bQB6fHkBuOc-mv5WWN7JiUJ_ys0o,1856
40
- accrete/contrib/ui/filter.py,sha256=PnBDVwl2iV3xBg5cphYiib5dUx-0wKHGtwS-FaBDbkA,12188
40
+ accrete/contrib/ui/filter.py,sha256=L7sBpmk454kaSZIQXe9hNj1Xbna8hJ2P-YTvmM7T5FE,12243
41
41
  accrete/contrib/ui/tests.py,sha256=mrbGGRNg5jwbTJtWWa7zSKdDyeB4vmgZCRc2nk6VY-g,60
42
42
  accrete/contrib/ui/urls.py,sha256=TUBlz_CGs9InTZoxM78GSnucA73I8knoh_obt12RUHM,186
43
43
  accrete/contrib/ui/views.py,sha256=WpBKMsxFFG8eG4IN7TW_TPE6i3OFF7gnLDTK7JMKti8,191
@@ -135,16 +135,16 @@ accrete/contrib/ui/static/bulma/versions/bulma-no-dark-mode.scss,sha256=w6Q80mCV
135
135
  accrete/contrib/ui/static/bulma/versions/bulma-no-helpers-prefixed.scss,sha256=6HCUc4hxyaj4_rHqUnoy7aMuFZECHDYh5jvp-1CEtfE,344
136
136
  accrete/contrib/ui/static/bulma/versions/bulma-no-helpers.scss,sha256=5dzAXSgReWUO8GXLbYTpOclPPD0xqvvBiCCX_GOR_5U,313
137
137
  accrete/contrib/ui/static/bulma/versions/bulma-prefixed.scss,sha256=Yj7oEO00jy_G_L32y6rwzp2P5p2YtQ2Pvq4aZhvBSE8,138
138
- accrete/contrib/ui/static/css/accrete.css,sha256=nnpSvbFxkWeTIO2YmULbJB0XlyYuLpPWuxpDkb80Ig8,604658
139
- accrete/contrib/ui/static/css/accrete.css.map,sha256=QDXGC9e92LBCUkLnxhU5J_OXc0ApVccDraQPxw-q10Q,94319
140
- accrete/contrib/ui/static/css/accrete.scss,sha256=2GTcZpbsQypAy1lTABVT_ffRMJJjfmIjFIw0XkhQOAo,9848
138
+ accrete/contrib/ui/static/css/accrete.css,sha256=pgbEKJKk3C0KXn_Vn43V90DGSC-J3Geg-imyTNuT4jk,604948
139
+ accrete/contrib/ui/static/css/accrete.css.map,sha256=g0TsYsK_LT_sa79uPNMFbzAyiUkaPwrUTw4jrE-g0Cg,94375
140
+ accrete/contrib/ui/static/css/accrete.scss,sha256=UHa62b7J14bEoiKYAmxm1dMlnb0lnpLDXWNbKT8kxX0,10385
141
141
  accrete/contrib/ui/static/css/fa.css,sha256=wiz7ZSCn_btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac,102641
142
142
  accrete/contrib/ui/static/css/icons.css,sha256=5550KHsaayeEtRaUdf0h7esQhyec-_5ZfecZ_sOC6v0,6334
143
143
  accrete/contrib/ui/static/icons/Logo.svg,sha256=hGZuxrAa-LRpFavFiF8Lnc7X9OQcqmb6Xl_dxx-27hM,1861
144
144
  accrete/contrib/ui/static/icons/accrete.svg,sha256=CWHJKIgk3hxL7xIaFSz2j1cK-eF1TroCbjcF58bgOIs,1024
145
145
  accrete/contrib/ui/static/js/filter.js,sha256=-8yGsI4juzA9ZkUS4Qrto4s5Wq4teRLyZfJm5dySm7o,24613
146
146
  accrete/contrib/ui/static/js/htmx.min.js,sha256=s73PXHQYl6U2SLEgf_8EaaDWGQFCm6H26I-Y69hOZp4,47755
147
- accrete/contrib/ui/static/js/list.js,sha256=OX_81ifRmawE-1QBU5Qpq_E6sHiiNwIPleETAn9EOJw,4280
147
+ accrete/contrib/ui/static/js/ui.js,sha256=pJm5Wc2bg9Bu0PWafz1cHpGrM5so4U11MkCKdstxUms,1015
148
148
  accrete/contrib/ui/static/webfonts/fa-brands-400.ttf,sha256=VlbVlrxZcWWkIYL2eyufF9KuR6nj7xsEK5pylzlzBwU,207972
149
149
  accrete/contrib/ui/static/webfonts/fa-brands-400.woff2,sha256=OokkzVIDooYocWrttc7wlD2kw7ROP_zukKsGOHtBxJA,117372
150
150
  accrete/contrib/ui/static/webfonts/fa-regular-400.ttf,sha256=XQLcm4WOPIWnlPh-N5hX9P7cTibPFQAXFKmg4LHSKU0,68004
@@ -160,13 +160,14 @@ accrete/contrib/ui/templates/django/forms/widgets/input.html,sha256=CRu81kTsbPwi
160
160
  accrete/contrib/ui/templates/django/forms/widgets/select.html,sha256=jT_UnHizHfdWTdJoSxjcIqTiR7NbVBA4bBSvkuDPRtw,394
161
161
  accrete/contrib/ui/templates/django/forms/widgets/text.html,sha256=MSmLlQc7PsPoDLVtTOOiWNprrsPriNr712yFxaHyDIo,47
162
162
  accrete/contrib/ui/templates/django/forms/widgets/textarea.html,sha256=c9BTedqb3IkXLyVYd0p9pR8DFnsXCNGoxVBWZTk_Fic,278
163
- accrete/contrib/ui/templates/ui/detail.html,sha256=23daOnFjl1rx32zJJ7MtZtRur1Z4-KeHNrbpNPJyliU,5181
164
- accrete/contrib/ui/templates/ui/form.html,sha256=R5digymvYfefbT4QmwzMzWm41GS-JA3CZU6zDTDWr9k,915
165
- accrete/contrib/ui/templates/ui/layout.html,sha256=HGLqygLUX86ED6Kr5W42mO7nhuHTp1lzIzFwBCuWWHc,15067
166
- accrete/contrib/ui/templates/ui/list.html,sha256=oDv8I9xxsxuwoNywRqt0n0leuKocnvViFCC0OFFENDk,1695
167
- accrete/contrib/ui/templates/ui/table.html,sha256=7Ewx5cKfwmNJ1cjLOgvi4AIHaXF8DLqT25_73-M8lMs,4198
168
- accrete/contrib/ui/templates/ui/partials/filter.html,sha256=j0Rz5NzOVVVfFoGrqn0OftREP3ZVed-fHC1y0_reRXo,6808
169
- accrete/contrib/ui/templates/ui/partials/form_errors.html,sha256=1_TQvTdiejsn-43YSyp2YfnP52P-MFYb-HGY0DLm4oA,991
163
+ accrete/contrib/ui/templates/ui/dashboard.html,sha256=udnwiSJEcn2wMaJfTs4P0Y20FU79VguK_9Lq4K2BqtM,160
164
+ accrete/contrib/ui/templates/ui/detail.html,sha256=b1HC1QCGooo6tLh7fLhEDPau1tIOzscLXP6R_PN758I,1093
165
+ accrete/contrib/ui/templates/ui/form.html,sha256=cd6VUNzfIZH2_iudQa_EkqsPaBjyTam4Fm-Kgh8YpkY,655
166
+ accrete/contrib/ui/templates/ui/layout.html,sha256=f8K0KDlh_eDz0UKH0IB34dBjPtDiNgsuPgysK-DYLgE,14792
167
+ accrete/contrib/ui/templates/ui/list.html,sha256=6jmChhCpj6iuSqAG7X_eD5ZjVvwU4cyynmvoH0-juTk,1740
168
+ accrete/contrib/ui/templates/ui/table.html,sha256=bdPN2F7e7i3FHcQ18e0HJKkYT64PpxPRALRjcirJKGQ,4243
169
+ accrete/contrib/ui/templates/ui/partials/filter.html,sha256=2vmeL3980rMmkRnmVtZh9mBHe6S0PTMjaGIN1J6SpNM,7184
170
+ accrete/contrib/ui/templates/ui/partials/form_errors.html,sha256=QjfRriD9Z5SlhIFX__nVXqB3rPg4icbG4G02kML8IcQ,1529
170
171
  accrete/contrib/ui/templates/ui/partials/form_modal.html,sha256=TQVkLypx8y1inZbvUYKtSNHrDXJM1xvYl8IsDDwQwkE,1093
171
172
  accrete/contrib/ui/templates/ui/partials/header.html,sha256=5ER9E6c-vwDxuIuMSXL4F_fq2zYY17R_0A0Ao--H4Us,6916
172
173
  accrete/contrib/ui/templates/ui/partials/onchange_form.html,sha256=K5twTGqRUW1iM2dGtdWntjsJvJVo5EIzKxX2HK-H1yw,160
@@ -213,12 +214,12 @@ accrete/contrib/user_registration/templates/user_registration/mail_templates/con
213
214
  accrete/migrations/0001_initial.py,sha256=azThbc8otEhxJwo8BIgOt5eC30mxXhKJLBAazZFe3BA,4166
214
215
  accrete/migrations/0002_initial.py,sha256=dFOM7kdHlx7pVAh8cTDlZMtciN4O9Z547HAzEKnygZE,1628
215
216
  accrete/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
216
- accrete/utils/__init__.py,sha256=BGXx2NwF4Sc6uaenKNvPZEmHuHVY1u97PPECrd1seA8,129
217
+ accrete/utils/__init__.py,sha256=YwEzwjz-E92LHhqeLsQ4167zXHHY1PFG6xcsAofnmBU,192
217
218
  accrete/utils/dates.py,sha256=apM6kt6JhGrKgoT0jfav1W-8AUVTxNc9xt3fJQ2n0JI,1492
218
- accrete/utils/forms.py,sha256=FHR9IP76dkULCtX4H68xbQG5uvkBQZnDEXSlHyz34iU,606
219
- accrete/utils/http.py,sha256=dR4p-Q8xoTlrjfx0sN--vkY4ZGtYUsqqquAfPNxsXx8,3249
219
+ accrete/utils/forms.py,sha256=UP6vCCTtXD5MqU2LWbNXtk2ZMMEmoty_tjLCbJlqYsY,2984
220
+ accrete/utils/http.py,sha256=mAtQRgADv7zu1_j7A-EKVyb-oqa5a21i4Gd0QfjzGV0,3540
220
221
  accrete/utils/models.py,sha256=EEhv7-sQVtQD24PEb3XcDUAh3VVhVFoMMLyFrDjGEaI,706
221
- accrete-0.0.53.dist-info/METADATA,sha256=e1PCIDM2ktypQyDHf3OG-iMzSjaI0-d8sKzkoMcgiWA,4892
222
- accrete-0.0.53.dist-info/WHEEL,sha256=as-1oFTWSeWBgyzh0O_qF439xqBe6AbBgt4MfYe5zwY,87
223
- accrete-0.0.53.dist-info/licenses/LICENSE,sha256=_7laeMIHnsd3Y2vJEXDYXq_PEXxIcjgJsGt8UIKTRWc,1057
224
- accrete-0.0.53.dist-info/RECORD,,
222
+ accrete-0.0.55.dist-info/METADATA,sha256=Ex39yLJvYLDO_BC1Y8M5RwMJ3fJvX-Ghn2SHYyLtINQ,4892
223
+ accrete-0.0.55.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
224
+ accrete-0.0.55.dist-info/licenses/LICENSE,sha256=_7laeMIHnsd3Y2vJEXDYXq_PEXxIcjgJsGt8UIKTRWc,1057
225
+ accrete-0.0.55.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.22.5
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,146 +0,0 @@
1
- const showFilterButton = document.getElementById('filter-button');
2
- const showActionButton = document.querySelectorAll('.action-modal-button');
3
- const applyFilterFromModalButton = document.getElementById('applyFilterFromModalButton');
4
- const applyFilterFromPanelButton = document.getElementById('applyFilterFromPanelButton');
5
- const tableRows = document.querySelectorAll("tbody > tr" );
6
- const selectAllCheckBox = document.getElementById('select-all-checkbox');
7
- const listCheckBoxes = document.querySelectorAll('.list-checkbox');
8
- const actionButtonsWithIds = document.querySelectorAll('.get-ids-param')
9
-
10
- if (showFilterButton) {
11
- showFilterButton.addEventListener('click', showFilter);
12
- applyFilterFromModalButton.addEventListener('click', applyFilterFromModal);
13
- applyFilterFromPanelButton.addEventListener('click', applyFilterFromPanel);
14
- }
15
-
16
- showActionButton.forEach((element) => {
17
- element.addEventListener('click', showActions);
18
- })
19
-
20
- tableRows.forEach((element) => {
21
- if (element.hasAttribute('data-detail-url')) {
22
- element.addEventListener('click', openTableRow);
23
- }
24
- })
25
-
26
- document.addEventListener('DOMContentLoaded', setFilter);
27
-
28
- if (selectAllCheckBox) {
29
- selectAllCheckBox.addEventListener('click', selectAll);
30
- }
31
-
32
- listCheckBoxes.forEach(box => {
33
- box.addEventListener('click', selectOne);
34
- })
35
-
36
- actionButtonsWithIds.forEach(button => {
37
- button.addEventListener('click', callActionWithIds);
38
- })
39
-
40
- function openTableRow() {
41
- // console.log(this)
42
- window.location = this.getAttribute('data-detail-url');
43
- }
44
-
45
- function selectAll() {
46
- const currentValue = selectAllCheckBox.checked;
47
- listCheckBoxes.forEach(checkBox => {
48
- checkBox.checked = currentValue;
49
- })
50
- }
51
-
52
- function selectOne(e) {
53
- e.stopPropagation();
54
- selectAllCheckBox.checked = false;
55
- }
56
-
57
- function showFilter() {
58
- let modal = document.getElementById('filter-modal');
59
- let closeActions = modal.querySelectorAll('.filter-modal-close');
60
- closeActions.forEach((action) => {
61
- action.addEventListener('click', hideFilter);
62
- })
63
- modal.classList.add('is-active');
64
- }
65
-
66
- function showActions() {
67
- let modal = document.getElementById('action-modal');
68
- let closeActions = modal.querySelectorAll('.action-modal-close');
69
- closeActions.forEach((action) => {
70
- action.addEventListener('click', hideActions);
71
- })
72
- modal.classList.add('is-active');
73
- }
74
-
75
- function hideActions() {
76
- let modal = document.getElementById('action-modal');
77
- modal.classList.remove('is-active');
78
- }
79
-
80
-
81
- function hideFilter() {
82
- let modal = document.getElementById('filter-modal');
83
- modal.classList.remove('is-active');
84
- }
85
-
86
- function setFilter() {
87
- let queryString = window.location.href.split('?')[1];
88
- if (queryString) {
89
- let terms = document.querySelectorAll('input, .filter-term');
90
- let queries = queryString.split('&');
91
-
92
- queries.forEach((query) => {
93
- terms.forEach((term) => {
94
- if (term.name === query.split('=')[0]) {
95
- term.value = decodeURIComponent(query.split('=')[1]);
96
- }
97
- })
98
- })
99
- }
100
- }
101
-
102
- function applyFilter(terms) {
103
- const baseURl = window.location.href.split('?')[0];
104
- let urlQueryString= '?';
105
-
106
- terms.forEach((term) => {
107
- if (term.value && term.value !== '') {
108
- urlQueryString += term.name + '=' + encodeURIComponent(term.value) + '&';
109
- }
110
- })
111
-
112
- window.location.assign(baseURl + urlQueryString);
113
- }
114
-
115
- function applyFilterFromModal() {
116
- let modal = document.getElementById('filter-modal');
117
- let terms = modal.querySelectorAll('input, .filter-term');
118
- applyFilter(terms);
119
- }
120
-
121
- function applyFilterFromPanel() {
122
- let panel = document.getElementById('filter-panel');
123
- let terms = panel.querySelectorAll('input, .filter-term');
124
- applyFilter(terms);
125
- }
126
-
127
- function resetFilter() {
128
- window.location.assign(window.location.href.split('?')[0]);
129
- }
130
-
131
- function getSelectedIdsUrlParam() {
132
- let ids = [];
133
- listCheckBoxes.forEach(box=> {
134
- if (box.checked) {
135
- ids.push(box.name);
136
- }
137
- })
138
- if (selectAllCheckBox.checked || !ids.length) {
139
- return ''
140
- }
141
- return 'list__id__in=' + ids
142
- }
143
-
144
- function callActionWithIds() {
145
- this.href += '&' + getSelectedIdsUrlParam();
146
- }