Browse Source

Use jquery to pre-fill code. Remove external password_reset.js as this code is only used once in this template.

Fabs 10 years ago
parent
commit
420cf9c624

+ 10 - 5
coin/members/templates/members/registration/password_reset_form.html

@@ -2,10 +2,6 @@
 {% load staticfiles %}
 {% load i18n %}
 
-{% block js %}
-<script src="{% static "js/password_reset.js" %}"></script>
-{% endblock %}
-
 {% block content %}
 
 <div class="row">
@@ -18,7 +14,7 @@
             {% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
         </div>
         {% endif %}
-    
+
         <form action="" method="post">{% csrf_token %}
             <label {% if form.id_email.errors %}class="error"{% endif %}>{% trans 'Email address' %}
                 {{ form.email }}
@@ -32,3 +28,12 @@
     </div>
 </div>
 {% endblock %}
+
+{% block js %}
+    <script>
+        $(function(){
+            email = $.urlParam('email');
+            if (email) $('#id_email').val(decodeURIComponent(email));
+        });
+    </script>
+{% endblock %}

+ 18 - 1
coin/static/js/illyse.js

@@ -1,3 +1,5 @@
+// TODO : Move it to VPN template only. We havn't to load this code at each page loa
+// TODO : jQueryfy it
 window.onload = function() {
 	var field = document.getElementById("passgen");
 	if (field != undefined) field.onclick = function() {
@@ -23,7 +25,7 @@ window.onload = function() {
 		xhr.send(null);
 		return false;
 	};
-	
+
 	var field = document.getElementById("trafic_zoom");
 	if (field != undefined) {
 		var select = document.createElement("select");
@@ -44,3 +46,18 @@ window.onload = function() {
 		field.parentNode.removeChild(field);
 	}
 };
+
+
+$(function() {
+    // Make URL parameters accessibles everywere by $.urlParam('my_param')
+    $.urlParam = function(name){
+        var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
+        if (results==null){
+           return null;
+        }
+        else{
+           return results[1] || 0;
+        }
+    }
+
+});

+ 0 - 7
coin/static/js/password_reset.js

@@ -1,7 +0,0 @@
-// Insert the content of the "email" GET parameter into the form
-var params = window.location.search;
-var components = params.substr(1).split("=");
-if (components[0] == "email") {
-    var field = document.getElementById("id_email");
-    field.value = decodeURIComponent(components[1]);
-}

+ 3 - 3
coin/templates/base.html

@@ -10,7 +10,6 @@
     <link rel="stylesheet" href="{% static "css/illyse.css" %}" />
     <link rel="stylesheet" href="{% static "css/offcanvas.css" %}">
     <script src="{% static "js/vendor/modernizr.js" %}"></script>
-    <script src="{% static "js/illyse.js" %}"></script>
     <link rel="icon" type="image/png" href="{% static "img/coinitem.png" %}"/>
     <link rel="icon" type="image/x-icon" href="{% static "img/favicon.ico" %}" />
 </head>
@@ -20,7 +19,7 @@
     <header>
        <h1><a href="{% url 'home' %}">COIN est un Outil pour un Internet Neutre</a></h1>
     </header>
-    
+
     {% if user.is_authenticated %}
     <div class="show-for-small">
         <a class="left-off-canvas-toggle button">Menu</a>
@@ -45,7 +44,7 @@
             {% endblock %}
         </div>
         {% endif %}
-        
+
         <div class="large-{% if user.is_authenticated %}9{% else %}12{% endif %} columns">
             {% block content %}{% endblock %}
         </div>
@@ -65,6 +64,7 @@
     <script src="{% static "js/vendor/jquery.js" %}"></script>
     <script src="{% static "js/foundation.min.js" %}"></script>
     <script src="{% static "js/foundation/foundation.offcanvas.js" %}"></script>
+    <script src="{% static "js/illyse.js" %}"></script>
     {% block js %}{% endblock %}
 
     <script>