django-spire 0.25.2__py3-none-any.whl → 0.26.0__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.
- django_spire/auth/templates/django_spire/auth/element/android_and_chrome_app_install_element.html +33 -0
- django_spire/auth/templates/django_spire/auth/element/ios_app_install_element.html +48 -0
- django_spire/auth/templates/django_spire/auth/page/auth_page.html +2 -1
- django_spire/auth/templates/django_spire/auth/page/login_page.html +2 -0
- django_spire/comment/mixins.py +3 -3
- django_spire/comment/templates/django_spire/comment/card/comment_list_card.html +8 -5
- django_spire/comment/templates/django_spire/comment/form/comment_form.html +3 -3
- django_spire/comment/templates/django_spire/comment/form/content/comment_form_content.html +1 -0
- django_spire/comment/templates/django_spire/comment/item/comment_item_ellipsis.html +12 -8
- django_spire/comment/views.py +8 -8
- django_spire/consts.py +1 -1
- django_spire/contrib/form/utils.py +3 -3
- django_spire/contrib/queryset/filter_tools.py +56 -14
- django_spire/contrib/queryset/mixins.py +24 -3
- django_spire/contrib/service/django_model_service.py +5 -6
- django_spire/core/management/commands/spire_startapp.py +42 -25
- django_spire/core/management/commands/spire_startapp_pkg/exceptions.py +5 -0
- django_spire/core/management/commands/spire_startapp_pkg/maps.py +64 -32
- django_spire/core/management/commands/spire_startapp_pkg/template/app/constants.py.template +1 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/app/forms.py.template +4 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/app/models.py.template +2 -1
- django_spire/core/management/commands/spire_startapp_pkg/template/app/querysets.py.template +15 -6
- django_spire/core/management/commands/spire_startapp_pkg/template/app/urls/__init__.py.template +1 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/app/urls/form_urls.py.template +6 -6
- django_spire/core/management/commands/spire_startapp_pkg/template/app/urls/page_urls.py.template +2 -2
- django_spire/core/management/commands/spire_startapp_pkg/template/app/urls/template_urls.py.template +12 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/app/views/form_views.py.template +10 -11
- django_spire/core/management/commands/spire_startapp_pkg/template/app/views/page_views.py.template +17 -3
- django_spire/core/management/commands/spire_startapp_pkg/template/app/views/template_views.py.template +40 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/card/${form_card_template_name}.html.template +1 -1
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/card/${list_base_card_template_name}.html.template +16 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/card/${list_items_card_template_name}.html.template +16 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/card/${list_table_card_template_name}.html.template +16 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/container/${list_container_template_name}.html.template +1 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/form/${list_filter_form_template_name}.html.template +30 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/item/${item_template_name}.html.template +32 -20
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/item/${list_items_template_name}.html.template +3 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/page/${detail_page_template_name}.html.template +3 -3
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/page/${form_page_template_name}.html.template +2 -2
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/page/${list_page_template_name}.html.template +2 -2
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/table/${table_row_template_name}.html.template +6 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/table/${table_rows_template_name}.html.template +3 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/table/${table_template_name}.html.template +6 -0
- django_spire/core/management/commands/spire_startapp_pkg/user_input.py +82 -9
- django_spire/core/management/commands/spire_startapp_pkg/validator.py +19 -6
- django_spire/core/querysets.py +19 -0
- django_spire/core/templates/django_spire/badge/base_badge.html +2 -3
- django_spire/core/templates/django_spire/base/base.html +1 -0
- django_spire/core/templates/django_spire/button/base_button.html +2 -1
- django_spire/core/templates/django_spire/card/title_card.html +13 -10
- django_spire/core/templates/django_spire/container/container.html +1 -1
- django_spire/core/templates/django_spire/filtering/form/base_session_filter_form.html +1 -1
- django_spire/core/templates/django_spire/form/field/_base_file_field.html +216 -0
- django_spire/core/templates/django_spire/form/field/_multi_checkbox_field.html +52 -0
- django_spire/core/templates/django_spire/form/field/base_field.html +128 -0
- django_spire/core/templates/django_spire/form/field/char_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/color_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/date_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/datetime_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/decimal_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/element/select_checkmark_element.html +4 -0
- django_spire/core/templates/django_spire/form/field/element/select_down_arrow_element.html +5 -0
- django_spire/core/templates/django_spire/form/field/email_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/input_field.html +13 -0
- django_spire/core/templates/django_spire/form/field/item/select_choice_item.html +15 -0
- django_spire/core/templates/django_spire/form/field/item/selected_choice_item.html +5 -0
- django_spire/core/templates/django_spire/form/field/list_field.html +112 -0
- django_spire/core/templates/django_spire/form/field/multi_file_field.html +90 -0
- django_spire/core/templates/django_spire/form/field/multi_select_field.html +155 -0
- django_spire/core/templates/django_spire/form/field/number_field.html +11 -0
- django_spire/core/templates/django_spire/form/field/password_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/radio_field.html +24 -0
- django_spire/core/templates/django_spire/form/field/range_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/search_and_select_field.html +119 -0
- django_spire/core/templates/django_spire/form/field/search_field.html +5 -0
- django_spire/core/templates/django_spire/form/field/select_field.html +78 -0
- django_spire/core/templates/django_spire/form/field/single_checkbox_field.html +27 -0
- django_spire/core/templates/django_spire/form/field/single_file_field.html +90 -0
- django_spire/core/templates/django_spire/form/field/telephone_field.html +1 -0
- django_spire/core/templates/django_spire/form/field/text_field.html +11 -0
- django_spire/core/templates/django_spire/form/field/time_field.html +1 -0
- django_spire/core/templates/django_spire/infinite_scroll/base.html +2 -1
- django_spire/core/templatetags/model_tags.py +34 -0
- django_spire/metric/report/tools.py +0 -2
- {django_spire-0.25.2.dist-info → django_spire-0.26.0.dist-info}/METADATA +1 -1
- {django_spire-0.25.2.dist-info → django_spire-0.26.0.dist-info}/RECORD +89 -45
- django_spire/core/management/commands/spire_startapp_pkg/template/app/tests/test_intelligence/__init__.py.template +0 -0
- django_spire/core/management/commands/spire_startapp_pkg/template/templates/card/${list_card_template_name}.html.template +0 -18
- {django_spire-0.25.2.dist-info → django_spire-0.26.0.dist-info}/WHEEL +0 -0
- {django_spire-0.25.2.dist-info → django_spire-0.26.0.dist-info}/licenses/LICENSE.md +0 -0
- {django_spire-0.25.2.dist-info → django_spire-0.26.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
{% load django_glue %}
|
|
2
|
+
|
|
3
|
+
<div x-data="{
|
|
4
|
+
value: null
|
|
5
|
+
}"
|
|
6
|
+
{% if glue_model_field %}
|
|
7
|
+
x-modelable="value"
|
|
8
|
+
x-model="{{ glue_model_field }}"
|
|
9
|
+
{% endif %}
|
|
10
|
+
|
|
11
|
+
{% if glue_field %}
|
|
12
|
+
x-modelable="value"
|
|
13
|
+
x-model="{{ glue_field }}.value"
|
|
14
|
+
{% endif %}
|
|
15
|
+
>
|
|
16
|
+
<div
|
|
17
|
+
x-data="{
|
|
18
|
+
glue_field: undefined,
|
|
19
|
+
init() {
|
|
20
|
+
let glue_model_field_name = '{{ glue_model_field }}'
|
|
21
|
+
let glue_field_name = '{{ glue_field }}'
|
|
22
|
+
|
|
23
|
+
if (glue_model_field_name) {
|
|
24
|
+
this.init_glue_model_field(glue_model_field_name)
|
|
25
|
+
} else if (glue_field_name) {
|
|
26
|
+
this.init_glue_field(glue_field_name)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (this.is_valid_glue_field()) {
|
|
30
|
+
this.set_field_attrs()
|
|
31
|
+
this.add_error_event_listener()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.$watch('glue_field', value => {
|
|
35
|
+
if (this.is_valid_glue_field()) {
|
|
36
|
+
this.set_field_attrs()
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
init_glue_model_field(glue_model_field_name) {
|
|
41
|
+
let path = glue_model_field_name.split('.')
|
|
42
|
+
this.glue_field = this[`${path[0]}`]['glue_fields'][`${path[1]}`]
|
|
43
|
+
},
|
|
44
|
+
init_glue_field(glue_field_name) {
|
|
45
|
+
this.glue_field = glue_field_name.split('.').reduce((acc, part) => acc && acc[part], this)
|
|
46
|
+
},
|
|
47
|
+
set_field_attrs() {
|
|
48
|
+
let form_field = this.$refs.glue_field
|
|
49
|
+
|
|
50
|
+
// Remove attrs that no longer exist
|
|
51
|
+
let attr_names = this.glue_field._attr_names
|
|
52
|
+
for (const attr_name of this.glue_field._historic_attr_names) {
|
|
53
|
+
if (!attr_names.includes(attr_name)) {
|
|
54
|
+
form_field.removeAttribute(attr_name)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Set attrs on field
|
|
59
|
+
for (let attr of this.glue_field.attrs) {
|
|
60
|
+
form_field.setAttribute(attr.name, attr.value)
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
add_error_event_listener() {
|
|
64
|
+
this.$refs.glue_field.addEventListener('invalid', (e) => {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
this.glue_field.error = e.target.validationMessage
|
|
67
|
+
this.$refs.glue_field.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
is_valid_glue_field() {
|
|
71
|
+
return this.glue_field && this.$refs.glue_field
|
|
72
|
+
}
|
|
73
|
+
}"
|
|
74
|
+
>
|
|
75
|
+
{% block field_label %}
|
|
76
|
+
<label
|
|
77
|
+
x-cloak
|
|
78
|
+
x-show="!glue_field._hide_label"
|
|
79
|
+
x-ref="label"
|
|
80
|
+
class="form-label"
|
|
81
|
+
:for="glue_field.id"
|
|
82
|
+
>
|
|
83
|
+
<span x-text="glue_field.label"></span>
|
|
84
|
+
<span x-cloak x-show="glue_field.required" class="text-danger">*</span>
|
|
85
|
+
|
|
86
|
+
<template x-if="glue_field.help_text && glue_field.help_text.trim() !== ''">
|
|
87
|
+
<span
|
|
88
|
+
x-data="{ is_tooltip_visible: false }"
|
|
89
|
+
class="position-relative mx-2"
|
|
90
|
+
>
|
|
91
|
+
<button
|
|
92
|
+
type="button"
|
|
93
|
+
class="btn btn-link p-0 lh-1"
|
|
94
|
+
style="text-decoration: none; color: inherit; outline: none !important; box-shadow: none !important;"
|
|
95
|
+
@mouseenter="is_tooltip_visible = true"
|
|
96
|
+
@mouseleave="is_tooltip_visible = false"
|
|
97
|
+
@click="is_tooltip_visible = !is_tooltip_visible; $event.currentTarget.blur();"
|
|
98
|
+
@focus="$event.currentTarget.blur();"
|
|
99
|
+
>
|
|
100
|
+
<i class="bi bi-question-circle-fill" style="font-size: 0.75rem;"></i>
|
|
101
|
+
</button>
|
|
102
|
+
<div
|
|
103
|
+
x-show="is_tooltip_visible"
|
|
104
|
+
class="fs-sm position-absolute p-2 rounded mt-2"
|
|
105
|
+
style="
|
|
106
|
+
min-width: 200px;
|
|
107
|
+
z-index: 1000;
|
|
108
|
+
top: 100%;
|
|
109
|
+
left: 0;
|
|
110
|
+
background-color: rgba(33, 37, 41, 0.85);
|
|
111
|
+
color: #fff;
|
|
112
|
+
font-weight: 400;
|
|
113
|
+
"
|
|
114
|
+
x-text="glue_field.help_text"
|
|
115
|
+
></div>
|
|
116
|
+
</span>
|
|
117
|
+
</template>
|
|
118
|
+
</label>
|
|
119
|
+
{% endblock %}
|
|
120
|
+
|
|
121
|
+
{% block field_content %}
|
|
122
|
+
{% endblock %}
|
|
123
|
+
|
|
124
|
+
<div x-show="glue_field.error">
|
|
125
|
+
<span class="text-danger glue-fs--1" x-text="glue_field.error"></span>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='text' %}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='color' %}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='date' %}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='datetime-local' %}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='number' %}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" class="bi bi-check ms-1" viewBox="0 0 16 16"
|
|
2
|
+
fill="currentColor">
|
|
3
|
+
<path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" class="bi bi-chevron-down"
|
|
2
|
+
viewBox="0 0 16 16">
|
|
3
|
+
<path fill-rule="evenodd"
|
|
4
|
+
d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='email' %}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{% extends 'django_spire/form/field/base_field.html' %}
|
|
2
|
+
|
|
3
|
+
{% block field_content %}
|
|
4
|
+
<input
|
|
5
|
+
{% if input_type %}type="{{ input_type }}"
|
|
6
|
+
{% else %}type="{% block input_type %}text{% endblock %}"{% endif %}
|
|
7
|
+
{% block input_field_attrs %}{{ input_field_attrs }}{% endblock %}
|
|
8
|
+
class="{% block input_field_class %}{% if input_field_class %}{{ input_field_class }}{% else %}form-control{% endif %}{% endblock %}"
|
|
9
|
+
x-ref="glue_field"
|
|
10
|
+
x-model="value"
|
|
11
|
+
:id="glue_field.id"
|
|
12
|
+
>
|
|
13
|
+
{% endblock %}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<div class="d-flex align-items-center justify-content-center" style="width: 35px;">
|
|
2
|
+
{% block choice_checkmark %}
|
|
3
|
+
<template x-if="value === choice[0]">
|
|
4
|
+
{% include 'django_spire/form/field/element/select_checkmark_element.html' %}
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<template x-if="value != choice[0]">
|
|
8
|
+
<span class="ms-3 ps-2"></span>
|
|
9
|
+
</template>
|
|
10
|
+
{% endblock %}
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<div class="d-flex align-items-center">
|
|
14
|
+
<span class="text-truncate" x-text="choice[1]"></span>
|
|
15
|
+
</div>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{% extends "django_spire/form/field/base_field.html" %}
|
|
2
|
+
|
|
3
|
+
{% block field_content %}
|
|
4
|
+
<div
|
|
5
|
+
x-data="{
|
|
6
|
+
item: null,
|
|
7
|
+
available: [],
|
|
8
|
+
choices: [],
|
|
9
|
+
selected: [],
|
|
10
|
+
queryset: [],
|
|
11
|
+
|
|
12
|
+
async init() {
|
|
13
|
+
this.glue_field.available = await this.glue_field.queryset.all();
|
|
14
|
+
this.glue_field.choices = await this.glue_field.queryset.to_choices();
|
|
15
|
+
this.glue_field.selected = await this.glue_field.selected.all();
|
|
16
|
+
|
|
17
|
+
this.selected = this.glue_field.selected
|
|
18
|
+
? Object.entries(this.glue_field.selected).map(([id, values]) => ({ id, ...values }))
|
|
19
|
+
: [];
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
async add_item() {
|
|
23
|
+
let item = this.glue_field.value;
|
|
24
|
+
let found = this.glue_field.choices.find(choice => choice[0] == item);
|
|
25
|
+
|
|
26
|
+
if (item && found) {
|
|
27
|
+
let selection = this.glue_field.available[item - 1];
|
|
28
|
+
|
|
29
|
+
this.selected.push({
|
|
30
|
+
id: item,
|
|
31
|
+
...selection
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
this.glue_field.choices = this.glue_field.choices.filter(choice => choice[0] != item);
|
|
35
|
+
|
|
36
|
+
if (this.glue_field.choices.length > 0) {
|
|
37
|
+
this.glue_field.value = this.glue_field.choices[0][0];
|
|
38
|
+
} else {
|
|
39
|
+
this.glue_field.value = '';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
async remove_item(index) {
|
|
45
|
+
let removed = this.selected[index]
|
|
46
|
+
this.selected.splice(index, 1)
|
|
47
|
+
|
|
48
|
+
this.glue_field.value = ''
|
|
49
|
+
|
|
50
|
+
let label = this.glue_field.display_label
|
|
51
|
+
|
|
52
|
+
this.glue_field.choices = [
|
|
53
|
+
...this.glue_field.choices,
|
|
54
|
+
[removed.id, removed[label]]
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
this.glue_field.value = removed.id
|
|
58
|
+
}
|
|
59
|
+
}"
|
|
60
|
+
x-effect="
|
|
61
|
+
glue_field.hide_label();
|
|
62
|
+
"
|
|
63
|
+
>
|
|
64
|
+
<div class="row g-2 mb-2">
|
|
65
|
+
<div x-ref="component">
|
|
66
|
+
{% block component_field %}
|
|
67
|
+
<div class="col-10">
|
|
68
|
+
{% include "django_spire/form/field/search_and_select_field.html" with glue_field=glue_field %}
|
|
69
|
+
</div>
|
|
70
|
+
{% endblock %}
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
{% block add_item_button %}
|
|
74
|
+
<div class="col-2 d-flex align-items-stretch">
|
|
75
|
+
<button
|
|
76
|
+
type="button"
|
|
77
|
+
@click.prevent="add_item()"
|
|
78
|
+
class="glue-btn glue-btn-primary w-100 h-100"
|
|
79
|
+
>
|
|
80
|
+
Add
|
|
81
|
+
</button>
|
|
82
|
+
</div>
|
|
83
|
+
{% endblock %}
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<template x-if="selected.length === 0">
|
|
87
|
+
<div class="mt-4">
|
|
88
|
+
No item(s) selected.
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
91
|
+
|
|
92
|
+
<template x-for="(item, index) in selected" :key="item.id">
|
|
93
|
+
<div class="row align-items-center glue-bg-layer-two-hover glue-list-item-container glue-border-bottom glue-border py-2">
|
|
94
|
+
{% if row %}
|
|
95
|
+
{% include row %}
|
|
96
|
+
{% else %}
|
|
97
|
+
{% block item_row_content %}
|
|
98
|
+
{% endblock %}
|
|
99
|
+
|
|
100
|
+
{% block remove_item_button %}
|
|
101
|
+
{% endblock %}
|
|
102
|
+
{% endif %}
|
|
103
|
+
</div>
|
|
104
|
+
</template>
|
|
105
|
+
|
|
106
|
+
<input
|
|
107
|
+
type="hidden"
|
|
108
|
+
name="{{ glue_field.name }}"
|
|
109
|
+
:value="JSON.stringify(selected)"
|
|
110
|
+
>
|
|
111
|
+
</div>
|
|
112
|
+
{% endblock %}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{% extends 'django_spire/form/field/_base_file_field.html' %}
|
|
2
|
+
|
|
3
|
+
{% block x-data %}
|
|
4
|
+
async handle_files_change(event) {
|
|
5
|
+
let files = Array.from(event.target.files || []);
|
|
6
|
+
|
|
7
|
+
for (let file of files) {
|
|
8
|
+
if (file.size > this.maximum_filesize) {
|
|
9
|
+
alert(`The file is too large (${this.format_file_size(file.size)}). Maximum size is
|
|
10
|
+
${this.format_file_size(this.maximum_filesize)}.`);
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let index = this.files.findIndex(existing => existing.name === file.name);
|
|
15
|
+
|
|
16
|
+
if (index !== -1) {
|
|
17
|
+
URL.revokeObjectURL(this.files[index].data);
|
|
18
|
+
URL.revokeObjectURL(this.files[index].preview);
|
|
19
|
+
this.files.splice(index, 1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let file_id = Date.now() + '-' + Math.random().toString(36).substr(2, 9);
|
|
23
|
+
let processed = file;
|
|
24
|
+
|
|
25
|
+
if (file.type.startsWith('image/') && file.type !== 'image/svg+xml' && this.compression) {
|
|
26
|
+
processed = await this.compress(file);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.objects[file_id] = processed;
|
|
30
|
+
|
|
31
|
+
let data = URL.createObjectURL(processed);
|
|
32
|
+
|
|
33
|
+
this.files.push({
|
|
34
|
+
id: file_id,
|
|
35
|
+
name: processed.name,
|
|
36
|
+
size: processed.size,
|
|
37
|
+
type: processed.type,
|
|
38
|
+
data: data,
|
|
39
|
+
preview: processed.type.startsWith('image/') ? data : null
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
this.show_dropdown = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.update_value();
|
|
46
|
+
this.show_dropdown = true;
|
|
47
|
+
this.update_form_files();
|
|
48
|
+
|
|
49
|
+
this.$refs.file_input.value = '';
|
|
50
|
+
this.$refs.camera_input.value = '';
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
remove_file(file_id) {
|
|
54
|
+
let file = this.files.find(file => file.id === file_id);
|
|
55
|
+
|
|
56
|
+
if (file) {
|
|
57
|
+
URL.revokeObjectURL(file.data);
|
|
58
|
+
if (file.preview) URL.revokeObjectURL(file.preview);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
delete this.objects[file_id];
|
|
62
|
+
|
|
63
|
+
this.files = this.files.filter(file => file.id !== file_id);
|
|
64
|
+
|
|
65
|
+
this.update_value();
|
|
66
|
+
this.update_form_files();
|
|
67
|
+
|
|
68
|
+
if (this.files.length === 0) {
|
|
69
|
+
this.show_dropdown = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
{% endblock %}
|
|
73
|
+
|
|
74
|
+
{% block upload_attributes %}multiple{% endblock %}
|
|
75
|
+
{% block file_input_attributes %}multiple{% endblock %}
|
|
76
|
+
{% block camera_input_attributes %}multiple{% endblock %}
|
|
77
|
+
|
|
78
|
+
{% block selection_display %}
|
|
79
|
+
<template x-if="files.length === 0">
|
|
80
|
+
<span>No files selected</span>
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
<template x-if="files.length > 0">
|
|
84
|
+
<span x-text="files.length + ' files selected'"></span>
|
|
85
|
+
</template>
|
|
86
|
+
{% endblock %}
|
|
87
|
+
|
|
88
|
+
{% block drop_area_text %}
|
|
89
|
+
<span>Click to add or drag and drop files here</span>
|
|
90
|
+
{% endblock %}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
{% extends 'django_spire/form/field/base_field.html' %}
|
|
2
|
+
|
|
3
|
+
{% block field_content %}
|
|
4
|
+
{# This can be removed and need to insert input fields to have getlist and get effect #}
|
|
5
|
+
<div
|
|
6
|
+
class="position-relative"
|
|
7
|
+
x-data="{
|
|
8
|
+
show_dropdown: false,
|
|
9
|
+
search: '',
|
|
10
|
+
init () {
|
|
11
|
+
this.parse_value()
|
|
12
|
+
|
|
13
|
+
this.$watch('glue_field.value', value => {
|
|
14
|
+
this.parse_value()
|
|
15
|
+
})
|
|
16
|
+
},
|
|
17
|
+
add_choice(choice) {
|
|
18
|
+
this.glue_field.value.push(choice[0])
|
|
19
|
+
},
|
|
20
|
+
get get_selected_choices() {
|
|
21
|
+
if (!Array.isArray(this.glue_field.value)) {
|
|
22
|
+
return []
|
|
23
|
+
}
|
|
24
|
+
return this.glue_field.choices.filter(choice => this.glue_field.value.includes(choice[0]))
|
|
25
|
+
},
|
|
26
|
+
get filtered_choices() {
|
|
27
|
+
if (!Array.isArray(this.glue_field.value)) {
|
|
28
|
+
return []
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const filtered_array = this.glue_field.choices.filter(choice => !this.glue_field.value.includes(choice[0]) && choice[1] !== '----------')
|
|
32
|
+
|
|
33
|
+
const search = this.search.toLowerCase()
|
|
34
|
+
return filtered_array.filter(filtered_choice => filtered_choice[1].toLowerCase().includes(search))
|
|
35
|
+
},
|
|
36
|
+
focus_input() {
|
|
37
|
+
setTimeout(() => this.$refs.search_input.focus(), 100)
|
|
38
|
+
},
|
|
39
|
+
parse_value(){
|
|
40
|
+
// It is already an array!
|
|
41
|
+
if (Array.isArray(this.glue_field.value)) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Parse the initial value into an array.
|
|
46
|
+
if (typeof(this.glue_field.value) == 'string' && this.glue_field.value.startsWith('[')){
|
|
47
|
+
value = JSON.parse(this.glue_field.value)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Must be an array.
|
|
52
|
+
this.glue_field.value = []
|
|
53
|
+
},
|
|
54
|
+
remove_choice(choice) {
|
|
55
|
+
this.glue_field.value = this.glue_field.value.filter(val => val !== choice[0])
|
|
56
|
+
},
|
|
57
|
+
}"
|
|
58
|
+
>
|
|
59
|
+
<template x-for="choice in get_selected_choices" :key="choice[0]">
|
|
60
|
+
<input hidden type="text" :name="glue_field.name" :value="choice[0]">
|
|
61
|
+
|
|
62
|
+
</template>
|
|
63
|
+
<div x-ref="inputs"></div>
|
|
64
|
+
|
|
65
|
+
{% block selected_choices %}
|
|
66
|
+
<button
|
|
67
|
+
class="form-control text-start d-flex justify-content-between"
|
|
68
|
+
type="button"
|
|
69
|
+
@click="show_dropdown = !show_dropdown; focus_input();"
|
|
70
|
+
>
|
|
71
|
+
<span class="d-flex flex-wrap align-items-center">
|
|
72
|
+
<template x-for="choice in get_selected_choices" :key="choice[0]">
|
|
73
|
+
<div class="d-inline-block my-1">
|
|
74
|
+
<span class="badge rounded-pill glue-fs--1 text-app-glue-primary fw-normal border me-1">
|
|
75
|
+
<span x-text="choice[1]"></span>
|
|
76
|
+
</span>
|
|
77
|
+
</div>
|
|
78
|
+
</template>
|
|
79
|
+
|
|
80
|
+
<template x-if="get_selected_choices.length === 0">
|
|
81
|
+
<span>----------</span>
|
|
82
|
+
</template>
|
|
83
|
+
</span>
|
|
84
|
+
|
|
85
|
+
<span class="d-flex align-items-center">
|
|
86
|
+
{% include 'django_spire/form/field/element/select_down_arrow_element.html' %}
|
|
87
|
+
</span>
|
|
88
|
+
</button>
|
|
89
|
+
{% endblock %}
|
|
90
|
+
|
|
91
|
+
<div
|
|
92
|
+
x-cloak
|
|
93
|
+
x-show="show_dropdown"
|
|
94
|
+
@click.outside="show_dropdown = false"
|
|
95
|
+
class="shadow border rounded-2 mt-2 position-absolute z-3 bg-app-glue-layer-one w-100 p-0 list-group"
|
|
96
|
+
style="max-height: 350px; overflow-y: auto; z-index: 3;"
|
|
97
|
+
@keydown.escape="show_dropdown = false"
|
|
98
|
+
x-trap.inert="show_dropdown"
|
|
99
|
+
>
|
|
100
|
+
<div class="glue-fs--2 fw-bold ms-2 my-1">
|
|
101
|
+
Select Many <span>"<span x-text="glue_field.label"></span>"</span>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<div class="m-1">
|
|
105
|
+
<input
|
|
106
|
+
x-model="search"
|
|
107
|
+
class="form-control py-1 glue-fs--2"
|
|
108
|
+
placeholder="Search..."
|
|
109
|
+
type="text"
|
|
110
|
+
x-ref="search_input"
|
|
111
|
+
@keydown.enter.prevent="add_choice(filtered_choices[0])"
|
|
112
|
+
>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<template x-for="(choice, index) in get_selected_choices" :key="index">
|
|
116
|
+
<div
|
|
117
|
+
class="glue-cursor-pointer glue-user-select py-1 d-flex align-items-center list-group-item px-0 bg-app-glue-layer-one-hover"
|
|
118
|
+
tabindex="0"
|
|
119
|
+
@click="remove_choice(choice)"
|
|
120
|
+
@keydown.enter.prevent="remove_choice(choice)"
|
|
121
|
+
>
|
|
122
|
+
{% block selected_choice_item %}
|
|
123
|
+
{% include 'django_spire/form/field/item/selected_choice_item.html' %}
|
|
124
|
+
{% endblock %}
|
|
125
|
+
</div>
|
|
126
|
+
</template>
|
|
127
|
+
|
|
128
|
+
<template x-if="get_selected_choices.length > 0 && filtered_choices.length !== 0">
|
|
129
|
+
<div>
|
|
130
|
+
<span class="d-block glue-fs--2 ms-3">Choices</span>
|
|
131
|
+
</div>
|
|
132
|
+
</template>
|
|
133
|
+
|
|
134
|
+
<template x-for="(choice, index) in filtered_choices" :key="choice[0]">
|
|
135
|
+
<div
|
|
136
|
+
class="glue-user-select py-1 d-flex align-items-center list-group-item px-0"
|
|
137
|
+
tabindex="0"
|
|
138
|
+
@click="glue_field.disabled_choices.includes(choice[0]) ? '' : add_choice(choice)"
|
|
139
|
+
:class="glue_field.disabled_choices.includes(choice[0]) ? 'opacity-50 glue-user-select glue-cursor-not-allowed' : 'glue-cursor-pointer bg-app-glue-layer-one-hover'"
|
|
140
|
+
@keydown.enter.prevent="add_choice(choice)"
|
|
141
|
+
>
|
|
142
|
+
{% block choice_item %}
|
|
143
|
+
{% include 'django_spire/form/field/item/select_choice_item.html' %}
|
|
144
|
+
{% endblock %}
|
|
145
|
+
</div>
|
|
146
|
+
</template>
|
|
147
|
+
|
|
148
|
+
<template x-if="filtered_choices.length === 0">
|
|
149
|
+
<div class="py-1">
|
|
150
|
+
<span class="d-block glue-fs--2 ms-3">No available choices</span>
|
|
151
|
+
</div>
|
|
152
|
+
</template>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
{% endblock %}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{% extends 'django_spire/form/field/base_field.html' %}
|
|
2
|
+
|
|
3
|
+
{% block field_content %}
|
|
4
|
+
<input
|
|
5
|
+
{% if input_type %}type="{{ input_type }}"{% else %}type="number"{% endif %}
|
|
6
|
+
class="form-control"
|
|
7
|
+
x-ref="glue_field"
|
|
8
|
+
x-model="value"
|
|
9
|
+
:id="glue_field.id"
|
|
10
|
+
>
|
|
11
|
+
{% endblock %}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='password' %}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{% extends 'django_spire/form/field/base_field.html' %}
|
|
2
|
+
|
|
3
|
+
{% block field_content %}
|
|
4
|
+
<div class="form-group">
|
|
5
|
+
<template x-for="choice in glue_field.choices" :key="choice[0]">
|
|
6
|
+
<div class="form-check">
|
|
7
|
+
<input
|
|
8
|
+
type="radio"
|
|
9
|
+
class="form-check-input"
|
|
10
|
+
:id="glue_field.id + '_' + choice[0]"
|
|
11
|
+
:name="glue_field.name"
|
|
12
|
+
:value="choice[0]"
|
|
13
|
+
:checked="value === choice[0]"
|
|
14
|
+
@change="this.value =choice[0]"
|
|
15
|
+
>
|
|
16
|
+
<label
|
|
17
|
+
class="form-check-label"
|
|
18
|
+
:for="glue_field.id + '_' + choice[0]"
|
|
19
|
+
x-text="choice[1]"
|
|
20
|
+
></label>
|
|
21
|
+
</div>
|
|
22
|
+
</template>
|
|
23
|
+
</div>
|
|
24
|
+
{% endblock %}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{% include 'django_spire/form/field/input_field.html' with input_type='range' %}
|