Supporto ai template per le checklist
This commit is contained in:
parent
56f4e10e84
commit
7c1582d29c
17
actions.php
17
actions.php
|
@ -5,6 +5,7 @@ include_once __DIR__.'/core.php';
|
|||
use Models\Note;
|
||||
use Models\User;
|
||||
use Modules\Checklists\Check;
|
||||
use Modules\Checklists\Checklist;
|
||||
|
||||
if (empty($structure) || empty($structure['enabled'])) {
|
||||
die(tr('Accesso negato'));
|
||||
|
@ -117,17 +118,27 @@ elseif (filter('op') == 'delete_nota') {
|
|||
flash()->info(tr('Nota interna aggiunta correttamente!'));
|
||||
}
|
||||
|
||||
// Rimozione checklist
|
||||
// Clonazione di una checklist
|
||||
elseif (filter('op') == 'clone_checklist') {
|
||||
$content = post('content');
|
||||
$checklist_id = post('checklist');
|
||||
$assigned_user = User::find(post('assigned_user'));
|
||||
|
||||
$checklist = Checklist::find($checklist_id);
|
||||
$checklist->copia($user, $assigned_user, $id_record);
|
||||
}
|
||||
|
||||
// Aggiunta check alla checklist
|
||||
elseif (filter('op') == 'add_check') {
|
||||
$content = post('content');
|
||||
$parent_id = post('parent') ?: null;
|
||||
|
||||
$assigned_user = User::find(post('assigned_user'));
|
||||
|
||||
$check = Check::build($user, $assigned_user, $structure, $id_record, $content, $parent_id);
|
||||
$check = Check::build($user, $structure, $id_record, $content, $assigned_user, $parent_id);
|
||||
}
|
||||
|
||||
// Rimozione checklist
|
||||
// Rimozione di un check della checklist
|
||||
elseif (filter('op') == 'delete_check') {
|
||||
$check_id = post('check_id');
|
||||
$check = Check::find($check_id);
|
||||
|
|
|
@ -44,17 +44,17 @@ echo '
|
|||
$(document).ready(function() {
|
||||
$("#module").change(function() {
|
||||
if ($(this).val()){
|
||||
$("#plugin").attr("disabled", true);
|
||||
$("#plugin").val("").attr("disabled", true);
|
||||
} else {
|
||||
$("#plugin").attr("disabled", false);
|
||||
$("#plugin").val("").attr("disabled", false);
|
||||
}
|
||||
});
|
||||
|
||||
$("#plugin").change(function() {
|
||||
if ($(this).val()){
|
||||
$("#module").attr("disabled", true);
|
||||
$("#module").val("").attr("disabled", true);
|
||||
} else {
|
||||
$("#module").attr("disabled", false);
|
||||
$("#module").val("").attr("disabled", false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,17 +17,17 @@ echo '
|
|||
<form action="" method="post" id="check-form">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{[ "type": "text", "label": "'.tr('Contenuto').'", "name": "content", "class": "unblockable", "required": 1 ]}
|
||||
{[ "type": "text", "label": "'.tr('Contenuto').'", "name": "content", "required": 1 ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Genitore').'", "name": "parent", "class": "unblockable", "values": '.json_encode($list).' ]}
|
||||
{[ "type": "select", "label": "'.tr('Genitore').'", "name": "parent", "values": '.json_encode($list).', "required": 1 ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Utente').'", "name": "assigned_user", "class": "unblockable", "ajax-source": "utenti", "required": 1 ]}
|
||||
{[ "type": "select", "label": "'.tr('Utente').'", "name": "assigned_user", "ajax-source": "utenti", "required": 1 ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -50,6 +50,22 @@ $(document).ready(function() {
|
|||
$("#check-add").click(function(event){
|
||||
addCheck(this);
|
||||
});
|
||||
|
||||
$("#parent").change(function(){
|
||||
if ($(this).val()) {
|
||||
$("#assigned_user").val("").attr("disabled", true).attr("required", false);
|
||||
} else {
|
||||
$("#assigned_user").val("").attr("disabled", false).attr("required", true);
|
||||
}
|
||||
});
|
||||
|
||||
$("#assigned_user").change(function(){
|
||||
if ($(this).val()) {
|
||||
$("#parent").val("").attr("disabled", true).attr("required", false);
|
||||
} else {
|
||||
$("#parent").val("").attr("disabled", false).attr("required", true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function addCheck(btn) {
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
include_once __DIR__.'/../../../core.php';
|
||||
|
||||
$manager_id = filter('manager_id');
|
||||
|
||||
$checklists = $structure->checklists();
|
||||
$list = [];
|
||||
foreach ($checklists as $checklist) {
|
||||
$list[] = [
|
||||
'id' => $checklist->id,
|
||||
'text' => $checklist->name,
|
||||
];
|
||||
}
|
||||
|
||||
echo '
|
||||
<form action="" method="post" id="check-form">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Checklist').'", "name": "checklist", "values": '.json_encode($list).', "required": 1 ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
{[ "type": "select", "label": "'.tr('Utente').'", "name": "assigned_user", "ajax-source": "utenti", "required": 1 ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PULSANTI -->
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-right">
|
||||
<button type="button" class="btn btn-primary" id="check-add">
|
||||
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>$(document).ready(init)</script>
|
||||
|
||||
<script type="module">
|
||||
import Checklist from "./modules/checklists/js/checklist.js";
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#check-add").click(function(event){
|
||||
addChecklist(this);
|
||||
});
|
||||
});
|
||||
|
||||
function addChecklist(btn) {
|
||||
var $form = $(btn).closest("form");
|
||||
|
||||
var continua = true;
|
||||
$form.find(":input:not(:button)").each(function (index, value) {
|
||||
continua &= $(this).parsley().validate();
|
||||
});
|
||||
|
||||
if (!continua) {
|
||||
swal({
|
||||
type: "error",
|
||||
title: "'.tr('Errore').'",
|
||||
text: "'.tr('Alcuni campi obbligatori non sono stati compilati correttamente.').'",
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var checklist = new Checklist({
|
||||
id_module: "'.$id_module.'",
|
||||
id_plugin: "'.$id_plugin.'",
|
||||
id_record: "'.$id_record.'",
|
||||
}, "'.$manager_id.'");
|
||||
|
||||
checklist.cloneChecklist({
|
||||
checklist: $form.find("#checklist").val(),
|
||||
assigned_user: $form.find("#assigned_user").val(),
|
||||
});
|
||||
|
||||
$form.closest(".modal").modal("hide");
|
||||
}
|
||||
</script>';
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use HTMLBuilder\Manager\ChecklistManager;
|
||||
use Modules\Checklists\HTMLBuilder\ChecklistManager;
|
||||
|
||||
echo '
|
||||
<form action="" method="post" id="edit-form">
|
||||
|
@ -37,17 +37,17 @@ echo '
|
|||
$(document).ready(function() {
|
||||
$("#module").change(function() {
|
||||
if ($(this).val()){
|
||||
$("#plugin").attr("disabled", true);
|
||||
$("#plugin").val("").attr("disabled", true);
|
||||
} else {
|
||||
$("#plugin").attr("disabled", false);
|
||||
$("#plugin").val("").attr("disabled", false);
|
||||
}
|
||||
});
|
||||
|
||||
$("#plugin").change(function() {
|
||||
if ($(this).val()){
|
||||
$("#module").attr("disabled", true);
|
||||
$("#module").val("").attr("disabled", true);
|
||||
} else {
|
||||
$("#module").attr("disabled", false);
|
||||
$("#module").val("").attr("disabled", false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,6 +4,12 @@ class Checklist {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
cloneChecklist(data){
|
||||
data.op = "clone_checklist";
|
||||
|
||||
this.request(data);
|
||||
}
|
||||
|
||||
addCheck(data){
|
||||
data.op = "add_check";
|
||||
|
||||
|
@ -30,24 +36,36 @@ class Checklist {
|
|||
});
|
||||
}
|
||||
|
||||
deleteCheck(id) {
|
||||
deleteCheck(id, user_id) {
|
||||
var check = this.findCheck(id);
|
||||
if (check.user_id != user_id && check.assigned_user_id != user_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
check.icon.removeClass("fa-check-square-o").addClass("fa-refresh fa-spin bg-danger").show();
|
||||
|
||||
this.request({
|
||||
op: "delete_check",
|
||||
check_id: id,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
toggleCheck(id) {
|
||||
toggleCheck(id, user_id) {
|
||||
var check = this.findCheck(id);
|
||||
if (check.assigned_user_id != user_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
check.icon.removeClass("fa-square-o fa-check-square-o ").addClass("fa-refresh fa-spin").show();
|
||||
|
||||
this.request({
|
||||
op: "toggle_check",
|
||||
check_id: id,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
findCheck(id) {
|
||||
|
@ -59,6 +77,8 @@ class Checklist {
|
|||
date: li.find(".check-date"),
|
||||
text: li.find(".check-text"),
|
||||
children: li.find(".check-children"),
|
||||
user_id: li.data('user_id'),
|
||||
assigned_user_id: li.data('assigned_user_id'),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -23,17 +23,23 @@ class Check extends Model
|
|||
* @param User $assigned_user
|
||||
* @param ChecklistTrait $structure
|
||||
* @param int $id_record
|
||||
* @param string $contenuto
|
||||
* @param int $id_parent
|
||||
* @param string $content
|
||||
* @param int $parent_id
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function build(User $user, User $assigned_user, $structure, $id_record, $contenuto, $id_parent = null)
|
||||
public static function build(User $user, $structure, $id_record, $content, User $assigned_user = null, $parent_id = null)
|
||||
{
|
||||
$model = parent::build();
|
||||
|
||||
$model->user()->associate($user);
|
||||
$model->id_parent = $parent_id;
|
||||
|
||||
if (empty($parent_id)) {
|
||||
$model->assignedUser()->associate($assigned_user);
|
||||
} else {
|
||||
$model->assignedUser()->associate($model->parent->assignedUser);
|
||||
}
|
||||
|
||||
if ($structure instanceof Module) {
|
||||
$model->module()->associate($structure);
|
||||
|
@ -42,8 +48,7 @@ class Check extends Model
|
|||
}
|
||||
|
||||
$model->id_record = $id_record;
|
||||
$model->id_parent = $id_parent;
|
||||
$model->content = $contenuto;
|
||||
$model->content = $content;
|
||||
|
||||
$model->save();
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
namespace Modules\Checklists;
|
||||
|
||||
use Common\Model;
|
||||
use Models\Module;
|
||||
use Models\Plugin;
|
||||
use Models\User;
|
||||
|
||||
class Checklist extends Model
|
||||
{
|
||||
|
@ -30,6 +33,24 @@ class Checklist extends Model
|
|||
return $this->checks()->whereNull('id_parent')->orderBy('created_at')->get();
|
||||
}
|
||||
|
||||
public function copia(User $user, User $assigned_user, $id_record)
|
||||
{
|
||||
$structure = $this->plugin ?: $this->module;
|
||||
|
||||
$checks = $this->mainChecks();
|
||||
$relations = [];
|
||||
|
||||
while (!$checks->isEmpty()) {
|
||||
$child = $checks->shift();
|
||||
$id_parent = $child->id_parent ? $relations[$child->id_parent] : null;
|
||||
|
||||
$check = Check::build($user, $structure, $id_record, $child->content, $assigned_user, $id_parent);
|
||||
$relations[$child->id] = $check->id;
|
||||
|
||||
$checks = $checks->merge($child->children);
|
||||
}
|
||||
}
|
||||
|
||||
/* Relazioni Eloquent */
|
||||
|
||||
public function checks()
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Modules\Checklists\HTMLBuilder;
|
||||
|
||||
use HTMLBuilder\Manager\ManagerInterface;
|
||||
use Models\User;
|
||||
use Modules;
|
||||
use Plugins;
|
||||
|
||||
|
@ -26,20 +27,13 @@ class ChecklistManager implements ManagerInterface
|
|||
$module = Modules::get('Checklists');
|
||||
$structure = Plugins::get($options['id_plugin']) ?: Modules::get($options['id_module']);
|
||||
|
||||
$utente = \Auth::user();
|
||||
|
||||
// ID del form
|
||||
$manager_id = 'checklist_'.$options['id_module'].'_'.$options['id_plugin'];
|
||||
|
||||
$checklists = $structure->checklists();
|
||||
$checklist_select = [];
|
||||
foreach ($checklists as $checklist) {
|
||||
$checklist_select[] = [
|
||||
'id' => $checklist->id,
|
||||
'text' => $checklist->name,
|
||||
];
|
||||
}
|
||||
|
||||
$result = '
|
||||
<div class="panel panel-primary" id="'.$manager_id.'" style="position:relative">
|
||||
<div class="panel panel-primary" id="'.$manager_id.'" style="position:relative">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.tr('Checklist').'</h3>
|
||||
</div>
|
||||
|
@ -70,10 +64,24 @@ class ChecklistManager implements ManagerInterface
|
|||
<br>';
|
||||
}
|
||||
|
||||
$checks = $structure->mainChecks($options['id_record']);
|
||||
$users = $checks->groupBy('id_utente_assegnato');
|
||||
|
||||
$result .= '
|
||||
<div class="row">';
|
||||
foreach ($users as $user_id => $checks) {
|
||||
$user = User::find($user_id);
|
||||
|
||||
$result .= '
|
||||
<div class="col-md-6" '.($utente->id != $user_id ? 'style="opacity: 0.5"' : '').'>
|
||||
<div class="box box-info">
|
||||
<div class="box-header">
|
||||
<h3 class="box-title">'.$user->nome_completo.'</h3>
|
||||
</div>
|
||||
|
||||
<div class="box-body">
|
||||
<ul class="checklist">';
|
||||
|
||||
$checks = $structure->mainChecks($options['id_record']);
|
||||
foreach ($checks as $check) {
|
||||
$result .= self::renderChecklist($check);
|
||||
}
|
||||
|
@ -81,7 +89,14 @@ class ChecklistManager implements ManagerInterface
|
|||
$result .= '
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$result .= '
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
$result .= '
|
||||
<script>$(document).ready(init)</script>
|
||||
|
@ -100,14 +115,22 @@ $(document).ready(function() {
|
|||
$(".check-item").click(function(event){
|
||||
var id = $(this).attr("id").replace("check_", "");
|
||||
|
||||
checklists["'.$manager_id.'"].toggleCheck(id);
|
||||
var result = checklists["'.$manager_id.'"].toggleCheck(id, '.$utente->id.');
|
||||
|
||||
if (!result){
|
||||
swal("'.tr('Errore').'", "'.tr('La tua utenza non corrisponde a quella assegnata al check').'", "error");
|
||||
}
|
||||
});
|
||||
|
||||
$(".check-delete").click(function(event){
|
||||
var li = $(this).closest("li");
|
||||
var id = li.attr("id").replace("check_", "");
|
||||
|
||||
checklists["'.$manager_id.'"].deleteCheck(id);
|
||||
var result = checklists["'.$manager_id.'"].deleteCheck(id, '.$utente->id.');
|
||||
|
||||
if (!result){
|
||||
swal("'.tr('Errore').'", "'.tr('La tua utenza non possiede i permessi di modificare questo check').'", "error");
|
||||
}
|
||||
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
@ -132,7 +155,7 @@ function deleteCheck(id) {
|
|||
public static function renderChecklist($check, $level = 0)
|
||||
{
|
||||
$result = '
|
||||
<li id="check_'.$check->id.'" class="check-item'.(!empty($check->checked_at) ? ' checked' : '').'">
|
||||
<li id="check_'.$check->id.'" class="check-item'.(!empty($check->checked_at) ? ' checked' : '').'" data-user_id="'.$check->id_utente.'" data-assigned_user_id="'.$check->id_utente_assegnato.'">
|
||||
'.str_repeat(' ', $level * 8).'
|
||||
|
||||
<i class="check-icon fa '.(!empty($check->checked_at) ? 'fa-check-square-o' : 'fa-square-o').'"></i>
|
||||
|
|
|
@ -14,7 +14,7 @@ trait ChecklistTrait
|
|||
|
||||
public function mainChecks($id_record)
|
||||
{
|
||||
return $this->hasMany(Check::class, $this->component_identifier)->where('id_record', $id_record)->whereNull('id_parent')->orderBy('created_at')->get();
|
||||
return $this->hasMany(Check::class, $this->component_identifier)->where('id_record', $id_record)->whereNull('id_parent')->orderBy('id_utente_assegnato', 'created_at')->get();
|
||||
}
|
||||
|
||||
public function checklists()
|
||||
|
|
|
@ -163,6 +163,16 @@ class User extends Model
|
|||
$this->image_file_id = $upload->id;
|
||||
}
|
||||
|
||||
public function getNomeCompletoAttribute()
|
||||
{
|
||||
$anagrafica = $this->anagrafica;
|
||||
if (empty($anagrafica)) {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
return $anagrafica->ragione_sociale.' ('.$this->username.')';
|
||||
}
|
||||
|
||||
/* Relazioni Eloquent */
|
||||
|
||||
public function group()
|
||||
|
|
Loading…
Reference in New Issue