Gestione titolo per le checklist e introduzione ckeditor

This commit is contained in:
MatteoPistorello 2023-07-21 17:19:43 +02:00
parent e39813d2bf
commit da53a916ae
10 changed files with 65 additions and 27 deletions

View File

@ -57,7 +57,8 @@ switch (post('op')) {
case 'add_item':
$content = post('content');
$parent_id = post('parent') ?: null;
$item = ChecklistItem::build($record, $content, $parent_id);
$is_titolo = post('is_titolo');
$item = ChecklistItem::build($record, $content, $parent_id, $is_titolo);
flash()->info(tr('Nuova riga della checklist creata!'));

View File

@ -100,6 +100,7 @@ switch(post('op')){
}
$record->content = post('content');
$record->is_titolo = post('is_titolo');
$record->save();
flash()->info(tr('Informazioni salvate correttamente!'));

View File

@ -33,29 +33,41 @@ foreach ($checks as $check) {
echo '
<form action="" method="post" id="check-form">
<div class="row">
<div class="col-md-9">
{[ "type": "text", "label": "'.tr('Contenuto').'", "name": "content", "required": 1 ]}
<div class="col-md-12">
'.input([
'type' => 'ckeditor',
'label' => tr('Contenuto'),
'name' => 'content',
'required' => 1,
'value' => ''
]).'
</div>
</div>
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Collega a').'", "name": "parent", "values": '.json_encode($list).' ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Collega a').'", "name": "parent", "values": '.json_encode($list).' ]}
<div class="col-md-6">
{[ "type": "checkbox", "label": "'.tr('Utilizza come titolo').'", "name": "is_titolo" ]}
</div>
</div>
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Utente assegnato').'", "name": "assigned_users", "ajax-source": "utenti", "multiple": 1 ]}
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Gruppo assegnato').'", "name": "group_id", "values": "query=SELECT id, nome AS text FROM zz_groups" ]}
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Gruppo assegnato').'", "name": "group_id", "values": "query=SELECT id, nome AS text FROM zz_groups" ]}
{[ "type": "select", "label": "'.tr('Utente assegnato').'", "name": "assigned_users", "ajax-source": "utenti", "multiple": 1 ]}
</div>
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="button" class="btn btn-primary" id="check-add">
<br><br><button type="button" class="btn btn-primary" id="check-add">
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
</button>
</div>
@ -128,7 +140,8 @@ function addCheck(btn) {
}, "'.$manager_id.'");
checklist.addCheck({
content: $form.find("#content").val(),
content: input("content").get(),
is_titolo: input("is_titolo").get(),
parent: $form.find("#parent").val(),
assigned_users: $form.find("#assigned_users").val(),
group_id: $form.find("#group_id").val(),

View File

@ -34,17 +34,30 @@ if($main_check){
<div class="row">
<div class="col-md-12">
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "content_edit", "required": 1, "value": "<?=$record->content?>" ]}
<?php
echo input([
'type' => 'ckeditor',
'label' => tr('Descrizione'),
'name' => 'content_edit',
'required' => 1,
'value' => htmlentities($record->content)
]);
?>
</div>
</div>
<div class="row">
<div class="col-md-12 text-right">
<button type="button" class="btn btn-success" id="save-btn"><i class='fa fa-check'></i> <?php echo tr('Salva'); ?></button>
<div class="col-md-4">
{[ "type": "checkbox", "label": "<?php echo tr('Utilizza come titolo'); ?>", "name": "is_titolo", "value": "<?php echo $record->is_titolo ?>" ]}
</div>
<div class="col-md-8 text-right">
<br><br><button type="button" class="btn btn-success" id="save-btn"><i class='fa fa-check'></i> <?php echo tr('Salva'); ?></button>
</div>
</div>
<script>
init();
$('#save-btn').click(function() {
$('#save-btn').attr('disabled', true);
$('#save-btn').html('<i class="fa fa-spinner fa-spin"></i> <?php echo tr('Salvataggio in corso...'); ?>');
@ -52,7 +65,8 @@ if($main_check){
$.post('<?php echo $rootdir; ?>/modules/checklists/ajax.php', {
op: "edit_check",
id_record: "<?=$id_record?>",
content: $('#content_edit').val(),
content: input('content_edit').get(),
is_titolo: input('is_titolo').get(),
main_check: "<?=$main_check?>",
}, function(){
location.reload();

View File

@ -90,16 +90,22 @@ echo '
<input type="hidden" name="op" value="add_item">
<input type="hidden" name="backto" value="record-edit">
<div class="col-md-6">
{[ "type": "text", "placeholder": "'.tr('Contenuto').'", "name": "content", "class": "unblockable", "required": 1 ]}
<div class="col-md-7">
'.input([
'type' => 'ckeditor',
'label' => tr('Contenuto'),
'name' => 'content',
'required' => 1,
'value' => ''
]).'
</div>
<div class="col-md-4">
{[ "type": "select", "placeholder": "'.tr('Genitore').'", "name": "parent", "class": "unblockable", "values": '.json_encode($list).' ]}
</div>
<div class="col-md-1 text-right">
<button type="submit" class="btn btn-success">
<div class="col-md-5 text-center">
{[ "type": "select", "label": "'.tr('Genitore').'", "name": "parent", "class": "unblockable", "values": '.json_encode($list).' ]}
<br>
{[ "type": "checkbox", "label": "'.tr('Utilizza come titolo').'", "name": "is_titolo" ]}
<br><br>
<button type="submit" class="btn btn-lg btn-success">
<i class="fa fa-upload"></i> '.tr('Crea').'
</button>
</div>

View File

@ -31,7 +31,7 @@ function renderChecklist($check, $level = 1, $parent = 0) {
<td style="padding-top:0px;padding-bottom:0px;border-top:0px;">
<table class="table" style="margin-bottom:0px;">
<tr>';
if (sizeof($check->children)>0 && setting('Utilizzare checklist genitore come titolo')) {
if ($check->is_titolo) {
$result .= '
<td style="width:40px;"></td>
<td colspan="3" style="border-top:0px;">

View File

@ -46,7 +46,7 @@ class Check extends Model
*
* @return self
*/
public static function build(User $user, $structure, $id_record, $content, $parent_id = null, $order = 99)
public static function build(User $user, $structure, $id_record, $content, $parent_id = null, $is_titolo = 0, $order = 99)
{
$model = new static();
@ -61,6 +61,7 @@ class Check extends Model
$model->id_record = $id_record;
$model->content = $content;
$model->is_titolo = $is_titolo;
// Ordinamento temporaneo alla creazione
$model->order = $order;

View File

@ -64,7 +64,7 @@ class Checklist extends Model
$child = $checks->shift();
$id_parent = $child->id_parent ? $relations[$child->id_parent] : null;
$check = Check::build($user, $structure, $id_record, $child->content, $id_parent, $child->order);
$check = Check::build($user, $structure, $id_record, $child->content, $id_parent, $child->is_titolo, $child->order);
$check->setAccess($users, $group_id);
$relations[$child->id] = $check->id;

View File

@ -39,13 +39,14 @@ class ChecklistItem extends Model
*
* @return self
*/
public static function build(Checklist $checklist, $contenuto, $id_parent = null)
public static function build(Checklist $checklist, $contenuto, $id_parent = null, $is_titolo = 0)
{
$model = new static();
$model->checklist()->associate($checklist);
$model->id_parent = $id_parent;
$model->content = $contenuto;
$model->is_titolo = $is_titolo;
$model->findOrder();

View File

@ -15,4 +15,5 @@ INSERT INTO `em_templates` (`id`, `id_module`, `name`, `icon`, `subject`, `tipo_
INSERT INTO `zz_settings` (`nome`, `valore`, `tipo`, `editable`, `sezione`, `order`, `help`) VALUES ('Numero di minuti di avanzamento delle sessioni delle attività', '1', 'string', '1', 'Attività', NULL, 'Specifica di quanti minuti aumentare o diminuire le sessioni di lavoro delle attività');
-- Aggiunta impostazione titolo checklist
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `created_at`, `order`, `help`) VALUES (NULL, 'Utilizzare checklist genitore come titolo', '0', 'boolean', '1', 'Generali', NULL, NULL, 'Attivando questa impostazione non sarà possibile spuntare le checklist genitore ma verranno utilizzate come titolo');
ALTER TABLE `zz_checks` ADD `is_titolo` BOOLEAN NOT NULL AFTER `id_parent`;
ALTER TABLE `zz_checklist_items` ADD `is_titolo` BOOLEAN NOT NULL AFTER `id_parent`;