2019-07-29 17:42:24 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* 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-29 17:42:24 +02:00
include_once __DIR__ . '/../../../core.php' ;
$manager_id = filter ( 'manager_id' );
2019-07-30 16:50:10 +02:00
$checklists = $structure -> checklists () -> orderBy ( 'created_at' ) -> get ();
2019-07-29 17:42:24 +02:00
$list = [];
foreach ( $checklists as $checklist ) {
$list [] = [
'id' => $checklist -> id ,
2024-03-26 18:05:18 +01:00
'text' => $checklist -> name ,
2019-07-29 17:42:24 +02:00
];
}
echo '
< form action = " " method = " post " id = " check-form " >
< div class = " row " >
2019-07-30 16:50:10 +02:00
< div class = " col-md-12 " >
2023-02-20 15:59:39 +01:00
{[ " type " : " select " , " label " : " '.tr('Checklist').' " , " name " : " checklist " , " values " : '.json_encode($list).' , " required " : 1 ]}
2019-07-29 17:42:24 +02:00
</ div >
2019-07-30 16:50:10 +02:00
</ div >
2020-07-31 14:25:50 +02:00
2019-07-30 16:50:10 +02:00
< div class = " row " >
2019-07-29 17:42:24 +02:00
< div class = " col-md-6 " >
2020-11-30 10:32:16 +01:00
{[ " type " : " select " , " label " : " '.tr('Utente assegnato').' " , " name " : " assigned_users " , " ajax-source " : " utenti " , " multiple " : 1 ]}
2019-07-30 16:50:10 +02:00
</ div >
2020-07-31 14:25:50 +02:00
2019-07-30 16:50:10 +02:00
< div class = " col-md-6 " >
2024-04-18 17:44:05 +02:00
{[ " type " : " select " , " label " : " '.tr('Gruppo assegnato').' " , " name " : " group_id " , " values " : " query=SELECT `zz_groups`.`id`, `title` AS text FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = '.prepare(Models \ Locale::getDefault()->id).') " ]}
2019-07-29 17:42:24 +02:00
</ div >
</ div >
2020-07-31 14:25:50 +02:00
2019-07-29 17:42:24 +02:00
<!-- 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 );
});
2019-07-30 16:50:10 +02:00
2020-07-31 14:25:50 +02:00
$ ( " #assigned_users " ) . change ( function () {
2020-11-30 10:32:16 +01:00
if ( $ ( this ) . selectData () && $ ( this ) . val () != " " ) {
2019-07-30 16:50:10 +02:00
$ ( " #group_id " ) . val ( " " ) . attr ( " disabled " , true ) . attr ( " required " , false );
} else {
$ ( " #group_id " ) . val ( " " ) . attr ( " disabled " , false ) . attr ( " required " , true );
}
});
2020-07-31 14:25:50 +02:00
$ ( " #group_id " ) . change ( function () {
2019-07-30 16:50:10 +02:00
if ( $ ( this ) . selectData ()) {
$ ( " #assigned_users " ) . val ( " " ) . attr ( " disabled " , true ) . attr ( " required " , false );
} else {
$ ( " #assigned_users " ) . val ( " " ) . attr ( " disabled " , false ) . attr ( " required " , true );
}
});
2019-07-29 17:42:24 +02:00
});
function addChecklist ( btn ) {
var $form = $ ( btn ) . closest ( " form " );
2020-07-31 14:25:50 +02:00
2019-07-29 17:42:24 +02:00
var continua = true ;
2020-07-31 14:25:50 +02:00
$form . find ( " :input:not(:button) " ) . each ( function ( index , value ) {
2019-07-29 17:42:24 +02:00
continua &= $ ( this ) . parsley () . validate ();
});
if ( ! continua ) {
swal ({
type : " error " ,
title : " '.tr('Errore').' " ,
text : " '.tr('Alcuni campi obbligatori non sono stati compilati correttamente.').' " ,
});
return ;
}
2020-07-31 14:25:50 +02:00
2019-07-29 17:42:24 +02:00
var checklist = new Checklist ({
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
id_record : " '. $id_record .' " ,
}, " '. $manager_id .' " );
2020-07-31 14:25:50 +02:00
2019-07-29 17:42:24 +02:00
checklist . cloneChecklist ({
checklist : $form . find ( " #checklist " ) . val (),
2019-07-30 17:32:28 +02:00
assigned_users : $form . find ( " #assigned_users " ) . val (),
group_id : $form . find ( " #group_id " ) . val (),
2019-07-29 17:42:24 +02:00
});
2020-07-31 14:25:50 +02:00
2019-07-29 17:42:24 +02:00
$form . closest ( " .modal " ) . modal ( " hide " );
}
</ script > ' ;