Skip to content

Commit

Permalink
[FIX] core js and update basic form submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
archetipo committed Aug 2, 2021
1 parent 9ee2a0b commit e4a15eb
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 64 deletions.
20 changes: 16 additions & 4 deletions web-client/core/Gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ def create(cls, request: Request, settings, templates):
return self

def clean_form(self, form_data):
logger.info(f"before ")
dat = {
k.replace('_in', '').replace('_tl', '').replace('_ck', '').replace('_sel', ''): str.strip(v) if
isinstance(v, str) else v for k, v in form_data.items()}
# logger.info(f"before")
dat = {}

dat = ujson.loads(form_data['formObj'])
for k, v in form_data.items():
if not k == 'formObj':
dat[k] = v

logger.info(f"after {dat}")
return dat

async def compute_datagrid_rows(self, key, model_name, rec_name=""):
Expand Down Expand Up @@ -84,6 +89,13 @@ async def server_post_action(self):
except ValueError as e:
try:
submit_data = await self.request.form()
logger.info("")
logger.info("")
logger.info("")
logger.info(submit_data)
logger.info("")
logger.info("")
logger.info("")
submitted_data = self.clean_form(submit_data._dict)
if "rec_name" in submitted_data and submitted_data.get("rec_name"):
allowed = self.name_allowed.match(submitted_data.get("rec_name"))
Expand Down
6 changes: 3 additions & 3 deletions web-client/core/main/custom_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,10 @@ def __init__(self, raw, builder, **kwargs):
super().__init__(raw, builder, **kwargs)

self.rows = []
self.multiple = self.raw['multiple']
self.multiple = False # self.raw.get("multiple")
self.add_enabled = True
self.dir = self.raw['dir']
self.webcam = self.raw['webcam']
self.dir = self.raw.get('dir')
self.webcam = self.raw.get('webcam')
self.uploaders = True
self.file_url = ""
# self.component_tmp = "file_container"
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

22 changes: 19 additions & 3 deletions web-client/core/themes/italia/templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</head>
<body>
<script nonce="2726c7f26c">window.__PUBLIC_PATH__ = "/static/fonts"</script>
<script type="text/javascript" src="/static/js/bootstrap-italia.bundle.min.js" nonce="2726c7f26c"></script>
<script type="text/javascript" src="/static/js/bootstrap-italia.bundle.min.js" nonce="2726c7f27c"></script>

<script type="text/javascript" src="/static/DataTables/datatables.min.js" nonce="2726c7f26c"></script>
<script type="text/javascript" src="/static/qr/js/qrcode-reader.min.js" nonce="2726c7f26c"></script>
Expand Down Expand Up @@ -139,9 +139,25 @@ <h3 class="sr-only">Sezione Link Utili</h3>
return obj;
}

function dataForm(form_name) {
function dataForm(form_name, inputfiles) {
let form = document.getElementById(form_name);
let formData = new FormData(form);
let jsonform = jsonForm(form_name)
var fileArr = [];
let formData = new FormData();
if (inputfiles) {
var i = 0, len = inputfiles.length;
for (; i < len; i++) {
let filed = inputfiles[i];
let lenfile = filed.files.length;
if (lenfile > 0) {
name = clean_key_id(filed.name)
formData.append("" + name, filed.files[0]);
}

}
}
formData.append('formObj', JSON.stringify(jsonform));

return formData;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
<div class="form-group">
<ul id="{{ key }}_list_exist" class="upload-file-list py-3">
{% if value %}
{% for item in value %}
<li id="{{ item['key'] }}" class="upload-file success">
<svg class="icon icon-sm" aria-hidden="true">
<use xlink:href="/static/svg/sprite.svg#it-file"></use>
</svg>
<a href="/client/attachment{{ item['url'] }}">
<span class="sr-only">Scarica{{ item['filename'] }}</span> {{ item['filename'] }}
</a>
{% if not disabled %}
<button id="remove_{{ item['key'] }}" class="remove_file" data-url="{{ item['url'] }}"
data-id="{{ item['key'] }}" data-filename="{{ item['filename'] }}"
data-file_path="{{ item['file_path'] }}"
<div class="mt-2">
<div class="form-row mt-2">
<ul id="{{ key }}_list_exist" class="upload-file-list">
{% if value %}
{% for item in value %}
<li id="{{ item['key'] }}" class="upload-file success">
<svg class="icon icon-sm" aria-hidden="true">
<use xlink:href="/static/svg/sprite.svg#it-file"></use>
</svg>
<a href="/client/attachment{{ item['url'] }}">
<span class="sr-only">Scarica{{ item['filename'] }}</span> {{ item['filename'] }}
</a>
{% if not disabled %}
<button id="remove_{{ item['key'] }}" class="remove_file" data-url="{{ item['url'] }}"
data-id="{{ item['key'] }}" data-filename="{{ item['filename'] }}"
data-file_path="{{ item['file_path'] }}"

>
<span class="sr-only">Metti nel cestino {{ item['file_name'] }} </span>
<svg class="icon icon-sm icon-danger" aria-hidden="true">
<use xlink:href="/static/svg/sprite.svg#it-delete"></use>
</svg>
</button>
{% endif %}
</li>
{% endfor %}
{% endif %}
</ul>
>
<span class="sr-only">Metti nel cestino {{ item['file_name'] }} </span>
<svg class="icon icon-sm icon-danger" aria-hidden="true">
<use xlink:href="/static/svg/sprite.svg#it-delete"></use>
</svg>
</button>
{% endif %}
</li>
{% endfor %}
{% endif %}
</ul>
</div>
{% if not disabled %}
<input type="file" name="{{ key }}_in" id="{{ key }}_in"
class="upload form-group text-center {{ customClass }}"
{% if filePattern %} accept="{{ filePattern }}" {% endif %}
{% if required and not value %} required {% endif %}
/>
<div class="form-row ">
<input type="file" name="{{ key }}_in" id="{{ key }}_in"
class="upload form-group text-center {{ customClass }}"
{% if filePattern %} accept="{{ filePattern }}" {% endif %}
{% if required and not value %} required {% endif %}
/>

<label for="{{ key }}_in">
<svg class="icon icon-sm" aria-hidden="true">
<use xlink:href="/static/svg/sprite.svg#it-upload"></use>
</svg>
<span>{{ label }}</span>
</label>
<label for="{{ key }}_in" class="">
<svg class="icon icon-sm" aria-hidden="true">
<use xlink:href="/static/svg/sprite.svg#it-upload"></use>
</svg>
<span>{{ label }}</span>
</label>

<ul id="{{ key }}_list" class="upload-file-list mt-n3">
</ul>
</div>
<ul id="{{ key }}_list" class="upload-file-list mt-2"></ul>
{% endif %}
</div>

<script>

{% if not disabled %}
const Item = ({key, i, url, file_name}) => `
<li id="${key}_${i}" class="upload-file success">
<li id="${key}_${i}" class="upload-file primary">
<svg class="icon icon-sm" aria-hidden="true">
<use xlink:href="/static/svg/sprite.svg#it-file"></use>
</svg>
<p >
<a >
<span class="sr-only">File caricato: ${file_name}</span> ${file_name}
</p>
</a>
<button disabled>
<span class="sr-only">In attesa di upload</span>
<svg class="icon icon-sm" aria-hidden="true"><use xlink:href="/static/svg/sprite.svg#it-exchange-circle"></use></svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ <h5 class="card-title py-3 {{ cls_title }}">{{ title }}</h5>

$("#{{ model }}").submit(function (e) {
e.preventDefault(); // save data
inputfiles = $("input:file");
if ($("#{{ model }}").valid()) {
let obj = dataForm("{{ model }}");
let obj = dataForm("{{ model }}", inputfiles);
execute_ajax(
"POST", "{{ api_action }}", '{{ authtoken }}',
'{{ req_id }}', obj, "global_progress_loader", "{{ model }}", true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@

<style>
.bootstrap-select-wrapper .dropdown.bootstrap-select .btn {
height: auto;
}
</style>
<div class="bootstrap-select-wrapper {% if hidden %} d-none {% endif %} {{ customClass }}" id="{{ key }}">
<label>{{ label }}</label>
<select data-live-search="true" data-boundary="window"
<select data-live-search="true" data-boundary="window"
id="{{ key }}_sel"
name="{{ key }}_sel"
data-dropup-auto="false"
data-live-search-placeholder="Sel. "
{% if required %} required="required" {% endif %}
{% if disabled %} disabled {% endif %}
{% if readonly %} readonly {% endif %}
{% if readonly %} readonly {% endif %}
multiple="true" data-multiple-separator=""
>

<option value="" {% if not value %} selected {% endif %}>--</option>
<option value="" {% if not value %} selected {% endif %}>--</option>
{% for item in options %}
<option value="{{ item['value'] }}"
data-content="<span class='select-pill'><span class='select-pill-text'>{{ item['label'] }}</span></span>"
Expand All @@ -23,8 +26,17 @@
</select>
<script type="text/javascript">
$("#{{ key }}_sel").selectpicker({
dropupAuto: false,
size: '4'
actionsBox:true
});

$("#{{ key }}_sel").off('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {

$(this).closest('div').find(".filter-option-inner-inner").addClass("d-flex flex-wrap");
console.log("#{{ key }}_sel changed.bs.select")


});


</script>
</div>

0 comments on commit e4a15eb

Please sign in to comment.