Commits

Konstantine Rybnikov  committed c64d6ca

almost done adding repositories

  • Participants
  • Parent commits 5694830

Comments (0)

Files changed (8)

File fat/fat_po_editor/bl/repository.py

 from fat_po_editor.models_mongo import Repository
 
 def get_all():
-    return []
+    return Repository.objects
 
 class UserAlertError(Exception): pass
 
     repository = Repository(path=path)
     repository.save()
     return repository
-
-def full_list():
-    Repository.objects()

File fat/fat_po_editor/models_mongo.py

 
 class Repository(Document):
     path = StringField(required=True)
+
+    meta = {
+        'allow_inheritance': False,
+        }

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

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

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

     }
 }
 
-.repositories-list {
-    .input-path {
+#repositories-list {
+    .repo-name {
         width: 500px;
     }
 }

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

     var $repository_list_ul = this.$repository_list_ul = $list.find('.repository-list');
     
     // 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);
-                    this.updateList(response.data.repositories);
-                } else if (response.status == 'fail') {
-                    AjaxUtil.error(
-                        response.data.message);
+    var onclick = (function(repoList) {
+        return function() {
+            var path = $add_path_input.val();
+
+            var callback = (function(repoList) {
+                return function(response) {
+                    if (response.status == 'success') {
+                        AjaxUtil.info(
+                            response.data.message);
+                        repoList.updateList(response.data.repositories);
+                    } else if (response.status == 'fail') {
+                        AjaxUtil.error(
+                            response.data.message);
+                    };
                 };
-            });
-    });
+            })(repoList);
+            $.post(
+                add_url,
+                { path: path },
+                callback);
+        };
+    })(this);
+    
+    this.$add_button.click(onclick);
     
     // autocomplete
     $add_path_input
 };
 
 RepositoriesList.prototype.updateList = function(repositories) {
+    console.log('finally here!');
     console.log(repositories);
     // 1. get list
     // 2. update list

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

         {% if repositories %}
         <ul class="repository-list">
             {% for repository in repositories %}
-            <li>{{ repository }}</li>
+            <li>{{ repository.path }}</li>
             {% endfor %}
         </ul>
         {% else %}

File fat/fat_po_editor/views/__init__.py

 from django.template import RequestContext
 from fat_po_editor import bl
 
-import repository
-
 def index(request):
     repositories = bl.repository.get_all()
     return (

File fat/fat_po_editor/views/repository.py

             return json_http_response_fail({
                         'message': e.message})
         
-        repositories = repository.full_list()
+        repositories = list(x.path for x in repository.get_all() or [])
         
         return (
             json_http_response_success({
                 'message': _(u'Repository path %(repository_path)s was added') % dict(
                     repository_path=repository_path),
-                'repositories': repositories,
-            }))
+                'repositories': repositories}))
     else:
         return HttpResponse(u'Waiting for POST data')