Browse Source

[security] Enable loading of non standard users/groups on the initial select dropdown

Enrico Berti 11 years ago
parent
commit
5580282b0d
1 changed files with 25 additions and 12 deletions
  1. 25 12
      apps/security/src/security/templates/hdfs.mako

+ 25 - 12
apps/security/src/security/templates/hdfs.mako

@@ -376,42 +376,55 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
 <script type="text/javascript">
 
   ko.bindingHandlers.select2 = {
-    init: function(element, valueAccessor, allBindingsAccessor, vm) {
+    init: function (element, valueAccessor, allBindingsAccessor, vm) {
       var options = ko.toJS(valueAccessor()) || {};
+
+      if (typeof valueAccessor().update != "undefined") {
+        if (options.type == "user" && viewModel.selectableHadoopUsers().indexOf(options.update) == -1) {
+          viewModel.availableHadoopUsers.push({
+            username: options.update
+          });
+        }
+        if (options.type == "group" && viewModel.selectableHadoopGroups().indexOf(options.update) == -1) {
+          viewModel.availableHadoopGroups.push({
+            name: options.update
+          });
+        }
+      }
       $(element)
           .select2(options)
-          .on("change", function(e){
-            if (typeof e.val != "undefined" && typeof valueAccessor().update != "undefined"){
+          .on("change", function (e) {
+            if (typeof e.val != "undefined" && typeof valueAccessor().update != "undefined") {
               valueAccessor().update(e.val);
             }
           })
-          .on("select2-open", function(){
-            $(".select2-input").off("keyup").data("type", options.type).on("keyup", function(e) {
-              if(e.keyCode === 13){
+          .on("select2-open", function () {
+            $(".select2-input").off("keyup").data("type", options.type).on("keyup", function (e) {
+              if (e.keyCode === 13) {
                 var _newVal = $(this).val();
                 var _type = $(this).data("type");
-                if (_type == "user"){
+                if (_type == "user") {
                   viewModel.availableHadoopUsers.push({
                     username: _newVal
                   });
                 }
-                if (_type == "group"){
+                if (_type == "group") {
                   viewModel.availableHadoopGroups.push({
                     name: _newVal
                   });
                 }
-                $(element).select2("val",  _newVal, true);
+                $(element).select2("val", _newVal, true);
                 $(element).select2("close");
               }
             });
           })
     },
-    update: function(element, valueAccessor, allBindingsAccessor, vm) {
-      if (typeof valueAccessor().update != "undefined"){
+    update: function (element, valueAccessor, allBindingsAccessor, vm) {
+      if (typeof valueAccessor().update != "undefined") {
         $(element).select2("val", valueAccessor().update());
       }
     }
-};
+  };
 
   var INITIAL = ${ initial | n,unicode };
   var viewModel = new HdfsViewModel(INITIAL);