mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-02 08:56:48 +01:00
Fix per inserimento e modifica nuove checklist
This commit is contained in:
parent
30ff4bb1f2
commit
278e77d715
@ -19,24 +19,37 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
use Modules\Checklists\Check;
|
||||
use Modules\Checklists\ChecklistItem;
|
||||
|
||||
switch(post('op')){
|
||||
|
||||
case "delete_check":
|
||||
$id = post('id');
|
||||
$main_check = post('main_check');
|
||||
|
||||
if($main_check){
|
||||
$record = ChecklistItem::find($id);
|
||||
}else{
|
||||
$record = Check::find($id);
|
||||
}
|
||||
|
||||
$record = Check::find($id);
|
||||
$record->delete();
|
||||
|
||||
break;
|
||||
|
||||
case "update_position":
|
||||
|
||||
$main_check = post('main_check');
|
||||
$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);
|
||||
if($main_check){
|
||||
foreach($order as $i => $id){
|
||||
$dbo->query("UPDATE zz_checklist_items SET `order`=".prepare($i)." WHERE id=".prepare($id));
|
||||
}
|
||||
}else{
|
||||
foreach($order as $i => $id){
|
||||
$dbo->query("UPDATE zz_checks SET `order`=".prepare($i)." WHERE id=".prepare($id));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@ -65,8 +78,14 @@ switch(post('op')){
|
||||
|
||||
case "edit_check":
|
||||
$id_record = post('id_record');
|
||||
$main_check = post('main_check');
|
||||
|
||||
if($main_check){
|
||||
$record = ChecklistItem::find($id_record);
|
||||
}else{
|
||||
$record = Check::find($id_record);
|
||||
}
|
||||
|
||||
$record = Check::find($id_record);
|
||||
$record->content = post('content');
|
||||
$record->save();
|
||||
|
||||
|
@ -18,16 +18,23 @@
|
||||
*/
|
||||
|
||||
include_once __DIR__.'/../../../core.php';
|
||||
use Modules\Checklists\ChecklistItem;
|
||||
use Modules\Checklists\Check;
|
||||
|
||||
$id_record = get("id_record");
|
||||
$record = Check::find($id_record);
|
||||
$main_check = get("main_check");
|
||||
|
||||
if($main_check){
|
||||
$record = ChecklistItem::find($id_record);
|
||||
}else{
|
||||
$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?>" ]}
|
||||
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "content_edit", "required": 1, "value": "<?=$record->content?>" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -45,7 +52,8 @@ $record = Check::find($id_record);
|
||||
$.post('<?php echo $rootdir; ?>/modules/checklists/ajax.php', {
|
||||
op: "edit_check",
|
||||
id_record: "<?=$id_record?>",
|
||||
content: $('#content').val()
|
||||
content: $('#content_edit').val(),
|
||||
main_check: "<?=$main_check?>",
|
||||
}, function(){
|
||||
location.reload();
|
||||
});
|
||||
|
@ -68,7 +68,7 @@ $(document).ready(function() {
|
||||
});
|
||||
</script>';
|
||||
|
||||
$checks = $record->checks;
|
||||
$checks = $record->mainChecks();
|
||||
|
||||
$list = [];
|
||||
foreach ($checks as $check) {
|
||||
@ -108,12 +108,15 @@ echo '
|
||||
|
||||
<ul class="todo-list checklist">';
|
||||
|
||||
$checks = $record->mainChecks();
|
||||
foreach ($checks as $check) {
|
||||
echo renderChecklist($check);
|
||||
}
|
||||
echo " <table class='table'>
|
||||
<tbody class='sort' data-sonof='0'>";
|
||||
foreach ($checks as $check) {
|
||||
echo renderChecklistInserimento($check);
|
||||
}
|
||||
echo " </tbody>
|
||||
</table>";
|
||||
|
||||
echo '
|
||||
echo '
|
||||
</ul>
|
||||
</div>
|
||||
</div>';
|
||||
@ -167,4 +170,49 @@ $(document).ready(function() {
|
||||
echo '
|
||||
<a class="btn btn-danger ask" data-backto="record-list">
|
||||
<i class="fa fa-trash"></i> '.tr('Elimina').'
|
||||
</a>';
|
||||
</a>
|
||||
|
||||
<script>
|
||||
|
||||
sortable(".sort", {
|
||||
axis: "y",
|
||||
handle: ".handle",
|
||||
cursor: "move",
|
||||
dropOnEmpty: true,
|
||||
scroll: true,
|
||||
});
|
||||
|
||||
sortable_table = sortable(".sort").length;
|
||||
|
||||
for(i=0; i<sortable_table; i++){
|
||||
sortable(".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(","),
|
||||
main_check: 1,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function delete_check(id){
|
||||
if(confirm("Eliminare questa checklist?")){
|
||||
$.post("'.$checklist_module->fileurl('ajax.php').'", {
|
||||
op: "delete_check",
|
||||
id: id,
|
||||
main_check: 1,
|
||||
}, function(){
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function edit_check(id){
|
||||
launch_modal("Modifica checklist", "'.$checklist_module->fileurl('components/edit-check.php').'?id_record="+id+"&main_check=1", 1);
|
||||
}
|
||||
|
||||
</script>';
|
@ -21,6 +21,8 @@ include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Checklists\Checklist;
|
||||
|
||||
$checklist_module = Modules::get('Checklists');
|
||||
|
||||
if (isset($id_record)) {
|
||||
$record = Checklist::find($id_record);
|
||||
}
|
||||
}
|
@ -56,36 +56,6 @@ class Checklist {
|
||||
});
|
||||
}
|
||||
|
||||
deleteCheck(id) {
|
||||
this.request({
|
||||
op: "rimuovi-check",
|
||||
check_id: id,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
toggleCheck(id) {
|
||||
this.request({
|
||||
op: "toggle-check",
|
||||
check_id: id,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
findCheck(id) {
|
||||
var li = $("#check_" + id);
|
||||
|
||||
return {
|
||||
item: li,
|
||||
input: li.find("input"),
|
||||
info: li.find(".badge"),
|
||||
text: li.find(".text"),
|
||||
children: li.find("ul"),
|
||||
};
|
||||
}
|
||||
|
||||
showLoader() {
|
||||
$("#loading_" + this.id).removeClass("hide");
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ function renderChecklist($check, $level = 1, $parent = 0) {
|
||||
]) : '').'
|
||||
</span>';
|
||||
}
|
||||
|
||||
$result .= '
|
||||
</td>';
|
||||
|
||||
@ -94,7 +93,72 @@ function renderChecklist($check, $level = 1, $parent = 0) {
|
||||
</td>
|
||||
|
||||
<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">
|
||||
<button class="btn btn-xs btn-default handle" title="Modifica ordine delle righe" draggable="true">
|
||||
<i class="fa fa-sort"></i>
|
||||
</button>
|
||||
</td>
|
||||
|
||||
</tr>';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function renderChecklistInserimento($check, $level = 1, $parent = 0)
|
||||
{
|
||||
|
||||
global $record;
|
||||
|
||||
$margin = ($level*20);
|
||||
|
||||
$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;border-top:0px;border-left:3px solid #eaeaea;">';
|
||||
$result .= '
|
||||
<span class="text">'.$check->content.'</span>';
|
||||
$result .= '
|
||||
</td>';
|
||||
|
||||
$result .= '
|
||||
<td style="width:40px;text-align:right;border-top:0px;">
|
||||
<div class="input-group-btn">
|
||||
<button class="btn btn-warning btn-xs" onclick="edit_check(\''.$check->id.'\')"><i class="fa fa-edit"></i></button>
|
||||
<button class="btn btn-danger btn-xs" onclick="delete_check(\''.$check->id.'\')"><i class="fa fa-trash"></i></button>
|
||||
</div>
|
||||
</td>';
|
||||
|
||||
|
||||
|
||||
$result .= '
|
||||
</tr>';
|
||||
|
||||
if(sizeof($check->children)>0){
|
||||
$result .= '
|
||||
<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 = $record->checks()->where('id_parent', $check->id)->orderBy('order')->get();
|
||||
foreach ($children as $child) {
|
||||
$result .= renderChecklistInserimento($child, $level + 1, $check->id);
|
||||
}
|
||||
$result .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
$result .= '
|
||||
</table>
|
||||
</td>
|
||||
|
||||
<td style="width:40px;text-align:center;border-top:0px;">
|
||||
<button class="btn btn-xs btn-default handle" title="Modifica ordine delle righe" draggable="true">
|
||||
<i class="fa fa-sort"></i>
|
||||
</button>
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user