mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-08 23:58:42 +01:00
Aggiunta possibilità di aggiornare l'ordine dei sottolivelli e di modificare la descrizione delle righe nelle checklist
This commit is contained in:
parent
81fc6c5cff
commit
11f7cce230
78
modules/checklists/ajax.php
Normal file
78
modules/checklists/ajax.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||||
|
* Copyright (C) DevCode s.n.c.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../core.php';
|
||||||
|
use Modules\Checklists\Check;
|
||||||
|
|
||||||
|
switch(post('op')){
|
||||||
|
|
||||||
|
case "delete_check":
|
||||||
|
$id = post('id');
|
||||||
|
|
||||||
|
$record = Check::find($id);
|
||||||
|
$record->delete();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "update_position":
|
||||||
|
|
||||||
|
$order = explode(',', post('order', true));
|
||||||
|
|
||||||
|
foreach($order as $i => $id){
|
||||||
|
$dbo->query("UPDATE zz_checks SET `order`=".prepare($i)." WHERE id=".prepare($id));
|
||||||
|
echo "UPDATE zz_checks SET `order`=".prepare($i)." WHERE id=".prepare($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "save_checkbox":
|
||||||
|
|
||||||
|
$id = post('id');
|
||||||
|
|
||||||
|
$record = Check::find($id);
|
||||||
|
$record->checked_by = $user->id;
|
||||||
|
$record->checked_at = date('Y-m-d H:i:s');
|
||||||
|
$record->save();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "remove_checkbox":
|
||||||
|
|
||||||
|
$id = post('id');
|
||||||
|
|
||||||
|
$record = Check::find($id);
|
||||||
|
$record->checked_by = NULL;
|
||||||
|
$record->checked_at = NULL;
|
||||||
|
$record->save();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "edit_check":
|
||||||
|
$id_record = post('id_record');
|
||||||
|
|
||||||
|
$record = Check::find($id_record);
|
||||||
|
$record->content = post('content');
|
||||||
|
$record->save();
|
||||||
|
|
||||||
|
flash()->info(tr('Informazioni salvate correttamente!'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
53
modules/checklists/components/edit-check.php
Normal file
53
modules/checklists/components/edit-check.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||||
|
* Copyright (C) DevCode s.r.l.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../../core.php';
|
||||||
|
use Modules\Checklists\Check;
|
||||||
|
|
||||||
|
$id_record = get("id_record");
|
||||||
|
$record = Check::find($id_record);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "content", "required": 1, "value": "<?=$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-save'></i> <?php echo tr('Salva'); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$('#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...'); ?>');
|
||||||
|
|
||||||
|
$.post('<?php echo $rootdir; ?>/modules/checklists/ajax.php', {
|
||||||
|
op: "edit_check",
|
||||||
|
id_record: "<?=$id_record?>",
|
||||||
|
content: $('#content').val()
|
||||||
|
}, function(){
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
104
modules/checklists/modutil.php
Executable file → Normal file
104
modules/checklists/modutil.php
Executable file → Normal file
@ -17,55 +17,89 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function renderChecklist($check, $level = 0)
|
function renderChecklist($check, $level = 1, $parent = 0) {
|
||||||
{
|
|
||||||
|
global $structure;
|
||||||
|
|
||||||
$user = auth()->getUser();
|
$user = auth()->getUser();
|
||||||
$enabled = $check->assignedUsers ? $check->assignedUsers->pluck('id')->search($user->id) !== false : true;
|
$enabled = $check->assignedUsers ? $check->assignedUsers->pluck('id')->search($user->id) !== false : true;
|
||||||
|
|
||||||
$result = '
|
$margin = ($level*20);
|
||||||
<li id="check_'.$check->id.'" class="check-item'.(!empty($check->checked_at) ? ' done' : '').'" '.(!$enabled ? 'style="opacity: 0.4"' : '').' data-id="'.$check->id.'">
|
|
||||||
<input type="checkbox" value="'.(!empty($check->checked_at) ? '1' : '0').'" '.(!empty($check->checked_at) ? 'checked' : '').'>
|
|
||||||
|
|
||||||
<span class="text">'.$check->content.'</span>';
|
$result = '
|
||||||
|
<tr id="check_'.$check->id.'" data-id="'.$check->id.'" class="sortablerow sonof_'.$parent.'" >
|
||||||
|
<td style="padding-top:0px;padding-bottom:0px;border-top:0px;">
|
||||||
|
<table class="table" style="margin-bottom:0px;">
|
||||||
|
<tr>';
|
||||||
|
|
||||||
|
$result .= '
|
||||||
|
<td style="width:40px;text-align:center;border-top:0px;border-left:3px solid #eaeaea;">
|
||||||
|
<input type="checkbox" class="checkbox" data-id="'.$check->id.'" value="'.(!empty($check->checked_at) ? '1' : '0').'" '.(!empty($check->checked_at) ? 'checked' : '').' '.(!$enabled ? 'disabled' : '').'>
|
||||||
|
</td>';
|
||||||
|
|
||||||
|
$result .= '
|
||||||
|
<td style="border-top:0px;">
|
||||||
|
<span class="text">'.$check->content.' </span>';
|
||||||
|
|
||||||
if (intval($check->assignedUsers->pluck('id')->toArray())>0){
|
if (intval($check->assignedUsers->pluck('id')->toArray())>0){
|
||||||
$result .= '<span class="label label-default">'. implode(',', $check->assignedUsers->pluck('username')->toArray()).'</span>';
|
$result .= ' <span class="label label-info pull-right" style="padding:6px 8px;" data-toggle="tooltip" title="Assegnato a '. implode(', ', $check->assignedUsers->pluck('username')->toArray()).'"><i class="fa fa-user"></i></span>';
|
||||||
}else{
|
}else{
|
||||||
$result .= '<span class="label label-danger">'. tr('Nessun utente assegnato').'</span>';
|
$result .= ' <span class="label label-danger pull-right" style="padding:6px 8px;">'. tr('Nessun utente assegnato').'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($check->user) || $check->user->id == $user->id) {
|
if(!empty($check->checked_at)){
|
||||||
|
$result .= '
|
||||||
|
<span class="label label-default pull-right" style="margin-right:5px;padding:6px 8px;">'.(!empty($check->checked_at) ? tr('Verificato da _NAME_ il _DATE_', [
|
||||||
|
'_NAME_' => $check->checkUser->username,
|
||||||
|
'_DATE_' => timestampFormat($check->checked_at),
|
||||||
|
]) : '').'
|
||||||
|
</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$result .= '
|
||||||
|
</td>';
|
||||||
|
|
||||||
|
$result .= '
|
||||||
|
<td style="width:40px;text-align:center;border-top:0px;">
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button class="btn btn-warning btn-xs '.(!$enabled ? 'disabled' : '').'" onclick="edit_check(\''.$check->id.'\')"><i class="fa fa-edit"></i></button>
|
||||||
|
<button class="btn btn-danger btn-xs '.(!$enabled ? 'disabled' : '').'" onclick="delete_check(\''.$check->id.'\')"><i class="fa fa-trash"></i></button>
|
||||||
|
</div>
|
||||||
|
</td>';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$result .= '
|
||||||
|
</tr>';
|
||||||
|
|
||||||
|
if(sizeof($check->children)>0){
|
||||||
$result .= '
|
$result .= '
|
||||||
<div class="tools">
|
<tr>
|
||||||
<i class="fa fa-trash-o check-delete"></i>
|
<td colspan="4" style="padding-left:'.$margin.'px;padding-right:0px;padding-top:0px;padding-bottom:0px;border-top:0px;">
|
||||||
</div>';
|
<table class="table" style="margin-bottom:0px;">
|
||||||
}
|
<tbody class="sort" data-sonof="'.$check->id.'">';
|
||||||
|
$children = $structure->checks()->where('id_parent', $check->id)->orderBy('order')->get();
|
||||||
if ($level == 0) {
|
foreach ($children as $child) {
|
||||||
|
$result .= renderChecklist($child, $level + 1, $check->id);
|
||||||
|
}
|
||||||
$result .= '
|
$result .= '
|
||||||
<span class="handle pull-right">
|
</tbody>
|
||||||
<i class="fa fa-ellipsis-v"></i>
|
</table>
|
||||||
<i class="fa fa-ellipsis-v"></i>
|
</td>
|
||||||
</span>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$result .= '
|
$result .= '
|
||||||
<span class="badge pull-right" style="margin-right:5px">'.(!empty($check->checked_at) ? tr('Verificato da _NAME_ il _DATE_', [
|
</table>
|
||||||
'_NAME_' => $check->checkUser->username,
|
</td>
|
||||||
'_DATE_' => timestampFormat($check->checked_at),
|
|
||||||
]) : '').'</span>';
|
|
||||||
|
|
||||||
$result .= '
|
<td style="width:40px;text-align:center;border-top:0px;">
|
||||||
<ul class="todo-list">';
|
<button class="btn btn-xs btn-default handle '.(!$enabled ? 'disabled' : '').'" title="Modifica ordine delle righe" draggable="true">
|
||||||
|
<i class="fa fa-sort"></i>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
|
||||||
$children = $check->children;
|
</tr>';
|
||||||
foreach ($children as $child) {
|
|
||||||
$result .= renderChecklist($child, $level + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result .= '
|
|
||||||
</ul>
|
|
||||||
</li>';
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -80,10 +114,10 @@ function renderChecklistHtml($check, $level = 0)
|
|||||||
$result = '
|
$result = '
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-center" style="width:30px;">
|
<td class="text-center" style="width:30px;">
|
||||||
'.(!empty($check->checked_at)?'<img src="'.ROOTDIR.'/templates/interventi/check.png" style="width:10px;">':'').'
|
'.(!empty($check->checked_at)?'<img src="'.ROOTDIR.'/templates/interventi/custom/check.png" style="width:10px;">':'').'
|
||||||
</td>
|
</td>
|
||||||
<td style="padding-left:'.$width.'px;">
|
<td style="padding-left:'.$width.'px;">
|
||||||
<span class="text">'.$check->content.'</span>
|
<span class="text"><b>'.$check->content.'</b>'.(!empty($check->value)?': '.$check->value:'').'</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
|
145
plugins/checks.php
Executable file → Normal file
145
plugins/checks.php
Executable file → Normal file
@ -57,15 +57,15 @@ if ($structure->permission == 'rw') {
|
|||||||
|
|
||||||
$checks = $structure->mainChecks($id_record);
|
$checks = $structure->mainChecks($id_record);
|
||||||
|
|
||||||
echo '
|
echo " <table class='table'>
|
||||||
<ul class="todo-list checklist">';
|
<tbody class='sort' data-sonof='0'>";
|
||||||
|
foreach ($checks as $check) {
|
||||||
foreach ($checks as $check) {
|
echo renderChecklist($check);
|
||||||
echo renderChecklist($check);
|
}
|
||||||
}
|
echo " </tbody>
|
||||||
|
</table>";
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>';
|
</div>';
|
||||||
@ -73,62 +73,95 @@ echo '
|
|||||||
echo '
|
echo '
|
||||||
<script>$(document).ready(init)</script>
|
<script>$(document).ready(init)</script>
|
||||||
|
|
||||||
<script type="module">
|
<script>
|
||||||
import Checklist from "./modules/checklists/js/checklist.js";
|
|
||||||
|
|
||||||
var checklists = checklists ? checklists : {};
|
$(document).ready(function(){
|
||||||
$(document).ready(function() {
|
$("[data-toggle=\'tooltip\']").tooltip();
|
||||||
checklists["'.$checks_id.'"] = new Checklist({
|
});
|
||||||
id_module: "'.$id_module.'",
|
|
||||||
id_plugin: "'.$id_plugin.'",
|
|
||||||
id_record: "'.$id_record.'",
|
|
||||||
}, "'.$checks_id.'");
|
|
||||||
|
|
||||||
sortable(".checklist", {
|
sortable("#tab_checks .sort", {
|
||||||
placeholder: "sort-highlight",
|
axis: "y",
|
||||||
handle: ".handle",
|
handle: ".handle",
|
||||||
forcePlaceholderSize: true,
|
cursor: "move",
|
||||||
zIndex: 999999,
|
dropOnEmpty: true,
|
||||||
})[0].addEventListener("sortupdate", function(e) {
|
scroll: true,
|
||||||
let order = $(".checklist > li[data-id]").toArray().map(a => $(a).data("id"))
|
});
|
||||||
|
|
||||||
$.post(globals.rootdir + "/actions.php", {
|
sortable_table = sortable("#tab_checks .sort").length;
|
||||||
id_module: globals.id_module,
|
|
||||||
id_plugin: "'.$id_plugin.'",
|
for(i=0; i<sortable_table; i++){
|
||||||
id_record: globals.id_record,
|
sortable("#tab_checks .sort")[i].addEventListener("sortupdate", function(e) {
|
||||||
op: "ordina-checks",
|
|
||||||
|
var sonof = $(this).data("sonof");
|
||||||
|
|
||||||
|
let order = $(this).find(".sonof_"+sonof+"[data-id]").toArray().map(a => $(a).data("id"))
|
||||||
|
|
||||||
|
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||||
|
op: "update_position",
|
||||||
order: order.join(","),
|
order: order.join(","),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(".checklist").todoList({
|
$("input[name^=\'value\']").keyup(function(){
|
||||||
onCheck: function () {
|
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||||
var id = $(this).parent().data("id");
|
op: "save_value",
|
||||||
|
value: $(this).val(),
|
||||||
checklists["'.$checks_id.'"].toggleCheck(id);
|
id: $(this).attr("data-id"),
|
||||||
},
|
|
||||||
onUnCheck: function () {
|
|
||||||
var id = $(this).parent().data("id");
|
|
||||||
|
|
||||||
checklists["'.$checks_id.'"].toggleCheck(id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".check-delete").click(function(event){
|
|
||||||
var li = $(this).closest("li");
|
|
||||||
var id = li.data("id");
|
|
||||||
|
|
||||||
swal({
|
|
||||||
title: "'.tr("Rimuovere l'elemento della checklist?").'",
|
|
||||||
html: "'.tr('Tutti gli elementi figli saranno rimossi di conseguenza. Continuare?').'",
|
|
||||||
showCancelButton: true,
|
|
||||||
confirmButtonText: "'.tr('Procedi').'",
|
|
||||||
type: "error",
|
|
||||||
}).then(function (result) {
|
|
||||||
checklists["'.$checks_id.'"].deleteCheck(id);
|
|
||||||
});
|
|
||||||
|
|
||||||
event.stopPropagation();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("textarea[name=\'note_checklist\']").keyup(function(){
|
||||||
|
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||||
|
op: "save_note",
|
||||||
|
value: $(this).val(),
|
||||||
|
id: $(this).attr("data-id"),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".checkbox").click(function(){
|
||||||
|
if($(this).is(":checked")){
|
||||||
|
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||||
|
op: "save_checkbox",
|
||||||
|
id: $(this).attr("data-id"),
|
||||||
|
});
|
||||||
|
|
||||||
|
parent = $(this).attr("data-id");
|
||||||
|
$("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){
|
||||||
|
if(!$(this).is(":checked")){
|
||||||
|
$(this).click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||||
|
op: "remove_checkbox",
|
||||||
|
id: $(this).attr("data-id"),
|
||||||
|
});
|
||||||
|
|
||||||
|
parent = $(this).attr("data-id");
|
||||||
|
$("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){
|
||||||
|
if($(this).is(":checked")){
|
||||||
|
$(this).click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function delete_check(id){
|
||||||
|
if(confirm("Eliminare questa checklist?")){
|
||||||
|
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||||
|
op: "delete_check",
|
||||||
|
id: id,
|
||||||
|
}, function(){
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function edit_check(id){
|
||||||
|
launch_modal("Modifica checklist", "'.$checklist_module->fileurl('components/edit-check.php').'?id_record="+id, 1);
|
||||||
|
}
|
||||||
|
|
||||||
</script>';
|
</script>';
|
||||||
|
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user