From d4d9102efdae50a91c75115aaceb276848a8ec16 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Sat, 11 Aug 2018 22:11:11 +0200 Subject: [PATCH] consentAdmin: move inline JS/CSS to assets --- .../consentAdmin/templates/consentadmin.php | 11 ++- .../consentAdmin/templates/consentadmin.twig | 11 ++- .../www/assets/css/consentAdmin.css | 17 ++++ .../www/assets/js/consentAdmin.js | 80 ++++++++++++++++++- .../www/assets/js/consentSimpleAjax.js | 70 ---------------- modules/consentAdmin/www/consentAdmin.php | 2 +- 6 files changed, 106 insertions(+), 85 deletions(-) delete mode 100644 modules/consentAdmin/www/assets/js/consentSimpleAjax.js diff --git a/modules/consentAdmin/templates/consentadmin.php b/modules/consentAdmin/templates/consentadmin.php index 59a9e8647..3895ef9f7 100644 --- a/modules/consentAdmin/templates/consentadmin.php +++ b/modules/consentAdmin/templates/consentadmin.php @@ -1,7 +1,6 @@ <?php $this->data['head'] = '<link rel="stylesheet" type="text/css" href="'.SimpleSAML\Module::getModuleURL("consentAdmin/assets/css/consentAdmin.css").'" />'."\n"; $this->data['head'] .= '<script type="text/javascript" src="'.SimpleSAML\Module::getModuleURL("consentAdmin/assets/js/consentAdmin.js").'"></script>'; - $this->data['head'] .= '<script type="text/javascript" src="'.SimpleSAML\Module::getModuleURL("consentAdmin/assets/js/consentSimpleAjax.js").'"></script>'; // default theme $this->includeAtTemplateBase('includes/header.php'); ?> @@ -13,7 +12,7 @@ <table> <tr> <th width="80%"><?php echo $this->t('{consentAdmin:consentadmin:service_provider_header}') ?></th> - <th width="140"><?php echo $this->t('{consentAdmin:consentadmin:status_header}') ?></th> + <th><?php echo $this->t('{consentAdmin:consentadmin:status_header}') ?></th> </tr> <?php $spList = $this->data['spList']; @@ -23,7 +22,7 @@ $attributes_text = $this->t('{consentAdmin:consentadmin:attributes_text}'); foreach ($spList as $spName => $spValues) { if (!is_null($spValues['serviceurl'])) { - $htmlSpName = '<a href="'.$spValues['serviceurl'].'" style="color: black; font-weight: bold;">'.htmlspecialchars($spValues['name']).'</a>'; + $htmlSpName = '<a class="serviceUrl" href="'.$spValues['serviceurl'].'">'.htmlspecialchars($spValues['name']).'</a>'; } else { $htmlSpName = htmlspecialchars($spValues['name']); } @@ -36,8 +35,8 @@ <tr class="$row_class"> <td> <table> - <tr class="$row_class"><td><span class='caSPName'><span title='$spDescription'>$htmlSpName</span> <span style="font-size: 80%;"onclick="javascript:toggleShowAttributes('$show_spid');"><span id='showing_$show_spid'>$show_text</span><span id='hiding_$show_spid' style='display:none;'>$hide_text</span>$attributes_text</span></span></td></tr> - <tr><td colspan="2" class="caAttributes"><div id="attributes_$show_spid" style="display: none;"> + <tr class="$row_class"><td><span class='caSPName'><span title='$spDescription'>$htmlSpName</span> <span class="show_hide" id="show_hide_$show_spid"><span id='showing_$show_spid'>$show_text</span><span id='hiding_$show_spid'>$hide_text</span> $attributes_text</span></span></td></tr> + <tr><td colspan="2" class="caAttributes"><div id="attributes_$show_spid"> TRSTART; $attributes = $spValues['attributes_by_sp']; if ($this->data['showDescription']) { @@ -62,7 +61,7 @@ TRSTART; </table> </td> -<td class='caAllowed'><input onclick="javascript:checkConsent(this.value, $show_spid, this.checked)" value='$consentValue' type='checkbox' $checkedAttr /><span id="consentText$show_spid">$consentText</span></td> +<td class='caAllowed'><input id="checkbox_$show_spid" class="checkbox" value='$consentValue' type='checkbox' $checkedAttr /><span id="consentText_$show_spid">$consentText</span></td> TRSTART; echo "</tr>\n"; $show_spid++; diff --git a/modules/consentAdmin/templates/consentadmin.twig b/modules/consentAdmin/templates/consentadmin.twig index e0eaf6d58..d27b8a63d 100644 --- a/modules/consentAdmin/templates/consentadmin.twig +++ b/modules/consentAdmin/templates/consentadmin.twig @@ -7,7 +7,6 @@ {% block postload %} <script src="{{ baseurlpath }}assets/js/consentAdmin.js"></script> -<script src="{{ baseurlpath }}assets/js/consentSimpleAjax.js"></script> {% endblock %} {% block content %} @@ -36,18 +35,18 @@ {% if spValues.serviceurl is defined %} {{ spValues.name|escape('html') }} {% else %} - <a href="{{ spValues.serviceurl }}" style="color: black; font-weight: bold">{{ spValues.name|escape('html') }}</a> + <a class="serviceUrl" href="{{ spValues.serviceurl }}">{{ spValues.name|escape('html') }}</a> {% endif %} </span> - <span style="font-size: 80%" onclick="javascript:toggleShowAttributes({{ loop.index0 }});"> + <span class="show_hide" id="show_hide_{{ loop.index0 }}"> <span id="showing_{{ loop.index0 }}">{{ '{consentAdmin:consentadmin:show}'|trans }}</span> - <span id="hiding_{{ loop.index0 }}" style="display: none">{{ '{consentAdmin:consentadmin:hide}'|trans }}</span> + <span id="hiding_{{ loop.index0 }}">{{ '{consentAdmin:consentadmin:hide}'|trans }}</span> {{ '{consentAdmin:consentadmin:attributes_text}'|trans }} </span> </span> </td> <td class="caAttributes"> - <div id="attributes_{{ loop.index0 }}" style="display: none"> + <div id="attributes_{{ loop.index0 }}"> {% if showDescription %} <p>{{ '{consentAdmin:consentadmin:consentadmin_purpose}'|trans }}{{ spValues.description|escape('html') }}</p> {% endif %} @@ -69,7 +68,7 @@ </div> </td> <td class="caAllowed"> - <input onclick="javascript:checkConsent(this.value, {{ loop.index0 }}, this.checked)" value='{{ spValues.consentValue }}' type='checkbox'{% if spValues.consentStatus == 'ok'%} checked="checked"{% endif %} /><span id="consentText{{ loop.index0 }}">{% if spValues.consentStatus == 'changed' %}attributes has changed{% endif %}</span> + <input class="checkbox" id="checkbox_{{ loop.index0 }}" value='{{ spValues.consentValue }}' type='checkbox'{% if spValues.consentStatus == 'ok'%} checked="checked"{% endif %} /><span id="consentText_{{ loop.index0 }}">{% if spValues.consentStatus == 'changed' %}attributes has changed{% endif %}</span> </td> </tr> {% endfor %} diff --git a/modules/consentAdmin/www/assets/css/consentAdmin.css b/modules/consentAdmin/www/assets/css/consentAdmin.css index 867350254..94c4a190c 100644 --- a/modules/consentAdmin/www/assets/css/consentAdmin.css +++ b/modules/consentAdmin/www/assets/css/consentAdmin.css @@ -20,3 +20,20 @@ tr.row1 td { a.orange { color: #ffd633; } + +span.show_hide { + font-size: 80%; +} + +a.serviceUrl { + color: black; + font-weight: bold; +} + +span[id^='hiding_'], span[id*='hiding_'] { + display: none; +} + +div[id^='attributes_'], div[id*='attributes_'] { + display: none; +} diff --git a/modules/consentAdmin/www/assets/js/consentAdmin.js b/modules/consentAdmin/www/assets/js/consentAdmin.js index cfe0fb71a..7c0359cd4 100644 --- a/modules/consentAdmin/www/assets/js/consentAdmin.js +++ b/modules/consentAdmin/www/assets/js/consentAdmin.js @@ -1,3 +1,79 @@ -function setConsentText(consentStatus, show_spid) { - document.getElementById("consentText" + show_spid).innerHTML = consentStatus; +var xmlHttp; + +function checkConsent() +{ + var show_spid = this.id.charAt(this.id.length-1); + var checkbox = document.getElementById("checkbox_"+show_spid); + + xmlHttp = GetXmlHttpObject() + if (xmlHttp == null) { + alert("Browser does not support HTTP Request") + return + } + + var url = "consentAdmin.php" + url = url+"?cv="+checkbox.value + url = url+"&action="+checkbox.checked + url = url+"&sid="+Math.random() + + xmlHttp.onreadystatechange=function() { + if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { + document.getElementById("consentText_" + show_spid).innerHTML = xmlHttp.responseText; + } + } + + xmlHttp.open("GET", url, true) + xmlHttp.send(null) } + +// This function creates an XMLHttpRequest +function GetXmlHttpObject() +{ + var xmlHttp = null; + try { + // Firefox, Opera 8.0+, Safari + xmlHttp = new XMLHttpRequest(); + } catch (e) { + //Internet Explorer + try { + xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + } + return xmlHttp; +} + +function toggleShowAttributes() +{ + var show_spid = this.id.charAt(this.id.length-1); + + var disp = document.getElementById('attributes_' + show_spid); + var showing = document.getElementById('showing_' + show_spid); + var hiding = document.getElementById('hiding_' + show_spid); + + disp.style.display = (disp.style.display == 'none' ? 'block' : 'none'); + showing.style.display = (disp.style.display == 'none' ? 'inline' : 'none'); + hiding.style.display = (disp.style.display == 'none' ? 'none' : 'inline'); +} + +document.addEventListener( + 'DOMContentLoaded', + function () { + var show_hide = document.getElementsByClassName("show_hide"); + for (var i = 0; i < show_hide.length; i++) { + show_hide[i].addEventListener( + 'click', + toggleShowAttributes + ); + } + + var checkbox = document.getElementsByClassName("checkbox"); + for (var i = 0; i < checkbox.length; i++) { + checkbox[i].addEventListener( + 'click', + checkConsent + ); + } + } +); diff --git a/modules/consentAdmin/www/assets/js/consentSimpleAjax.js b/modules/consentAdmin/www/assets/js/consentSimpleAjax.js deleted file mode 100644 index 7ea896c63..000000000 --- a/modules/consentAdmin/www/assets/js/consentSimpleAjax.js +++ /dev/null @@ -1,70 +0,0 @@ -var xmlHttp; - -function checkConsent(consentValue, show_spid, checkAction) -{ - xmlHttp=GetXmlHttpObject() - if (xmlHttp==null) { - alert ("Browser does not support HTTP Request") - - return - } - - var url="consentAdmin.php" - url=url+"?cv="+consentValue - url=url+"&action="+checkAction - url=url+"&sid="+Math.random() - xmlHttp.onreadystatechange=function() { - if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") - { - setConsentText(xmlHttp.responseText, show_spid); - } -} - - xmlHttp.open("GET",url,true) - xmlHttp.send(null) -} - -// This function will be automaticly called when the Ajax call is done returning data -function stateChanged() { - if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") - { - //Alert("Status of consent:" + xmlHttp.responseText ); - } -} - -// This function creates an XMLHttpRequest -function GetXmlHttpObject() { - var xmlHttp=null; - try - { - // Firefox, Opera 8.0+, Safari - xmlHttp=new XMLHttpRequest(); - } - catch (e) - { - //Internet Explorer - try - { - xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); - } - catch (e) - { - xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); - } - } - - return xmlHttp; -} - -function toggleShowAttributes(show_spid) { - var disp = document.getElementById('attributes_' + show_spid); - //var showhide = document.getElementById('showhide_' + show_spid); - var showing = document.getElementById('showing_' + show_spid); - var hiding = document.getElementById('hiding_' + show_spid); - - disp.style.display = (disp.style.display == 'none' ? 'block' : 'none'); - //showhide.innerHTML = (disp.style.display == 'none' ? 'Show' : 'Hide') - showing.style.display = (disp.style.display == 'none' ? 'inline' : 'none'); - hiding.style.display = (disp.style.display == 'none' ? 'none' : 'inline'); - //alert('hiding display'+hiding.display); -} diff --git a/modules/consentAdmin/www/consentAdmin.php b/modules/consentAdmin/www/consentAdmin.php index 628d1c4e0..c1a2a0277 100644 --- a/modules/consentAdmin/www/consentAdmin.php +++ b/modules/consentAdmin/www/consentAdmin.php @@ -150,7 +150,7 @@ if (!empty($_GET['action'])) { // Remove services, whitch have consent disabled if (isset($idp_metadata['consent.disable'])) { - foreach ($idp_metadata['consent.disable'] AS $disable) { + foreach ($idp_metadata['consent.disable'] as $disable) { if (array_key_exists($disable, $all_sp_metadata)) { unset($all_sp_metadata[$disable]); } -- GitLab