/*************************************************
 * Copyright (c) 2015 Ansible, Inc.
 *
 * All Rights Reserved
 *************************************************/

export default
    angular.module('rbacUiControl', [])
        .service('rbacUiControlService', ['$q', 'GetBasePath', 'Rest', 'Wait', function($q, GetBasePath, Rest, Wait){
            this.canAdd = function(apiPath) {
                var canAddVal = $q.defer();

                if (apiPath.indexOf("api/v1") > -1) {
                    Rest.setUrl(apiPath);
                } else {
                    Rest.setUrl(GetBasePath(apiPath));
                }

                Wait("start");
                Rest.options()
                    .success(function(data) {
                        if (data.actions.POST) {
                            canAddVal.resolve(true);
                        } else {
                            canAddVal.reject(false);
                        }
                        Wait("stop");
                    });

                return canAddVal.promise;
            };
        }]);

/*************************************************
 * Copyright (c) 2015 Ansible, Inc.
 *
 * All Rights Reserved
 *************************************************/

export default
    angular.module('rbacUiControl', [])
        .service('rbacUiControlService', ['$q', 'GetBasePath', 'Rest', 'Wait', function($q, GetBasePath, Rest, Wait){
            this.canAdd = function(apiPath) {
                var canAddVal = $q.defer();

                if (/api\/v[0-9]+\//.test(apiPath)) {
                    Rest.setUrl(apiPath);
                } else {
                    Rest.setUrl(GetBasePath(apiPath));
                }

                Wait("start");
                Rest.options()
                    .success(function(data) {
                        if (data.actions.POST) {
                            canAddVal.resolve(true);
                        } else {
                            canAddVal.reject(false);
                        }
                        Wait("stop");
                    });

                return canAddVal.promise;
            };
        }]);

Fix issue preventing inventory groups from loading
Fix issue preventing inventory groups from loading

A conditional was in place to check if a URL included the base path,
if so, it was supposed to use the URL as-is, otherwise it should get
the URL by referencing a property in an object containing default
URLs.

The conditional checked only for 'api/v1'. Since we're at v2, the
check failed eventually resulting in a `replace` call on an
undefined value.  I replaced the conditional to pattern match
api/v*/ instead.
