]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7677 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 31 Jul 2025 16:34:29 +0000 (18:34 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 31 Jul 2025 16:34:29 +0000 (18:34 +0200)
app/Models/ELearningMedia.php
resources/elearningmedia/js/app.js
resources/views/elearningmedia/index.blade.php

index 636065d61c65d49df407f1dd14dc1caafd04c19d..7b7bed504344f0738437d926ae779640e0f4aa2e 100644 (file)
@@ -87,6 +87,7 @@ class ELearningMedia extends ToolboxModel
         $this->addField('file', Files::class, __('Media'), ['acceptedFiles' => static::MEDIA_TYPES]);
         $this->addField('', FormSeparator::class);
         $this->addField('complete_button', Checkbox::class, __('Marquer terminer après un clic sur un bouton'), ['default' => true, 'when' => ['type' => 'pdf']]);
+        $this->addField('complete_button_close', Checkbox::class, __('Le bouton ferme également le cours'), ['default' => false, 'when' => ['type' => 'pdf', 'complete_button' => 1]]);
         $this->addField('complete_pct', Percent::class, __('Marquer terminé quand ce pourcentage est lu'), ['default' => 75, 'when' => ['complete_button' => 0, 'type' => ['logical_operator' => 'OR', 'values' => ['video', 'audio']]]]);
     }
 
@@ -116,7 +117,8 @@ class ELearningMedia extends ToolboxModel
 
         /** @var Media $file */
         $file = $this->getMediaInField('file')->first()->getPath();
-        self::compileFromFile($file, $dest, $this->title, $organization, 'MEDIA_' . $this->id, $this->locale, $this->scorm_version, $this->type === 'pdf' && $this->complete_button ? "'button'" : $this->complete_pct);
+        $settings = ['complete_button_close' => $this->complete_button_close];
+        self::compileFromFile($file, $dest, $this->title, $organization, 'MEDIA_' . $this->id, $this->locale, $this->scorm_version, $this->type === 'pdf' && $this->complete_button ? "'button'" : $this->complete_pct, $settings);
     }
 
     /**
@@ -126,10 +128,11 @@ class ELearningMedia extends ToolboxModel
      * @param $organization string
      * @param $reference string
      * @param $complete_pct int|string
+     * @param $settings array
      * @return string
      * @throws \Exception
      */
-    public static function compileFromFile($file, $dest, $title, $organization, $reference, $locale = 'en', $scorm_version = Version::SCORM_2004, $complete_pct = 75)
+    public static function compileFromFile($file, $dest, $title, $organization, $reference, $locale = 'en', $scorm_version = Version::SCORM_2004, $complete_pct = 75, $settings = [])
     {
         $spl = new \SplFileInfo($file);
         $ext = mb_strtolower($spl->getExtension());
@@ -159,7 +162,7 @@ class ELearningMedia extends ToolboxModel
         }
         $vdir->copy($file, 'media.' . $ext);
         $translations = ElearningTranslate::getLocaleTranslations($locale, true);
-        $vdir->file_put_contents('index.html', view('elearningmedia.index', ['complete_pct' => $complete_pct, 'title' => $title, 'type' => $type, 'translations' => $translations]));
+        $vdir->file_put_contents('index.html', view('elearningmedia.index', ['settings' => $settings, 'complete_pct' => $complete_pct, 'title' => $title, 'type' => $type, 'translations' => $translations]));
         $vdir->sync(true);
         return $title;
     }
index 5a63fe8546b294879e4f04109ba8309a4554f8f8..d197bf49d2a04899c9a1ec1b1534bd1890eaed2d 100644 (file)
@@ -97,11 +97,20 @@ function showCompleteButton() {
     btn.classList.add('visible');
     btn.addEventListener('click', function (e) {
         markComplete();
+        if(settings.complete_button_close){
+            closeCourse();
+        }
         e.preventDefault();
         return false;
     });
 }
 
+function closeCourse(){
+    parent.close();
+    top.close();
+    window.close();
+}
+
 function markComplete() {
     cubeSCORM.scormMarkAsComplete();
 }
index 6832bc0902d35c7a18740578a33075bd28b49814..e4efd8c0ca2ff58914adb7b033b22aee2c995d86 100644 (file)
@@ -17,6 +17,7 @@
     <script>
         var type = '{{$type}}';
         var progressComplete = {!! $complete_pct !!};
+        var settings = @json($settings);
     </script>
 </head>
 <body>