]> git.openstreetmap.org Git - osqa.git/blob - forum/skins/default/templates/ask.html
Improvements on full text search.
[osqa.git] / forum / skins / default / templates / ask.html
1 {% extends "base.html" %}
2 <!-- template ask.html -->
3 {% load i18n %}
4 {% load extra_tags %}
5 {% block title %}{% spaceless %}{% trans "Ask a question" %}{% endspaceless %}{% endblock %}
6 {% block forejs %}
7         <script type='text/javascript' src='{% media  "/media/js/wmd/showdown.js" %}'></script>
8         <script type='text/javascript' src='{% media  "/media/js/wmd/wmd.js" %}'></script>
9         <link rel="stylesheet" type="text/css" href="{% media  "/media/js/wmd/wmd.css" %}" />
10         <script type="text/html" id="question-summary-template">
11             <div class="answer-summary">
12                 <a href="%URL%"><div class="answer-votes">%SCORE%</div></a>
13                 <div class="answer-link">
14                     <a class="question-hyperlink" href="%URL%" title="%SUMMARY%">%TITLE%</a>
15                 </div>
16             </div>
17         </script>
18         <script type="text/javascript">
19         $().ready(function(){
20             //set current module button style
21             $("#nav_ask").attr('className',"on");
22             $('#editor').TextAreaResizer();
23
24             //toggle preview of editor
25                         //todo remove copy-paste
26             var display = true;
27             var txt = "[{% trans "hide preview" %}]";
28             $('#pre-collapse').text(txt);
29             $('#pre-collapse').bind('click', function(){
30                 txt = display ? "[{% trans "show preview" %}]" : "[{% trans "hide preview" %}]";
31                 display = !display;
32                 $('#previewer').toggle();
33                 $('#pre-collapse').text(txt);
34             });
35
36             //Tags autocomplete action
37                 $("#id_tags").autocomplete("/matching_tags", {
38                 minChars: 1,
39                         matchContains: true,
40                 max: 20,
41                 multiple: true,
42                 multipleSeparator: " ",
43                         /*formatItem: function(row, i, max) {
44                                 return row.n + " ("+ row.c +")";
45                         },
46                 formatResult: function(row, i, max){
47                     return row.n;
48                 }*/
49                 formatItem: function(row, i, max, value) {
50                     return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")";
51                 },
52
53                 formatResult: function(row, i, max, value){
54                     return row[0];
55                 }
56
57             });
58
59             var $input = $('#id_title');
60             var $box = $('#ask-related-questions');
61             var template = $('#question-summary-template').html()
62
63             function reload_suggestion_box(q) {
64                 $.post('{% url related_questions %}', {title: q}, function(data) {
65                     if (data) {
66                         var html = '';
67                         for (var i = 0; i < data.length; i++) {
68                             var item = template.replace(new RegExp('%URL%', 'g'), data[i].url)
69                                                .replace(new RegExp('%SCORE%', 'g'), data[i].score)
70                                                .replace(new RegExp('%TITLE%', 'g'), data[i].title)
71                                                .replace(new RegExp('%SUMMARY%', 'g'), data[i].summary);
72
73                             html += item;
74
75                         }
76                         $('#ask-related-questions').html(html);
77                     }
78                 }, 'json');
79             }
80
81             $input.keyup(function(e) {
82                 var q = $input.val().trim();
83
84                 if (e.which == 32 && q.length > 8 && q.split(' ').length > 2) {
85                     reload_suggestion_box(q);
86                 }
87
88                 return true;
89             });
90
91             $input.change(function() {
92                 var q = $input.val().trim();
93
94                 if (q.length > 8) {
95                     reload_suggestion_box(q);
96                 }
97             });
98         });
99         </script>
100 {% endblock %}
101
102 {% block content %}
103 <div id="main-bar" class="headNormal">
104         {% trans "Ask a question" %}
105 </div>
106 <div id="main-body" class="ask-body">
107     <div id="askform">
108         <form id="fmask" action="" method="post" >
109                         {% if not request.user.is_authenticated %}
110             <div class="message">
111                             <p>{% trans "login to post question info" %}</p>
112             </div>
113             {% else %}
114                 {% ifequal settings.EMAIL_VALIDATION 'on' %}
115                     {% if not request.user.email_isvalid %}
116                         <div class="message">
117                             {% blocktrans with request.user.email as email %}must have valid {{email}} to post, 
118                             see {{email_validation_faq_url}}
119                             {% endblocktrans %}
120                         </div>
121                     {% endif %}
122                 {% endifequal %}
123                         {% endif %}
124             <div class="form-item">
125                 <label for="id_title" ><strong>{{ form.title.label_tag }}:</strong></label> <span class="form-error"></span><br/>
126                 {{ form.title }} {{ form.title.errors }}
127                 <div class="title-desc">
128                     {{ form.title.help_text }}
129                 </div>
130             </div>
131             <div id="ask-related-questions"></div>
132             <div class="form-item">
133                 <div id="wmd-button-bar" class="wmd-panel"></div>
134                 {{ form.text }} {{ form.text.errors }}
135                 <div class="preview-toggle">
136                     <table width="100%">
137                         <tr>
138                             <td>
139                                 <span id="pre-collapse" title="{% trans "Toggle the real time Markdown editor preview" %}">{% trans "toggle preview" %}</span>
140                             </td>
141                             {% if settings.WIKI_ON %}
142                             <td class="tright">
143                                 {{ form.wiki }} <span class="help_text" title="{{form.wiki.help_text}}">{{ form.wiki.label_tag }} </span>
144                             </td>
145                             {% endif %}
146                         </tr>
147
148                     </table>
149                 </div>
150                 <div id="previewer" class="wmd-preview"></div>
151                 <span class="form-error"></span>
152             </div>
153             <div class="form-item">
154                 <strong>{{ form.tags.label_tag }}:</strong> {% trans "(required)" %} <span class="form-error"></span><br/>
155                 {{ form.tags }}  {{ form.tags.errors }}
156             </div>
157                         <p class="title-desc">
158                                 {{ form.tags.help_text }}
159                         </p>
160             {% if not request.user.is_authenticated %}
161             <input name="ask" type="submit" value="{% trans "Login/signup to post your question" %}" class="submit" />
162                         {% else %}
163             <input name="ask" type="submit" value="{% trans "Ask your question" %}" class="submit" />
164             {% endif %}
165         </form>
166     </div>
167 </div>
168 {% endblock %}
169
170 {% block sidebar %}
171 {% include "question_edit_tips.html" %}
172 {% endblock %}
173
174 {% block endjs %}
175 {% endblock %}
176 <!-- end template ask.html -->