(function() {
    'use strict'; // NOSONAR

    angular.module('ClubController').controller('clubController', ClubController);

    function ClubController(clubService, alertService, $translate, $log) {
        var vm = this;
        vm.alert = alertService.getAlert();
        vm.club = {};

        clubService.getClubs().then(function(clubs) {
            vm.clubs = clubs;

        }, function() {
            alertService.setAlert($translate.instant('FAILED_FETCH'));
        });

        vm.closeAlert = function() {
            alertService.clearAlert();
        };

        vm.addClub = function(club) {
            clubService.addClub(club).then(function() {
                vm.club = {};
                vm.addClubForm.$setPristine();
                vm.addClubForm.$setUntouched();

            }, function(errResponse) {
                $log.warn("Failed to create event", errResponse);
                alertService.setAlert($translate.instant('FAILED_ADD'));
            });
        };

        vm.removeClub = function(club) {
            clubService.removeClub(club).then(function() {}, function() {
              alertService.setAlert($translate.instant('FAILED_REMOVE'));
            });
        };

        vm.updateClub = function(club) {
            clubService.updateClub(club).then(function() {}, function() {
              alertService.setAlert($translate.instant('FAILED_UPDATE'));
            });
        };

        vm.validClubName = function(club) {
            if (typeof club === 'undefined' || typeof club.club === 'undefined') {
                return false;
            }

            if (club.club.length < 3 || club.club.length > 254) {
                return false;
            }

            for (var i=0; i < vm.clubs.length; i++) {
                var existing = vm.clubs[i];
                if (existing.id !== club.id && existing.club === club.club) {
                    return false;
                }
            }
            return true;
        };
    };

})();
@@ -1439,163 +1439,145 @@
     
-vm.validClubName = function(club) %7B%0A            if (typeof club === 'undefined' %7C%7C typeof club.club === 'undefined') %7B%0A                return false
+function isClubNameInUse(club) %7B%0A            for (var i=0; i %3C vm.clubs.length; i++) %7B%0A                var existing = vm.clubs%5Bi%5D
 ;%0A      
     
@@ -1568,33 +1568,24 @@
 s%5Bi%5D;%0A      
-      %7D%0A%0A
             
@@ -1586,68 +1586,135 @@
     
-  
 if (
-club.club.length %3C 3 %7C%7C club.club.length %3E 254) %7B%0A    
+existing.id !== club.id && existing.club === club.club) %7B%0A                    return true;%0A                %7D%0A            %7D%0A
     
@@ -1747,195 +1747,249 @@
     
+%7D%0A%0A
     
-%7D%0A%0A            for (var i=0; i %3C vm.clubs.length; i++) %7B%0A                var existing = vm.clubs%5Bi%5D;%0A                if (existing.id !== club.id && existing.club === club.club) %7B%0A    
+    vm.validClubName = function(club) %7B%0A            if (typeof club === 'undefined' %7C%7C typeof club.club === 'undefined') %7B%0A                return false;%0A            %7D%0A%0A            if (club.club.length %3C 3 %7C%7C club.club.length %3E 254) %7B%0A
     
@@ -2026,35 +2026,18 @@
         
-    %7D%0A            
 %7D
+%0A
 %0A       
@@ -2040,36 +2040,54 @@
          return 
-true
+!isClubNameInUse(club)
 ;%0A        %7D;%0A   

Reduce the complexity of club name validation