incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [41/50] git commit: [#6392] ticket:444 Refactored js and removed redirects from ajax controllers
Date Thu, 26 Sep 2013 18:29:59 GMT
[#6392] ticket:444 Refactored js and removed redirects from ajax controllers

Also bugfixes in js code.


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/82be4a42
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/82be4a42
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/82be4a42

Branch: refs/heads/tv/6612
Commit: 82be4a42ea8056633eb77da205a656e687ea0fbf
Parents: 170205b
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 24 13:39:16 2013 +0300
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Sep 24 17:36:25 2013 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                            |  9 +-
 .../templates/admin_widgets/card_field.html     | 18 ++--
 .../allura/templates/app_admin_permissions.html | 91 +++++++++++---------
 3 files changed, 64 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/82be4a42/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index e51b70a..efa61a6 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -589,14 +589,15 @@ class DefaultAdminController(BaseController):
     @require_post()
     def block_user(self, username, perm, reason=None):
         if not username or not perm:
-            redirect(request.referer)
+            return dict(error='Enter username')
         user = model.User.by_username(username)
         if not user:
             return dict(error='User "%s" not found' % username)
         ace = model.ACE.deny(user.project_role()._id, perm, reason)
         if not model.ACL.contains(ace, self.app.acl):
             self.app.acl.append(ace)
-        return dict(user_id=str(user._id))
+            return dict(user_id=str(user._id), username=user.username, reason=reason)
+        return dict(error='User "%s" already blocked' % user.username)
 
     @validate(dict(user_id=V.Set(),
                    perm=V.UnicodeString()))
@@ -610,12 +611,14 @@ class DefaultAdminController(BaseController):
         users = model.User.query.find({'_id': {'$in': user_id}}).all()
         if not users:
             return dict(error='Select user to unblock')
+        unblocked = []
         for user in users:
             ace = model.ACE.deny(user.project_role()._id, perm)
             ace = model.ACL.contains(ace, self.app.acl)
             if ace:
                 self.app.acl.remove(ace)
-        redirect(request.referer)
+                unblocked.append(str(user._id))
+        return dict(unblocked=unblocked)
 
     @expose('jinja:allura:templates/app_admin_permissions.html')
     @without_trailing_slash

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/82be4a42/Allura/allura/ext/admin/templates/admin_widgets/card_field.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/admin_widgets/card_field.html b/Allura/allura/ext/admin/templates/admin_widgets/card_field.html
index 19988d5..e731290 100644
--- a/Allura/allura/ext/admin/templates/admin_widgets/card_field.html
+++ b/Allura/allura/ext/admin/templates/admin_widgets/card_field.html
@@ -72,11 +72,11 @@
         </a>
     </li>
 
-    {% if block_list and block_list.get(name) %}
-      <li>
-        <a href="#" class="block-list">Block List</a>
-        <div class="block-list grid-13" style="display: none">
-          <ul>
+    <li{% if not block_list or not block_list.get(name) %} style="display:none;"{% endif
%}>
+      <a href="#" class="block-list">Block List</a>
+      <div class="block-list grid-13" style="display: none">
+        <ul>
+        {% if block_list and block_list.get(name) %}
           {% for u, reason in block_list[name] %}
           <li>
             <label>
@@ -84,9 +84,9 @@
             </label>
           </li>
           {% endfor %}
-          </ul>
-        </div>
-      </li>
-    {% endif %}
+        {% endif %}
+        </ul>
+      </div>
+    </li>
   </ul>
 </div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/82be4a42/Allura/allura/templates/app_admin_permissions.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/app_admin_permissions.html b/Allura/allura/templates/app_admin_permissions.html
index f14860a..6fa5246 100644
--- a/Allura/allura/templates/app_admin_permissions.html
+++ b/Allura/allura/templates/app_admin_permissions.html
@@ -68,7 +68,7 @@
 <script type="text/javascript">
   var current_block_list;
   $('a.block-user').click(function(){
-      current_block_list = $(this).parent().parent().find('div.block-list')     
+      current_block_list = $(this).parent().parent().find('div.block-list')
       var deck =  $(this).closest('ul.deck');
       var role = deck.find('li.tcenter h3').text();
       $('input.block_user_role').val(role);
@@ -81,50 +81,57 @@
       $('input.block_user_role').val(role);
       $('div.model-block-list').html(userlist.html());
   });
-  $('form[action="block_user"], form[action="unblock_user"]').submit(function() {
-    var form = $(this),
-        username = form.find('#block_user'),
-        reason = form.find("textarea[name='reason']")
 
-    if(form.is(':visible')) {
-        $.ajax({
-            data: form.serialize(),
-            type: form.attr('method'),
-            url:  form.attr('action'),
-            success: function(data) {
-                if(data.error){
-                    flash(data.error, 'error');
-                }
-                else {
-                    form.parent().slideUp('fast');
-                    $('.lb_overlay').hide();
 
-                    if(form.attr('action') == 'block_user') {
-                        if(username.val().length != 0) {
-                            current_block_list
-                              .find('ul')
-                              .append('<li><label>' + 
-                                      '<input type="checkbox" value="' + data.user_id
+ '"name="user_id">' +
-                                      username.val() + ' (' +
-                                      reason.val() + ')' +
-                                      '</label></li>');
-                        }
-                    }
-                    else {
-                        var checked = form.find('input:checked');
-                        checked.each(function(i, e) {
-                            current_block_list
-                              .find('label:contains("'+$(e).parent().text()+'")')
-                              .parent()
-                              .remove()
-                        });
-                    }
-                    form.find("input[type=text], textarea").val("");
-                }
-              }
-            });
-        return false;
+  $('form[action="block_user"], form[action="unblock_user"').submit(function() {
+    var form = $(this);
+
+    function display_error(data) {
+      if (data.error) {
+        flash(data.error, 'error');
+        return true;
+      }
+      return false;
+    }
+    function after() {
+      form.parent().slideUp('fast');
+      $('.lb_overlay').hide();
+    }
+    function on_block_user_success(data) {
+      if (display_error(data)) { return; }
+
+      current_block_list.find('ul').append(
+        '<li><label><input type="checkbox" value="' + data.user_id + '"name="user_id">'
+        + data.username + (data.reason ? ' (' + data.reason + ')' : '') + '</label></li>'
+      );
+      // show 'Block List' button
+      current_block_list.parent('li').show();
+      form.find('input[type="text"], textarea').val('');
+      after();
     }
+    function on_unblock_user_success(data) {
+      if (display_error(data)) { return; }
+
+      for (var i in data.unblocked) {
+        var uid = data.unblocked[i];
+        current_block_list.find(':checkbox[name="user_id"][value="' + uid + '"]').parent().parent().remove();
+      }
+      if (current_block_list.find(':checkbox[name="user_id"]').length == 0) {
+        // hide 'Block List' button
+        current_block_list.parent('li').hide();
+      }
+      after();
+    }
+
+    var callback = form.attr('action') == 'block_user' ? on_block_user_success : on_unblock_user_success;
+
+    $.ajax({
+      data: form.serialize(),
+      type: form.attr('method'),
+      url:  form.attr('action'),
+      success: callback
+    });
+    return false;
   });
 </script>
 {% endblock %}


Mime
View raw message