diff --git a/class/actions_digiquali.class.php b/class/actions_digiquali.class.php index 14014f87..1a80de64 100644 --- a/class/actions_digiquali.class.php +++ b/class/actions_digiquali.class.php @@ -132,6 +132,27 @@ public function doActions(array $parameters, $object, string $action): int require_once __DIR__ . '/../class/survey.class.php'; } + if (strpos($parameters['context'], 'controlpublicsignature') !== false) { + if ($action == 'add_signature') { + $data = json_decode(file_get_contents('php://input'), true); + $subControlList = $object->fetchAll('', '', 0, 0, ['fk_control' => $object->id]); + + if(is_array($subControlList) && !empty($subControlList)) { + foreach ($subControlList as $subControl) { + $signatory = new SaturneSignature($this->db, 'digiquali', 'control'); + $signatory->fetch(0, '', ' AND fk_object =' . "'" . $subControl->id . "' AND object_type='control'"); + $signatory->signature = $data['signature']; + $signatory->signature_date = dol_now(); + + $result = $signatory->update($user, true); + if ($result > 0) { + $signatory->setSigned($user, false, 'public'); + } + } + } + } + } + if (!$error) { $this->results = array('myreturn' => 999); $this->resprints = 'A text to show'; diff --git a/class/control.class.php b/class/control.class.php index c6c1dcc8..d893151b 100644 --- a/class/control.class.php +++ b/class/control.class.php @@ -128,6 +128,8 @@ class Control extends SaturneObject 'verdict' => ['type' => 'smallint', 'label' => 'Verdict', 'enabled' => 1, 'position' => 110, 'notnull' => 0, 'visible' => 5, 'showinpwa' => 1, 'index' => 1, 'positioncard' => 20, 'arrayofkeyval' => [0 => '', 1 => 'OK', 2 => 'KO', 3 => 'N/A']], 'photo' => ['type' => 'text', 'label' => 'Photo', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 0, 'showinpwa' => 0], 'track_id' => ['type' => 'text', 'label' => 'TrackID', 'enabled' => 1, 'position' => 125, 'notnull' => 0, 'visible' => 2, 'showinpwa' => 0], + 'mass_control' => ['type' => 'boolean', 'label' => 'MassControl', 'enabled' => 1, 'position' => 126, 'notnull' => 0, 'visible' => 0, 'showinpwa' => 0], + 'fk_control' => ['type' => 'integer:Control:digiquali/class/control.class.php', 'label' => 'Control', 'picto' => 'control', 'enabled' => 1, 'position' => 127, 'notnull' => 0, 'visible' => 0, 'showinpwa' => 0, 'foreignkey' => 'digiquali_control.rowid'], 'fk_user_creat' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'picto' => 'user', 'enabled' => 1, 'position' => 130, 'notnull' => 1, 'visible' => 0, 'showinpwa' => 0, 'foreignkey' => 'user.rowid'], 'fk_user_modif' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'picto' => 'user', 'enabled' => 1, 'position' => 140, 'notnull' => 0, 'visible' => 0, 'showinpwa' => 0, 'foreignkey' => 'user.rowid'], 'fk_sheet' => ['type' => 'integer:Sheet:digiquali/class/sheet.class.php', 'label' => 'Sheet', 'picto' => 'fontawesome_fa-list_fas_#d35968', 'enabled' => 1, 'position' => 12, 'notnull' => 1, 'visible' => 5, 'showinpwa' => 0, 'index' => 1, 'css' => 'maxwidth500 widthcentpercentminusxx', 'foreignkey' => 'digiquali_sheet.rowid'], @@ -235,6 +237,16 @@ class Control extends SaturneObject */ public int $fk_sheet; + /** + * @var int Control ID. + */ + public $fk_control; + + /** + * @var bool Mass control. + */ + public $mass_control; + /** * @var int|string|null User ID. */ @@ -586,6 +598,7 @@ public function createFromClone(User $user, int $fromID, array $options): int } $object->context = 'createfromclone'; + $object->fk_control = $options['fk_control']; $object->fetchObjectLinked('','', $object->id, 'digiquali_' . $object->element, 'OR', 1, 'sourcetype', 0); diff --git a/core/modules/digiquali/digiqualidocuments/controldocument/doc_controldocument_odt.modules.php b/core/modules/digiquali/digiqualidocuments/controldocument/doc_controldocument_odt.modules.php index 404563e2..5a0b2f8f 100644 --- a/core/modules/digiquali/digiqualidocuments/controldocument/doc_controldocument_odt.modules.php +++ b/core/modules/digiquali/digiqualidocuments/controldocument/doc_controldocument_odt.modules.php @@ -199,6 +199,7 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo } $odfHandler->mergeSegment($listLines); } + } } @@ -289,6 +290,75 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo } $odfHandler->mergeSegment($listLines); } + + // Get sub control list. + $foundTagForLines = 1; + try { + $listLines = $odfHandler->setSegment('subcontrols'); + + } catch (OdfException|OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template. + $foundTagForLines = 0; + $listLines = ''; + dol_syslog($e->getMessage()); + } + + // Loop on previous photos array. + if ($foundTagForLines) { + if($object->mass_control > 0) { + $linkableElements = get_sheet_linkable_objects(); + + if (is_array($linkableElements) && !empty($linkableElements)) { + foreach ($linkableElements as $linkableElement) { + $nameField[$linkableElement['link_name']] = $linkableElement['name_field']; + $objectInfo[$linkableElement['link_name']] = [ + 'title' => $linkableElement['langs'], + 'className' => $linkableElement['className'] + ]; + } + } + $subControlList = $object->fetchAll('', '', 0, 0, ['fk_control' => $object->id]); + if (is_array($subControlList) && !empty($subControlList)) { + foreach ($subControlList as $subControl) { + $subControl->fetchObjectLinked($subControl->fk_sheet, 'digiquali_sheet', null, '', 'OR', 1, 'position', 0); + $tmpArray['subcontrol_ref'] = $subControl->ref; + $tmpArray['subcontrol_note'] = $subControl->note_public; + $tmpArray['subcontrol_verdict'] = ($subControl->verdict == 1) ? 'OK' : 'KO'; + //get object linked + $subControl->fetchObjectLinked('', '', $subControl->id, 'digiquali_control', 'OR', 1, 'sourcetype', 0); + if (is_array($subControl->linkedObjectsIds) && !empty($subControl->linkedObjectsIds)) { + foreach($subControl->linkedObjectsIds as $linkedObjectType => $linkedObjectId) { + $className = $objectInfo[$linkedObjectType]['className']; + $linkedObject = new $className($this->db); + $linkedObjectId = array_shift($linkedObjectId); + $result = $linkedObject->fetch($linkedObjectId); + if ($result > 0) { + $objectNameField = $nameField[$linkedObjectType]; + if (strstr($objectNameField, ',')) { + $nameFields = explode(', ', $objectNameField); + if (is_array($nameFields) && !empty($nameFields)) { + foreach ($nameFields as $subnameField) { + $objectName = $linkedObject->$subnameField . chr(0x0A); + } + } + } else { + $objectName = $linkedObject->$objectNameField . chr(0x0A); + } + } + $tmpArray['subcontrol_object_label'] = rtrim($objectName, chr(0x0A)); + $tmpArray['subcontrol_object_ref'] = $linkedObject->ref; + } + + } + $this->setTmpArrayVars($tmpArray, $listLines, $outputLangs); + + } + } + } + $odfHandler->mergeSegment($listLines); + } + + } catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); @@ -317,87 +387,133 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa $object = $moreParam['object']; if (!empty($object->photo)) { - $path = $conf->digiquali->multidir_output[$conf->entity] . '/control/' . $object->ref . '/photos'; + $path = $conf->digiquali->multidir_output[$conf->entity] . '/control/' . $object->ref . '/photos'; $fileSmall = saturne_get_thumb_name($object->photo, getDolGlobalString('DIGIQUALI_DOCUMENT_MEDIA_VIGNETTE_USED')); - $image = $path . '/thumbs/' . $fileSmall; + $image = $path . '/thumbs/' . $fileSmall; $tmpArray['photoDefault'] = $image; } else { - $noPhoto = '/public/theme/common/nophoto.png'; + $noPhoto = '/public/theme/common/nophoto.png'; $tmpArray['photoDefault'] = DOL_DOCUMENT_ROOT . $noPhoto; } $outputLangs->loadLangs(['products', 'bills', 'orders', 'contracts', 'projects', 'companies']); - $sheet = new Sheet($this->db); - $usertmp = new User($this->db); + $sheet = new Sheet($this->db); + $usertmp = new User($this->db); $projecttmp = new Project($this->db); $sheet->fetch($object->fk_sheet); $usertmp->fetch($object->fk_user_controller); $projecttmp->fetch($object->projectid); - $object->fetchObjectLinked('', '', $object->id, 'digiquali_control', 'OR', 1, 'sourcetype', 0); - $linkableElements = get_sheet_linkable_objects(); - - if (is_array($linkableElements) && !empty($linkableElements)) { - foreach ($linkableElements as $linkableElement) { - $nameField[$linkableElement['link_name']] = $linkableElement['name_field']; - $objectInfo[$linkableElement['link_name']] = [ - 'title' => $linkableElement['langs'], - 'className' => $linkableElement['className'] - ]; - } - foreach ($object->linkedObjectsIds as $linkedObjectType => $linkedObjectsIds) { - $className = $objectInfo[$linkedObjectType]['className']; - $linkedObject = new $className($this->db); - $result = $linkedObject->fetch(array_shift($object->linkedObjectsIds[$linkedObjectType])); - if ($result > 0) { - $objectName = ''; - $objectNameField = $nameField[$linkedObjectType]; - if (strstr($objectNameField, ',')) { - $nameFields = explode(', ', $objectNameField); - if (is_array($nameFields) && !empty($nameFields)) { - foreach ($nameFields as $subnameField) { - $objectName .= $linkedObject->$subnameField . ' '; - } - } - } else { - $objectName = $linkedObject->$objectNameField; - } - $tmpArray['object_label_ref'] .= $objectName . chr(0x0A); - $tmpArray['object_type'] = $outputLangs->transnoentities($objectInfo[$linkedObjectType]['title']) . ' : '; - } - } - } - - $tmpArray['control_ref'] = $object->ref; - $tmpArray['object_label_ref'] = rtrim($tmpArray['object_label_ref'], chr(0x0A)); - $tmpArray['control_date'] = dol_print_date($object->date_creation, 'dayhour', 'tzuser'); - $tmpArray['project_label'] = $projecttmp->ref . ' - ' . $projecttmp->title; - $tmpArray['sheet_ref'] = $sheet->ref; - $tmpArray['sheet_label'] = $sheet->label; - - switch ($object->verdict) { - case 1: - $tmpArray['verdict'] = 'OK'; - break; - case 2: - $tmpArray['verdict'] = 'KO'; - break; - default: - $tmpArray['verdict'] = ''; - break; - } + $object->fetchObjectLinked('', '', $object->id, 'digiquali_control', 'OR', 1, 'sourcetype', 0); + $linkableElements = get_sheet_linkable_objects(); - $tmpArray['public_note'] = $object->note_public; + if (is_array($linkableElements) && !empty($linkableElements)) { + foreach ($linkableElements as $linkableElement) { + $nameField[$linkableElement['link_name']] = $linkableElement['name_field']; + $objectInfo[$linkableElement['link_name']] = [ + 'title' => $linkableElement['langs'], + 'className' => $linkableElement['className'] + ]; + } + foreach ($object->linkedObjectsIds as $linkedObjectType => $linkedObjectsIds) { + $className = $objectInfo[$linkedObjectType]['className']; + $linkedObject = new $className($this->db); + $objectName = ''; + if (is_array($object->linkedObjectsIds[$linkedObjectType]) && !empty($object->linkedObjectsIds[$linkedObjectType])) { + foreach ($object->linkedObjectsIds[$linkedObjectType] as $linkedObjectId) { + $result = $linkedObject->fetch($linkedObjectId); + if ($result > 0) { + $objectNameField = $nameField[$linkedObjectType]; + if (strstr($objectNameField, ',')) { + $nameFields = explode(', ', $objectNameField); + if (is_array($nameFields) && !empty($nameFields)) { + foreach ($nameFields as $subnameField) { + $objectName .= $linkedObject->$subnameField . chr(0x0A); + } + } + } else { + $objectName .= $linkedObject->$objectNameField . chr(0x0A); + } + } + } - $tmpArray['mycompany_name'] = $conf->global->MAIN_INFO_SOCIETE_NOM; - $tmpArray['mycompany_address'] = (!empty($conf->global->MAIN_INFO_SOCIETE_ADRESS) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_ADRESS : ''); - $tmpArray['mycompany_website'] = (!empty($conf->global->MAIN_INFO_SOCIETE_WEBSITE) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_WEBSITE : ''); - $tmpArray['mycompany_mail'] = (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_MAIL : ''); - $tmpArray['mycompany_phone'] = (!empty($conf->global->MAIN_INFO_SOCIETE_PHONE) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_PHONE : ''); + $tmpArray['object_label_ref'] .= $objectName; + $tmpArray['object_type'] = $outputLangs->transnoentities($objectInfo[$linkedObjectType]['title']) . ' : '; + } - $moreParam['tmparray'] = $tmpArray; + } + if ($object->mass_control > 0) { + $subControlSheet = new Sheet($this->db); + $subControlList = $object->fetchAll('', '', 0, 0, ['fk_control' => $object->id]); + if (is_array($subControlList) && !empty($subControlList)) { + foreach ($subControlList as $subControl) { + $subControlSheet->fetch($subControl->fk_sheet); + $subControl->fetchObjectLinked('', '', $subControl->id, 'digiquali_control', 'OR', 1, 'sourcetype', 0); + if (is_array($subControl->linkedObjectsIds) && !empty($subControl->linkedObjectsIds)) { + foreach ($subControl->linkedObjectsIds as $linkedObjectType => $linkedObjectsIds) { + $className = $objectInfo[$linkedObjectType]['className']; + $linkedObject = new $className($this->db); + $objectName = ''; + if (is_array($subControl->linkedObjectsIds[$linkedObjectType]) && !empty($subControl->linkedObjectsIds[$linkedObjectType])) { + foreach ($subControl->linkedObjectsIds[$linkedObjectType] as $linkedObjectId) { + $result = $linkedObject->fetch($linkedObjectId); + if ($result > 0) { + $objectNameField = $nameField[$linkedObjectType]; + if (strstr($objectNameField, ',')) { + $nameFields = explode(', ', $objectNameField); + if (is_array($nameFields) && !empty($nameFields)) { + foreach ($nameFields as $subnameField) { + $objectName .= $linkedObject->$subnameField . chr(0x0A); + } + } + } else { + $objectName .= $linkedObject->$objectNameField . chr(0x0A); + } + } + } + + $tmpArray['object_label_ref'] .= $objectName; + $tmpArray['object_type'] = $outputLangs->transnoentities($objectInfo[$linkedObjectType]['title']) . ' : '; + + $tmpArray['subcontrol_sheet_ref'] = $subControlSheet->ref; + $tmpArray['subcontrol_sheet_label'] = $subControlSheet->label; + } + } + } + } + } + } + $tmpArray['control_ref'] = $object->ref; + $tmpArray['object_label_ref'] = rtrim($tmpArray['object_label_ref'], chr(0x0A)); + $tmpArray['control_date'] = dol_print_date($object->date_creation, 'dayhour', 'tzuser'); + $tmpArray['project_label'] = $projecttmp->ref . ' - ' . $projecttmp->title; + $tmpArray['sheet_ref'] = $sheet->ref; + $tmpArray['sheet_label'] = $sheet->label; + + switch ($object->verdict) { + case 1: + $tmpArray['verdict'] = 'OK'; + break; + case 2: + $tmpArray['verdict'] = 'KO'; + break; + default: + $tmpArray['verdict'] = ''; + break; + } + + $tmpArray['public_note'] = $object->note_public; - return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam); + $tmpArray['mycompany_name'] = $conf->global->MAIN_INFO_SOCIETE_NOM; + $tmpArray['mycompany_address'] = (!empty($conf->global->MAIN_INFO_SOCIETE_ADRESS) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_ADRESS : ''); + $tmpArray['mycompany_website'] = (!empty($conf->global->MAIN_INFO_SOCIETE_WEBSITE) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_WEBSITE : ''); + $tmpArray['mycompany_mail'] = (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_MAIL : ''); + $tmpArray['mycompany_phone'] = (!empty($conf->global->MAIN_INFO_SOCIETE_PHONE) ? ' - ' . $conf->global->MAIN_INFO_SOCIETE_PHONE : ''); + + $moreParam['tmparray'] = $tmpArray; + + return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam); + } } } diff --git a/core/modules/modDigiQuali.class.php b/core/modules/modDigiQuali.class.php index 46e9664d..e3e9eb2b 100644 --- a/core/modules/modDigiQuali.class.php +++ b/core/modules/modDigiQuali.class.php @@ -129,6 +129,7 @@ public function __construct($db) 'main', 'controladmin', 'surveyadmin', + 'controlpublicsignature' ], // Set this to 1 if features of module are opened to external users 'moduleforexternal' => 0, @@ -234,7 +235,8 @@ public function __construct($db) $i++ => ['DIGIQUALI_CONTROLDOCUMENT_ADDON', 'chaine', 'mod_controldocument_standard', '', 0, 'current'], $i++ => ['DIGIQUALI_CONTROLDOCUMENT_ADDON_ODT_PATH', 'chaine', 'DOL_DOCUMENT_ROOT/custom/digiquali/documents/doctemplates/controldocument/', '', 0, 'current'], $i++ => ['DIGIQUALI_CONTROLDOCUMENT_CUSTOM_ADDON_ODT_PATH', 'chaine', 'DOL_DATA_ROOT' . (($conf->entity == 1 ) ? '/' : '/' . $conf->entity . '/') . 'ecm/digiquali/controldocument/', '', 0, 'current'], - $i++ => ['DIGIQUALI_CONTROLDOCUMENT_DEFAULT_MODEL', 'chaine', 'template_controldocument_photo' ,'', 0, 'current'], + $i++ => ['DIGIQUALI_CONTROLDOCUMENT_DEFAULT_MODEL', 'chaine', 'template_controldocument_photo' ,'', 0, 'current'], + $i++ => ['DIGIQUALI_MASSCONTROLDOCUMENT_DEFAULT_MODEL', 'chaine', 'template_masscontroldocument' ,'', 0, 'current'], $i++ => ['DIGIQUALI_DOCUMENT_MEDIA_VIGNETTE_USED', 'chaine', 'small','', 0, 'current'], //CONST SURVEY DOCUMENT diff --git a/core/tpl/digiquali_answers.tpl.php b/core/tpl/digiquali_answers.tpl.php index b6b95084..a1a80fff 100644 --- a/core/tpl/digiquali_answers.tpl.php +++ b/core/tpl/digiquali_answers.tpl.php @@ -31,17 +31,20 @@ if (is_array($sheet->linkedObjects['digiquali_question']) && !empty($sheet->linkedObjects['digiquali_question'])) { foreach ($sheet->linkedObjects['digiquali_question'] as $question) { + $questionAnswer = ''; $comment = ''; $result = $objectLine->fetchFromParentWithQuestion($object->id, $question->id); + if (is_array($result) && !empty($result)) { $objectLine = array_shift($result); $questionAnswer = $objectLine->answer; $comment = $objectLine->comment; } + if (!$user->conf->DIGIQUALI_SHOW_ONLY_QUESTIONS_WITH_NO_ANSWER or empty($questionAnswer)) { ?> -
Commentaire non enregistré
'),$(this).addClass("show-comment-unsaved-message")),window.digiquali.object.updateButtonsStatus()},window.digiquali.object.updateButtonsStatus=function(){$("#saveButton").removeClass("butActionRefused"),$("#saveButton").addClass("butAction"),$("#saveButton").css("background","#0d8aff"),$(".fa-circle").css("display","inline"),$("#saveButton").attr("onclick",'$("#saveObject").submit()'),$(".validateButton").removeClass("butAction"),$("#dialog-confirm-actionButtonValidate").removeAttr("id"),$(".validateButton").addClass("butActionRefused")},window.digiquali.object.saveAnswer=function(t,e,i){var o=window.saturne.toolbox.getToken(),n=window.saturne.toolbox.getQuerySeparator(document.URL);window.saturne.loader.display($(".table-id-"+t)),$.ajax({url:document.URL+n+"action=save&token="+o,type:"POST",data:JSON.stringify({autoSave:!0,questionId:t,answer:e,comment:i}),processData:!1,contentType:!1,success:function(t){$(".fiche").replaceWith($(t).find(".fiche"))},error:function(){}})},window.digiquali.question={},window.digiquali.question.init=function(){window.digiquali.question.event()},window.digiquali.question.event=function(){$(document).on("click",".clicked-photo-preview",window.digiquali.question.previewPhoto),$(document).on("click",".ui-dialog-titlebar-close",window.digiquali.question.closePreviewPhoto),$(document).on("click","#show_photo",window.digiquali.question.showPhoto),$(document).on("click",".answer-picto .item, .wpeo-table .item",window.digiquali.question.selectAnswerPicto)},window.digiquali.question.previewPhoto=function(t){$(this).hasClass("photo-ok")?$("#dialogforpopup").attr("style","border: 10px solid #47e58e"):$(this).hasClass("photo-ko")&&$("#dialogforpopup").attr("style","border: 10px solid #e05353")},window.digiquali.question.closePreviewPhoto=function(t){$("#dialogforpopup").attr("style","border:")},window.digiquali.question.showPhoto=function(){var t=$(this).closest(".question-table").find(".linked-medias");t.hasClass("hidden")?(t.attr("style",""),t.removeClass("hidden")):(t.attr("style","display:none"),t.addClass("hidden"))},window.digiquali.question.selectAnswerPicto=function(t){var e=$(this).closest(".wpeo-dropdown");$(this).closest(".content").removeClass("active"),e.find(".dropdown-toggle span").hide(),e.find(".dropdown-toggle.button-picto").html($(this).closest(".wpeo-tooltip-event").html()),e.find(".input-hidden-picto").val($(this).data("label"))},window.digiquali.sheet={},window.digiquali.sheet.init=function(){window.digiquali.sheet.event()},window.digiquali.sheet.event=function(){}; \ No newline at end of file +window.digiquali||(window.digiquali={},window.digiquali.scriptsLoaded=!1),window.digiquali.scriptsLoaded||(window.digiquali.init=function(){window.digiquali.load_list_script()},window.digiquali.load_list_script=function(){if(!window.digiquali.scriptsLoaded){var t=void 0,o=void 0;for(t in window.digiquali)for(o in window.digiquali[t].init&&window.digiquali[t].init(),window.digiquali[t])window.digiquali[t]&&window.digiquali[t][o]&&window.digiquali[t][o].init&&window.digiquali[t][o].init();window.digiquali.scriptsLoaded=!0}},window.digiquali.refresh=function(){var t=void 0,o=void 0;for(t in window.digiquali)for(o in window.digiquali[t].refresh&&window.digiquali[t].refresh(),window.digiquali[t])window.digiquali[t]&&window.digiquali[t][o]&&window.digiquali[t][o].refresh&&window.digiquali[t][o].refresh()},$(document).ready(window.digiquali.init)),window.digiquali.control={},window.digiquali.control.init=function(){window.digiquali.control.event()},window.digiquali.control.event=function(){$(document).on("click",".validateButton",window.digiquali.control.getAnswerCounter),$(document).on("change","#fk_sheet",window.digiquali.control.showSelectObjectLinked),$(document).on("click",".clipboard-copy",window.digiquali.control.copyToClipboard),$(document).on("change","#productId",window.digiquali.control.refreshLotSelector),$(document).on("change",'[name="mass_control"]',window.digiquali.control.showSubControlsModel),$(document).on("click",".switch-public-control-view",window.digiquali.control.switchPublicControlView),$(document).on("click",".show-only-questions-with-no-answer",window.digiquali.control.showOnlyQuestionsWithNoAnswer),$(document).on("click",".photo-sheet-category",window.digiquali.control.getSheetCategoryID),$(document).on("click",".photo-sheet-sub-category",window.digiquali.control.getSheetSubCategoryID),$(document).on("click",".photo-sheet",window.digiquali.control.getSheetID),$(document).on("click",".saveSubControl:not(.butActionRefused)",window.digiquali.control.saveSubControl),$(document).on("click",".validateSubControl:not(.butActionRefused)",window.digiquali.control.validateSubControl),$(document).on("click",".reopenSubControl:not(.butActionRefused)",window.digiquali.control.reopenSubControl),$(document).on("click",".lockSubControl:not(.butActionRefused)",window.digiquali.control.lockSubControl),$(document).on("click",".saveSubControlAnswers",window.digiquali.control.saveSubControlAnswers),$(document).ready(function(){$(".verdict-box").on("click",function(t){$(this).hasClass("disabled")&&(t.stopPropagation(),t.preventDefault())})})},window.digiquali.control.getAnswerCounter=function(t){let o=0;jQuery("#tablelines").children().each(function(){0<$(this).find(".answer.active").length&&(o+=1)}),document.cookie="answerCounter="+o},window.digiquali.control.showSelectObjectLinked=function(){var t=$(this).val(),o=window.saturne.toolbox.getToken(),e=window.saturne.toolbox.getQuerySeparator(document.URL),e=document.URL+e+"fk_sheet="+t+"&token="+o;window.saturne.loader.display($(".linked-objects")),$.ajax({url:e,type:"POST",processData:!1,contentType:!1,success:function(t){$(".linked-objects").replaceWith($(t).find(".linked-objects"))},error:function(){}})},window.digiquali.control.copyToClipboard=function(t){var o=$(".copy-to-clipboard").attr("value");navigator.clipboard.writeText(o).then(()=>{$(".clipboard-copy").animate({backgroundColor:"#59ed9c"},200,()=>{$(".clipboard-copy").attr("class","fas fa-check clipboard-copy"),$(this).tooltip({items:".clipboard-copy",content:$("#copyToClipboardTooltip").val()}),$(this).tooltip("open"),$(".clipboard-copy").attr("style","")})})},window.digiquali.control.refreshLotSelector=function(t){var o=document.getElementById("add_control_equipment"),o=new FormData(o),e=window.saturne.toolbox.getToken(),o=o.get("productId"),e=document.URL+"&token="+e;e+="&fk_product="+o,window.saturne.loader.display($(".product-lot")),$.ajax({url:e,type:"POST",processData:!1,contentType:!1,success:function(t){$(".product-lot").replaceWith($(t).find(".product-lot"))},error:function(){}})},window.digiquali.control.switchPublicControlView=function(t){var o=$(this).find(".public-control-view").val(),e=window.saturne.toolbox.getToken();let i=document.URL+"&token="+e;i+=0==o?"&show_control_list=1":"&show_last_control=1",window.saturne.loader.display($(".signature-container")),$.ajax({url:i,type:"POST",processData:!1,contentType:!1,success:function(t){$("#publicControlHistory").replaceWith($(t).find("#publicControlHistory"))},error:function(){}})},window.digiquali.control.showOnlyQuestionsWithNoAnswer=function(){var t=window.saturne.toolbox.getQuerySeparator(document.URL),o=window.saturne.toolbox.getToken();let e;e=$(this).hasClass("fa-toggle-off")?1:0,window.saturne.loader.display($(this)),$.ajax({url:document.URL+t+"action=show_only_questions_with_no_answer&token="+o,type:"POST",processData:!1,data:JSON.stringify({showOnlyQuestionsWithNoAnswer:e}),contentType:!1,success:function(t){$(".progress-info").replaceWith($(t).find(".progress-info")),$(".question-answer-container").replaceWith($(t).find(".question-answer-container"))},error:function(){}})},window.digiquali.control.getSheetCategoryID=function(){let o=$(this).attr("value");var t=window.saturne.toolbox.getToken(),e=window.saturne.toolbox.getQuerySeparator(document.URL);window.saturne.loader.display($(".sheet-images-container")),$.ajax({url:document.URL+e+"sheetCategoryID="+o+"&token="+t,type:"POST",processData:!1,contentType:!1,success:function(t){$(".sheet-images-container").replaceWith($(t).find(".sheet-images-container")),$(".photo-sheet-category[value="+o+"]").css("border","3px solid #0d8aff"),$(".photo-sheet-category[value="+o+"]").addClass("photo-sheet-category-active"),$(".linked-objects").replaceWith($(t).find(".linked-objects"))},error:function(){}})},window.digiquali.control.getSheetSubCategoryID=function(){let o=$(".photo-sheet-category-active").attr("value"),e=$(this).attr("value");var t=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL);window.saturne.loader.display($(".sheet-images-container")),$.ajax({url:document.URL+i+"sheetCategoryID="+o+"&sheetSubCategoryID="+e+"&token="+t,type:"POST",processData:!1,contentType:!1,success:function(t){$(".sheet-images-container").replaceWith($(t).find(".sheet-images-container")),$(".photo-sheet-category[value="+o+"]").css("border","3px solid #0d8aff"),$(".photo-sheet-category[value="+o+"]").addClass("photo-sheet-category-active"),$(".photo-sheet-sub-category[value="+e+"]").css("border","3px solid #0d8aff"),$(".photo-sheet-sub-category[value="+e+"]").addClass("photo-sheet-sub-category-active"),$(".linked-objects").replaceWith($(t).find(".linked-objects"))},error:function(){}})},window.digiquali.control.getSheetID=function(){let o=$(this).attr("data-object-id");var t=$(".photo-sheet-category-active").attr("value"),e=$(".photo-sheet-sub-category-active").attr("value"),i=window.saturne.toolbox.getToken(),n=window.saturne.toolbox.getQuerySeparator(document.URL);window.saturne.loader.display($(".sheet-elements")),window.saturne.loader.display($(".linked-objects")),$.ajax({url:document.URL+n+"fk_sheet="+o+"&sheetCategoryID="+t+"&sheetSubCategoryID="+e+"&token="+i,type:"POST",processData:!1,contentType:!1,success:function(t){$(".sheet-elements").replaceWith($(t).find(".sheet-elements")),$(".photo-sheet[data-object-id="+o+"]").css("border","3px solid #0d8aff"),$(".linked-objects").replaceWith($(t).find(".linked-objects"))},error:function(){}})},window.digiquali.control.saveSubControl=function(){let a=$(this).attr("data-control-id"),s=$(this).attr("data-main-control-id");var t=$(this).closest(".table-row").find(".note-public").val();let d=[];$(this).closest(".table-row").find(".select-answer").each(function(){var t=$(this).attr("data-questionid"),o=$(this).find(".question-answer").val(),e=$(this).closest(".wpeo-table").find(".question-comment").val();d[t]={answer:o,comment:e}});var o=$(this).closest(".table-row").find('.verdict-option input[type="radio"]:checked').val();let c=window.saturne.toolbox.getToken();window.saturne.loader.display($(this).closest(".table-row"));var e=document.URL.replace(/id=\d+/,"id="+a);$.ajax({url:e+"&token="+c+"&action=confirm_setVerdict&verdict="+o+"¬eControl="+t,type:"POST",processData:!1,contentType:!1,data:[],success:async function(t){for(var[o,e]of Object.entries(d)){var i=document.URL.replace(/id=\d+/,"id="+a);await window.digiquali.object.saveAnswer(o,e.answer,e.comment,i+"&action=save&token="+c)}var n=document.URL.replace(/id=\d+/,"id="+s);$.ajax({url:n,type:"GET",processData:!1,contentType:!1,data:[],success:function(t){$(".wpeo-loader").removeClass("wpeo-loader"),$(".sub-control-"+a).replaceWith($(t).find(".sub-control-"+a))}})},error:function(){}})},window.digiquali.control.lockSubControl=function(){let o=$(this).attr("data-control-id"),e=$(this).attr("data-main-control-id");var t=window.saturne.toolbox.getToken(),i=(window.saturne.loader.display($(this).closest(".table-row")),document.URL.replace(/id=\d+/,"id="+o));$.ajax({url:i+"&token="+t+"&action=confirm_lock",type:"POST",processData:!1,contentType:!1,data:[],success:function(){var t=document.URL.replace(/id=\d+/,"id="+e);$.ajax({url:t,type:"GET",processData:!1,contentType:!1,data:[],success:function(t){$(".sub-control-"+o).replaceWith($(t).find(".sub-control-"+o))}})},error:function(){}})},window.digiquali.control.validateSubControl=function(){let o=$(this).attr("data-control-id"),e=$(this).attr("data-main-control-id");var t=window.saturne.toolbox.getToken(),i=(window.saturne.loader.display($(this).closest(".table-row")),document.URL.replace(/id=\d+/,"id="+o));$.ajax({url:i+"&token="+t+"&action=confirm_validate&confirm=yes",type:"POST",processData:!1,contentType:!1,data:[],success:function(){var t=document.URL.replace(/id=\d+/,"id="+e);$.ajax({url:t,type:"GET",processData:!1,contentType:!1,data:[],success:function(t){$(".sub-control-"+o).replaceWith($(t).find(".sub-control-"+o))}})},error:function(){}})},window.digiquali.control.reopenSubControl=function(){let o=$(this).attr("data-control-id"),e=$(this).attr("data-main-control-id");var t=window.saturne.toolbox.getToken(),i=(window.saturne.loader.display($(this).closest(".table-row")),document.URL.replace(/id=\d+/,"id="+o));$.ajax({url:i+"&token="+t+"&action=confirm_set_reopen&confirm=yes",type:"POST",processData:!1,contentType:!1,data:[],success:function(){var t=document.URL.replace(/id=\d+/,"id="+e);$.ajax({url:t,type:"GET",processData:!1,contentType:!1,data:[],success:function(t){$(".sub-control-"+o).replaceWith($(t).find(".sub-control-"+o))}})},error:function(){}})},window.digiquali.control.saveSubControlAnswers=async function(){let o=$(this).attr("data-control-id");var t=$(this).attr("data-main-control-id");window.saturne.loader.display($(this));let i=[];$(this).closest(".table-row").find(".select-answer").each(function(){var t=$(this).attr("data-questionid"),o=$(this).find(".question-answer").val(),e=$(this).closest(".wpeo-table").find(".question-comment").val();i[t]={answer:o,comment:e}});var e,n,a=window.saturne.toolbox.getToken();let s=document.URL.replace(/id=\d+/,"id="+o);for([e,n]of Object.entries(i))await window.digiquali.object.saveAnswer(e,n.answer,n.comment,s+"&action=save&token="+a);s=document.URL.replace(/id=\d+/,"id="+t),$.ajax({url:s,type:"GET",processData:!1,contentType:!1,data:[],success:function(t){$(".sub-control-"+o).replaceWith($(t).find(".sub-control-"+o)),$(".wpeo-loader").removeClass("wpeo-loader")}})},window.digiquali.control.showSubControlsModel=function(){$(".sub-controls-model").attr("style",""),$(".sub-controls-model").find(".select2-container").css("width","500px")},window.digiquali.object={},window.digiquali.object.init=function(){window.digiquali.object.event()},window.digiquali.object.event=function(){$(document).on("change",".object-table.linked-objects select",window.digiquali.object.disableOtherSelectors),$(document).on("click",".answer:not(.disable)",window.digiquali.object.selectAnswer),$(document).on("input",".input-answer:not(.disable)",window.digiquali.object.selectAnswer),$(document).on("keyup",".question-comment",window.digiquali.object.showCommentUnsaved),$(document).on("click",".verdict-box",window.digiquali.object.updateButtonsStatus)},window.digiquali.object.disableOtherSelectors=function(){var t=document.getElementById("createObjectForm"),t=new FormData(t),o=$(this).attr("id");0<=t.get(o)?$(".object-table.linked-objects").find("select").not("#"+o).attr("disabled",1):$(".object-table.linked-objects").find("select").not("#"+o).removeAttr("disabled")},window.digiquali.object.selectAnswer=function(){var o=$(this).closest(".select-answer.answer-cell"),t=o.attr("data-questionId"),e=$(this).closest(".table-id-"+t).attr("data-publicInterface"),i=$(this).closest(".table-id-"+t).attr("data-autoSave");let n="";var a=$(this).hasClass("answer")?$(this).attr("value"):$(this).val(),s=$(this).closest(".table-id-"+t).find("#comment"+t).val(),d=$(this).closest(".table-id-"+t).attr("data-control-id");if($(this).closest(".table-cell").hasClass("select-answer")){if($(this).hasClass("multiple-answers")){$(this).closest("span").toggleClass("active");let t=[];o.find(".multiple-answers.active").each(function(){t.push($(this).attr("value"))}),n=t}else $(this).closest(".table-cell").find(".answer.active").css("background-color","#fff"),$(this).closest(".table-cell").find("span").removeClass("active"),$(this).closest("span").addClass("active"),n=a;$(this).hasClass("active")?(o=$(this).closest(".answer-cell").find(".answer-color-"+$(this).attr("value")).val(),$(this).attr("style",$(this).attr("style")+" background:"+o+";")):$(this).attr("style",$(this).attr("style")+" background:#fff;"),$(this).closest(".answer-cell").find(".question-answer").val(n)}e||1!=i||$(this).hasClass("multiple-answers")?window.digiquali.object.updateButtonsStatus(d):window.digiquali.object.saveAnswer(t,n,s)},window.digiquali.object.showCommentUnsaved=function(){$(this).hasClass("show-comment-unsaved-message")||($(this).after('Commentaire non enregistré
'),$(this).addClass("show-comment-unsaved-message")),window.digiquali.object.updateButtonsStatus()},window.digiquali.object.updateButtonsStatus=function(t){t=stringIsInteger(t)?t:$(this).attr("data-control-id"),$("#saveButton"+t).removeClass("butActionRefused"),$("#saveButton"+t).addClass("butAction"),$(".fa-circle").css("display","inline"),$("#saveButton"+t).attr("onclick",'$("#saveObject'+t+'").submit()'),$(".validateButton"+t).removeClass("butAction"),$("#dialog-confirm-actionButtonValidate"+t).removeAttr("id"),$(".validateButton"+t).addClass("butActionRefused")},window.digiquali.object.saveAnswer=function(t,o,e,i=""){var n=window.saturne.toolbox.getToken(),a=window.saturne.toolbox.getQuerySeparator(document.URL),a=i||document.URL+a+"action=save&token="+n;i.length<1&&window.saturne.loader.display($(".table-id-"+t)),$.ajax({url:a,type:"POST",data:JSON.stringify({autoSave:!0,questionId:t,answer:o,comment:e}),processData:!1,contentType:!1,success:function(t){i.length<1&&$(".fiche").replaceWith($(t).find(".fiche"))},error:function(){}})},window.digiquali.question={},window.digiquali.question.init=function(){window.digiquali.question.event()},window.digiquali.question.event=function(){$(document).on("click",".clicked-photo-preview",window.digiquali.question.previewPhoto),$(document).on("click",".ui-dialog-titlebar-close",window.digiquali.question.closePreviewPhoto),$(document).on("click","#show_photo",window.digiquali.question.showPhoto),$(document).on("click",".answer-picto .item, .wpeo-table .item",window.digiquali.question.selectAnswerPicto)},window.digiquali.question.previewPhoto=function(t){$(this).hasClass("photo-ok")?$("#dialogforpopup").attr("style","border: 10px solid #47e58e"):$(this).hasClass("photo-ko")&&$("#dialogforpopup").attr("style","border: 10px solid #e05353")},window.digiquali.question.closePreviewPhoto=function(t){$("#dialogforpopup").attr("style","border:")},window.digiquali.question.showPhoto=function(){var t=$(this).closest(".question-table").find(".linked-medias");t.hasClass("hidden")?(t.attr("style",""),t.removeClass("hidden")):(t.attr("style","display:none"),t.addClass("hidden"))},window.digiquali.question.selectAnswerPicto=function(t){var o=$(this).closest(".wpeo-dropdown");$(this).closest(".content").removeClass("active"),o.find(".dropdown-toggle span").hide(),o.find(".dropdown-toggle.button-picto").html($(this).closest(".wpeo-tooltip-event").html()),o.find(".input-hidden-picto").val($(this).data("label"))},window.digiquali.sheet={},window.digiquali.sheet.init=function(){window.digiquali.sheet.event()},window.digiquali.sheet.event=function(){}; \ No newline at end of file diff --git a/js/modules/control.js b/js/modules/control.js index 9d23e407..a46f61a8 100644 --- a/js/modules/control.js +++ b/js/modules/control.js @@ -32,11 +32,27 @@ window.digiquali.control.event = function() { $( document ).on( 'change', '#fk_sheet', window.digiquali.control.showSelectObjectLinked); $( document ).on( 'click', '.clipboard-copy', window.digiquali.control.copyToClipboard ); $( document ).on( 'change', '#productId', window.digiquali.control.refreshLotSelector ); + $( document ).on( 'change', '[name="mass_control"]', window.digiquali.control.showSubControlsModel ); $( document ).on( 'click', '.switch-public-control-view', window.digiquali.control.switchPublicControlView ); $(document).on('click', '.show-only-questions-with-no-answer', window.digiquali.control.showOnlyQuestionsWithNoAnswer); $(document).on('click', '.photo-sheet-category', window.digiquali.control.getSheetCategoryID); $(document).on('click', '.photo-sheet-sub-category', window.digiquali.control.getSheetSubCategoryID); $(document).on('click', '.photo-sheet', window.digiquali.control.getSheetID); + $(document).on('click', '.saveSubControl:not(.butActionRefused)', window.digiquali.control.saveSubControl); + $(document).on('click', '.validateSubControl:not(.butActionRefused)', window.digiquali.control.validateSubControl); + $(document).on('click', '.reopenSubControl:not(.butActionRefused)', window.digiquali.control.reopenSubControl); + $(document).on('click', '.lockSubControl:not(.butActionRefused)', window.digiquali.control.lockSubControl); + $(document).on('click', '.saveSubControlAnswers', window.digiquali.control.saveSubControlAnswers); + $(document).ready(function() { + $('.verdict-box').on('click', function(event) { + if ($(this).hasClass('disabled')) { + event.stopPropagation(); + event.preventDefault(); + } + }); + }); + + }; /** @@ -311,3 +327,245 @@ window.digiquali.control.getSheetID = function() { error: function() {} }); }; + +/** + * Save sub control + * + * @since 1.15.0 + * @version 1.15.0 + * + * @return {void} + */ +window.digiquali.control.saveSubControl = function() { + let subControlID = $(this).attr('data-control-id'); + let mainControlId = $(this).attr('data-main-control-id'); + let notePublic = $(this).closest('.table-row').find('.note-public').val(); + + let questionIds = []; + $(this).closest('.table-row').find('.select-answer').each(function() { + let questionId = $(this).attr('data-questionid'); + + let answer = $(this).find('.question-answer').val(); + let comment = $(this).closest('.wpeo-table').find('.question-comment').val(); + + questionIds[questionId] = { + 'answer': answer, + 'comment': comment + }; + }); + + let verdict = $(this).closest('.table-row').find('.verdict-option input[type="radio"]:checked').val(); + let token = window.saturne.toolbox.getToken(); + + window.saturne.loader.display($(this).closest('.table-row')); + let url = document.URL.replace(/id=\d+/, 'id=' + subControlID); + $.ajax({ + url: url + '&token=' + token + '&action=confirm_setVerdict&verdict=' + verdict + '¬eControl=' + notePublic, + type: 'POST', + processData: false, + contentType: false, + data: [], + success: async function(resp) { + for (const [questionId, answer] of Object.entries(questionIds)) { + let url = document.URL.replace(/id=\d+/, 'id=' + subControlID); + await window.digiquali.object.saveAnswer(questionId, answer.answer, answer.comment, url + '&action=save&token=' + token); + } + + let url = document.URL.replace(/id=\d+/, 'id=' + mainControlId); + $.ajax({ + url: url, + type: 'GET', + processData: false, + contentType: false, + data: [], + success: function (resp) { + $('.wpeo-loader').removeClass('wpeo-loader') + $('.sub-control-' + subControlID).replaceWith($(resp).find('.sub-control-' + subControlID)); + } + }); + }, + error: function() {} + }); +} + +/** + * Lock sub control + * + * @since 1.15.0 + * @version 1.15.0 + * + * @return {void} + */ +window.digiquali.control.lockSubControl = function() { + let subControlID = $(this).attr('data-control-id'); + let mainControlId = $(this).attr('data-main-control-id'); + let token = window.saturne.toolbox.getToken(); + + window.saturne.loader.display($(this).closest('.table-row')); + + let url = document.URL.replace(/id=\d+/, 'id=' + subControlID); + $.ajax({ + url: url + '&token=' + token + '&action=confirm_lock', + type: 'POST', + processData: false, + contentType: false, + data: [], + success: function () { + let url = document.URL.replace(/id=\d+/, 'id=' + mainControlId); + $.ajax({ + url: url, + type: 'GET', + processData: false, + contentType: false, + data: [], + success: function (resp) { + $('.sub-control-' + subControlID).replaceWith($(resp).find('.sub-control-' + subControlID)); + } + }); + }, + error: function () { + } + }); +} + +/** + * Validate sub control + * + * @since 1.15.0 + * @version 1.15.0 + * + * @return {void} + */ +window.digiquali.control.validateSubControl = function() { + let subControlID = $(this).attr('data-control-id'); + let mainControlId = $(this).attr('data-main-control-id'); + let token = window.saturne.toolbox.getToken(); + + window.saturne.loader.display($(this).closest('.table-row')); + + let url = document.URL.replace(/id=\d+/, 'id=' + subControlID); + $.ajax({ + url: url + '&token=' + token + '&action=confirm_validate&confirm=yes', + type: 'POST', + processData: false, + contentType: false, + data: [], + success: function () { + let url = document.URL.replace(/id=\d+/, 'id=' + mainControlId); + $.ajax({ + url: url, + type: 'GET', + processData: false, + contentType: false, + data: [], + success: function (resp) { + $('.sub-control-' + subControlID).replaceWith($(resp).find('.sub-control-' + subControlID)); + } + }); + }, + error: function () { + } + }); +} + +/** + * Reopen sub control + * + * @since 1.15.0 + * @version 1.15.0 + * + * @return {void} + */ +window.digiquali.control.reopenSubControl = function() { + let subControlID = $(this).attr('data-control-id'); + let mainControlId = $(this).attr('data-main-control-id'); + let token = window.saturne.toolbox.getToken(); + + window.saturne.loader.display($(this).closest('.table-row')); + + let url = document.URL.replace(/id=\d+/, 'id=' + subControlID); + $.ajax({ + url: url + '&token=' + token + '&action=confirm_set_reopen&confirm=yes', + type: 'POST', + processData: false, + contentType: false, + data: [], + success: function () { + let url = document.URL.replace(/id=\d+/, 'id=' + mainControlId); + $.ajax({ + url: url, + type: 'GET', + processData: false, + contentType: false, + data: [], + success: function (resp) { + $('.sub-control-' + subControlID).replaceWith($(resp).find('.sub-control-' + subControlID)); + } + }); + }, + error: function () { + } + }); +} + +/** + * Save sub control answers + * + * @since 1.15.0 + * @version 1.15.0 + * + * @return {void} + */ +window.digiquali.control.saveSubControlAnswers = async function() { + let subControlID = $(this).attr('data-control-id'); + let mainControlId = $(this).attr('data-main-control-id'); + + window.saturne.loader.display($(this)); + + let questionIds = []; + $(this).closest('.table-row').find('.select-answer').each(function () { + let questionId = $(this).attr('data-questionid'); + + let answer = $(this).find('.question-answer').val(); + let comment = $(this).closest('.wpeo-table').find('.question-comment').val(); + + questionIds[questionId] = { + 'answer': answer, + 'comment': comment + }; + }); + + let token = window.saturne.toolbox.getToken(); + + let url = document.URL.replace(/id=\d+/, 'id=' + subControlID); + + for (const [questionId, answer] of Object.entries(questionIds)) { + await window.digiquali.object.saveAnswer(questionId, answer.answer, answer.comment, url + '&action=save&token=' + token); + } + + url = document.URL.replace(/id=\d+/, 'id=' + mainControlId); + $.ajax({ + url: url, + type: 'GET', + processData: false, + contentType: false, + data: [], + success: function (resp) { + $('.sub-control-' + subControlID).replaceWith($(resp).find('.sub-control-' + subControlID)); + $('.wpeo-loader').removeClass('wpeo-loader'); + } + }); +} + +/** + * Show sub controls model + * + * @since 1.15.0 + * @version 1.15.0 + * + * @return {void} + */ +window.digiquali.control.showSubControlsModel = function() { + $('.sub-controls-model').attr('style', ''); + $('.sub-controls-model').find('.select2-container').css('width', '500px') +} diff --git a/js/modules/object.js b/js/modules/object.js index 433acd99..7069aebf 100644 --- a/js/modules/object.js +++ b/js/modules/object.js @@ -63,6 +63,7 @@ window.digiquali.object.event = function() { $(document).on( 'click', '.answer:not(.disable)', window.digiquali.object.selectAnswer); $(document).on( 'input', '.input-answer:not(.disable)', window.digiquali.object.selectAnswer); $(document).on( 'keyup', '.question-comment', window.digiquali.object.showCommentUnsaved); + $(document).on( 'click', '.verdict-box', window.digiquali.object.updateButtonsStatus); }; /** @@ -103,6 +104,7 @@ window.digiquali.object.selectAnswer = function() { let answer = ''; let answerValue = $(this).hasClass('answer') ? $(this).attr('value') : $(this).val(); let comment = $(this).closest('.table-id-' + questionId).find('#comment' + questionId).val(); + let controlId = $(this).closest('.table-id-' + questionId).attr('data-control-id'); if ($(this).closest('.table-cell').hasClass('select-answer')) { if ($(this).hasClass('multiple-answers')) { $(this).closest('span').toggleClass('active'); @@ -130,7 +132,7 @@ window.digiquali.object.selectAnswer = function() { if (!publicInterface && autoSave == 1 && !$(this).hasClass('multiple-answers')) { window.digiquali.object.saveAnswer(questionId, answer, comment); } else { - window.digiquali.object.updateButtonsStatus(); + window.digiquali.object.updateButtonsStatus(controlId); } }; @@ -158,16 +160,16 @@ window.digiquali.object.showCommentUnsaved = function() { * * @return {void} */ -window.digiquali.object.updateButtonsStatus = function() { - $('#saveButton').removeClass('butActionRefused'); - $('#saveButton').addClass('butAction'); - $('#saveButton').css('background', '#0d8aff'); +window.digiquali.object.updateButtonsStatus = function(controlId) { + controlId = stringIsInteger(controlId) ? controlId : $(this).attr('data-control-id'); + $('#saveButton' + controlId).removeClass('butActionRefused'); + $('#saveButton' + controlId).addClass('butAction'); $('.fa-circle').css('display', 'inline'); - $('#saveButton').attr('onclick','$("#saveObject").submit()'); + $('#saveButton' + controlId).attr('onclick','$("#saveObject'+controlId+'").submit()'); - $('.validateButton').removeClass('butAction'); - $('#dialog-confirm-actionButtonValidate').removeAttr('id'); - $('.validateButton').addClass('butActionRefused'); + $('.validateButton' + controlId).removeClass('butAction'); + $('#dialog-confirm-actionButtonValidate' + controlId).removeAttr('id'); + $('.validateButton' + controlId).addClass('butActionRefused'); }; /** @@ -179,15 +181,20 @@ window.digiquali.object.updateButtonsStatus = function() { * @param {int} questionId Question ID * @param {string} answer Answer value * @param {string} comment Comment value + * @param {string} customUrl URL to save answer * @return {void} */ -window.digiquali.object.saveAnswer = function(questionId, answer, comment) { +window.digiquali.object.saveAnswer = function(questionId, answer, comment, customUrl = '') { let token = window.saturne.toolbox.getToken(); let querySeparator = window.saturne.toolbox.getQuerySeparator(document.URL); - window.saturne.loader.display($('.table-id-' + questionId)); + let url = customUrl ? customUrl : document.URL + querySeparator + 'action=save&token=' + token + + if (customUrl.length < 1) { + window.saturne.loader.display($('.table-id-' + questionId)); + } $.ajax({ - url: document.URL + querySeparator + 'action=save&token=' + token, + url: url, type: 'POST', data: JSON.stringify({ autoSave: true, @@ -198,7 +205,9 @@ window.digiquali.object.saveAnswer = function(questionId, answer, comment) { processData: false, contentType: false, success: function(resp) { - $('.fiche').replaceWith($(resp).find('.fiche')); + if (customUrl.length < 1) { + $('.fiche').replaceWith($(resp).find('.fiche')); + } }, error: function() {} }); diff --git a/langs/fr_FR/digiquali.lang b/langs/fr_FR/digiquali.lang index 1d6bc92e..faaf5a93 100644 --- a/langs/fr_FR/digiquali.lang +++ b/langs/fr_FR/digiquali.lang @@ -349,6 +349,17 @@ QuestionAnswered = Réponse/Question LastStatusDate = Dernières dates de statut ValidationDate = Date de validation ReOpenDate = Date de réouverture +MassControl = Contrôle en masse +LinkedControlList = Liste des contrôles liés +NewMassControl = Nouveau contrôle en masse +ControlledObject = Objet contrôlé +SubControlSheet = Modèle des sous-contrôles +AddAnObjectToControl = Ajouter un objet à contrôler +SubControlsMustBeLockedToSetVerdict = Les sous-contrôles doivent être verrouillés pour définir le verdict +MainControlMustBeDraftToEditSubControls = Le contrôle principal doit être brouillon pour éditer les sous-contrôles +ParentControl = Contrôle parent +NoSubControlFound = Aucun sous-contrôle trouvé + # # ControlDet @@ -362,6 +373,7 @@ AnswerPhoto = Photo AutoSaveActionQuestionAnswer = Sauvegarde automatique des réponses aux questions AutoSaveActionQuestionAnswerDescription = Sauvegarde automatiquement les réponses aux questions lors du choix de la réponse NoObjectLineAnswersPhoto = Pas de photos sur les réponses du %s +Answers = Réponses # # ControlDocument - Fiche de Contrôle @@ -378,6 +390,8 @@ controldocument = fiche de controle controldocument.odt = Fiche de Contrôle controldocument_photo.odt = Fiche de Contrôle avec photos controldocument_photo = fiche de controle avec photos +masscontroldocument = Fiche de Contrôle en masse +masscontroldocument.odt = Fiche de Contrôle en masse @@ -441,3 +455,4 @@ Remain = reste InProgressAndLocked = -- (En cours + verrouillé) -- NoObservations = Pas d'observations BasedOnModel = Basé sur le modèle +ShowDocument = Afficher le document diff --git a/lib/digiquali_control.lib.php b/lib/digiquali_control.lib.php index d1815940..2468cd15 100644 --- a/lib/digiquali_control.lib.php +++ b/lib/digiquali_control.lib.php @@ -58,5 +58,5 @@ function control_prepare_head(Control $object): array $moreparam['documentType'] = 'ControlDocument'; $moreparam['attendantTableMode'] = 'simple'; - return saturne_object_prepare_head($object, $head, $moreparam, true); + return saturne_object_prepare_head($object, $head, $moreparam, !($object->fk_control > 0)); } diff --git a/sql/control/llx_digiquali_control.key.sql b/sql/control/llx_digiquali_control.key.sql index 43a4909b..de696059 100644 --- a/sql/control/llx_digiquali_control.key.sql +++ b/sql/control/llx_digiquali_control.key.sql @@ -21,3 +21,4 @@ ALTER TABLE llx_digiquali_control ADD INDEX idx_digiquali_control_fk_user_contro ALTER TABLE llx_digiquali_control ADD INDEX idx_digiquali_control_fk_projectid (projectid); ALTER TABLE llx_digiquali_control ADD UNIQUE INDEX uk_digiquali_control_ref (ref, entity); ALTER TABLE llx_digiquali_control ADD CONSTRAINT llx_digiquali_control_fk_user_creat FOREIGN KEY (fk_user_creat) REFERENCES llx_user(rowid); +ALTER TABLE llx_digiquali_control ADD CONSTRAINT llx_digiquali_control_fk_control FOREIGN KEY (fk_control) REFERENCES llx_digiquali_control(rowid); diff --git a/sql/control/llx_digiquali_control.sql b/sql/control/llx_digiquali_control.sql index 8c2d0d52..5abff4f0 100644 --- a/sql/control/llx_digiquali_control.sql +++ b/sql/control/llx_digiquali_control.sql @@ -32,6 +32,8 @@ CREATE TABLE llx_digiquali_control( control_date datetime, next_control_date datetime, success_rate double(24,8), + mass_control boolean, + fk_control integer, fk_user_creat integer NOT NULL, fk_user_modif integer, fk_sheet integer NOT NULL, diff --git a/sql/update.sql b/sql/update.sql index f9b2a97b..b9e16e34 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -127,3 +127,8 @@ ALTER TABLE `llx_digiquali_survey` ADD `success_rate` DOUBLE(24,8) NULL AFTER `p -- 1.13.0 ALTER TABLE `llx_digiquali_control` ADD `label` VARCHAR(255) NULL AFTER `status`; + +-- 1.15.0 +ALTER TABLE `llx_digiquali_control` ADD `mass_control` BOOLEAN NULL AFTER `success_rate`; +ALTER TABLE `llx_digiquali_control` ADD `fk_control` INTEGER NULL AFTER `mass_control`; +ALTER TABLE llx_digiquali_control ADD CONSTRAINT llx_digiquali_control_fk_control FOREIGN KEY (fk_control) REFERENCES llx_digiquali_control(rowid); diff --git a/view/control/control_card.php b/view/control/control_card.php index 19ba3012..55ff4d65 100644 --- a/view/control/control_card.php +++ b/view/control/control_card.php @@ -90,6 +90,7 @@ $ecmfile = new EcmFiles($db); $ecmdir = new EcmDirectory($db); $category = new Categorie($db); +$parentControl = new Control($db); // View objects $form = new Form($db); @@ -151,6 +152,13 @@ $options['photos'] = GETPOST('clone_photos'); if ($object->id > 0) { $result = $object->createFromClone($user, $object->id, $options); + $subControlList = $object->fetchAll('', '', 0, 0, ['fk_control' => $object->id]); + if (is_array($subControlList) && !empty($subControlList)) { + foreach ($subControlList as $subControl) { + $options['fk_control'] = $result; + $subControl->createFromClone($user, $subControl->id, $options); + } + } if ($result > 0) { header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result); exit(); @@ -167,8 +175,11 @@ if (!empty($linkableElements)) { foreach ($linkableElements as $linkableElementType => $linkableElement) { - if (!empty(GETPOST($linkableElement['post_name'])) && GETPOST($linkableElement['post_name']) > 0) { - $controlledObjectSelected++; + $post = GETPOST('multi_' . $linkableElement['post_name'], 'array'); + if (is_array($post) && !empty($post)) { + foreach($post as $postSingle) { + $controlledObjectSelected++; + } } } } @@ -221,7 +232,7 @@ if ($action == 'confirm_setVerdict' && $permissiontosetverdict && !GETPOST('cancel', 'alpha')) { $object->fetch($id); if (!$error) { - $object->verdict = GETPOST('verdict', 'int'); + $object->verdict = GETPOST('verdict', 'int') ?: null; $object->note_public .= (!empty($object->note_public) ? chr(0x0A) : '') . GETPOST('noteControl'); $result = $object->update($user); if ($result > 0) { @@ -260,6 +271,35 @@ } } + //Action to add sub controls + if ($action == 'mass_control_add_object') { + $object->fetch($id); + $linkableElements = get_sheet_linkable_objects(); + $controlledObjectSelected = 0; + + if (!empty($linkableElements)) { + foreach ($linkableElements as $linkableElementType => $linkableElement) { + $post = GETPOST($linkableElement['post_name']); + if (!empty($post)) { + $objectType = $linkableElement['link_name']; + $objectId = $post; + + $controlToCreate = new Control($db); + + $controlToCreate->fk_sheet = GETPOST('fk_sub_controls_sheet'); + $controlToCreate->label = $object->label; + $controlToCreate->status = $object::STATUS_DRAFT; + $controlToCreate->fk_user_controller = $object->fk_user_controller; + $controlToCreate->fk_control = $object->id; + + $controlId = $controlToCreate->create($user, true); + + $controlToCreate->add_object_linked($linkableElement['link_name'], $objectId); + } + } + } + } + // Actions confirm_lock, confirm_archive require_once __DIR__ . '/../../../saturne/core/tpl/actions/object_workflow_actions.tpl.php'; @@ -398,6 +438,20 @@ print ''; } + // Mass control + print '