(function(angular) {
    "use strict";

    var app = angular.module('FindOneService', []);
    app.factory('FindOneService', ['$http', '$rootScope', function($http, $rootScope){
        return function(data){

            if(data.global.viewMode === 'list') return;
            var select = 'id,singleUrl,name,type,shortDescription,terms',
                requestAction = 'findOne',
                page=null,
                result = {},
                sData = {},
                entity,
                numRequests = 1;

            $rootScope.spinnerCount++;

            entity = data.global.openEntity.type;
            sData.id = 'EQ(' + data.global.openEntity.id + ')';



            if(entity === 'event'){
                result[entity] = {
                    space: {},
                    events: {}
                };

                $rootScope.spinnerCount++;
                numRequests++;

                select += ',endereco';
                apiFindOne('space', select, sData, page, requestAction).success(function(rs){
                    result[entity].space = rs;
                    endRequest();
                });
                apiSpaceEvents(data.global.openEntity.id, $rootScope.searchArgs.map.event).success(function(rs){
                    result[entity].events = rs;
                    endRequest();
                });;
            }else{
                apiFindOne(entity, select, sData, page, requestAction).success(function(rs){
                    result[entity] = rs;
                    endRequest();
                });
            }

            function endRequest(){
                numRequests--;
                $rootScope.spinnerCount--;
                if(numRequests === 0){
                    $rootScope.$emit('findOneResultReady', result);
                }
            }

            function apiFindOne(entity, select, searchData, page, action) {
                action = action || 'find';
                if(entity === 'space')
                    select += ',endereco,acessibilidade';
                searchData['@select'] = select;
                searchData['@files'] = '(avatar.avatarBig):url';
                var querystring = "";
                for(var att in searchData) {
                    querystring += "&"+att+"="+searchData[att];
                }
                return $http({method: 'GET', url: MapasCulturais.baseURL + 'api/' + entity + '/' + action + '/?'+querystring, data:searchData});
            }

            function apiSpaceEvents(spaceId, searchData) {
                var action = 'findBySpace';
                searchData['spaceId'] = spaceId;
                searchData['@select'] = select + ',classificacaoEtaria';
                searchData['@files'] = '(avatar.avatarBig):url';
                var querystring = "";
                for(var att in searchData) {
                    querystring += "&"+att+"="+searchData[att];
                }
                return $http({method: 'GET', url: MapasCulturais.baseURL + 'api/' + entity + '/' + action + '/?'+querystring, data:searchData});
            }
        };
    }]);
})(angular);





@@ -829,16 +829,68 @@
     %7D;%0A%0A
+                if (data.global.enabled.event)%7B%0A    
         
@@ -932,32 +932,36 @@
                 
+  
+  
 numRequests++;%0A%0A
@@ -956,24 +956,28 @@
 equests++;%0A%0A
+    
             
@@ -1003,16 +1003,20 @@
 ereco';%0A
+    
         
@@ -1113,32 +1113,36 @@
                 
+    
 result%5Bentity%5D.s
@@ -1148,24 +1148,28 @@
 space = rs;%0A
+    
             
@@ -1198,36 +1198,44 @@
                 
-%7D);%0A
+    %7D);%0A    
                 
@@ -1343,32 +1343,36 @@
                 
+    
 result%5Bentity%5D.e
@@ -1379,24 +1379,110 @@
 vents = rs;%0A
+                        endRequest();%0A                    %7D);;%0A                %7Delse%7B%0A
             
@@ -1512,35 +1512,32 @@
                %7D
-);;
 %0A            %7Del

Fix findOneService event request error if not event entity enabled