From 4ccf1253c3a229d7707379bacd051b96875058f4 Mon Sep 17 00:00:00 2001
From: Myriam Delaruelle
 <Myriam Delaruelle@bdn-un-mdelarue.ad.univ-lorraine.fr>
Date: Mon, 30 Aug 2021 09:57:14 +0200
Subject: [PATCH] added fixed colum + icons

---
 competency_iena_competencies_mgmt.php  |   5 +
 js/matrix.js                           |  65 ++++++------
 lang/en/block_competency_iena.php      |   1 +
 lang/fr/block_competency_iena.php      |   1 +
 styles.css                             |  56 ++++++++++-
 templates/matrix_competencies.mustache | 133 +++++++++++++------------
 6 files changed, 163 insertions(+), 98 deletions(-)

diff --git a/competency_iena_competencies_mgmt.php b/competency_iena_competencies_mgmt.php
index 502a1e9..a5b4b98 100644
--- a/competency_iena_competencies_mgmt.php
+++ b/competency_iena_competencies_mgmt.php
@@ -143,7 +143,9 @@
 	$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js'),true);
 	$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js'),true);
 	$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/fixedcolumns/3.2.4/js/dataTables.fixedColumns.min.js'),true);
+	$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js'),true);
 	$PAGE->requires->css(new \moodle_url('https://cdn.datatables.net/1.10.16/css/jquery.dataTables.css'));
+	$PAGE->requires->css(new \moodle_url('https://cdn.datatables.net/fixedcolumns/3.3.3/css/fixedColumns.dataTables.min.css'));
 	$PAGE->requires->js("/blocks/competency_iena/js/file.js");
 	$PAGE->requires->js("/blocks/competency_iena/js/matrix.js");
 	$PAGE->requires->js("/blocks/competency_iena/js/dropdown.js");
@@ -206,6 +208,9 @@
 					$module_competencies = $competency_instance->get_competencies_by_moduleID($key);
 					$module_matrix->mcompetencies=array();
 					foreach ($competencies as $competency) {
+						if(empty($competency->description)){
+							$competency->description=get_string('no_competency_description', 'block_competency_iena');
+						}
 						$key=array_search($competency->id, array_column($module_competencies, 'id'));
 						if($key !== false){
 							array_push($module_matrix->mcompetencies, $module_competencies[$key]);
diff --git a/js/matrix.js b/js/matrix.js
index cd10b99..1e8cb4c 100644
--- a/js/matrix.js
+++ b/js/matrix.js
@@ -12,7 +12,7 @@ jQuery(document).ready(function($){
 		leftColumns: 1
 		},
 		'bFilter': false, 
-		'bInfo': false
+		'bInfo': false,
 	});
 
 	$('.fram-iena').hide();
@@ -186,44 +186,47 @@ function addActivities(url, idcourse){
 }
 
 function supprimer_lien(obj) {
-	var t = obj.parentNode;
-	var p = t.parentNode;   
-	var c = p.children;
+	var res = window.confirm('Etes-vous sûr de vouloir supprimer le lien entre cette activité et cette compétence ?');
+	if (res) {
+		var t = obj.parentNode;
+		var p = t.parentNode;   
+		var c = p.children;
 
-	c[0].setAttribute("style", "display:none");
-	c[1].setAttribute("style", "display:none");
-	c[2].setAttribute("style", "display:inline");
+		c[0].setAttribute("style", "display:none");
+		c[1].setAttribute("style", "display:none");
+		c[2].setAttribute("style", "display:inline");
 
-	var div_id = c[0].id;
+		var div_id = c[0].id;
 
-	var module_id = div_id.split('-')[0];
-	module_id = module_id.replace ( /[^\d.]/g, '' );
+		var module_id = div_id.split('-')[0];
+		module_id = module_id.replace ( /[^\d.]/g, '' );
 
-	var competency_id = div_id.split('-')[1];
-	competency_id = competency_id.replace ( /[^\d.]/g, '' );
+		var competency_id = div_id.split('-')[1];
+		competency_id = competency_id.replace ( /[^\d.]/g, '' );
 
-	var url = window.location.href;
+		var url = window.location.href;
 
-	var info = [];
-	info[0] = module_id ;
-	info[1] = competency_id ;
-	info[2] = "delete" ;
+		var info = [];
+		info[0] = module_id ;
+		info[1] = competency_id ;
+		info[2] = "delete" ;
 
-	$.ajax({
-		type: "POST",
-		data: {info:info},
-		url: url,
-		timeout: 10000,
-		contentType: 'application/x-www-form-urlencoded',
-		success: function (data, status) {
-			if (status == "success") {
-			//changeColor(p); 
+		$.ajax({
+			type: "POST",
+			data: {info:info},
+			url: url,
+			timeout: 10000,
+			contentType: 'application/x-www-form-urlencoded',
+			success: function (data, status) {
+				if (status == "success") {
+				//changeColor(p); 
+				}
+			},
+			error: function (xhr, status, error) {
+				alert(status);
 			}
-		},
-		error: function (xhr, status, error) {
-			alert(status);
-		}
-	});
+		});
+	}
 
 }
 
diff --git a/lang/en/block_competency_iena.php b/lang/en/block_competency_iena.php
index 832cac4..8add205 100644
--- a/lang/en/block_competency_iena.php
+++ b/lang/en/block_competency_iena.php
@@ -85,4 +85,5 @@
     $string['select_act'] = 'Activities selector';
     $string['manage_matrix'] = 'Edit matrix';
     $string['manage_matrix_end'] = 'Exit edit mode';
+    $string['no_competency_description'] = 'This competency doesn\'t have a description' ;
 ?>
\ No newline at end of file
diff --git a/lang/fr/block_competency_iena.php b/lang/fr/block_competency_iena.php
index d59f4dc..d492fe0 100644
--- a/lang/fr/block_competency_iena.php
+++ b/lang/fr/block_competency_iena.php
@@ -84,6 +84,7 @@
     $string['select_act'] = 'Sélecteur d\'activités';
     $string['manage_matrix'] = 'Modifier la matrice';
     $string['manage_matrix_end'] = 'Quitter le mode édition';
+    $string['no_competency_description'] = 'Cette compétence n\'a pas de description.';
 
 
 
diff --git a/styles.css b/styles.css
index 2987feb..4d498a9 100644
--- a/styles.css
+++ b/styles.css
@@ -187,11 +187,63 @@
 }
 
 
-div.dataTables_wrapper {
+/*div.dataTables_wrapper {
     width: 100%;
     margin: 0 auto;
 }
 
+div.dataTables_scrollHead{
+    width: 99.9%!important;
+}
+
+#tab_mgmt{
+    width: 99.9%!important;
+}
 table.dataTable{
     border-collapse: collapse !important;
-}
\ No newline at end of file
+}
+
+.DTFC_LeftBodyLiner{
+    overflow-x: hidden;
+}
+*/
+
+/*#tab_mgmt{
+    margin-left: 1.7px;
+}
+
+.DTFC_LeftBodyLiner{
+    overflow-x: hidden;
+}*/
+
+.td-section{
+    border: none!important;
+}
+
+#tab_mgmt, .dataTable {
+    border-collapse: collapse!important;
+}
+
+.dataTable{
+    box-sizing: border-box!important;
+}
+
+
+.iena-matrix-button{
+    margin-top: 10px;
+}
+#tab_mgmt{
+    margin-left: 0px;
+}
+
+.dataTable thead th{
+    position: relative;
+}
+
+.dataTable thead th i{
+    top: 8px;
+    right: 0;
+    position: absolute;
+    cursor: pointer;
+}
+
diff --git a/templates/matrix_competencies.mustache b/templates/matrix_competencies.mustache
index 9509efa..81af798 100644
--- a/templates/matrix_competencies.mustache
+++ b/templates/matrix_competencies.mustache
@@ -1,73 +1,76 @@
 <h3>{{# str }} manage_comp, block_competency_iena{{/ str }}</h3>
 <p>{{# str }} add_comment, block_competency_iena{{/ str }}</p>
 
-<table id="tab_mgmt" class="table-bordered display dataTable"  >
-<thead>
-	<tr>
-		<th>Activités</th>
-		{{#competencies}}
-			<th style="max-width: 170px; overflow: hidden;">
-				{{#edit}}<i class="fa fa-remove icon-red-iena" style="font-size:24px;color:#dc493a" onclick='supprimer_lien_cpt({{id}})'></i>{{/edit}}
-				<a href='{{link}}' style='color: black;'>
-					<p style="word-wrap: break-word;">{{#shortentext}} 45, {{shortname}}{{/shortentext}}</p>
-				</a>
-			</th>
-		{{/competencies}}
-	</tr>
-</thead>
-<tbody>
-	{{#sections_matrix}}
-		<tr class="bg-primary">
-			<td class="bg-primary text-white">
-				{{name}}
-			</td>
+<table id="tab_mgmt" class="table-bordered order-column row-border dataTable" >
+	<thead>
+		<tr>
+			<th>Activités</th>
 			{{#competencies}}
-			<td class="td_section"></td>
+				<th style="max-width: 170px; overflow: hidden;text-align:center">
+					{{#edit}}<i class="icon fa fa-trash fa-fw " style="color:#dc493a" onclick='supprimer_lien_cpt({{id}})'></i>{{/edit}}
+					<a href='{{link}}' style='color: black;display:inline-block'>
+						<p style="word-wrap: break-word;">{{#shortentext}} 45, {{shortname}}{{/shortentext}}</p>
+					</a>
+					<a class="btn btn-link p-0" role="button" data-container="body" data-toggle="popover" data-placement="top" data-content="{{description}}" data-html="true" tabindex="0" data-trigger="focus" data-original-title="" title="">
+					  <i class="icon fa fa-question-circle text-info fa-fw " title="{{shortname}}" aria-label="{{shortname}}"></i>
+					</a>
+				</th>
 			{{/competencies}}
 		</tr>
-		{{#matrix_modules}}
-		<tr>
-			<td><a href="{{link}}">{{name}}</a></td>
-			{{#mcompetencies}}
-				<td class="text-success" align=right>
-					{{#module_ruleoutcomestring}}
-					<span style="display:inline" id="divmodule{{moduleid}}-competency{{id}}">
-						<p style="margin:0">{{module_ruleoutcomestring}}</p>
-							{{#edit}}
-							<i class="fa fa-remove icon-red-iena" style="font-size:24px;color:#dc493a" onclick='supprimer_lien(this)'></i>
-							{{/edit}}
-						
-					</span> 
-					{{/module_ruleoutcomestring}}
-					{{^module_ruleoutcomestring}}
-					<span style="display:none" id="divmodule{{moduleid}}-competency{{id}}">
-						<p style="margin:0">{{module_ruleoutcomestring}}</p>
-							{{#edit}}
-							<i class="fa fa-remove icon-red-iena" style="font-size:24px;color:#dc493a" onclick='supprimer_lien(this)'></i>
-							{{/edit}}
-						
-					</span>
-					{{/module_ruleoutcomestring}}
-					{{#edit}}
-					<div style="display:none">
-						<select id="selmodule{{moduleid}}-competence{{id}}"">
-							<option value="0">{{# str }} nothing, block_competency_iena{{/ str }}</option>
-							<option value="1">{{# str }} add_proof, block_competency_iena{{/ str }}</option>
-							<option value="2">{{# str }} send_valide, block_competency_iena{{/ str }}</option>
-							<option value="3">{{# str }} mark_ok_competency, block_competency_iena{{/ str }}</option>
-						</select>
+	</thead>
+	<tbody>
+		{{#sections_matrix}}
+			<tr class="bg-primary text-white">
+				<td class="">
+					{{name}}
+				</td>
+				{{#competencies}}
+				<td class="td-section"></td>
+				{{/competencies}}
+			</tr>
+			{{#matrix_modules}}
+			<tr>
+				<td><a href="{{link}}">{{name}}</a></td>
+				{{#mcompetencies}}
+					<td class="text-success" align=right>
+						{{#module_ruleoutcomestring}}
+						<span style="display:inline" id="divmodule{{moduleid}}-competency{{id}}">
+							<p style="margin:0">{{module_ruleoutcomestring}}</p>
+								{{#edit}}
+								<i class="icon fa fa-trash fa-fw" style="color:#dc493a" onclick='supprimer_lien(this)'></i>
+								{{/edit}}
+							
+						</span> 
+						{{/module_ruleoutcomestring}}
+						{{^module_ruleoutcomestring}}
+						<span style="display:none" id="divmodule{{moduleid}}-competency{{id}}">
+							<p style="margin:0">{{module_ruleoutcomestring}}</p>
+								{{#edit}}
+								<i class="icon fa fa-trash fa-fw " style="color:#dc493a" onclick='supprimer_lien(this)'></i>
+								{{/edit}}
+							
+						</span>
+						{{/module_ruleoutcomestring}}
+						{{#edit}}
+						<div style="display:none">
+							<select id="selmodule{{moduleid}}-competence{{id}}"">
+								<option value="0">{{# str }} nothing, block_competency_iena{{/ str }}</option>
+								<option value="1">{{# str }} add_proof, block_competency_iena{{/ str }}</option>
+								<option value="2">{{# str }} send_valide, block_competency_iena{{/ str }}</option>
+								<option value="3">{{# str }} mark_ok_competency, block_competency_iena{{/ str }}</option>
+							</select>
 
-						<i class="fa fa-check icon-green-iena" onclick='select_update(this)'></i>
-					</div>
-					<i class="fa fa-edit icon-blue-iena" data-edit='editOff' onclick='showFilter(this)'></i>
-					{{/edit}}
+							<i class="fa fa-check icon-green-iena" onclick='select_update(this)'></i>
+						</div>
+						<i class="icon fa fa-pencil fa-fw" style="color:rgb(33, 37, 41)" data-edit='editOff' onclick='showFilter(this)'></i>
+						{{/edit}}
 
-				</td>
-			{{/mcompetencies}}
-		</tr>
-		{{/matrix_modules}}
-	{{/sections_matrix}}
-</tbody>
+					</td>
+				{{/mcompetencies}}
+			</tr>
+			{{/matrix_modules}}
+		{{/sections_matrix}}
+	</tbody>
 </table>
 
 {{#edit}}
@@ -75,16 +78,16 @@
 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#cpt-modal">{{# str }} add_comp, block_competency_iena {{/ str }}</button>
 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#activities-modal">{{# str }} add_activities, block_competency_iena {{/ str }}</button>
 
-<form method="post" action="{{edit_link}}&editmode=false">  
+<form method="post" class="iena-matrix-button" action="{{edit_link}}&editmode=false">  
  
-  <button type="submit" class="btn btn-primary">{{# str }} manage_matrix_end, block_competency_iena {{/ str }}</button>
+  <button type="submit" class="btn btn-secondary">{{# str }} manage_matrix_end, block_competency_iena {{/ str }}</button>
   
 </form>
 	{{> block_competency_iena/modal_competencies}}
 	{{> block_competency_iena/modal_activities}}
 {{/edit}}
 {{^edit}}
-<form method="post" action="{{edit_link}}&editmode=true">  
+<form method="post" class="iena-matrix-button" action="{{edit_link}}&editmode=true">  
  
   <button type="submit" class="btn btn-primary">{{# str }} manage_matrix, block_competency_iena {{/ str }}</button>
   
-- 
GitLab