Sha256: 05aca80039d102afe1f2e81df663199da8685702a19cca9a2d9acee6fa0dedb0

Contents?: true

Size: 1.1 KB

Versions: 179

Compression:

Stored size: 1.1 KB

Contents

/**
 * @ngdoc service
 * @name Bastion.service.directive:FormUtils
 *
 * @requires uuid4
 *
 * @description
 *   A set of utilities that are useful when using forms.
 */
angular.module('Bastion.utils').service('FormUtils', ['uuid4', function (uuid4) {
    var regex = new RegExp("[^a-z0-9\\-_]+", 'gi'),
        replacement = "_",
        isASCII;

    /**
     * @ngdoc function
     * @name Bastion.service.FormUtils#labelize
     * @methodOf Bastion.service.FormUtils
     * @function
     *
     * @description
     *   Turns a resource's name attribute into a labelized value.
     *
     * @param {Resource} resource An object representing a resource entity with a name property
     * @returns {Bastion.service.FormUtils} Self for chaining.
     */
    this.labelize = function (resource) {
        if (resource.name) {
            resource.label = (isASCII(resource.name) && resource.name.length <= 128) ?
                resource.name.replace(regex, replacement) : uuid4.generate();
        }

        return this;
    };

    isASCII = function isASCII(str) {
        return (/^[\x00-\x7F]*$/).test(str);
    };

}]);

Version data entries

179 entries across 179 versions & 2 rubygems

Version Path
katello-4.14.2 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.15.0 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.15.0.rc2 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.15.0.rc1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.14.1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.14.0 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.14.0.rc3 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.14.0.rc2 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.14.0.rc1.1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.14.0.rc1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.13.1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.13.0 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.12.1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.13.0.rc1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.12.0 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.12.0.rc3 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.12.0.rc2 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.12.0.rc1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.11.1 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js
katello-4.11.0 engines/bastion/app/assets/javascripts/bastion/utils/form-utils.service.js