{"size": 1946, "ext": "js", "max_stars_repo_path": "src/javascript/rules/_ts-validation-rule-initiative-no-theme.js", "max_stars_repo_name": "CustomAgile/revamped-validation-app", "max_stars_repo_stars_event_min_datetime": "2021-03-22T21:45:21.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T21:45:21.000Z", "max_issues_repo_path": "src/javascript/rules/_ts-validation-rule-initiative-no-theme.js", "max_issues_repo_name": "CustomAgile/revamped-validation-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/javascript/rules/_ts-validation-rule-initiative-no-theme.js", "max_forks_repo_name": "CustomAgile/revamped-validation-app", "max_forks_repo_forks_event_min_datetime": "2016-08-18T18:36:17.000Z", "max_forks_repo_forks_event_max_datetime": "2016-12-02T01:11:50.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 30.8888888889, "max_line_length": 117, "alphanum_fraction": 0.5524152107}
Ext.define('CA.techservices.validation.InitiativeNoThemeRule',{
    extend: 'CA.techservices.validation.BaseRule',
    alias:  'widget.tsinitiativenothemerule',
    
   
    config: {
        /*
        ** projectPortfolioRoot set in base class and on constructor
        */
        projectPortfolioRoot: null,
        /*
        * [{Rally.wsapi.data.Model}] portfolioItemTypes the list of PIs available
        * we're going to use the first level ones (different workspaces name their portfolio item levels differently)
        */
        portfolioItemTypes:[],
        //model: 'PortfolioItem/Initiative',
        label: 'Initiative needs Parent' 
    },
    getModel:function(){
        return this.portfolioItemTypes[1];  // 0-feature,1-initiative, etc..
    },
    getDescription: function() {
        var msg = Ext.String.format(
            "{0} must be linked to a {1}",
            /[^\/]*$/.exec(this.getModel()),
            this.portfolioItemTypes[2]
        );
        return msg;
    },
    
    getFetchFields: function() {
        return ['Name','Parent'];
    },
    getLabel: function(){
        this.label = Ext.String.format(
            "{0} without {1}",
            /[^\/]*$/.exec(this.getModel()), //regex retrieves string after 'PortfolioItem/'
            /[^\/]*$/.exec(this.portfolioItemTypes[2])
            );
        return this.label;
    },
    isValidField: function(model, field_name) {
        var field_defn = model.getField(field_name);
        return ( !Ext.isEmpty(field_defn) );
    },
    
    applyRuleToRecord: function(record) {

        if ( Ext.isEmpty(record.get('Parent') ) ) {
            return this.getDescription();   
        } else {
            return null; // no rule violation
        }
    },
    
    getFilters: function() {        

        // return Rally.data.wsapi.Filter.and([
        //     {property:'Parent',operator:'=',value:null}
        // ]);
        return [];
    }
});