From 11f7cce2307293260fdb25299dd5a6ed5e22a363 Mon Sep 17 00:00:00 2001 From: Matteo Date: Mon, 27 Feb 2023 11:14:58 +0100 Subject: [PATCH] =?UTF-8?q?Aggiunta=20possibilit=C3=A0=20di=20aggiornare?= =?UTF-8?q?=20l'ordine=20dei=20sottolivelli=20e=20di=20modificare=20la=20d?= =?UTF-8?q?escrizione=20delle=20righe=20nelle=20checklist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/checklists/ajax.php | 78 ++++++++++ modules/checklists/components/edit-check.php | 53 +++++++ modules/checklists/modutil.php | 104 ++++++++----- plugins/checks.php | 145 ++++++++++++------- 4 files changed, 289 insertions(+), 91 deletions(-) create mode 100644 modules/checklists/ajax.php create mode 100644 modules/checklists/components/edit-check.php mode change 100755 => 100644 modules/checklists/modutil.php mode change 100755 => 100644 plugins/checks.php diff --git a/modules/checklists/ajax.php b/modules/checklists/ajax.php new file mode 100644 index 000000000..92abafa51 --- /dev/null +++ b/modules/checklists/ajax.php @@ -0,0 +1,78 @@ +. + */ + +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; +} + +?> \ No newline at end of file diff --git a/modules/checklists/components/edit-check.php b/modules/checklists/components/edit-check.php new file mode 100644 index 000000000..804df8dd5 --- /dev/null +++ b/modules/checklists/components/edit-check.php @@ -0,0 +1,53 @@ +. + */ + +include_once __DIR__.'/../../../core.php'; +use Modules\Checklists\Check; + +$id_record = get("id_record"); +$record = Check::find($id_record); + +?> + +
+
+ {[ "type": "text", "label": "", "name": "content", "required": 1, "value": "content?>" ]} +
+
+ +
+
+ +
+
+ + \ No newline at end of file diff --git a/modules/checklists/modutil.php b/modules/checklists/modutil.php old mode 100755 new mode 100644 index 8027ef8da..cc1e1f550 --- a/modules/checklists/modutil.php +++ b/modules/checklists/modutil.php @@ -17,55 +17,89 @@ * along with this program. If not, see . */ -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 = ' -
  • - checked_at) ? 'checked' : '').'> + $margin = ($level*20); - '.$check->content.''; + $result = ' + + + + '; + + $result .= ' + '; + + $result .= ' + '; + + $result .= ' + '; + + + + $result .= ' + '; + + if(sizeof($check->children)>0){ $result .= ' -
    - -
    '; - } - - if ($level == 0) { + + + '; } $result .= ' - '.(!empty($check->checked_at) ? tr('Verificato da _NAME_ il _DATE_', [ - '_NAME_' => $check->checkUser->username, - '_DATE_' => timestampFormat($check->checked_at), - ]) : '').''; +
    + checked_at) ? 'checked' : '').' '.(!$enabled ? 'disabled' : '').'> + + '.$check->content.' '; if (intval($check->assignedUsers->pluck('id')->toArray())>0){ - $result .= ''. implode(',', $check->assignedUsers->pluck('username')->toArray()).''; + $result .= ' '; }else{ - $result .= ''. tr('Nessun utente assegnato').''; + $result .= ' '. tr('Nessun utente assegnato').''; } - if (empty($check->user) || $check->user->id == $user->id) { + if(!empty($check->checked_at)){ + $result .= ' + '.(!empty($check->checked_at) ? tr('Verificato da _NAME_ il _DATE_', [ + '_NAME_' => $check->checkUser->username, + '_DATE_' => timestampFormat($check->checked_at), + ]) : '').' + '; + } + + $result .= ' + +
    + + +
    +
    + + '; + $children = $structure->checks()->where('id_parent', $check->id)->orderBy('order')->get(); + foreach ($children as $child) { + $result .= renderChecklist($child, $level + 1, $check->id); + } $result .= ' - - - - '; + +
    +
    + - $result .= ' -
      '; + + + - $children = $check->children; - foreach ($children as $child) { - $result .= renderChecklist($child, $level + 1); - } - - $result .= ' -
    -
  • '; + '; return $result; } @@ -80,10 +114,10 @@ function renderChecklistHtml($check, $level = 0) $result = ' - '.(!empty($check->checked_at)?'':'').' + '.(!empty($check->checked_at)?'':'').' - '.$check->content.' + '.$check->content.''.(!empty($check->value)?': '.$check->value:'').' '; diff --git a/plugins/checks.php b/plugins/checks.php old mode 100755 new mode 100644 index 9f6635891..00d8b4414 --- a/plugins/checks.php +++ b/plugins/checks.php @@ -57,15 +57,15 @@ if ($structure->permission == 'rw') { $checks = $structure->mainChecks($id_record); -echo ' - '; @@ -73,62 +73,95 @@ echo ' echo ' -'; + +?> \ No newline at end of file