Repository: incubator-ranger
Updated Branches:
  refs/heads/stack 6edf6d868 -> 639527222


RANGER-203: UI fixes in pluggable service model implementation


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

Branch: refs/heads/stack
Commit: 63952722220d2ffc6f55e6cebe23f09a7a5960f4
Parents: 6edf6d8
Author: Gautam Borad <[email protected]>
Authored: Mon Feb 9 07:58:16 2015 -0800
Committer: Madhan Neethiraj <[email protected]>
Committed: Mon Feb 9 07:58:16 2015 -0800

----------------------------------------------------------------------
 .../service-defs/ranger-servicedef-hdfs.json    |  2 +-
 ranger-util/.gitignore                          |  2 +
 .../scripts/models/BackboneFormDataType.js      | 31 +++++--
 .../main/webapp/scripts/models/RangerPolicy.js  |  7 ++
 .../main/webapp/scripts/modules/XAOverrides.js  | 88 +++++++++++++++++---
 .../src/main/webapp/scripts/utils/XAUtils.js    | 17 +++-
 .../scripts/views/policies/PermissionList.js    | 11 ++-
 .../views/policies/RangerPolicyCreate.js        |  3 +
 .../scripts/views/policies/RangerPolicyForm.js  | 43 ++++++----
 .../webapp/scripts/views/reports/AuditLayout.js |  2 +-
 .../scripts/views/service/ServiceCreate.js      |  5 --
 .../webapp/scripts/views/service/ServiceForm.js | 45 +++++++++-
 security-admin/src/main/webapp/styles/xa.css    |  4 +
 13 files changed, 210 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/agents-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
----------------------------------------------------------------------
diff --git 
a/agents-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json 
b/agents-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
old mode 100644
new mode 100755
index cf8f008..56160d9
--- a/agents-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
+++ b/agents-common/src/main/resources/service-defs/ranger-servicedef-hdfs.json
@@ -35,7 +35,7 @@
     {"name":"username",                                "type":"string",  
"subType":"",             "mandatory":true, "label":"Username"},
     {"name":"password",                                
"type":"password","subType":"",             "mandatory":true, 
"label":"Password"},
     {"name":"fs.default.name",                         "type":"string",  
"subType":"",             "mandatory":true, "label":"Namenode URL"},
-    {"name":"hadoop.security.authorization",           "type":"bool",    
"subType":"TrueFalse",    "mandatory":true, "defaultValue":"false"},
+    {"name":"hadoop.security.authorization",           "type":"bool",    
"subType":"YesTrue:NoFalse",    "mandatory":true, "defaultValue":"false"},
     {"name":"hadoop.security.authentication",          "type":"enum",    
"subType":"authnType",    "mandatory":true, "defaultValue":"simple"},
     {"name":"hadoop.security.auth_to_local",           "type":"string",  
"subType":"",             "mandatory":false},
     {"name":"dfs.datanode.kerberos.principal",         "type":"string",  
"subType":"",             "mandatory":false},

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/ranger-util/.gitignore
----------------------------------------------------------------------
diff --git a/ranger-util/.gitignore b/ranger-util/.gitignore
index b83d222..3019b97 100644
--- a/ranger-util/.gitignore
+++ b/ranger-util/.gitignore
@@ -1 +1,3 @@
+/src/gen/org/apache/ranger/common/package-info.java
 /target/
+/bin/

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js 
b/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
index 847cecf..cff762a 100644
--- a/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
+++ b/security-admin/src/main/webapp/scripts/models/BackboneFormDataType.js
@@ -54,7 +54,7 @@ define(function(require) {
                                                                        var 
optionsTitle = _.map(optionsAttrs,function(field){ return field.name;});
                                                                        
formObj['sameLevelOpts'] = optionsTitle;
                                                                        
samelevelFieldCreated.push(v.level);
-                                                                       
+
                                                                        
v.name='sameLevel'+v.level;
                                                                        v.label 
= '';
                                                                }
@@ -63,14 +63,29 @@ define(function(require) {
                                                        }
                                                        break;
                                                case 'bool':
-                                                       formObj.type = 
'Checkbox';
-                                                       formObj.options = {     
y : 'Yes',n : 'No'};
+                                                       
if(!_.isUndefined(v.subType) && !_.isEmpty(v.subType)){
+                                                               formObj.type = 
'Select';
+                                                               var subType = 
v.subType.split(':')
+                                                               formObj.options 
= [subType[0].substr(0, subType[0].length - 4), subType[1].substr(0, 
subType[1].length - 5)];
+                                                               //to set 
default value 
+                                                               
if(form.model.isNew()){
+                                                                       
if(!_.isUndefined(v.defaultValue) && v.defaultValue === "false"){
+                                                                               
form.model.set(v.name, subType[1].substr(0, subType[1].length - 5))
+                                                                       }
+                                                               }
+                                                       }else{
+                                                               formObj.type = 
'Checkbox';
+                                                               formObj.options 
= {     y : 'Yes',n : 'No'};
+                                                       }
                                                        break;
                                                case 'int':formObj.type = 
'Number';break;
                                                case 'enum':
                                                        var enumObj = 
_.find(enums, function(e) {return e && e.name == v.subType;});
                                                        formObj.type = 'Select';
-                                                       formObj.options = 
_.pluck(_.compact(enumObj.elements),'label');
+//                                                     formObj.options = 
_.pluck(_.compact(enumObj.elements),'label');
+                                                       formObj.options = 
_.map((enumObj.elements), function(obj) {
+                                                               return { 
'label' : obj.label, 'val': obj.name};
+                                                       });
                                                        break;
                                                case 'path' : 
                                                        /*formObj.type = 'Text';
@@ -98,10 +113,16 @@ define(function(require) {
 
                                        formObj.title = v.label || v.name;
                                        formObj.validators = [];
-                                       if (_.has(v, 'mandatory') && 
v.mandatory) {
+                                       if (_.has(v, 'mandatory') && 
v.mandatory && v.type != 'bool') {
                                                
formObj.validators.push('required');
                                                formObj.title = formObj.title + 
" *"
                                        }
+                                       if(form.model.isNew()){
+                                               if(_.has(v, 'defaultValue') && 
!_.isEmpty(v.defaultValue) && v.type != 'bool'){
+                                                       form.model.set(v.name, 
v.defaultValue)
+                                               }
+                                       }
+                                       
                                        formObj['class'] = 'serviceConfig';
                                        var name = v.name;
                                        attrs[name] = formObj;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/models/RangerPolicy.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/models/RangerPolicy.js 
b/security-admin/src/main/webapp/scripts/models/RangerPolicy.js
index 70de6f7..a0a0cd8 100644
--- a/security-admin/src/main/webapp/scripts/models/RangerPolicy.js
+++ b/security-admin/src/main/webapp/scripts/models/RangerPolicy.js
@@ -54,6 +54,13 @@ define(function(require){
 
                        // Overwrite your schema definition here
                        return _.extend(attrs,{
+                               id : {
+                                       type            : 'Text',
+                                       title           : 'Policy ID *',
+                                       validators      : ['required'],
+                                       editorAttrs     :{ 'disabled' : "true"},
+
+                               },
                                name : {
                                        type            : 'Text',
                                        title           : 'Policy Name *',

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/modules/XAOverrides.js 
b/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
index 2dd0421..bbacdac 100644
--- a/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
+++ b/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
@@ -360,7 +360,8 @@
                        
                          initialize: function(options) {
                            Form.editors.Base.prototype.initialize.call(this, 
options);
-                           _.extend(this, 
_.pick(this.schema,'excludeSupport','recursiveSupport','select2Opts','resourcesAtSameLevel','sameLevelOpts','level','initilializePathPlugin'));
+                           _.extend(this, 
_.pick(this.schema,'excludeSupport','recursiveSupport','select2Opts','resourcesAtSameLevel','sameLevelOpts','level',
+                                       'initilializePathPlugin', 
'validators','name'));
 
                            this.template = this.getTemplate();
 //                         this.resourceObj = { 'level' : this.level};
@@ -370,13 +371,16 @@
                          },
                          getTemplate : function() {
                                  var optionsHtml="", selectTemplate = 
'',excludeSupportToggleDiv='', recursiveSupportToggleDiv='';
+                                 this.preserveResourceValues = {};
                                    
if(!_.isUndefined(this.resourcesAtSameLevel) && this.resourcesAtSameLevel){
                                        _.each(this.sameLevelOpts, 
function(option){ 
-                                               return optionsHtml += "<option 
value='"+option+"'>"+option+"</option>"
-                                       });
+                                               return optionsHtml += "<option 
value='"+option+"'>"+option+"</option>";
+                                               
+                                       },this);
                                        selectTemplate = '<select 
data-js="resourceType" class="btn dropdown-toggle" style="margin-right: 
18px;margin-left: -116px;width: 100px;height: 29px;font-family: 
Tahoma;font-size: 14px;border-radius: 10px;border: 2px #cccccc solid;">\
                                                '+optionsHtml+'\
                                                </select>';
+                                       
                                    }
                                    if(!_.isUndefined(this.excludeSupport) && 
this.excludeSupport){
                                        excludeSupportToggleDiv = '<div 
class="toggle-xa include-toggle" data-js="include"><div  
class="toggle"></div></div>';
@@ -395,7 +399,8 @@
                           * Adds the editor to the DOM
                           */
                          render: function() {
-                               var that = this;
+                               var that = this, dirtyFieldValue = null;
+                               var XAUtil = require('utils/XAUtils');
                                this.$el.html( this.template );
                                this.$resource = this.$el.find(this.ui.resource)
                            this.$excludeSupport = 
this.$el.find(this.ui.excludeSupport)
@@ -404,22 +409,41 @@
 
                            if(!_.isNull(this.value) && !_.isEmpty(this.value)){
                                this.$resource.val(this.value.values.toString())
+                               
+                               //check dirty field value for resource
+                               this.$resource.on('change', function(e) {
+//                                     
that.checkDirtyFieldForSelect2($(e.currentTarget), that, this.value);
+                               });
+                               //to preserve resources values to text field
+                               if(!_.isUndefined(this.value.resourceType)){
+                                       
this.preserveResourceValues[this.value.resourceType] = 
this.value.values.toString();    
+                               }else{
+                                       this.preserveResourceValues[this.name] 
= this.value.values.toString(); 
+                               }
                            }
                            if(!_.isUndefined(this.select2Opts)){
-                               this.$resource.select2(this.select2Opts);
+                               
this.$resource.select2(this.select2Opts).on('change',function(e){
+                                       console.log(e)
+                                       
that.preserveResourceValues[that.$resourceType.val()] = e.currentTarget.value;
+                                       //check dirty field value for resource
+//                                     dirtyFieldValue = 
XAUtil.checkDirtyFieldForSelect2($(e.currentTarget), dirtyFieldValue, that)
+                                       
that.checkDirtyFieldForSelect2($(e.currentTarget), that, this.value);
+                                       
+                               });
                            }
-                               var isExcludes = true, isRecursive = true;
+                               var isExcludes = false, isRecursive = true;
                                if(this.excludeSupport){
                                        if(!_.isNull(this.value)){
-                                               this.value.isExcludes = 
_.isUndefined(this.value.isExcludes) ? true : this.value.isExcludes;
+                                               this.value.isExcludes = 
_.isUndefined(this.value.isExcludes) ? false : this.value.isExcludes;
                                                isExcludes = 
this.value.isExcludes
                                        }
                                        this.$excludeSupport.toggles({
-                                               on: isExcludes,
+                                               on: !isExcludes,
                                                text : {on : 'include', off : 
'exclude' },
                                                width: 80,
                                        }).on('toggle', function (e, active) {
-                                           that.value.isExcludes = active;
+                                           that.value.isExcludes = !active;
+                                           
XAUtil.checkDirtyFieldForToggle($(e.currentTarget))
                                        });
                                }
                                if(this.recursiveSupport){
@@ -434,6 +458,7 @@
 //                                             height: 20
                                        }).on('toggle', function (e, active) {
                                            that.value.isRecursive = active;
+                                           
XAUtil.checkDirtyFieldForToggle($(e.currentTarget))
                                        });
                                }
                                if(!_.isUndefined(this.$resourceType) && 
this.$resourceType.length > 0){
@@ -442,7 +467,11 @@
                                        }
                                        this.$resourceType.on('change', 
function(e) {
                                                
if(!_.isUndefined(that.select2Opts)){
-                                                       
that.$resource.select2('val', '')
+                                                       
if(!_.isUndefined(that.preserveResourceValues[e.currentTarget.value])){
+                                                               
that.$resource.select2('val', 
that.preserveResourceValues[e.currentTarget.value].split(','))
+                                                       }else{
+                                                               
that.$resource.select2('val', '')
+                                                       }
                                                  }else{
                                                          
that.$resource.val('');
                                                  }
@@ -451,6 +480,7 @@
                                                that.value.isRecursive = true;
                                                
that.$excludeSupport.trigger('toggleOn');
                                                
that.$recursiveSupport.trigger('toggleOn');
+                                               
($(e.currentTarget).addClass('dirtyField'))
                                        });
                                }
                            return this;
@@ -461,7 +491,12 @@
                                  if(!_.isUndefined(this.$resourceType) && 
this.$resourceType.length > 0){
                                          this.value['resourceType'] = 
this.$resourceType.val();  
                                  }
-                                 this.value['resource'] = 
this.$resource.val(); 
+                                 this.value['resource'] = this.$resource.val();
+                                 //for validation
+                                 if(!_.isUndefined(this.validators) && 
($.inArray('required',this.validators) != -1)){
+                                         if(_.isEmpty(this.value.resource))
+                                                 return null;
+                                 }
                                  return this.value;
                                  //return this.$el.find('.active').text() == 
"ON" ? true : false;
                          },
@@ -469,6 +504,37 @@
                          setValue: function(val) {
                                  return true;
                          },
+                         checkDirtyFieldForSelect2 : function($el,that,value) {
+                                 var defaultResourceValue = 
_.isUndefined(that.value.values) ? [] : that.value.values;  
+//                             that.value.values = this.value;
+                               
+                               if($el.hasClass('dirtyField')){
+                                       var tmpValue={};
+                                       if(_.isEmpty(value)){
+                                               tmpValue.values = []
+                                       }else{
+                                               tmpValue.values = 
value.split(',');
+                                       }       
+                                       tmpValue.isExcludes = 
that.value.isExcludes;
+                                       tmpValue.isRecursive = 
that.value.isRecursive;
+                                       if(_.isEqual(tmpValue, 
dirtyFieldValue)){
+                                               $el.removeClass('dirtyField');
+                                       }
+                                       
+                               }else if(!$el.hasClass('dirtyField')){
+                                       $el.addClass('dirtyField');
+                                       if(!_.isNull(that.value)){
+                                               that.value.values = 
defaultResourceValue;
+                                               
if(_.isUndefined(that.value.isExcludes)){
+                                                       that.value.isExcludes = 
that.excludeSupport ? true : false;
+                                               }
+                                               
if(_.isUndefined(that.value.isRecursive)){
+                                                       that.value.isRecursive 
= that.RecursiveSupport ? true : false;
+                                               }
+                                       }
+                                       dirtyFieldValue =  that.value
+                               }
+                         }
                        
                        });
          

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/utils/XAUtils.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/utils/XAUtils.js 
b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
index 2acef28..b2514f3 100644
--- a/security-admin/src/main/webapp/scripts/utils/XAUtils.js
+++ b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
@@ -462,13 +462,22 @@ define(function(require) {
                                $elem.addClass('dirtyField');
                        }
        };
-       XAUtils.checkDirtyFieldForToggle = function(fieldEditor){
-               if(fieldEditor.$el.hasClass('dirtyField')){
-                       fieldEditor.$el.removeClass('dirtyField');
+       XAUtils.checkDirtyFieldForToggle = function($el){
+               if($el.hasClass('dirtyField')){
+                       $el.removeClass('dirtyField');
                }else{
-                       fieldEditor.$el.addClass('dirtyField');
+                       $el.addClass('dirtyField');
                }
        };
+       XAUtils.checkDirtyFieldForSelect2 = function($el, dirtyFieldValue, 
that){
+               if($el.hasClass('dirtyField') && _.isEqual($el.val(), 
dirtyFieldValue.toString())){
+                       $el.removeClass('dirtyField');
+               }else if(!$el.hasClass('dirtyField')){
+                       $el.addClass('dirtyField');
+                       dirtyFieldValue =  !_.isUndefined(that.value.values) ? 
that.value.values : '';
+               }
+               return dirtyFieldValue;
+       };
        XAUtils.enumToSelectLabelValuePairs = function(myEnum) {
                return _.map(myEnum, function(o){
                        return {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js 
b/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
index a1f95c5..7cf66a9 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/PermissionList.js
@@ -98,7 +98,7 @@ define(function(require) {
                                
                                
if(!_.isUndefined(this.model.get('conditions'))){
                                        _.each(this.model.get('conditions'), 
function(obj){
-                                               
this.$el.find('input[data-js="'+obj.type+'"]').val(obj.value.toString())
+                                               
this.$el.find('input[data-js="'+obj.type+'"]').val(obj.values.toString())
                                        },this);
                                }
                                _.each(this.model.get('accesses'), function(p){
@@ -127,7 +127,7 @@ define(function(require) {
                                }, this);
                                //Set PolicyCondtion Obj to show in edit mode
                                _.each(this.model.get('conditions'), 
function(p){
-                                       this.conditions[p.type] = p.value;
+                                       this.conditions[p.type] = p.values;
                                }, this);
                        }
                },
@@ -247,6 +247,8 @@ define(function(require) {
                                                values = _.without(values,"-1")
                                        }
 //                             that.checkDirtyFieldForGroup(values);
+                                       
+                                       
                                        var permTypeArr = [];
                                        var valArr = _.map(values, function(id){
                                                if(!_.isUndefined(id)){
@@ -331,7 +333,9 @@ define(function(require) {
                                                                i++;
                                                                return 
_.isEmpty(val) ? '' : '<span class="'+label+'">'+name+' : '+ val + '</span>';   
 
                                                        });
-                                                       var cond = _.map(value, 
function(val, name) {return {'type' : name, 'value' :val};});
+                                                       var cond = _.map(value, 
function(val, name) {
+                                                               return {'type' 
: name, 'values' : !_.isArray(val) ?  val.split(',') : val};
+                                                       });
                                                        
that.model.set('conditions', cond);
                                                        $(this).html(html);
                                                        
that.ui.addConditionsSpan.find('i').attr('class', 'icon-pencil');
@@ -372,6 +376,7 @@ define(function(require) {
                },
                evClickTD : function(e){
                        var $el = $(e.currentTarget);
+                       XAUtil.checkDirtyFieldForToggle($el);
                        //Set Delegated Admin value 
                        if(!_.isUndefined($el.find('input').data('js'))){
                                
this.model.set('delegateAdmin',$el.find('input').is(':checked'))

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js 
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
index 7c40ade..eacf119 100644
--- 
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
+++ 
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
@@ -117,7 +117,10 @@ define(function(require){
 
                /** on render callback */
                onRender: function() {
+                       XAUtil.showAlerForDisabledPolicy(this);
                        this.rForm.show(this.form);
+                       this.rForm.$el.dirtyFields();
+                       
XAUtil.preventNavigation(localization.tt('dialogMsg.preventNavPolicyForm'),this.rForm.$el);
                },
                onSave: function(){
                        var that = this, valid = false;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js 
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
index d4e1a83..d077ca1 100644
--- a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
+++ b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyForm.js
@@ -70,12 +70,9 @@ define(function(require){
                        this.on('isAuditEnabled:change', function(form, 
fieldEditor){
                        this.evAuditChange(form, fieldEditor);
                });
-                       this.on('isRecursive:change', function(form, 
fieldEditor){
-                       this.evRecursiveChange(form, fieldEditor);
-               });
-                       this.on('resourceStatus:change', function(form, 
fieldEditor){
-                       this.evResourceStatusChange(form, fieldEditor);
-               });
+                       this.on('isEnabled:change', function(form, fieldEditor){
+                               this.evIsEnabledChange(form, fieldEditor);
+                       });
                },
 
                /** fields for the form
@@ -86,12 +83,16 @@ define(function(require){
                },
                getSchema : function(){
                        var attrs = {};
+                       var basicSchema = ['id', 'name','isEnabled']
                        var schemaNames = ['description', 'isAuditEnabled'];
+                       if(this.model.isNew()){
+                               basicSchema.shift();
+                       }
                        
                        var formDataType = new BackboneFormDataType();
                        attrs = 
formDataType.getFormElements(this.rangerServiceDefModel.get('resources'),this.rangerServiceDefModel.get('enums'),
 attrs, this);
                        
-                       var attr1 = _.pick(_.result(this.model,'schemaBase'), 
'name','isEnabled');
+                       var attr1 = 
_.pick(_.result(this.model,'schemaBase'),basicSchema);
                        var attr2 = 
_.pick(_.result(this.model,'schemaBase'),schemaNames);
                        return _.extend(attr1,_.extend(attrs,attr2));
                },
@@ -111,13 +112,10 @@ define(function(require){
                        
this.$el.find('.field-isEnabled').find('.control-label').remove();
                },
                evAuditChange : function(form, fieldEditor){
-                       XAUtil.checkDirtyFieldForToggle(fieldEditor);
+                       XAUtil.checkDirtyFieldForToggle(fieldEditor.$el);
                },
-               evRecursiveChange : function(form, fieldEditor){
-                       XAUtil.checkDirtyFieldForToggle(fieldEditor);
-               },
-               evResourceStatusChange : function(form, fieldEditor){
-                       XAUtil.checkDirtyFieldForToggle(fieldEditor);
+               evIsEnabledChange : function(form, fieldEditor){
+                       XAUtil.checkDirtyFieldForToggle(fieldEditor.$el);
                },
                setupForm : function() {
                        if(!this.model.isNew()){
@@ -248,7 +246,10 @@ define(function(require){
                },
                /** all post render plugin initialization */
                initializePathPlugins: function(){
-                       var that= this; 
+                       var that= this,defaultValue = [];
+                       if(!this.model.isNew() && 
_.isUndefined(this.model.get('path'))){
+                               defaultValue = this.model.get('path').values;
+                       }
                        function split( val ) {
                                return val.split( /,\s*/ );
                        }
@@ -288,8 +289,8 @@ define(function(require){
                                                        dataType : 'json',
                                                        contentType: 
"application/json; charset=utf-8",
                                                }).done(function(data){
-                                                       if(data.vXStrings){
-                                                               
response(data.vXStrings);
+                                                       if(data){
+                                                               response(data);
                                                        } else {
                                                                response();
                                                        }
@@ -350,6 +351,9 @@ define(function(require){
                                        return false;
                                }
                                        }
+                       }).on('change',function(e){
+                               //check dirty field for tagit input type : 
`path`
+                               
XAUtil.checkDirtyField($(e.currentTarget).val(), defaultValue.toString(), 
$(e.currentTarget))
                        });
        
                        
@@ -407,11 +411,14 @@ define(function(require){
                                                },
                                                results: function (data, page) 
{ 
                                                        var results = [];
-                                                       
if(!_.isUndefined(data)){
+                                                       if(data.length > 0){
+                                                               results = 
data.map(function(m, i){      return {id : m, text: m};       });
+                                                       }
+                                                       
/*if(!_.isUndefined(data)){
                                                                
if(data.resultSize != "0"){
                                                                        results 
= data.vXStrings.map(function(m, i){    return {id : m.value, text: m.value};   
});
                                                                }
-                                                       }
+                                                       }*/
                                                        return { 
                                                                results : 
results
                                                        };

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js 
b/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
index e8496db..ac3ab7d 100644
--- a/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
+++ b/security-admin/src/main/webapp/scripts/views/reports/AuditLayout.js
@@ -736,7 +736,7 @@ define(function(require) {
                                                formatter: _.extend({}, 
Backgrid.CellFormatter.prototype, {
                                                        fromRaw: function 
(rawValue, model) {
                                                                if(rawValue == 
-1){
-                                                                       return 
rawValue;
+                                                                       return 
'--';
                                                                }       
                                                                var 
rangerService = new RangerService();
                                                                
rangerService.urlRoot += '/name/'+model.get('repoName'); 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js 
b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
index 413f125..4347479 100644
--- a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
@@ -88,11 +88,6 @@ define(function(require){
                        /*if(! this.model.isNew()){
                                this.setupModel();
                        }*/
-                       if(!this.model.isNew()){
-                               
_.each(this.model.attributes.configs,function(name, value){
-                                       this.model.set(value,name)
-                               },this);
-                       }
                        this.form = new ServiceForm({
                                model : this.model,
                                rangerServiceDefModel : 
this.rangerServiceDefModel,

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js 
b/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
index fc3ddae..b4a255a 100644
--- a/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
+++ b/security-admin/src/main/webapp/scripts/views/service/ServiceForm.js
@@ -23,6 +23,8 @@ define(function(require){
 
        var Backbone            = require('backbone');
        var XAEnums                     = require('utils/XAEnums');
+       var XAUtil                      = require('utils/XAUtils');
+       
        var localization        = require('utils/XALangSupport');
        var BackboneFormDataType        = 
require('models/BackboneFormDataType');
 
@@ -56,6 +58,7 @@ define(function(require){
                initialize: function(options) {
                        console.log("initialized a ServiceForm Form View");
                        _.extend(this, _.pick(options, 
'rangerServiceDefModel'));
+                       this.setupFormForEditMode();
                Backbone.Form.prototype.initialize.call(this, options);
 
                        this.bindEvents();
@@ -63,6 +66,9 @@ define(function(require){
 
                /** all events binding here */
                bindEvents : function(){
+                       this.on('isEnabled:change', function(form, fieldEditor){
+                               this.evIsEnabledChange(form, fieldEditor);
+                       });
                },
 
                /** schema for the form
@@ -90,6 +96,18 @@ define(function(require){
                        this.initializePlugins();
                        this.renderCustomFields();
                },
+               setupFormForEditMode : function() {
+                       if(!this.model.isNew()){
+                               
_.each(this.model.get('configs'),function(value, name){
+                                       var configObj = 
_.findWhere(this.rangerServiceDefModel.get('configs'),{'name' : name });
+                                       if(configObj.type == 'bool'){
+                                               this.model.set(name, 
this.getStringFromBoolean(configObj, value))
+                                       }else{
+                                               this.model.set(name, value)
+                                       }
+                               },this);
+                       }
+               },
                setupForm : function() {
                        if(this.model.isNew()){
                                
this.fields.isEnabled.editor.setValue(XAEnums.ActiveStatus.STATUS_ENABLED.value);
@@ -102,6 +120,9 @@ define(function(require){
                                }
                        }       
                },
+               evIsEnabledChange : function(form, fieldEditor){
+                       XAUtil.checkDirtyFieldForToggle(fieldEditor.$el);
+               },
                /** all custom field rendering */
                renderCustomFields: function(){
                },
@@ -121,7 +142,11 @@ define(function(require){
                        var config = {};
                        
_.each(this.rangerServiceDefModel.get('configs'),function(obj){
                                if(!_.isNull(obj)){
-                                       config[obj.name] = 
that.model.get(obj.name).toString();
+                                       if(obj.type == 'bool'){
+                                               config[obj.name] = 
that.getBooleanForConfig(obj, that.model);
+                                       }else{
+                                               config[obj.name] = 
that.model.get(obj.name).toString();
+                                       }
                                        that.model.unset(obj.name);
                                }
                        });
@@ -147,7 +172,23 @@ define(function(require){
                        var index = $.inArray(elem,arr);
                        if(index >= 0) arr.splice(index,1);
                        return arr;
-               }
+               },
+               getBooleanForConfig : function(cofigObj, model) {
+                       var subType = cofigObj.subType.split(':');
+                       if(subType[0].indexOf(model.get(cofigObj.name)) >= 0 ){
+                               return true;
+                       }else{
+                               return false;
+                       }
+               },
+               getStringFromBoolean : function(configObj, value) {
+                       var subType = configObj.subType.split(':');
+                       if(subType[0].toLowerCase().indexOf(value) >= 0 ){
+                               return subType[0].substr(0, subType[0].length - 
4);
+                       }else{
+                               return subType[1].substr(0, subType[0].length - 
5);
+                       }
+               },
        });
 
        return ServiceForm;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/63952722/security-admin/src/main/webapp/styles/xa.css
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/styles/xa.css 
b/security-admin/src/main/webapp/styles/xa.css
index 18110c2..468155e 100644
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@ -1736,4 +1736,8 @@ margin-bottom: 5px;
 .recursive-toggle-path {
 margin-left: 347px;
 margin-top: -29px;
+}
+.policy-form .help-inline {
+       position: relative;
+       top: 10px;
 }
\ No newline at end of file

Reply via email to