Commits

Konstantine Rybnikov committed c1928ba

lost of ajax logif and I like my fattie more and more ^___^

  • Participants
  • Parent commits 8861ed7

Comments (0)

Files changed (10)

File fat/fat_po_editor/bl/repository.py

 
 from django.utils.translation import ugettext as _
 
+from fat_po_editor.models_mongo import Repository
+
 def get_all():
     return []
 
     if not os.path.exists(path):
         raise UserAlertError(_(u'Path %(path)s does not exist.') % dict(
                 path=path))
+    # repostiory = Repository(path=path)
+    # repository.save()

File fat/fat_po_editor/static/css/main.css

     background: rgba(78, 207, 255, 0.1); }
   #js-messages .error {
     background: rgba(255, 50, 50, 0.1); }
+
+.repositories-list .input-path {
+  width: 500px; }

File fat/fat_po_editor/static/css/main.scss

         background: rgba(255, 50, 50, 0.1);
     }
 }
+
+.repositories-list {
+    .input-path {
+        width: 500px;
+    }
+}

File fat/fat_po_editor/static/js/ajax_util.js

     $messagesContainer.append($message);
     $message
         .slideDown('fast')
-        .delay(1000)
+        .delay(2000)
         .slideUp('fast', function() {
             $message.remove();
         });

File fat/fat_po_editor/static/js/repositories_list.js

+var RepositoriesList = makeClass();
+
+RepositoriesList.prototype.init = function(options) {
+    // add button options
+    var $add_button = this.$add_button = options['$add_button'];
+    var $add_path_input = this.$add_path_input = options['$add_path_input'];
+    var add_url = this.add_url = options['add_url'];
+    
+    // autocomplete options
+    var autocomplete_url = this.autocomplete_url = options['autocomplete_url'];
+
+    // this.updateList options
+    var $repository_list_url = this.$repository_list_url = options['$repository_list_url'];
+    
+    // add button
+    this.$add_button.click(function() {
+        var path = $add_path_input.val();
+        $.post(
+            add_url,
+            { path: path },
+            function(response) {
+                if (response.status == 'success') {
+                    AjaxUtil.info(
+                        response.data.message);
+                } else if (response.status == 'fail') {
+                    AjaxUtil.error(
+                        response.data.message);
+                };
+            });
+    });
+    
+    // autocomplete
+    $add_path_input
+        .autocomplete({source: autocomplete_url});
+};
+
+RepositoriesList.prototype.updateList = function() {
+    // 1. get list
+    // 2. update list
+};

File fat/fat_po_editor/templates/fat_po_editor/base.html

 {% load js_util %}
-
 <!doctype html>
 <html>
   <head>
-    <title></title>
+    <title>Fat Po Editor</title>
     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
     <link rel="stylesheet" href="{{ STATIC_URL }}css/base.css" type="text/css" media="screen" />
     <link rel="stylesheet" href="{{ STATIC_URL }}css/main.css" type="text/css" media="screen" />
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js"></script>
     <script type="text/javascript" src="{{ STATIC_URL }}js/oop.js"></script>
     <script type="text/javascript" src="{{ STATIC_URL }}js/ajax_util.js"></script>
+    {% additional_js_render %}
     <script type="text/javascript">
         {% domready_render %}
     </script>

File fat/fat_po_editor/templates/fat_po_editor/index.html

 {% load repository %}
 
 {% block content %}
-
 <div id="js-messages"></div>
 
 <h1>{% trans "Fat po editor" %}</h1>
 </p>
 
 {% repositories_list repositories %}
-
 {% endblock %}

File fat/fat_po_editor/templates/fat_po_editor/repositories_list.html

 {% load js_util %}
 {% load i18n %}
-
+{% add_js %}
+<script type="text/javascript" src="{{ STATIC_URL }}js/repositories_list.js"></script>
+{% end_add_js %}
 <h3>List of repositories</h2>
 <p>
     {% if repositories %}
-    <ul>
+    <ul id="repository-list-ul">
         {% for repository in repositories %}
         <li>{{ repository }}</li>
         {% endfor %}
     {% endif %}
 </p>
 <p class="repositories-list">
-    <input type="text" name="path" value="" id="repository_add_path" />
-    {% domready %}
-        $('#repository_add_path')
-            .autocomplete({source: "{% url fat_po_editor.views.repository.path_autocomplete %}"});
-    {% enddomready %}
+    <input type="text" name="path" value="" id="repository_add_path" class="input-path" />
     <a href="javascript:void(0)"
        class="pseudo"
        id="add-repo">Add</a>
     {% domready %}
-        $('#add-repo').click(function() {
-            var path = $('#repository_add_path').val();
-            $.post(
-                '{% url fat_po_editor.views.repository.add %}',
-                { path: path },
-                function(response) {
-                    if (response.status == 'success') {
-                        AjaxUtil.info(
-                            response.data.message);
-                    } else if (response.status == 'fail') {
-                        AjaxUtil.error(
-                            response.data.message);
-                    };
-                });
-        });
+        var repolist = (
+            new RepositoriesList({
+                $add_button: $('#add-repo'),
+                $add_path_input: $('#repository_add_path'),
+                add_url: '{% url fat_po_editor.views.repository.add %}',
+                autocomplete_url: "{% url fat_po_editor.views.repository.path_autocomplete %}",
+                $repository_list_url: $('#repository-list-ul')}));
     {% enddomready %}
     
     {# {% url fat_po_editor.views.repository.add %} #}

File fat/fat_po_editor/templatetags/js_util.py

 
 register = template.Library()
 
+# domready
 _domready_stack = []
 
 @register.tag
         self.nodelist = nodelist
         
     def render(self, context):
-        # if 'dom_ready' not in context:
-        #     context['dom_ready'] = []
-        # context['dom_ready'].append(self.nodelist.render(context))
         _domready_stack.append(self.nodelist.render(context))
         return ''
 
     def render(self, context):
         global _domready_stack
         
-        # if 'dom_ready' in context:
-        #     return u"\n".join(context['dom_ready'])
-        # return ''
-        
         to_return = u"\n".join(_domready_stack)
         _domready_stack = []
         return to_return
+
+# additional_js
+_additional_js_stack = []
+
+@register.tag
+def add_js(parser, token):
+    nodelist = parser.parse(('end_add_js',))
+    parser.delete_first_token()
+    return AddJsNode(nodelist)
+
+class AddJsNode(template.Node):
+    def __init__(self, nodelist):
+        self.nodelist = nodelist
+    
+    def render(self, context):
+        _additional_js_stack.append(self.nodelist.render(context))
+        return ''
+
+@register.tag
+def additional_js_render(parser, token):
+    return AdditionalJsRenderNode()
+
+class AdditionalJsRenderNode(template.Node):
+    def render(self, context):
+        global _additional_js_stack
+        
+        to_return = u"\n".join(_additional_js_stack)
+        _additional_js_stack = []
+        return to_return

File fat/fat_po_editor/templatetags/repository.py

 
 register = template.Library()
 
-@register.inclusion_tag('fat_po_editor/repositories_list.html')
-def repositories_list(repositories):
-    return {'repositories': repositories}
+@register.inclusion_tag('fat_po_editor/repositories_list.html', takes_context=True)
+def repositories_list(context, repositories):
+    return {'repositories': repositories,
+            'STATIC_URL': context['STATIC_URL']}