]> git.openstreetmap.org Git - osqa.git/commitdiff
Adds question and answer metrics (chars and words) on the editors, and in the "more...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 14 Sep 2010 17:37:03 +0000 (17:37 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 14 Sep 2010 17:37:03 +0000 (17:37 +0000)
Small css tweaks and a typo on the bulk manager.

git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@595 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/skins/default/media/js/osqa.main.js
forum/skins/default/templates/answer_edit.html
forum/skins/default/templates/ask.html
forum/skins/default/templates/base_content.html
forum/skins/default/templates/osqaadmin/nodeman.html
forum/skins/default/templates/question.html
forum/skins/default/templates/question_edit.html
forum/templatetags/node_tags.py

index 79cda45e948d52adfeb4620fb8a2424cc9e782cd..bca7a5c74f8feb107ed4eb9bc4df82d4bd7913df 100644 (file)
@@ -449,7 +449,7 @@ $(function() {
                 $container.slideDown('slow');\r
                 $add_comment_link.fadeOut('slow');\r
                 $textarea.focus();\r
-                window.setInterval(function() {\r
+                interval = window.setInterval(function() {\r
                     process_form_changes();\r
                 }, 200);\r
             }\r
@@ -529,6 +529,39 @@ $(function() {
             return false;\r
         });\r
     });\r
+\r
+    if ($('#editor').length) {\r
+        var $editor = $('#editor');\r
+        var $previewer = $('#previewer');\r
+        var $container = $('#editor-metrics');\r
+\r
+        var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;\r
+        var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;\r
+        var editor_interval = null;\r
+\r
+        $editor.focus(function() {\r
+            if (editor_interval == null) {\r
+                editor_interval = window.setInterval(function() {\r
+                    recalc_metrics();\r
+                }, 200);\r
+            }\r
+        });\r
+\r
+        function recalc_metrics() {\r
+            var text = $previewer.text();\r
+\r
+            var char_count = text.length;\r
+            var fullStr = text + " ";\r
+            var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");\r
+            var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");\r
+            var splitString = cleanedStr.split(" ");\r
+            var word_count = splitString.length - 1;\r
+\r
+            var metrics = char_count + " " + (char_count == 1 ? messages.character : messages.characters);\r
+            metrics += " / " + word_count + " " + (word_count == 1 ? messages.word : messages.words);\r
+            $container.html(metrics);\r
+        }\r
+    }\r
 });\r
 \r
 //var scriptUrl, interestingTags, ignoredTags, tags, $;\r
index 2737294e0e2c73d0d092af7c0fbc8605994dfffc..c9d846626eb4a94bdfc2e044bd34b0e41a350faf 100644 (file)
@@ -75,6 +75,7 @@
                 <span class="form-error"></span>
                 <div class="preview-toggle"><span id="pre-collapse" 
                                        title="{% trans "Toggle the real time Markdown editor preview" %}">{% trans "toggle preview" %}</span>
+                           <span style="text-align: right; margin-left: 200px;" id="editor-metrics"></span>
                                {% if settings.WIKI_ON %}
                     <div style="float:right;">
                         {{ form.wiki }} <span style="color:#000;cursor:help" title="{{form.wiki.help_text}}">{{ form.wiki.label_tag }} </span>
index 4e64fbab54edfabaa9131a372b6e74f625cbae4d..b027ce49bf7b8f042a4c26131331496fdcb1731d 100644 (file)
                             <td>
                                 <span id="pre-collapse" title="{% trans "Toggle the real time Markdown editor preview" %}">{% trans "toggle preview" %}</span>
                             </td>
+                            <td style="text-align: right;" id="editor-metrics"></td>
                             {% if settings.WIKI_ON %}
                             <td class="tright">
                                 {{ form.wiki }} <span class="help_text" title="{{form.wiki.help_text}}">{{ form.wiki.label_tag }} </span>
index 26a0d52e97adeeaefe8af79d182fab23c70dc282..f92161edcb0aa0dbfef0bce479a410489264d6c8 100644 (file)
                 cancel: "{% trans "Cancel" %}",
                 close: "{% trans "Close" %}",
                 ok: "{% trans "Ok" %}",
-                matching_tags_url: "{% url matching_tags %}"
+                matching_tags_url: "{% url matching_tags %}",
+                word: "{% trans "word" %}",
+                words: "{% trans "words" %}",
+                character: "{% trans "character" %}",
+                characters: "{% trans "characters" %}"
             }
         /* ]] */
         </script>
index 816558d9cbfa64c141fd9d5e9cea801aa26906a0..997fab57864b732991ccad268cbf9cd75cc6cdca 100644 (file)
             margin-right: 12px;
         }
 
-        #result_list tr.row1 td.deleted {
+        #result_list tr td.deleted {
             background-color: #FDD;
+            border-bottom: 1px solid #a9a9a9;
         }
 
-        #result_list tr.row2 td.deleted {
-            background-color: #FEE;
-        }
-
-        #result_list tr.row1 td.accepted {
+        #result_list tr td.accepted {
             background-color: #DFD;
-        }
-
-        #result_list tr.row2 td.accepted {
-            background-color: #EFD;
+            border-bottom: 1px solid #a9a9a9;
         }
 
         span.question-deleted {
                         <option selected="selected" value="">---------</option>
                         <option value="delete_selected">{% trans "Mark deleted" %}</option>
                         <option value="undelete_selected">{% trans "Undelete" %}</option>
-                        <option value="hard_delete_selected">{% trans "Delete completelly" %}</option>
+                        <option value="hard_delete_selected">{% trans "Delete completely" %}</option>
                         <option value="close_selected">{% trans "Close (questions only)" %}</option>
                     </select>
                 </label>
index 16c6a55143eeb8e4ed8ef9da76b97d0261f7fa0c..1b5b8e3cec313e43324b98cf705fb8228969f1ab 100644 (file)
                                             {% trans "toggle preview" %}\r
                                     </span>\r
                                 </td>\r
+                                <td style="text-align: right;" id="editor-metrics"></td>\r
                                 {% if settings.WIKI_ON %}\r
                                 <td style="text-align:right;">\r
                                     {{ answer.wiki }} \r
index 69bf688ef6df0bae9bd98768e5c1c5a5f3fb585a..12163bed8247b18d11fdd7b3aaf7c6c432874f13 100644 (file)
                             <td>
                                 <span id="pre-collapse" title="{% trans "Toggle the real time Markdown editor preview" %}">{% trans "toggle preview" %}</span>
                             </td>
+                            <td style="text-align: right;" id="editor-metrics"></td>
                             {% if settings.WIKI_ON %}
                             <td style="text-align:right;">
                                 {{ form.wiki }} <span style="color:#000;cursor:help" title="{{form.wiki.help_text}}">{{ form.wiki.label_tag }} </span>
index 8a685ce86abb50f082300cbfa94bc45a6760dc75..33bd45fdf97aa6a76df6458a8e77157e93001e60 100644 (file)
@@ -1,7 +1,10 @@
 from datetime import datetime, timedelta\r
+import re\r
 \r
 from forum.models import Question, Action\r
-from django.utils.translation import ugettext as _\r
+from django.utils.translation import ungettext, ugettext as _\r
+from django.utils.html import strip_tags\r
+from django.utils.safestring import mark_safe\r
 from django.core.urlresolvers import reverse\r
 from django import template\r
 from forum.actions import *\r
@@ -134,6 +137,21 @@ def post_controls(post, user):
             menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}),\r
                         command=True, withprompt=True))\r
 \r
+        if user.is_superuser or user.is_staff:\r
+            plain_text = strip_tags(post.html)\r
+\r
+            char_count = len(plain_text)\r
+            fullStr = plain_text + " "\r
+            left_trimmedStr = re.sub(re.compile(r"^[^\w]+", re.IGNORECASE), "", fullStr)\r
+            cleanedStr = re.sub(re.compile(r"[^\w]+", re.IGNORECASE), " ", left_trimmedStr)\r
+            splitString = cleanedStr.split(" ")\r
+            word_count = len(splitString) - 1\r
+\r
+            metrics = mark_safe("<b>%s %s / %s %s</b>" % (char_count, ungettext('character', 'characters', char_count),\r
+                                        word_count, ungettext('word', 'words', word_count)))\r
+\r
+            menu.append(post_control(metrics, "#", command=False, withprompt=False))\r
+\r
     return {'controls': controls, 'menu': menu, 'post': post, 'user': user}\r
 \r
 @register.inclusion_tag('node/comments.html')\r