openstamanager/plugins/checks.php

139 lines
4.6 KiB
PHP
Raw Normal View History

2019-07-30 16:50:10 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* 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/>.
*/
2019-07-30 16:50:10 +02:00
include_once __DIR__.'/../core.php';
$checklist_module = Modules::get('Checklists');
$checks_id = 'checklist_'.$id_module.'_'.$id_plugin;
echo '
2019-07-31 09:25:54 +02:00
<div id="'.$checks_id.'">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">'.tr('Checklist').'</h3>
</div>
<div class="box-body" style="position:relative">
<div id="loading_'.$checks_id.'" class="text-center hide component-loader">
<div>
<i class="fa fa-refresh fa-spin fa-3x fa-fw"></i>
<span class="sr-only">'.tr('Caricamento...').'</span>
</div>
</div>';
2019-07-30 16:50:10 +02:00
// Form per la creazione di una nuova checklist
if ($structure->permission == 'rw') {
echo '
2019-07-31 09:25:54 +02:00
<div class="row">
<div class="col-md-12">
<a class="btn btn-sm btn-primary" data-href="'.$checklist_module->fileurl('components/add-check.php').'?id_module='.$id_module.'&id_record='.$id_record.'&id_plugin='.$id_plugin.'&manager_id='.$checks_id.'" data-toggle="tooltip" data-title="'.tr('Aggiungi check').'">
2020-11-30 10:32:16 +01:00
<i class="fa fa-plus"></i> '.tr('Nuova').'
2019-07-31 09:25:54 +02:00
</a>
2020-09-07 15:04:06 +02:00
2019-07-31 09:25:54 +02:00
<a class="btn btn-sm btn-primary" data-href="'.$checklist_module->fileurl('components/add-checklist.php').'?id_module='.$id_module.'&id_record='.$id_record.'&id_plugin='.$id_plugin.'&manager_id='.$checks_id.'" data-toggle="tooltip" data-title="'.tr('Aggiungi check').'">
2020-11-30 10:32:16 +01:00
<i class="fa fa-plus"></i> '.tr('Checklist predefinite').'
2019-07-31 09:25:54 +02:00
</a>
</div>
2019-07-30 16:50:10 +02:00
</div>
2020-09-07 15:04:06 +02:00
2019-07-31 09:25:54 +02:00
<div class="clearfix"></div>
<br>';
2019-07-30 16:50:10 +02:00
}
$checks = $structure->mainChecks($id_record);
echo '
2019-07-31 09:25:54 +02:00
<ul class="todo-list checklist">';
2019-07-30 16:50:10 +02:00
foreach ($checks as $check) {
echo renderChecklist($check);
}
echo '
2019-07-31 09:25:54 +02:00
</ul>
</div>
2019-07-30 16:50:10 +02:00
</div>
</div>';
echo '
<script>$(document).ready(init)</script>
<script type="module">
import Checklist from "./modules/checklists/js/checklist.js";
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.'");
2020-09-07 15:04:06 +02:00
2019-07-30 16:50:10 +02:00
$(".checklist").sortable({
placeholder: "sort-highlight",
handle: ".handle",
forcePlaceholderSize: true,
zIndex: 999999,
update: function(event, ui) {
var order = [];
$(".checklist > li").each( function(){
order.push($(this).data("id"));
});
$.post(globals.rootdir + "/actions.php", {
id_module: "'.$id_module.'",
id_plugin: "'.$id_plugin.'",
id_record: "'.$id_record.'",
op: "sort_checks",
order: order.join(","),
});
}
});
2020-09-07 15:04:06 +02:00
2019-07-30 16:50:10 +02:00
$(".checklist").todoList({
onCheck : function () {
var id = $(this).parent().data("id");
2020-09-07 15:04:06 +02:00
2019-07-30 16:50:10 +02:00
checklists["'.$checks_id.'"].toggleCheck(id);
},
onUnCheck: function () {
var id = $(this).parent().data("id");
checklists["'.$checks_id.'"].toggleCheck(id);
}
});
2020-09-07 15:04:06 +02:00
2019-07-30 16:50:10 +02:00
$(".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);
});
2020-09-07 15:04:06 +02:00
event.stopPropagation();
2019-07-30 16:50:10 +02:00
});
});
</script>';