Преглед изворни кода

HUE-799 [ua] Fix delete group action.

The list_groups.mako template had a javascript function that created a popup.
The template for the popup was taken and put into delete_group.mako.
Then, the delete_group view was updated to include appropriate context vars.
New javascript code was added to appropriately call an HTML page by sending X-Requested-With header.
The result of this call is placed into a container, which is then shown to the user.

No new tests were added. We need to consider more javascript oriented tests.
abec пре 13 година
родитељ
комит
7a40908

+ 28 - 0
apps/useradmin/src/useradmin/templates/delete_group.mako

@@ -0,0 +1,28 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+<%!
+from django.utils.translation import ugettext as _
+%>
+<form id="deleteGroupForm" action="${path}" method="POST">
+<div class="modal-header">
+    <a href="#" class="close" data-dismiss="modal">&times;</a>
+    <h3 id="deleteGroupMessage">${_("Are you sure you want to delete")} ${groupname}${_("?")}</h3>
+</div>
+<div class="modal-footer">
+    <input type="submit" class="btn primary" value="${_('Yes')}"/>
+    <a href="javascript:void(0);" class="btn secondary" data-dismiss="modal">${_('No')}</a>
+</div>
+</form>

+ 11 - 19
apps/useradmin/src/useradmin/templates/list_groups.mako

@@ -67,18 +67,7 @@ ${layout.menubar(section='groups', _=_)}
 </div>
 
 
-<div id="deleteGroup" class="modal hide fade groupModal">
-    <form id="deleteGroupForm" action="" method="POST">
-    <div class="modal-header">
-        <a href="#" class="close" data-dismiss="modal">&times;</a>
-        <h3 id="deleteGroupMessage">${_('Confirm action')}</h3>
-    </div>
-    <div class="modal-footer">
-        <input type="submit" class="btn primary" value="${_('Yes')}"/>
-        <a href="#" class="btn secondary hideModal">${_('No')}</a>
-    </div>
-    </form>
-</div>
+<div id="deleteGroup" class="modal hide fade groupModal"></div>
 
 
 
@@ -104,14 +93,17 @@ ${layout.menubar(section='groups', _=_)}
 
             $(".confirmationModal").click(function(){
                 var _this = $(this);
-                $.getJSON(_this.attr("data-confirmation-url"), function(data){
-                    $("#deleteGroupForm").attr("action", data.path);
-                    $("#deleteGroupMessage").text(_this.attr("alt"));
+                $.ajax({
+                    url: _this.attr("data-confirmation-url"),
+                    beforeSend: function(xhr){
+                        xhr.setRequestHeader("X-Requested-With", "Hue");
+                    },
+                    dataType: "html",
+                    success: function(data){
+                        $("#deleteGroup").html(data);
+                        $("#deleteGroup").modal("show");
+                    }
                 });
-                $("#deleteGroup").modal("show");
-            });
-            $(".hideModal").click(function(){
-                $("#deleteGroup").modal("hide");
             });
 
             $("#filterInput").keyup(function(){

+ 2 - 4
apps/useradmin/src/useradmin/views.py

@@ -96,13 +96,11 @@ def delete_group(request, name):
         __groups_lock.release()
 
       # Send a flash message saying "deleted"?
-      return list_groups(request)
+      return redirect(reverse(list_groups))
     except Group.DoesNotExist:
       raise PopupException(_("Group not found."))
   else:
-    return render("confirm.mako",
-      request,
-      dict(path=request.path, title=_("Delete group?")))
+    return render("delete_group.mako", request, dict(path=request.path, groupname=name))
 
 class UserChangeForm(django.contrib.auth.forms.UserChangeForm):
   """