From 26759436aae5fb2dd0edab609da4be4ee3dcc043 Mon Sep 17 00:00:00 2001
From: Myriam Delaruelle
 <Myriam Delaruelle@bdn-un-mdelarue.ad.univ-lorraine.fr>
Date: Thu, 7 Oct 2021 10:29:02 +0200
Subject: [PATCH] display/hide course infos but with jquery

---
 amd/build/header.js              | 66 +++++++++++++++++++++++++++++++
 amd/src/suivi.js                 | 68 --------------------------------
 js/param_section.js              |  5 ---
 lang/en/format_iena.php          |  2 +
 lang/fr/format_iena.php          |  2 +
 styles.css                       | 24 ++++++++---
 templates/course-header.mustache | 15 +++++--
 7 files changed, 100 insertions(+), 82 deletions(-)
 create mode 100644 amd/build/header.js
 delete mode 100644 amd/src/suivi.js
 delete mode 100644 js/param_section.js

diff --git a/amd/build/header.js b/amd/build/header.js
new file mode 100644
index 0000000..ef5d253
--- /dev/null
+++ b/amd/build/header.js
@@ -0,0 +1,66 @@
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle 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.
+//
+// Moodle 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 Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Handle add/remove competency links.
+ *
+ * @module     format_iena/suivi
+ * @package    format_iena
+ * @copyright  2021 Myriam Delaruelle
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+define(['jquery', 'core/ajax', 'core/str'],
+       function($, ajax, str) {
+
+       	return{
+       		
+       		registerHeader:function(){
+	    		$("#button-collapse").click(function(){
+	    			if($("#summary-wrapper").hasClass('collapsed')){
+	    				$("#summary-wrapper").animate({ "max-height": '7rem' }, "slow" );
+	    				var message=str.get_string('displayInfos', 'format_iena');
+		    			$.when(message).done(function(localizedEditString) {
+						    $("#button-collapse").text(localizedEditString);
+						});	
+
+	    			}
+	    			else{
+	    				var height= $("#summary-collapse").css("height");
+		    			$("#summary-wrapper").animate({ "max-height": height }, "slow" );
+		    			var message=str.get_string('hideInfos', 'format_iena');
+		    			$.when(message).done(function(localizedEditString) {
+						    $("#button-collapse").text(localizedEditString);
+						});	
+		    			
+		    			
+	    			}
+	    			$("#summary-wrapper").toggleClass("collapsed");
+	    			
+	    			
+	    		})
+	    		
+       		}
+       		
+
+       		
+       		
+       	}
+
+   
+
+
+   
+  
+});
diff --git a/amd/src/suivi.js b/amd/src/suivi.js
deleted file mode 100644
index fd68765..0000000
--- a/amd/src/suivi.js
+++ /dev/null
@@ -1,68 +0,0 @@
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle 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.
-//
-// Moodle 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 Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Handle add/remove competency links.
- *
- * @module     tool_lp/competencies
- * @package    tool_lp
- * @copyright  2015 Damyon Wiese <damyon@moodle.com>
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-define(['jquery'],
-       function($, notification, ajax, templates, str, Picker, dragdrop, Pending) {
-
-    
-
-    /**
-     * Pick a competency
-     *
-     * @method pickCompetency
-     * @return {Promise}
-     */
-  
-    function registerSelectAll(){
-    	$('#iena-select-all').on('click', function(e){
-    		console.log("on sélectionne tout");
-    		select_all_studs(e);
-
-    	})
-    }
-
-    function select_all_studs(e) {
-		//e.preventDefault();
-		console.log("this one src");
-		var counter = 0;
-		var checks = document.querySelectorAll("#table-body tr");
-		for (var i = 0; i < checks.length; i++) {
-			if ( checks[i].style.display != "none" || data.all_selected ) {
-				var box = checks[i].querySelector("input[type='checkbox']");
-				box.checked = !data.all_selected;
-				counter++;
-			}
-		}
-		if ( counter > 0 ) {
-			
-			
-			data.all_selected = !data.all_selected;
-		}
-	}
-
-
-	console.log("on passe par ici");
-	//registerSelectAll();
-
-  
-});
diff --git a/js/param_section.js b/js/param_section.js
deleted file mode 100644
index dcb8978..0000000
--- a/js/param_section.js
+++ /dev/null
@@ -1,5 +0,0 @@
-(function() {
-
-// inclus nul part. 
-
-})()
\ No newline at end of file
diff --git a/lang/en/format_iena.php b/lang/en/format_iena.php
index c100569..1a7ce58 100644
--- a/lang/en/format_iena.php
+++ b/lang/en/format_iena.php
@@ -93,5 +93,7 @@ By definition an unnamed section is displayed as <strong>section [N]</strong>.';
 	$string['display_course_infos']="Show/hide course information";
 	$string['my_progress']="My progress in the course: ";
 	$string['table_progress']="Tracking";
+	$string['displayInfos']="Display course informations";
+	$string['hideInfos']="Hide course informations";
 
 
diff --git a/lang/fr/format_iena.php b/lang/fr/format_iena.php
index 68c8d34..a4cf640 100644
--- a/lang/fr/format_iena.php
+++ b/lang/fr/format_iena.php
@@ -93,5 +93,7 @@ By definition an unnamed section is displayed as <strong>section [N]</strong>.';
 	$string['display_course_infos']="Afficher/Masquer les informations du cours";
 	$string['my_progress']="Ma progression dans le cours : ";
 	$string['table_progress']="Suivi des étudiants";
+	$string['displayInfos']="Afficher les infos du cours";
+	$string['hideInfos']="Masquer les infos du cours";
 
 
diff --git a/styles.css b/styles.css
index ee99dfa..89b9d7c 100644
--- a/styles.css
+++ b/styles.css
@@ -576,19 +576,31 @@ ul.nav.navbar-nav.ml-auto {
 }
 
 
- #title-summary-iena{
- 	padding-left: 0;
+ #summary-wrapper{
+ 	padding-left: 1px;
+ 	display: block;
+	max-height: 7rem;
+	height: auto;
+	overflow: hidden;
+	margin-bottom: 5px;
  }
 
-#title-summary-iena #summary-collapse.collapse:not(.show) {
+/*#title-summary-iena #summary-collapse.collapse:not(.show) {
   display: block;
-  height: 7rem;
+  max-height: 7rem;
+  height: auto;
   overflow: hidden;
+
 }
 
 #title-summary-iena #summary-collapse.collapsing {
-  height: 4rem;
-}
+	height: auto;
+  max-height: 100rem;
+      -webkit-transition: max-height .35s ease;
+    -o-transition: max-height .35s ease;
+    transition: max-height .35s ease;
+    transition: max-height 1s ease;
+}*/;
 
 
 
diff --git a/templates/course-header.mustache b/templates/course-header.mustache
index f7605b0..00e6e70 100644
--- a/templates/course-header.mustache
+++ b/templates/course-header.mustache
@@ -68,8 +68,17 @@
 			<h3>
 				{{# str }} aboutcourse, format_iena {{/ str}}
 			</h3>
-			<div class="collapse" id="summary-collapse" aria-expanded="false">{{{ summary }}}</div>
-			<a role="button" class="collapsed" data-toggle="collapse" href="#summary-collapse" aria-expanded="false" aria-controls="summary-collapse">Afficher / Masquer les infos du cours</a>
+			<div id="summary-wrapper">
+				<div id="summary-collapse" aria-expanded="false">{{{ summary }}}</div>
+			</div>
+			<a role="button" href="#" onclick="return false" id="button-collapse" aria-expanded="false" aria-controls="summary-collapse">{{# str }} displayInfos, format_iena {{/ str}}</a>
 		</div>
 	</div>
-</div>
\ No newline at end of file
+</div>
+
+{{#js}}
+require(['format_iena/header'], function(module) {
+    module.registerHeader();
+
+});
+{{/js}}
\ No newline at end of file
-- 
GitLab