From d65cbb88e4f576edc4e36d9a5233e764bd4a2c16 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Sat, 11 Aug 2018 23:22:52 +0200
Subject: [PATCH] # This is a combination of 2 commits. # The first commit's
 message is:

core: move inline JS to assets

# This is the 2nd commit message:

Move assets to assets-dir + PSR-2
---
 modules/core/templates/loginuserpass.php      |  5 +-
 modules/core/templates/loginuserpass.twig     |  8 +-
 modules/core/www/assets/js/loginuserpass.js   | 14 ++++
 .../templates/memcachestat.tpl.php            | 80 +++++++------------
 .../templates/memcachestat.twig               |  2 +-
 .../css/memcacheMonitor.css}                  |  0
 6 files changed, 51 insertions(+), 58 deletions(-)
 create mode 100644 modules/core/www/assets/js/loginuserpass.js
 rename modules/memcacheMonitor/www/{style.css => assets/css/memcacheMonitor.css} (100%)

diff --git a/modules/core/templates/loginuserpass.php b/modules/core/templates/loginuserpass.php
index 61b166088..4e012eee1 100644
--- a/modules/core/templates/loginuserpass.php
+++ b/modules/core/templates/loginuserpass.php
@@ -159,14 +159,13 @@ if ($this->data['errorcode'] !== null) {
             <tr id="submit">
                 <td class="loginicon"></td><td></td>
                 <td>
-                    <button class="btn"
-                            onclick="this.value='<?php echo $this->t('{login:processing}'); ?>';
-                                this.disabled=true; this.form.submit(); return true;" tabindex="6">
+                    <button id="submit_button" class="btn" tabindex="6">
                         <?php echo $this->t('{login:login_button}'); ?>
                     </button>
                 </td>
             </tr>
         </table>
+        <input type="hidden" id="processing_trans" value="<?php echo $this->t('{login:processing}'); ?>" />
         <?php
         foreach ($this->data['stateparams'] as $name => $value) {
             echo('<input type="hidden" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" />');
diff --git a/modules/core/templates/loginuserpass.twig b/modules/core/templates/loginuserpass.twig
index 7f27bc186..49fe67bf6 100644
--- a/modules/core/templates/loginuserpass.twig
+++ b/modules/core/templates/loginuserpass.twig
@@ -2,6 +2,10 @@
 
 {% extends "@core/base.twig" %}
 
+{% block postload %}
+<script src="{{baseurlpath}}assets/js/loginuserpass.js"></script>
+{% endblock %}
+
 {% block content %}
     {% if errorcode -%}
     <div class="pure-g">
@@ -99,10 +103,10 @@
 
             </div> <!-- form-align-->
             <br><br>
-            <button class="pure-button pure-button-red pure-input-1-2 pure-input-sm-1-1 right" type="submit" onclick="this.value='{{ 'Processing...'|trans }}';" tabindex="6">
+            <button class="pure-button pure-button-red pure-input-1-2 pure-input-sm-1-1 right" id="submit_button" type="submit" tabindex="6">
                 {{ 'Login'|trans }}
             </button>
-
+            <input type='hidden' id="processing_trans" value="{{ 'Processing...'|trans }}" />
             {% for name, value in stateparams -%}
                 <input type="hidden" name="{{ name }}" value="{{ value }}" />
             {%- endfor %}
diff --git a/modules/core/www/assets/js/loginuserpass.js b/modules/core/www/assets/js/loginuserpass.js
new file mode 100644
index 000000000..c9ade78a1
--- /dev/null
+++ b/modules/core/www/assets/js/loginuserpass.js
@@ -0,0 +1,14 @@
+document.addEventListener(
+    'DOMContentLoaded',
+    function () {
+        var button = document.getElementById("submit_button");
+        button.addEventListener(
+            'click',
+            function () {
+                var translation = document.getElementById("processing_trans");
+                this.disabled = true;
+                this.innerHTML = translation.value;
+            }
+        );
+    }
+);
diff --git a/modules/memcacheMonitor/templates/memcachestat.tpl.php b/modules/memcacheMonitor/templates/memcachestat.tpl.php
index 9a9a3399d..e3815c72b 100644
--- a/modules/memcacheMonitor/templates/memcachestat.tpl.php
+++ b/modules/memcacheMonitor/templates/memcachestat.tpl.php
@@ -1,42 +1,19 @@
 <?php
 
-$this->data['head'] = '<style type="text/css">
-	table.statustable td, table.statustable th { 
-		border: 1px solid #eee;
-		padding: 2px 6px;
-	}
-	table.statustable {
-		border-collapse: collapse;
-	}
-	.bmax {
-		border: 1px solid #555;
-		background: #eee;
-	}
-	.bused {
-		border-right: 1px solid #555;
-		border-bottom: 1px solid #555;
-		color: white;
-		background: #833;
-	}
-</style>
-';
-
-
-
+$this->data['head'] = '<link href="'.$this->data['baseurlpath'].'assets/css/memcacheMonitor.css" rel="stylesheet" />';
 $this->includeAtTemplateBase('includes/header.php');
 
 $title = $this->data['title'];
 $table = $this->data['table'];
 
-
 // Identify column headings
 $column_titles = array();
-foreach($table as $row_title => $row_data) {
-	foreach($row_data as $ct => $foo) {
-		if(!in_array($ct, $column_titles, true)) {
-			$column_titles[] = $ct;
-		}
-	}
+foreach ($table as $row_title => $row_data) {
+    foreach ($row_data as $ct => $foo) {
+        if (!in_array($ct, $column_titles, true)) {
+            $column_titles[] = $ct;
+        }
+    }
 }
 
 ?>
@@ -48,28 +25,28 @@ foreach($table as $row_title => $row_data) {
 <tr>
 <th></th>
 <?php
-foreach($column_titles as $ct) {
-	echo '<th>' . htmlspecialchars($ct) . '</th>' . "\n";
+foreach ($column_titles as $ct) {
+    echo '<th>'.htmlspecialchars($ct).'</th>'."\n";
 }
 ?>
 </tr>
 
 <?php
-foreach($table as $row_title => $row_data) {
-	echo '<tr>' . "\n";
-	echo '<th class="rowtitle" style="text-align: right">' . $this->t($this->data['rowtitles'][$row_title]) . '</th>' . "\n";
+foreach ($table as $row_title => $row_data) {
+    echo '<tr>' . "\n";
+    echo '<th class="rowtitle" style="text-align: right">'.$this->t($this->data['rowtitles'][$row_title]).'</th>'."\n";
 
-	foreach($column_titles as $ct) {
-		echo '<td>';
+    foreach ($column_titles as $ct) {
+        echo '<td>';
 
-		if(array_key_exists($ct, $row_data)) {
-			echo htmlspecialchars($row_data[$ct]);
-		}
+        if (array_key_exists($ct, $row_data)) {
+            echo htmlspecialchars($row_data[$ct]);
+        }
 
-		echo '</td>' . "\n";
-	}
+        echo '</td>' . "\n";
+    }
 
-	echo '</tr>' . "\n";
+    echo '</tr>' . "\n";
 }
 ?>
 
@@ -77,15 +54,14 @@ foreach($table as $row_title => $row_data) {
 
 <?php
 if (array_key_exists('bytes', $this->data['statsraw']) && array_key_exists('limit_maxbytes', $this->data['statsraw'])) {
-	foreach($this->data['statsraw']['bytes'] as $key => $row_data) {
-		echo ('<h3>Storage usage on [' . $key . ']</h3>');
-		$maxpix = 400;
-		$pix = floor($this->data['statsraw']['bytes'][$key]*$maxpix / $this->data['statsraw']['limit_maxbytes'][$key]);
-		
-		echo('<div class="bmax" style="width: ' .  $maxpix. 'px"><div class="bused" style="width: ' . $pix . 'px">
-		Used: ' . $table['bytes'][$key] . '
-		</div>Total available: ' . $table['limit_maxbytes'][$key] . '</div>');
-	}
+    foreach ($this->data['statsraw']['bytes'] as $key => $row_data) {
+        echo ('<h3>Storage usage on ['.$key.']</h3>');
+        $maxpix = 400;
+        $pix = floor($this->data['statsraw']['bytes'][$key]*$maxpix / $this->data['statsraw']['limit_maxbytes'][$key]);
+
+        echo '<div class="bmax" style="width: '.$maxpix.'px"><div class="bused" style="width: '.$pix.'px">Used: '.
+            $table['bytes'][$key].'</div>Total available: '.$table['limit_maxbytes'][$key].'</div>';
+    }
 }
 
 $this->includeAtTemplateBase('includes/footer.php');
diff --git a/modules/memcacheMonitor/templates/memcachestat.twig b/modules/memcacheMonitor/templates/memcachestat.twig
index f3d4cbd01..fdc4af4bd 100644
--- a/modules/memcacheMonitor/templates/memcachestat.twig
+++ b/modules/memcacheMonitor/templates/memcachestat.twig
@@ -2,7 +2,7 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-    <link href="{{ baseurlpath }}style.css" rel="stylesheet" />
+    <link href="{{ baseurlpath }}assets/css/memcacheMonitor.css" rel="stylesheet" />
 {% endblock %}
 
 {% block content %}
diff --git a/modules/memcacheMonitor/www/style.css b/modules/memcacheMonitor/www/assets/css/memcacheMonitor.css
similarity index 100%
rename from modules/memcacheMonitor/www/style.css
rename to modules/memcacheMonitor/www/assets/css/memcacheMonitor.css
-- 
GitLab