Skip to content

Commit 2101ad1

Browse files
feat: migliorie gestione allegati
1 parent 7c40d32 commit 2101ad1

15 files changed

Lines changed: 362 additions & 108 deletions

File tree

actions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
if (filter('op') == 'aggiungi-allegato' && !empty($_FILES) && !empty($_FILES['file']['name'])) {
124124
$upload = Uploads::upload($_FILES['file'], [
125125
'name' => filter('nome_allegato'),
126-
'category' => filter('categoria'),
126+
'id_category' => filter('id_category') ?: null,
127127
'id_module' => $id_module,
128128
'id_plugin' => $id_plugin,
129129
'id_record' => $id_record,
@@ -223,12 +223,12 @@
223223
if (sizeof($id_allegati) == 1) {
224224
$upload = Upload::find($id_allegati[0]);
225225
$upload->name = post('nome_allegato');
226-
$upload->category = post('categoria_allegato');
226+
$upload->id_category = post('categoria_allegato') ?: null;
227227
$upload->save();
228228
} else {
229229
foreach ($id_allegati as $id_allegato) {
230230
$upload = Upload::find($id_allegato);
231-
$upload->category = post('categoria_allegato');
231+
$upload->id_category = post('categoria_allegato') ?: null;
232232
$upload->save();
233233
}
234234
}

ajax.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
include_once __DIR__.'/core.php';
2222

2323
use Models\Hook;
24+
use Modules\CategorieFiles\Categoria;
2425

2526
switch (filter('op')) {
2627
// Imposta un valore ad un array di $_SESSION
@@ -68,7 +69,8 @@
6869
break;
6970

7071
case 'list_attachments':
71-
echo '{( "name": "filelist_and_upload", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "id_plugin": "'.$id_plugin.'" )}';
72+
$category = get('id_category') ? Categoria::find(get('id_category'))->name : null;
73+
echo '{( "name": "filelist_and_upload", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "id_plugin": "'.$id_plugin.'", "category": "'.$category.'" )}';
7274

7375
break;
7476

assets/src/js/functions/allegati.js

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function initGestioneAllegati(gestione) {
4848
id_module: gestione.data('id_module'),
4949
id_plugin: gestione.data('id_plugin'),
5050
id_record: gestione.data('id_record'),
51+
id_category: gestione.data('id_category')
5152
}).toString();
5253

5354
let dragdrop = new Dropzone(dropzone_id, {
@@ -96,40 +97,6 @@ function modificaCategoriaAllegati(gestione, pulsanteModifica) {
9697
inputNome.removeClass("hidden");
9798
}
9899

99-
/**
100-
* Funzione per salvare le modifiche effettuate su una categoria di allegati.
101-
* @param gestione
102-
* @param pulsanteSalva
103-
*/
104-
function salvaCategoriaAllegati(gestione, pulsanteSalva) {
105-
const categoria = $(pulsanteSalva).parent().parent();
106-
107-
const nome = categoria.find(".box-title");
108-
const inputNome = categoria.find(".category-name");
109-
110-
mostraCaricamentoAllegati(gestione);
111-
112-
$.ajax({
113-
url: globals.rootdir + "/actions.php",
114-
cache: false,
115-
type: "POST",
116-
data: {
117-
op: "modifica-categoria-allegato",
118-
id_module: gestione.data('id_module'),
119-
id_plugin: gestione.data('id_plugin'),
120-
id_record: gestione.data('id_record'),
121-
category: nome.text(),
122-
name: inputNome.val(),
123-
},
124-
success: function (data) {
125-
ricaricaAllegati(gestione);
126-
},
127-
error: function (gestione) {
128-
ricaricaAllegati(gestione);
129-
}
130-
});
131-
}
132-
133100
/**
134101
* Funzione per caricare un nuovo allegato.
135102
* @param gestione
@@ -176,6 +143,7 @@ function ricaricaAllegati(gestione) {
176143
id_module: gestione.data('id_module'),
177144
id_plugin: gestione.data('id_plugin'),
178145
id_record: gestione.data('id_record'),
146+
id_category: gestione.data('id_category')
179147
}).toString();
180148

181149
$(id).load(globals.rootdir + "/ajax.php?" + params, function () {
@@ -295,34 +263,3 @@ function rimuoviAllegato(button) {
295263
});
296264
}).catch(swal.noop);
297265
}
298-
299-
function impostaCategorieAllegatiDisponibili(gestione, categorie) {
300-
// Disabilitazione per rimozione input in aggiunta
301-
return;
302-
303-
const id = "#" + gestione.attr('id');
304-
const input = $("#modifica-allegato #categoria_allegato")[0];
305-
306-
autocomplete({
307-
minLength: 0,
308-
input: input,
309-
emptyMsg: globals.translations.noResults,
310-
fetch: function (text, update) {
311-
text = text.toLowerCase();
312-
const suggestions = categorie.filter(n => n.toLowerCase().startsWith(text));
313-
314-
// Trasformazione risultati in formato leggibile
315-
const results = suggestions.map(function (result) {
316-
return {
317-
label: result,
318-
value: result
319-
}
320-
});
321-
322-
update(results);
323-
},
324-
onSelect: function (item) {
325-
input.value = item.label;
326-
},
327-
});
328-
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"Modules\\Partitario\\": ["modules/partitario/custom/src/", "modules/partitario/src/"],
116116
"Modules\\StatoEmail\\": ["modules/stato_email/custom/src/", "modules/stato_email/src/"],
117117
"Modules\\FileAdapters\\": ["modules/adattatori_archiviazione/custom/src/", "modules/adattatori_archiviazione/src/"],
118+
"Modules\\CategorieFiles\\": ["modules/categorie_files/custom/src/", "modules/categorie_files/src/"],
118119
"Plugins\\AssicurazioneCrediti\\": ["plugins/assicurazione_crediti/custom/src/", "plugins/assicurazione_crediti/src/"],
119120
"Plugins\\ExportFE\\": ["plugins/exportFE/custom/src/", "plugins/exportFE/src/"],
120121
"Plugins\\ImportFE\\": ["plugins/importFE/custom/src/", "plugins/importFE/src/"],

include/modifica_allegato.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
*/
2020

21+
use Models\Module;
2122
use Models\Upload;
2223

2324
$id_allegati = (array) json_decode(filter('id_allegati'));
@@ -37,13 +38,13 @@
3738
{[ "type": "text", "label": "'.tr('Nome').'", "name": "nome_allegato", "value": "'.$allegato->name.'" ]}
3839
</div>
3940
<div class="col-md-6">
40-
{[ "type": "text", "label": "'.tr('Categoria').'", "name": "categoria_allegato", "value": "'.$allegato->category.'", "disabled": "'.intval(in_array($allegato->category, ['Fattura Elettronica'])).'" ]}
41+
{[ "type": "select", "label": "'.tr('Categoria').'", "name": "categoria_allegato", "ajax-source": "categorie-files", "value": "'.$allegato->id_category.'", "disabled": "'.intval(in_array($allegato->categoria->name, ['Fattura Elettronica'])).'", "icon-after": "add|'.Module::where('name', 'Categorie file')->first()->id.'" ]}
4142
</div>';
4243
} else {
4344
$allegato = Upload::find($id_allegati[0]);
4445
echo '
4546
<div class="col-md-6">
46-
{[ "type": "text", "label": "'.tr('Categoria').'", "name": "categoria_allegato", "value": "" ]}
47+
{[ "type": "select", "label": "'.tr('Categoria').'", "name": "categoria_allegato", "ajax-source": "categorie-files", "value": "", "icon-after": "add|'.Module::where('name', 'Categorie file')->first()->id.'" ]}
4748
</div>';
4849
}
4950
echo '
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../core.php';
22+
23+
use Modules\CategorieFiles\Categoria;
24+
25+
switch (post('op')) {
26+
case 'update':
27+
$name = post('name');
28+
$categoria_new = Categoria::where('name', '=', $name)->where('deleted_at', '=', null)->where('id','!=', $id_record)->first();
29+
30+
if (!empty($categoria_new)) {
31+
flash()->error(tr('Categoria _NAME_ già esistente!', [
32+
'_NAME_' => $name,
33+
]));
34+
} else {
35+
$categoria->name = $name;
36+
$categoria->save();
37+
38+
flash()->info(tr('Informazioni salvate correttamente!'));
39+
}
40+
41+
break;
42+
43+
case 'add':
44+
$name = post('name');
45+
$categoria_new = Categoria::where('name', '=', $name)->where('deleted_at', '=', null)->first();
46+
47+
if (!empty($categoria_new)) {
48+
flash()->error(tr('Categoria _NAME_ già esistente!', [
49+
'_NAME_' => $name,
50+
]));
51+
} else {
52+
$categoria = Categoria::build();
53+
$categoria->name = $name;
54+
$id_record = $dbo->lastInsertedID();
55+
$categoria->save();
56+
57+
if (isAjaxRequest()) {
58+
echo json_encode(['id' => $id_record, 'text' => $name]);
59+
}
60+
61+
flash()->info(tr('Nuova categoria file aggiunta!'));
62+
}
63+
64+
break;
65+
66+
case 'delete':
67+
$dbo->query('UPDATE `zz_files_categories` SET `deleted_at` = NOW() WHERE `id` = '.prepare($id_record));
68+
69+
flash()->info(tr('Categoria eliminata!'));
70+
71+
break;
72+
}

modules/categorie_files/add.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../core.php';
21+
22+
?><form action="" method="post" id="add-form">
23+
<input type="hidden" name="op" value="add">
24+
<input type="hidden" name="backto" value="record-edit">
25+
26+
<div class="row">
27+
<div class="col-md-12">
28+
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "name", "required": 1, "value": "", "extra": "" ]}
29+
</div>
30+
</div>
31+
32+
<!-- PULSANTI -->
33+
<div class="modal-footer">
34+
<div class="col-md-12 text-right">
35+
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
36+
</div>
37+
</div>
38+
</form>
39+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../../core.php';
22+
23+
switch ($resource) {
24+
case 'categorie-files':
25+
$query = 'SELECT `zz_files_categories`.`id`, `zz_files_categories`.`name` as descrizione FROM `zz_files_categories` ORDER BY `name` ASC';
26+
27+
foreach ($elements as $element) {
28+
$filter[] = '`zz_files_categories`.`id`='.prepare($element);
29+
}
30+
31+
if (empty($filter)) {
32+
$where[] = '`deleted_at` IS NULL';
33+
}
34+
35+
if (!empty($search)) {
36+
$search_fields[] = '`zz_files_categories`.`name` LIKE '.prepare('%'.$search.'%');
37+
}
38+
39+
break;
40+
}

modules/categorie_files/edit.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../core.php';
21+
22+
?><form action="" method="post" id="edit-form">
23+
<input type="hidden" name="backto" value="record-edit">
24+
<input type="hidden" name="op" value="update">
25+
26+
<div class="card card-primary">
27+
<div class="card-header">
28+
<h3 class="card-title"><?php echo tr('Dati'); ?></h3>
29+
</div>
30+
31+
<div class="card-body">
32+
<div class="row">
33+
<div class="col-md-6">
34+
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "name", "required": 1, "value": "$name$" ]}
35+
</div>
36+
</div>
37+
</div>
38+
</div>
39+
</form>
40+
41+
<?php
42+
43+
echo '
44+
<a class="btn btn-danger ask" data-backto="record-list">
45+
<i class="fa fa-trash"></i> '.tr('Elimina').'
46+
</a>';

0 commit comments

Comments
 (0)