mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-02 17:07:01 +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/>.
|
||||
*/
|
||||
|
||||
function renderChecklist($check, $level = 0)
|
||||
{
|
||||
function renderChecklist($check, $level = 1, $parent = 0) {
|
||||
|
||||
global $structure;
|
||||
|
||||
$user = auth()->getUser();
|
||||
$enabled = $check->assignedUsers ? $check->assignedUsers->pluck('id')->search($user->id) !== false : true;
|
||||
|
||||
$result = '
|
||||
<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' : '').'>
|
||||
$margin = ($level*20);
|
||||
|
||||
<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){
|
||||
$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{
|
||||
$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 .= '
|
||||
<div class="tools">
|
||||
<i class="fa fa-trash-o check-delete"></i>
|
||||
</div>';
|
||||
}
|
||||
|
||||
if ($level == 0) {
|
||||
<tr>
|
||||
<td colspan="4" style="padding-left:'.$margin.'px;padding-right:0px;padding-top:0px;padding-bottom:0px;border-top:0px;">
|
||||
<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();
|
||||
foreach ($children as $child) {
|
||||
$result .= renderChecklist($child, $level + 1, $check->id);
|
||||
}
|
||||
$result .= '
|
||||
<span class="handle pull-right">
|
||||
<i class="fa fa-ellipsis-v"></i>
|
||||
<i class="fa fa-ellipsis-v"></i>
|
||||
</span>';
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$result .= '
|
||||
<span class="badge pull-right" style="margin-right:5px">'.(!empty($check->checked_at) ? tr('Verificato da _NAME_ il _DATE_', [
|
||||
'_NAME_' => $check->checkUser->username,
|
||||
'_DATE_' => timestampFormat($check->checked_at),
|
||||
]) : '').'</span>';
|
||||
</table>
|
||||
</td>
|
||||
|
||||
$result .= '
|
||||
<ul class="todo-list">';
|
||||
<td style="width:40px;text-align:center;border-top:0px;">
|
||||
<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;
|
||||
foreach ($children as $child) {
|
||||
$result .= renderChecklist($child, $level + 1);
|
||||
}
|
||||
|
||||
$result .= '
|
||||
</ul>
|
||||
</li>';
|
||||
</tr>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
@ -80,10 +114,10 @@ function renderChecklistHtml($check, $level = 0)
|
||||
$result = '
|
||||
<tr>
|
||||
<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 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>
|
||||
</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);
|
||||
|
||||
echo '
|
||||
<ul class="todo-list checklist">';
|
||||
|
||||
foreach ($checks as $check) {
|
||||
echo renderChecklist($check);
|
||||
}
|
||||
echo " <table class='table'>
|
||||
<tbody class='sort' data-sonof='0'>";
|
||||
foreach ($checks as $check) {
|
||||
echo renderChecklist($check);
|
||||
}
|
||||
echo " </tbody>
|
||||
</table>";
|
||||
|
||||
echo '
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
@ -73,62 +73,95 @@ echo '
|
||||
echo '
|
||||
<script>$(document).ready(init)</script>
|
||||
|
||||
<script type="module">
|
||||
import Checklist from "./modules/checklists/js/checklist.js";
|
||||
<script>
|
||||
|
||||
var checklists = checklists ? checklists : {};
|
||||
$(document).ready(function() {
|
||||
checklists["'.$checks_id.'"] = new Checklist({
|
||||
id_module: "'.$id_module.'",
|
||||
id_plugin: "'.$id_plugin.'",
|
||||
id_record: "'.$id_record.'",
|
||||
}, "'.$checks_id.'");
|
||||
$(document).ready(function(){
|
||||
$("[data-toggle=\'tooltip\']").tooltip();
|
||||
});
|
||||
|
||||
sortable(".checklist", {
|
||||
placeholder: "sort-highlight",
|
||||
handle: ".handle",
|
||||
forcePlaceholderSize: true,
|
||||
zIndex: 999999,
|
||||
})[0].addEventListener("sortupdate", function(e) {
|
||||
let order = $(".checklist > li[data-id]").toArray().map(a => $(a).data("id"))
|
||||
sortable("#tab_checks .sort", {
|
||||
axis: "y",
|
||||
handle: ".handle",
|
||||
cursor: "move",
|
||||
dropOnEmpty: true,
|
||||
scroll: true,
|
||||
});
|
||||
|
||||
$.post(globals.rootdir + "/actions.php", {
|
||||
id_module: globals.id_module,
|
||||
id_plugin: "'.$id_plugin.'",
|
||||
id_record: globals.id_record,
|
||||
op: "ordina-checks",
|
||||
sortable_table = sortable("#tab_checks .sort").length;
|
||||
|
||||
for(i=0; i<sortable_table; i++){
|
||||
sortable("#tab_checks .sort")[i].addEventListener("sortupdate", function(e) {
|
||||
|
||||
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(","),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(".checklist").todoList({
|
||||
onCheck: function () {
|
||||
var id = $(this).parent().data("id");
|
||||
|
||||
checklists["'.$checks_id.'"].toggleCheck(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();
|
||||
$("input[name^=\'value\']").keyup(function(){
|
||||
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||
op: "save_value",
|
||||
value: $(this).val(),
|
||||
id: $(this).attr("data-id"),
|
||||
});
|
||||
});
|
||||
|
||||
$("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>';
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user