Commits

Diego Búrigo Zacarão committed 902100f

Added searching feature for Lotte.

  • Participants
  • Parent commits c43d026

Comments (0)

Files changed (5)

File transifex/site_media/css/base.css

   font-size: 80%;
 }
 
-body.search.project_list span.highlight{
+.highlight{
   background-color: #ffffba;
   font-weight: bolder;
 }

File transifex/site_media/js/jquery.highlight-3.js

+/*
+
+highlight v3
+
+Highlights arbitrary terms.
+
+<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
+
+MIT license.
+
+Johann Burkard
+<http://johannburkard.de>
+<mailto:jb@eaio.com>
+
+*/
+
+jQuery.fn.highlight = function(pat) {
+ function innerHighlight(node, pat) {
+  var skip = 0;
+  if (node.nodeType == 3) {
+   var pos = node.data.toUpperCase().indexOf(pat);
+   if (pos >= 0) {
+    var spannode = document.createElement('span');
+    spannode.className = 'highlight';
+    var middlebit = node.splitText(pos);
+    var endbit = middlebit.splitText(pat.length);
+    var middleclone = middlebit.cloneNode(true);
+    spannode.appendChild(middleclone);
+    middlebit.parentNode.replaceChild(spannode, middlebit);
+    skip = 1;
+   }
+  }
+  else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
+   for (var i = 0; i < node.childNodes.length; ++i) {
+    i += innerHighlight(node.childNodes[i], pat);
+   }
+  }
+  return skip;
+ }
+ return this.each(function() {
+  innerHighlight(this, pat.toUpperCase());
+ });
+};
+
+jQuery.fn.removeHighlight = function() {
+ return this.find("span.highlight").each(function() {
+  this.parentNode.firstChild.nodeName;
+  with (this.parentNode) {
+   replaceChild(this.firstChild, this);
+   normalize();
+  }
+ }).end();
+};

File transifex/site_media/js/web_editor.js

 
     // Actions for show/hide translated entries
     $("input[name='only_translated']").change(function(){
-        $("#filter_entries").attr('value', 'true')
+        $("#filter_entries").attr('value', 'true');
          $(this).closest("form").submit();
     });
 
     // Actions for show/hide fuzzy entries
     $("input[name='only_fuzzy']").change(function(){
-        $("#filter_entries").attr('value', 'true')
+        $("#filter_entries").attr('value', 'true');
         $(this).closest("form").submit();
     });
 
     // Actions for show/hide untranslated entries
     $("input[name='only_untranslated']").change(function(){
-        $("#filter_entries").attr('value', 'true')
+        $("#filter_entries").attr('value', 'true');
         $(this).closest("form").submit();
     });
 
+    // Clean action for button 'clear'
+    $("input[name='clear']").click(function(){
+        $("input[name='string']").attr('value','');
+    });
+
     // Actions for show/hide contexts
     $("input[name='toggle_contexts']").change(function(){
         toggle_contexts()

File transifex/templates/webtrans/transfile_edit.html

 <script type="text/javascript" src="{{ MEDIA_URL }}js/tablesorted.js"></script>
 <script type="text/javascript" src="{{ MEDIA_URL }}js/table_pagination.js"></script>
 <script type="text/javascript" src="{{ MEDIA_URL }}js/web_editor.js"></script>
+<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.highlight-3.js"></script>
 
 <!-- Google suggest -->
 <script src="http://www.google.com/jsapi" type="text/javascript"></script>    
 <script type="text/javascript">
-//<!--
+
 {% if WEBTRANS_SUGGESTIONS %}
   google.load("language", "1");
   {% include 'webtrans/js/google-translate.js' %}
 {% endif %}
-//-->
+
+{% if string %}
+$(function(){
+    $("#trans_web_edit tbody p").highlight('{{ string }}');
+});
+{% endif %}
 </script>
 {% endblock %}
 
   <form action='' method='post' class='webtrans'>
   <h3>{% trans "Current status for this page" %}</h3>
 
-<fieldset class="floatright">
-  <legend>{% trans "Settings" %}</legend>
-  <table class="definition">
-  <tr>
-    <th>{% trans "Verbose editing:" %}</th>
-    <td><input id="toggle_contexts" type="checkbox" {% if toggle_contexts %}checked="checked"{% endif %} name="toggle_contexts" /></td>
-  </tr>
-  </table>
-</fieldset>
+<div class="floatright" >
+    <fieldset>
+    <legend>{% trans "Settings" %}</legend>
+    <table class="definition">
+    <tr>
+        <th>{% trans "Verbose editing:" %}</th>
+        <td><input id="toggle_contexts" type="checkbox" {% if toggle_contexts %}checked="checked"{% endif %} name="toggle_contexts" /></td>
+    </tr>
+    </table>
+    </fieldset>
 
+   <input class="i16 find" type="text" value="{{ string }}" size="15" name="string"/>
+   <input class="i16 filter" type="submit" value="{% trans "Filter" %}"/>
+   <input class="i16 clear" type="submit" name="clear" value="{% trans "Clear" %}"/>
+</div>
   <table class="definition stats_totals">
   <input id="filter_entries" type="hidden" name="filter_entries"/>
   <tr>

File transifex/webtrans/wizards.py

         if i == cindex:
             return chunk
 
+def has_string(entry, string):
+    """Return True if string is found in any attr of the po entry."""
+    if string in entry.msgid:
+        return True
+    if entry.msgid_plural:
+        if string in entry.msgid_plural:
+            return True
+        for value in entry.msgstr_plural.values():
+            if string in value:
+                return True
+    else:
+        if string in entry.msgstr:
+            return True
+
+
 class TransFormWizard(SessionWizard):
 
     ENTRIES_PER_PAGE = settings.WEBTRANS_ENTRIES_PER_PAGE
 
         # Getting filtering settings
         if f:
-            self.only_translated = f['only_translated']
-            self.only_fuzzy = f['only_fuzzy']
-            self.only_untranslated = f['only_untranslated']
+            self.only_translated = f.get('only_translated', None)
+            self.only_fuzzy = f.get('only_fuzzy', None)
+            self.only_untranslated = f.get('only_untranslated', None)
+            self.string = f.get('string', '')
         else: # Default values
             self.only_translated = False
             self.only_fuzzy = True
             self.only_untranslated = True
+            self.string = ''
             self.store_filters(self.only_translated, self.only_fuzzy, 
-                self.only_untranslated)
+                self.only_untranslated, self.string)
 
         # Getting po_entries based on the filter settings
         self.po_entries_list = self.filter_po_entries()
         # Filtering
         po_entries_list = []
         for entry in entries:
+            if self.string and not has_string(entry, self.string):
+                continue
             if entry.translated():
                 if self.only_translated:
                     po_entries_list.append(entry)
                     po_entries_list.append(entry)
         return po_entries_list
 
-    def store_filters(self, only_translated, only_fuzzy, only_untranslated):
+    def store_filters(self, only_translated, only_fuzzy, only_untranslated, string):
         """Store the filter options in the session."""
         self._storage['filters'] = {'only_translated': only_translated,
                                     'only_fuzzy': only_fuzzy,
-                                    'only_untranslated': only_untranslated}
+                                    'only_untranslated': only_untranslated,
+                                    'string': string,}
 
     def get_stored_filters(self):
         """Get the stored filter options from the session."""
             only_translated = request.POST.get('only_translated', None)
             only_fuzzy = request.POST.get('only_fuzzy', None)
             only_untranslated = request.POST.get('only_untranslated', None)
+            string = request.POST.get('string', None)
 
             # If filter changed
             if only_translated != self.only_translated or \
                 only_fuzzy != self.only_fuzzy or \
-                only_untranslated  != self.only_untranslated:
+                only_untranslated  != self.only_untranslated or \
+                string != self.string:
 
                 self.only_translated = only_translated
                 self.only_fuzzy = only_fuzzy
                 self.only_untranslated = only_untranslated
+                self.string = string
 
                 # Store the current filters
                 self.store_filters(self.only_translated, self.only_fuzzy, 
-                    self.only_untranslated)
+                    self.only_untranslated, self.string)
 
                 if 'steps' in self._storage:
                     del self._storage['steps']
             'only_translated': self.only_translated,
             'only_fuzzy': self.only_fuzzy,
             'only_untranslated': self.only_untranslated,
+            'string': self.string,
             'initial_entries_count':(self.next_step(request, self.step) * 
                                      self.ENTRIES_PER_PAGE),
             })