]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/skins/default/templates/ask.html
disabling the submit buttons for question and answers.
[osqa.git] / forum / skins / default / templates / ask.html
index ac393cde3355fabec8aa0aa1af44fd53c83396e5..6be8f59e9f74c1836538195020fe91bf4ef8ddd3 100644 (file)
@@ -1,7 +1,6 @@
 {% extends "base.html" %}
 <!-- template ask.html -->
-{% load i18n %}
-{% load extra_tags %}
+{% load i18n extra_tags extra_filters %}
 {% block title %}{% spaceless %}{% trans "Ask a question" %}{% endspaceless %}{% endblock %}
 {% block forejs %}
         <script type='text/javascript' src='{% media  "/media/js/wmd/showdown.js" %}'></script>
@@ -16,7 +15,7 @@
             </div>
         </script>
         <script type="text/javascript">
-        $().ready(function(){
+        $(function(){
             //set current module button style
             $("#nav_ask").attr('className',"on");
             $('#editor').TextAreaResizer();
             });
 
             //Tags autocomplete action
-               $("#id_tags").autocomplete("/matching_tags", {
+               $("#id_tags").autocomplete("/matching_tags/", {
                 minChars: 1,
                        matchContains: true,
                 max: 20,
                 multiple: true,
                 multipleSeparator: " ",
-                       /*formatItem: function(row, i, max) {
+
+                       /*
+                       formatItem: function(row, i, max) {
                                return row.n + " ("+ row.c +")";
                        },
                 formatResult: function(row, i, max){
                     return row.n;
-                }*/
+                }
+                */
+
                 formatItem: function(row, i, max, value) {
                     return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")";
                 },
                 }
 
             });
+        });
 
-            var $input = $('#id_title');
-            var $box = $('#ask-related-questions');
-            var template = $('#question-summary-template').html()
-
-            function reload_suggestion_box(q) {
-                $.post('{% url related_questions %}', {title: q}, function(data) {
-                    if (data) {
-                        var html = '';
-                        for (var i = 0; i < data.length; i++) {
-                            var item = template.replace(new RegExp('%URL%', 'g'), data[i].url)
-                                               .replace(new RegExp('%SCORE%', 'g'), data[i].score)
-                                               .replace(new RegExp('%TITLE%', 'g'), data[i].title)
-                                               .replace(new RegExp('%SUMMARY%', 'g'), data[i].summary);
-
-                            html += item;
-
-                        }
-                        $('#ask-related-questions').html(html);
-                    }
-                }, 'json');
+        function beforeUnload(e) {
+            if($("input#id_title")[0].value != "" || $("textarea#editor")[0].value != "" || $("input#id_tags")[0].value != "") {
+                yourWorkWillBeLost(e);
             }
-
-            $input.keyup(function(e) {
-                var q = $input.val().trim();
-
-                if (e.which == 32 && q.length > 8 && q.split(' ').length > 2) {
-                    reload_suggestion_box(q);
-                }
-
-                return true;
+            return false;
+        }
+        window.addEventListener('beforeunload', beforeUnload, true);
+
+        function submitClicked() {
+            window.removeEventListener('beforeunload', beforeUnload, true);
+            $("input.submit").each(function() {
+                this.disabled=true;
             });
+        }
 
-            $input.change(function() {
-                var q = $input.val().trim();
-
-                if (q.length > 8) {
-                    reload_suggestion_box(q);
-                }
-            });
-        });
+        var related_questions_url = "{% url related_questions %}";
         </script>
+        <script src="{% media "/media/js/osqa.ask.js" %}" type="text/javascript"></script>
 {% endblock %}
 
 {% block content %}
 </div>
 <div id="main-body" class="ask-body">
     <div id="askform">
-        <form id="fmask" action="" method="post" >
+        <form id="fmask" action="" method="post" accept-charset="utf-8">
                        {% if not request.user.is_authenticated %}
             <div class="message">
-                           <p>{% trans "login to post question info" %}</p>
+                <span class="strong big">{% trans "You are welcome to start submitting your question anonymously." %}</span>
+                <p>{% blocktrans %}
+                    After submiting your question, you will be redirected to the login/signup page.
+                    Your question will be saved in the current session and will be published after you login with your existing account,
+                    or signup for a new account{% endblocktrans %}{% if "ask"|contained_in:settings.REQUIRE_EMAIL_VALIDATION_TO %}
+                    {% trans "and validate your email." %}{% else %}.{% endif %}</p>
             </div>
             {% else %}
-                {% ifequal settings.EMAIL_VALIDATION 'on' %}
-                    {% if not request.user.email_isvalid %}
-                        <div class="message">
-                            {% blocktrans with request.user.email as email %}must have valid {{email}} to post, 
-                            see {{email_validation_faq_url}}
-                            {% endblocktrans %}
-                        </div>
-                    {% endif %}
-                {% endifequal %}
+                {% if not request.user.email_valid_and_can_ask %}
+                    <div class="message">
+                        {% blocktrans %}Remember, your question will not be published until you validate your email.{% endblocktrans %}
+                        <a href="{% url send_validation_email %}">{% trans "Send me a validation link." %}</a>
+                    </div>
+                {% endif %}
                        {% endif %}
             <div class="form-item">
                 <label for="id_title" ><strong>{{ form.title.label_tag }}:</strong></label> <span class="form-error"></span><br/>
             {% if not request.user.is_authenticated %}
             <input name="ask" type="submit" value="{% trans "Login/signup to post your question" %}" class="submit" />
                        {% else %}
-            <input name="ask" type="submit" value="{% trans "Ask your question" %}" class="submit" />
+            <input name="ask" type="submit" value="{% trans "Ask your question" %}" class="submit" onclick="submitClicked()" />
             {% endif %}
         </form>
     </div>