Browse Source

[security] Restyled roles add/undo/save buttons and fixed groups multi-select

Enrico Berti 11 years ago
parent
commit
4b591a7
2 changed files with 40 additions and 33 deletions
  1. 9 15
      apps/security/src/security/templates/hive.mako
  2. 31 18
      apps/security/static/js/common.ko.js

+ 9 - 15
apps/security/src/security/templates/hive.mako

@@ -204,8 +204,11 @@ ${ layout.menubar(section='hive') }
                     <span data-bind="foreach: groups, visible: ! showEditGroups() && ! groupsChanged()">
                       <span data-bind="text: $data"></span>
                     </span>
+                    <span data-bind="visible: ! showEditGroups() && ! groupsChanged() && groups().length == 0">
+                      <i class="fa fa-plus"></i> ${ _('Add a group') }
+                    </span>
                   </a>
-                  <div data-bind="visible: showEditGroups() || groups().length == 0 || groupsChanged()">
+                  <div data-bind="visible: showEditGroups() || groupsChanged()">
                     <select data-bind="options: $root.selectableHadoopGroups, selectedOptions: groups, select2: { update: groups, type: 'group'}" size="5" multiple="true" style="width: 400px"></select>
                     <a href="javascript: void(0)" data-bind="visible: groupsChanged, click: resetGroups">
                       <i class="fa fa-undo"></i>
@@ -228,22 +231,13 @@ ${ layout.menubar(section='hive') }
                   </div>
                 </td>
               </tr>
-              <tr>
+              <tr data-bind="visible: $data.showPrivileges">
                 <td colspan="2"></td>
                 <td colspan="4">
-                  <div class="acl-block pointer add-acl" data-bind="click: addPrivilege, visible: $data.showPrivileges" title="${ _('Add privilege') }">
-                    <i class="fa fa-plus"></i>
-                  </div>
-                </td>
-              </tr>
-              <tr>
-                <td colspan="2"></td>
-                <td colspan="4">
-                  <div class="acl-block pointer add-acl" data-bind="click: $root.list_sentry_privileges_by_role, visible: privilegesChanged().length > 0" title="${ _('Undo') }">
-                    <i class="fa fa-undo"></i>
-                  </div>
-                  <div class="acl-block pointer add-acl" data-bind="click: $root.role.savePrivileges, visible: privilegesChanged().length > 0" title="${ _('Save') }">
-                    <i class="fa fa-save"></i>                    
+                  <div class="acl-block acl-actions">
+                    <span class="pointer" data-bind="click: addPrivilege, visible: $data.showPrivileges" title="${ _('Add privilege') }"><i class="fa fa-plus"></i></span>
+                    <span class="pointer" data-bind="click: $root.list_sentry_privileges_by_role, visible: privilegesChanged().length > 0" title="${ _('Undo') }"> &nbsp; <i class="fa fa-undo"></i></span>
+                    <span class="pointer" data-bind="click: $root.role.savePrivileges, visible: privilegesChanged().length > 0" title="${ _('Save') }"> &nbsp; <i class="fa fa-save"></i></span>
                   </div>
                 </td>
               </tr>              

+ 31 - 18
apps/security/static/js/common.ko.js

@@ -26,10 +26,13 @@ ko.bindingHandlers.select2 = {
       }
       if (options.type == "group") {
         if (options.update instanceof Array) {
+          console.log("WHELLA")
           options.update.forEach(function(opt){
+            console.log("mongo")
+            console.log(opt)
             if (viewModel.selectableHadoopGroups().indexOf(opt) == -1){
               viewModel.availableHadoopGroups.push({
-                name: options.update
+                name: opt
               });
             }
           });
@@ -57,26 +60,36 @@ ko.bindingHandlers.select2 = {
         .on("select2-open", function () {
           $(".select2-input").off("keyup").data("type", options.type).on("keyup", function (e) {
             if (e.keyCode === 13) {
+              var _isArray = options.update instanceof Array;
               var _newVal = $(this).val();
               var _type = $(this).data("type");
-              if (_type == "user") {
-                viewModel.availableHadoopUsers.push({
-                  username: _newVal
-                });
+              if ($.trim(_newVal) != "") {
+                if (_type == "user") {
+                  viewModel.availableHadoopUsers.push({
+                    username: _newVal
+                  });
+                }
+                if (_type == "group") {
+                  viewModel.availableHadoopGroups.push({
+                    name: _newVal
+                  });
+                }
+                if (_type == "action") {
+                  viewModel.availableActions.push(_newVal);
+                }
+                if (_type == "scope") {
+                  viewModel.availablePrivileges.push(_newVal);
+                }
+                if (_isArray){
+                  var _vals = $(element).select2("val");
+                  _vals.push(_newVal);
+                  $(element).select2("val", _vals, true);
+                }
+                else {
+                  $(element).select2("val", _newVal, true);
+                }
+                $(element).select2("close");
               }
-              if (_type == "group") {
-                viewModel.availableHadoopGroups.push({
-                  name: _newVal
-                });
-              }
-              if (_type == "action") {
-                viewModel.availableActions.push(_newVal);
-              }
-              if (_type == "scope") {
-                viewModel.availablePrivileges.push(_newVal);
-              }
-              $(element).select2("val", _newVal, true);
-              $(element).select2("close");
             }
           });
         })